refactor(ui): clean code

This commit is contained in:
Fu Diwei
2024-12-09 17:48:44 +08:00
parent 588e89e8fe
commit 07a443f6c4
19 changed files with 57 additions and 88 deletions

View File

@@ -4,7 +4,7 @@ import { CopyToClipboard } from "react-copy-to-clipboard";
import { Clipboard as ClipboardIcon } from "lucide-react";
import { type Certificate } from "@/domain/certificate";
import { saveFiles2Zip } from "@/lib/file";
import { saveFiles2Zip } from "@/utils/file";
type CertificateDetailProps = {
data: Certificate;

View File

@@ -8,7 +8,7 @@ import { ClientResponseError } from "pocketbase";
import { Button } from "@/components/ui/button";
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { readFileContent } from "@/lib/file";
import { readFileContent } from "@/utils/file";
import { PbErrorData } from "@/domain/base";
import { accessProvidersMap, accessTypeFormSchema, type Access, type KubernetesConfig } from "@/domain/access";
import { save } from "@/repository/access";

View File

@@ -8,7 +8,7 @@ import { ClientResponseError } from "pocketbase";
import { Button } from "@/components/ui/button";
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { readFileContent } from "@/lib/file";
import { readFileContent } from "@/utils/file";
import { PbErrorData } from "@/domain/base";
import { accessProvidersMap, accessTypeFormSchema, type Access, type SSHConfig } from "@/domain/access";
import { save } from "@/repository/access";

View File

@@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { getErrMsg } from "@/utils/error";
import { NotifyChannels, NotifyChannelBark } from "@/domain/settings";
import { update } from "@/repository/settings";
import { useNotifyContext } from "@/providers/notify";
@@ -113,7 +113,7 @@ const Bark = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -137,7 +137,7 @@ const Bark = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -173,7 +173,7 @@ const Bark = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { getErrMsg } from "@/utils/error";
import { NotifyChannelDingTalk, NotifyChannels } from "@/domain/settings";
import { useNotifyContext } from "@/providers/notify";
import { update } from "@/repository/settings";
@@ -113,7 +113,7 @@ const DingTalk = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -139,7 +139,7 @@ const DingTalk = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -173,7 +173,7 @@ const DingTalk = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { getErrMsg } from "@/utils/error";
import { NotifyChannelEmail, NotifyChannels } from "@/domain/settings";
import { useNotifyContext } from "@/providers/notify";
import { update } from "@/repository/settings";
@@ -136,7 +136,7 @@ const Mail = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -160,7 +160,7 @@ const Mail = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -196,7 +196,7 @@ const Mail = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,7 +6,7 @@ import { useNotifyContext } from "@/providers/notify";
import { NotifyChannelLark, NotifyChannels } from "@/domain/settings";
import { useEffect, useState } from "react";
import { update } from "@/repository/settings";
import { getErrMessage } from "@/lib/error";
import { getErrMsg } from "@/utils/error";
import { useToast } from "@/components/ui/use-toast";
import { useTranslation } from "react-i18next";
import { notifyTest } from "@/api/notify";
@@ -109,7 +109,7 @@ const Lark = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -135,7 +135,7 @@ const Lark = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -169,7 +169,7 @@ const Lark = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,8 +6,8 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { isValidURL } from "@/lib/url";
import { getErrMsg } from "@/utils/error";
import { isValidURL } from "@/utils/url";
import { NotifyChannels, NotifyChannelServerChan } from "@/domain/settings";
import { update } from "@/repository/settings";
import { useNotifyContext } from "@/providers/notify";
@@ -120,7 +120,7 @@ const ServerChan = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -144,7 +144,7 @@ const ServerChan = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -180,7 +180,7 @@ const ServerChan = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { getErrMsg } from "@/utils/error";
import { NotifyChannels, NotifyChannelTelegram } from "@/domain/settings";
import { update } from "@/repository/settings";
import { useNotifyContext } from "@/providers/notify";
@@ -113,7 +113,7 @@ const Telegram = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -137,7 +137,7 @@ const Telegram = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -173,7 +173,7 @@ const Telegram = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),

View File

@@ -6,8 +6,8 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { getErrMessage } from "@/lib/error";
import { isValidURL } from "@/lib/url";
import { getErrMsg } from "@/utils/error";
import { isValidURL } from "@/utils/url";
import { NotifyChannels, NotifyChannelWebhook } from "@/domain/settings";
import { update } from "@/repository/settings";
import { useNotifyContext } from "@/providers/notify";
@@ -120,7 +120,7 @@ const Webhook = () => {
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),
@@ -144,7 +144,7 @@ const Webhook = () => {
description: t("settings.notification.push_test_message.succeeded.message"),
});
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("settings.notification.push_test_message.failed.message"),
@@ -180,7 +180,7 @@ const Webhook = () => {
setChannels(resp);
} catch (e) {
const msg = getErrMessage(e);
const msg = getErrMsg(e);
toast({
title: t("common.save.failed.message"),