refactor: clean code

This commit is contained in:
Fu Diwei 2025-12-25 22:06:23 +08:00
parent d49f543247
commit af50635751
10 changed files with 20 additions and 11 deletions

View File

@ -4,7 +4,7 @@ import { createSchemaFieldRule } from "antd-zod";
import { z } from "zod";
import Show from "@/components/Show";
import { isDomain, isEmail, isIPv4, isIPv6, isPortNumber } from "@/utils/validator";
import { isEmail, isHostname, isPortNumber } from "@/utils/validator";
import { useFormNestedFieldsContext } from "./_context";
@ -127,7 +127,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
const { t } = i18n;
return z.object({
smtpHost: z.string().refine((v) => isDomain(v) || isIPv4(v) || isIPv6(v), t("common.errmsg.host_invalid")),
smtpHost: z.string().refine((v) => isHostname(v), t("common.errmsg.host_invalid")),
smtpPort: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")),
smtpTls: z.boolean().nullish(),
username: z.string().nonempty(t("access.form.email_username.placeholder")),

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -97,7 +97,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!);
if (!v) return true;
return isDomain(v);
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -150,7 +150,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -111,7 +111,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v);
if (!v) return true;
return isDomain(v);
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {

View File

@ -110,7 +110,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
.string()
.nullish()
.refine((v) => {
return !v || isDomain(v!, { allowWildcard: true });
if (!v) return true;
return isDomain(v, { allowWildcard: true });
}, t("common.errmsg.domain_invalid")),
})
.superRefine((values, ctx) => {