mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-04 12:40:08 +00:00
improve: add missing try-catch cases (#86)
* improve: add missing try-catch cases * i18n: support german * chore: auto-fix linting and formatting issues --------- Co-authored-by: uubulb <uubulb@users.noreply.github.com>
This commit is contained in:
6973
package-lock.json
generated
6973
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -115,9 +116,17 @@ export const AlertRuleCard: React.FC<AlertRuleCardProps> = ({ data, mutate }) =>
|
|||||||
const onSubmit = async (values: z.infer<typeof alertRuleFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof alertRuleFormSchema>) => {
|
||||||
values.rules = JSON.parse(values.rules_raw)
|
values.rules = JSON.parse(values.rules_raw)
|
||||||
const { rules_raw, ...requiredFields } = values
|
const { rules_raw, ...requiredFields } = values
|
||||||
data?.id
|
try {
|
||||||
? await updateAlertRule(data.id, requiredFields)
|
data?.id
|
||||||
: await createAlertRule(requiredFields)
|
? await updateAlertRule(data.id, requiredFields)
|
||||||
|
: await createAlertRule(requiredFields)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -84,7 +85,15 @@ export const CronCard: React.FC<CronCardProps> = ({ data, mutate }) => {
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof cronFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof cronFormSchema>) => {
|
||||||
data?.id ? await updateCron(data.id, values) : await createCron(values)
|
try {
|
||||||
|
data?.id ? await updateCron(data.id, values) : await createCron(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -85,7 +86,15 @@ export const DDNSCard: React.FC<DDNSCardProps> = ({ data, providers, mutate }) =
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof ddnsFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof ddnsFormSchema>) => {
|
||||||
data?.id ? await updateDDNSProfile(data.id, values) : await createDDNSProfile(values)
|
try {
|
||||||
|
data?.id ? await updateDDNSProfile(data.id, values) : await createDDNSProfile(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -61,7 +62,15 @@ export const NATCard: React.FC<NATCardProps> = ({ data, mutate }) => {
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof natFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof natFormSchema>) => {
|
||||||
data?.id ? await updateNAT(data.id, values) : await createNAT(values)
|
try {
|
||||||
|
data?.id ? await updateNAT(data.id, values) : await createNAT(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -62,9 +63,17 @@ export const NotificationGroupCard: React.FC<NotificationGroupCardProps> = ({ da
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof notificationGroupFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof notificationGroupFormSchema>) => {
|
||||||
data?.group.id
|
try {
|
||||||
? await updateNotificationGroup(data.group.id, values)
|
data?.group.id
|
||||||
: await createNotificationGroup(values)
|
? await updateNotificationGroup(data.group.id, values)
|
||||||
|
: await createNotificationGroup(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -80,7 +81,15 @@ export const NotifierCard: React.FC<NotifierCardProps> = ({ data, mutate }) => {
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof notificationFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof notificationFormSchema>) => {
|
||||||
data?.id ? await updateNotification(data.id, values) : await createNotification(values)
|
try {
|
||||||
|
data?.id ? await updateNotification(data.id, values) : await createNotification(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ export const ProfileCard = ({ className }: { className: string }) => {
|
|||||||
try {
|
try {
|
||||||
await updateProfile(values)
|
await updateProfile(values)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
toast(t("Error"), {
|
toast(t("Error"), {
|
||||||
description: `${e}`,
|
description: t("Results.UnExpectedError"),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -62,9 +63,17 @@ export const ServerGroupCard: React.FC<ServerGroupCardProps> = ({ data, mutate }
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof serverGroupFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof serverGroupFormSchema>) => {
|
||||||
data?.group.id
|
try {
|
||||||
? await updateServerGroup(data.group.id, values)
|
data?.group.id
|
||||||
: await createServerGroup(values)
|
? await updateServerGroup(data.group.id, values)
|
||||||
|
: await createServerGroup(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -62,7 +63,15 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof serverFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof serverFormSchema>) => {
|
||||||
await updateServer(data!.id!, values)
|
try {
|
||||||
|
await updateServer(data!.id!, values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -103,9 +104,17 @@ export const ServiceCard: React.FC<ServiceCardProps> = ({ data, mutate }) => {
|
|||||||
const onSubmit = async (values: z.infer<typeof serviceFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof serviceFormSchema>) => {
|
||||||
values.skip_servers = conv.arrToRecord(values.skip_servers_raw)
|
values.skip_servers = conv.arrToRecord(values.skip_servers_raw)
|
||||||
const { skip_servers_raw, ...requiredFields } = values
|
const { skip_servers_raw, ...requiredFields } = values
|
||||||
data?.id
|
try {
|
||||||
? await updateService(data.id, requiredFields)
|
data?.id
|
||||||
: await createService(requiredFields)
|
? await updateService(data.id, requiredFields)
|
||||||
|
: await createService(requiredFields)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { zodResolver } from "@hookform/resolvers/zod"
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
import { KeyedMutator } from "swr"
|
import { KeyedMutator } from "swr"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
@@ -63,7 +64,15 @@ export const UserCard: React.FC<UserCardProps> = ({ mutate }) => {
|
|||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
const onSubmit = async (values: z.infer<typeof userFormSchema>) => {
|
const onSubmit = async (values: z.infer<typeof userFormSchema>) => {
|
||||||
await createUser(values)
|
try {
|
||||||
|
await createUser(values)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
toast(t("Error"), {
|
||||||
|
description: t("Results.UnExpectedError"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
await mutate()
|
await mutate()
|
||||||
form.reset()
|
form.reset()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
setProfile(user)
|
setProfile(user)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
setProfile(undefined)
|
setProfile(undefined)
|
||||||
console.log("Error fetching profile", error)
|
console.error("Error fetching profile", error)
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}, [])
|
}, [])
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import i18n from "i18next"
|
import i18n from "i18next"
|
||||||
import { initReactI18next } from "react-i18next"
|
import { initReactI18next } from "react-i18next"
|
||||||
|
|
||||||
|
import deTranslation from "../locales/de/translation.json"
|
||||||
import enTranslation from "../locales/en/translation.json"
|
import enTranslation from "../locales/en/translation.json"
|
||||||
import itTranslation from "../locales/it/translation.json"
|
import itTranslation from "../locales/it/translation.json"
|
||||||
import zhCNTranslation from "../locales/zh-CN/translation.json"
|
import zhCNTranslation from "../locales/zh-CN/translation.json"
|
||||||
@@ -19,6 +20,9 @@ const resources = {
|
|||||||
"zh-TW": {
|
"zh-TW": {
|
||||||
translation: zhTWTranslation,
|
translation: zhTWTranslation,
|
||||||
},
|
},
|
||||||
|
"de-DE": {
|
||||||
|
translation: deTranslation,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStoredLanguage = () => {
|
const getStoredLanguage = () => {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ function Login() {
|
|||||||
<div className="mt-3 flex flex-col space-y-2">
|
<div className="mt-3 flex flex-col space-y-2">
|
||||||
{settingData?.config?.oauth2_providers?.map((p: string) => (
|
{settingData?.config?.oauth2_providers?.map((p: string) => (
|
||||||
<Button
|
<Button
|
||||||
className="w-full rounded-lg shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] bg-muted text-primary hover:bg-muted/80 hover:text-primary/80"
|
className="w-full rounded-lg shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] bg-muted text-primary hover:bg-muted/80 hover:text-primary/80 mb-3"
|
||||||
onClick={() => loginWith(p)}
|
onClick={() => loginWith(p)}
|
||||||
>
|
>
|
||||||
{p === "GitHub" && <GitHubIcon className="-mt-[1px] size-4" />}
|
{p === "GitHub" && <GitHubIcon className="-mt-[1px] size-4" />}
|
||||||
|
|||||||
@@ -118,14 +118,18 @@ export default function ProfilePage() {
|
|||||||
</section>
|
</section>
|
||||||
{profile.oauth2_bind?.[provider.toLowerCase()] ? (
|
{profile.oauth2_bind?.[provider.toLowerCase()] ? (
|
||||||
<Button
|
<Button
|
||||||
className="w-fit bg-red-600 hover:bg-red-500 dark:text-white rounded-lg shadow-[inset_0_1px_0_rgba(255,255,255,0.2)]"
|
className="w-fit bg-red-600 hover:bg-red-500 dark:text-white rounded-lg shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] my-1"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => unbindO2(provider)}
|
onClick={() => unbindO2(provider)}
|
||||||
>
|
>
|
||||||
Unbind
|
Unbind
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<Button size="sm" onClick={() => bindO2(provider)}>
|
<Button
|
||||||
|
className="my-1"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => bindO2(provider)}
|
||||||
|
>
|
||||||
Bind
|
Bind
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const nezhaLang: Record<string, string> = {
|
|||||||
"zh-CN": "简体中文(中国大陆)",
|
"zh-CN": "简体中文(中国大陆)",
|
||||||
"zh-TW": "正體中文(台灣)",
|
"zh-TW": "正體中文(台灣)",
|
||||||
"en-US": "English",
|
"en-US": "English",
|
||||||
|
"de-DE": "Deutsch",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const wafBlockReasons: Record<number, string> = {
|
export const wafBlockReasons: Record<number, string> = {
|
||||||
|
|||||||
Reference in New Issue
Block a user