mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 22:19:51 +00:00
refactor(ui): clean code
This commit is contained in:
parent
588e89e8fe
commit
07a443f6c4
@ -4,7 +4,7 @@ import { CopyToClipboard } from "react-copy-to-clipboard";
|
|||||||
import { Clipboard as ClipboardIcon } from "lucide-react";
|
import { Clipboard as ClipboardIcon } from "lucide-react";
|
||||||
|
|
||||||
import { type Certificate } from "@/domain/certificate";
|
import { type Certificate } from "@/domain/certificate";
|
||||||
import { saveFiles2Zip } from "@/lib/file";
|
import { saveFiles2Zip } from "@/utils/file";
|
||||||
|
|
||||||
type CertificateDetailProps = {
|
type CertificateDetailProps = {
|
||||||
data: Certificate;
|
data: Certificate;
|
||||||
|
@ -8,7 +8,7 @@ import { ClientResponseError } from "pocketbase";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { readFileContent } from "@/lib/file";
|
import { readFileContent } from "@/utils/file";
|
||||||
import { PbErrorData } from "@/domain/base";
|
import { PbErrorData } from "@/domain/base";
|
||||||
import { accessProvidersMap, accessTypeFormSchema, type Access, type KubernetesConfig } from "@/domain/access";
|
import { accessProvidersMap, accessTypeFormSchema, type Access, type KubernetesConfig } from "@/domain/access";
|
||||||
import { save } from "@/repository/access";
|
import { save } from "@/repository/access";
|
||||||
|
@ -8,7 +8,7 @@ import { ClientResponseError } from "pocketbase";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { readFileContent } from "@/lib/file";
|
import { readFileContent } from "@/utils/file";
|
||||||
import { PbErrorData } from "@/domain/base";
|
import { PbErrorData } from "@/domain/base";
|
||||||
import { accessProvidersMap, accessTypeFormSchema, type Access, type SSHConfig } from "@/domain/access";
|
import { accessProvidersMap, accessTypeFormSchema, type Access, type SSHConfig } from "@/domain/access";
|
||||||
import { save } from "@/repository/access";
|
import { save } from "@/repository/access";
|
||||||
|
@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { NotifyChannels, NotifyChannelBark } from "@/domain/settings";
|
import { NotifyChannels, NotifyChannelBark } from "@/domain/settings";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
@ -113,7 +113,7 @@ const Bark = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -137,7 +137,7 @@ const Bark = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -173,7 +173,7 @@ const Bark = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { NotifyChannelDingTalk, NotifyChannels } from "@/domain/settings";
|
import { NotifyChannelDingTalk, NotifyChannels } from "@/domain/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
@ -113,7 +113,7 @@ const DingTalk = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -139,7 +139,7 @@ const DingTalk = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -173,7 +173,7 @@ const DingTalk = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { NotifyChannelEmail, NotifyChannels } from "@/domain/settings";
|
import { NotifyChannelEmail, NotifyChannels } from "@/domain/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
@ -136,7 +136,7 @@ const Mail = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -160,7 +160,7 @@ const Mail = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -196,7 +196,7 @@ const Mail = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,7 +6,7 @@ import { useNotifyContext } from "@/providers/notify";
|
|||||||
import { NotifyChannelLark, NotifyChannels } from "@/domain/settings";
|
import { NotifyChannelLark, NotifyChannels } from "@/domain/settings";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { notifyTest } from "@/api/notify";
|
import { notifyTest } from "@/api/notify";
|
||||||
@ -109,7 +109,7 @@ const Lark = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -135,7 +135,7 @@ const Lark = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -169,7 +169,7 @@ const Lark = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,8 +6,8 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { isValidURL } from "@/lib/url";
|
import { isValidURL } from "@/utils/url";
|
||||||
import { NotifyChannels, NotifyChannelServerChan } from "@/domain/settings";
|
import { NotifyChannels, NotifyChannelServerChan } from "@/domain/settings";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
@ -120,7 +120,7 @@ const ServerChan = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -144,7 +144,7 @@ const ServerChan = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -180,7 +180,7 @@ const ServerChan = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,7 +6,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { NotifyChannels, NotifyChannelTelegram } from "@/domain/settings";
|
import { NotifyChannels, NotifyChannelTelegram } from "@/domain/settings";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
@ -113,7 +113,7 @@ const Telegram = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -137,7 +137,7 @@ const Telegram = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -173,7 +173,7 @@ const Telegram = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -6,8 +6,8 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { isValidURL } from "@/lib/url";
|
import { isValidURL } from "@/utils/url";
|
||||||
import { NotifyChannels, NotifyChannelWebhook } from "@/domain/settings";
|
import { NotifyChannels, NotifyChannelWebhook } from "@/domain/settings";
|
||||||
import { update } from "@/repository/settings";
|
import { update } from "@/repository/settings";
|
||||||
import { useNotifyContext } from "@/providers/notify";
|
import { useNotifyContext } from "@/providers/notify";
|
||||||
@ -120,7 +120,7 @@ const Webhook = () => {
|
|||||||
description: t("settings.notification.config.saved.message"),
|
description: t("settings.notification.config.saved.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
@ -144,7 +144,7 @@ const Webhook = () => {
|
|||||||
description: t("settings.notification.push_test_message.succeeded.message"),
|
description: t("settings.notification.push_test_message.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.notification.push_test_message.failed.message"),
|
title: t("settings.notification.push_test_message.failed.message"),
|
||||||
@ -180,7 +180,7 @@ const Webhook = () => {
|
|||||||
|
|
||||||
setChannels(resp);
|
setChannels(resp);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = getErrMessage(e);
|
const msg = getErrMsg(e);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("common.save.failed.message"),
|
title: t("common.save.failed.message"),
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
export const getErrMessage = (error: unknown): string => {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
return error.message;
|
|
||||||
} else if (typeof error === "object" && error !== null && "message" in error) {
|
|
||||||
return String(error.message);
|
|
||||||
} else if (typeof error === "string") {
|
|
||||||
return error;
|
|
||||||
} else {
|
|
||||||
return "Something went wrong";
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,35 +0,0 @@
|
|||||||
export const convertZulu2Beijing = (zuluTime: string) => {
|
|
||||||
const utcDate = new Date(zuluTime);
|
|
||||||
|
|
||||||
// Format the Beijing time
|
|
||||||
const formattedBeijingTime = new Intl.DateTimeFormat("zh-CN", {
|
|
||||||
year: "numeric",
|
|
||||||
month: "2-digit",
|
|
||||||
day: "2-digit",
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit",
|
|
||||||
hour12: false,
|
|
||||||
timeZone: "Asia/Shanghai",
|
|
||||||
}).format(utcDate);
|
|
||||||
|
|
||||||
return formattedBeijingTime;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getLeftDays = (zuluTime: string) => {
|
|
||||||
const time = convertZulu2Beijing(zuluTime);
|
|
||||||
const date = time.split(" ")[0];
|
|
||||||
const now = new Date();
|
|
||||||
const target = new Date(date);
|
|
||||||
const diff = target.getTime() - now.getTime();
|
|
||||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
|
||||||
return days;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const diffDays = (date1: string, date2: string) => {
|
|
||||||
const target1 = new Date(date1);
|
|
||||||
const target2 = new Date(date2);
|
|
||||||
const diff = target1.getTime() - target2.getTime();
|
|
||||||
const days = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
|
||||||
return days;
|
|
||||||
};
|
|
@ -9,7 +9,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { getPocketBase } from "@/repository/pocketbase";
|
import { getPocketBase } from "@/repository/pocketbase";
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
@ -45,7 +45,7 @@ const Account = () => {
|
|||||||
navigate("/login");
|
navigate("/login");
|
||||||
}, 500);
|
}, 500);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getErrMessage(e);
|
const message = getErrMsg(e);
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.account.email.failed.message"),
|
title: t("settings.account.email.failed.message"),
|
||||||
description: message,
|
description: message,
|
||||||
|
@ -8,7 +8,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { getPocketBase } from "@/repository/pocketbase";
|
import { getPocketBase } from "@/repository/pocketbase";
|
||||||
|
|
||||||
const formSchema = z
|
const formSchema = z
|
||||||
@ -46,7 +46,7 @@ const Password = () => {
|
|||||||
try {
|
try {
|
||||||
await getPocketBase().admins.authWithPassword(getPocketBase().authStore.model?.email, values.oldPassword);
|
await getPocketBase().admins.authWithPassword(getPocketBase().authStore.model?.email, values.oldPassword);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getErrMessage(e);
|
const message = getErrMsg(e);
|
||||||
form.setError("oldPassword", { message });
|
form.setError("oldPassword", { message });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ const Password = () => {
|
|||||||
navigate("/login");
|
navigate("/login");
|
||||||
}, 500);
|
}, 500);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getErrMessage(e);
|
const message = getErrMsg(e);
|
||||||
toast({
|
toast({
|
||||||
title: t("settings.password.failed.message"),
|
title: t("settings.password.failed.message"),
|
||||||
description: message,
|
description: message,
|
||||||
|
@ -11,7 +11,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { SSLProvider as SSLProviderType, SSLProviderSetting, Setting } from "@/domain/settings";
|
import { SSLProvider as SSLProviderType, SSLProviderSetting, Setting } from "@/domain/settings";
|
||||||
import { getSetting, update } from "@/repository/settings";
|
import { getSetting, update } from "@/repository/settings";
|
||||||
import { produce } from "immer";
|
import { produce } from "immer";
|
||||||
@ -84,7 +84,7 @@ const SSLProvider = () => {
|
|||||||
description: t("common.update.succeeded.message"),
|
description: t("common.update.succeeded.message"),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = getErrMessage(e);
|
const message = getErrMsg(e);
|
||||||
toast({
|
toast({
|
||||||
title: t("common.update.failed.message"),
|
title: t("common.update.failed.message"),
|
||||||
description: message,
|
description: message,
|
||||||
|
@ -13,7 +13,7 @@ import WorkflowLog from "@/components/workflow/WorkflowLog";
|
|||||||
import { cn } from "@/components/ui/utils";
|
import { cn } from "@/components/ui/utils";
|
||||||
import WorkflowProvider from "@/components/workflow/WorkflowProvider";
|
import WorkflowProvider from "@/components/workflow/WorkflowProvider";
|
||||||
import { allNodesValidated, WorkflowNode } from "@/domain/workflow";
|
import { allNodesValidated, WorkflowNode } from "@/domain/workflow";
|
||||||
import { getErrMessage } from "@/lib/error";
|
import { getErrMsg } from "@/utils/error";
|
||||||
import { useWorkflowStore, WorkflowState } from "@/stores/workflow";
|
import { useWorkflowStore, WorkflowState } from "@/stores/workflow";
|
||||||
import { ArrowLeft } from "lucide-react";
|
import { ArrowLeft } from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
@ -128,7 +128,7 @@ const WorkflowDetail = () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast({
|
toast({
|
||||||
title: t("workflow.detail.action.run.failed"),
|
title: t("workflow.detail.action.run.failed"),
|
||||||
description: getErrMessage(e),
|
description: getErrMsg(e),
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
15
ui/src/utils/error.ts
Normal file
15
ui/src/utils/error.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export const getErrMsg = (error: unknown): string => {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return error.message;
|
||||||
|
} else if (typeof error === "object" && error != null) {
|
||||||
|
if ("message" in error) {
|
||||||
|
return String(error.message);
|
||||||
|
} else if ("msg" in error) {
|
||||||
|
return String(error.msg);
|
||||||
|
}
|
||||||
|
} else if (typeof error === "string") {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Something went wrong";
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user