mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 05:59:50 +00:00
refactor(ui): clean code
This commit is contained in:
parent
949660bc01
commit
daa5b44f8e
@ -7,7 +7,7 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { type AccessConfigForSSH } from "@/domain/access";
|
import { type AccessConfigForSSH } from "@/domain/access";
|
||||||
import { readFileContent } from "@/utils/file";
|
import { readFileContent } from "@/utils/file";
|
||||||
import { validDomainName, validIPv4Address, validIPv6Address } from "@/utils/validators";
|
import { validDomainName, validIPv4Address, validIPv6Address, validPortNumber } from "@/utils/validators";
|
||||||
|
|
||||||
type AccessFormSSHConfigFieldValues = Nullish<AccessConfigForSSH>;
|
type AccessFormSSHConfigFieldValues = Nullish<AccessConfigForSSH>;
|
||||||
|
|
||||||
@ -34,11 +34,13 @@ const AccessFormSSHConfig = ({ form: formInst, formName, disabled, initialValues
|
|||||||
host: z
|
host: z
|
||||||
.string({ message: t("access.form.ssh_host.placeholder") })
|
.string({ message: t("access.form.ssh_host.placeholder") })
|
||||||
.refine((v) => validDomainName(v) || validIPv4Address(v) || validIPv6Address(v), t("common.errmsg.host_invalid")),
|
.refine((v) => validDomainName(v) || validIPv4Address(v) || validIPv6Address(v), t("common.errmsg.host_invalid")),
|
||||||
port: z
|
port: z.preprocess(
|
||||||
|
(v) => Number(v),
|
||||||
|
z
|
||||||
.number({ message: t("access.form.ssh_port.placeholder") })
|
.number({ message: t("access.form.ssh_port.placeholder") })
|
||||||
.int()
|
.int(t("access.form.ssh_port.placeholder"))
|
||||||
.gte(1, t("common.errmsg.port_invalid"))
|
.refine((v) => validPortNumber(v), t("common.errmsg.port_invalid"))
|
||||||
.lte(65535, t("common.errmsg.port_invalid")),
|
),
|
||||||
username: z
|
username: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, "access.form.ssh_username.placeholder")
|
.min(1, "access.form.ssh_username.placeholder")
|
||||||
|
@ -3,6 +3,8 @@ import { Form, Input, InputNumber, Switch } from "antd";
|
|||||||
import { createSchemaFieldRule } from "antd-zod";
|
import { createSchemaFieldRule } from "antd-zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import { validPortNumber } from "@/utils/validators";
|
||||||
|
|
||||||
const NotifyChannelEditFormEmailFields = () => {
|
const NotifyChannelEditFormEmailFields = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -11,11 +13,13 @@ const NotifyChannelEditFormEmailFields = () => {
|
|||||||
.string({ message: t("settings.notification.channel.form.email_smtp_host.placeholder") })
|
.string({ message: t("settings.notification.channel.form.email_smtp_host.placeholder") })
|
||||||
.min(1, t("settings.notification.channel.form.email_smtp_host.placeholder"))
|
.min(1, t("settings.notification.channel.form.email_smtp_host.placeholder"))
|
||||||
.max(256, t("common.errmsg.string_max", { max: 256 })),
|
.max(256, t("common.errmsg.string_max", { max: 256 })),
|
||||||
smtpPort: z
|
smtpPort: z.preprocess(
|
||||||
|
(v) => Number(v),
|
||||||
|
z
|
||||||
.number({ message: t("settings.notification.channel.form.email_smtp_port.placeholder") })
|
.number({ message: t("settings.notification.channel.form.email_smtp_port.placeholder") })
|
||||||
.int()
|
.int(t("settings.notification.channel.form.email_smtp_port.placeholder"))
|
||||||
.gte(1, t("common.errmsg.port_invalid"))
|
.refine((v) => validPortNumber(v), t("common.errmsg.port_invalid"))
|
||||||
.lte(65535, t("common.errmsg.port_invalid")),
|
),
|
||||||
smtpTLS: z.boolean().nullish(),
|
smtpTLS: z.boolean().nullish(),
|
||||||
username: z
|
username: z
|
||||||
.string({ message: t("settings.notification.channel.form.email_username.placeholder") })
|
.string({ message: t("settings.notification.channel.form.email_username.placeholder") })
|
||||||
|
@ -114,24 +114,27 @@ const ApplyNodeConfigForm = forwardRef<ApplyNodeConfigFormInstance, ApplyNodeCon
|
|||||||
.split(MULTIPLE_INPUT_DELIMITER)
|
.split(MULTIPLE_INPUT_DELIMITER)
|
||||||
.every((e) => validIPv4Address(e) || validIPv6Address(e) || validDomainName(e));
|
.every((e) => validIPv4Address(e) || validIPv6Address(e) || validDomainName(e));
|
||||||
}, t("common.errmsg.host_invalid")),
|
}, t("common.errmsg.host_invalid")),
|
||||||
dnsPropagationTimeout: z
|
dnsPropagationTimeout: z.preprocess(
|
||||||
.union([
|
(v) => (v == null || v === "" ? undefined : Number(v)),
|
||||||
z.number().int().gte(1, t("workflow_node.apply.form.dns_propagation_timeout.placeholder")),
|
z
|
||||||
z.string().refine((v) => !v || /^[1-9]\d*$/.test(v), t("workflow_node.apply.form.dns_propagation_timeout.placeholder")),
|
.number()
|
||||||
])
|
.int(t("workflow_node.apply.form.dns_propagation_timeout.placeholder"))
|
||||||
.nullish(),
|
.gte(1, t("workflow_node.apply.form.dns_propagation_timeout.placeholder"))
|
||||||
dnsTTL: z
|
.nullish()
|
||||||
.union([
|
),
|
||||||
z.number().int().gte(1, t("workflow_node.apply.form.dns_ttl.placeholder")),
|
dnsTTL: z.preprocess(
|
||||||
z.string().refine((v) => !v || /^[1-9]\d*$/.test(v), t("workflow_node.apply.form.dns_ttl.placeholder")),
|
(v) => (v == null || v === "" ? undefined : Number(v)),
|
||||||
])
|
z.number().int(t("workflow_node.apply.form.dns_ttl.placeholder")).gte(1, t("workflow_node.apply.form.dns_ttl.placeholder")).nullish()
|
||||||
.nullish(),
|
),
|
||||||
disableFollowCNAME: z.boolean().nullish(),
|
disableFollowCNAME: z.boolean().nullish(),
|
||||||
disableARI: z.boolean().nullish(),
|
disableARI: z.boolean().nullish(),
|
||||||
skipBeforeExpiryDays: z
|
skipBeforeExpiryDays: z.preprocess(
|
||||||
|
(v) => Number(v),
|
||||||
|
z
|
||||||
.number({ message: t("workflow_node.apply.form.skip_before_expiry_days.placeholder") })
|
.number({ message: t("workflow_node.apply.form.skip_before_expiry_days.placeholder") })
|
||||||
.int(t("workflow_node.apply.form.skip_before_expiry_days.placeholder"))
|
.int(t("workflow_node.apply.form.skip_before_expiry_days.placeholder"))
|
||||||
.gte(1, t("workflow_node.apply.form.skip_before_expiry_days.placeholder")),
|
.gte(1, t("workflow_node.apply.form.skip_before_expiry_days.placeholder"))
|
||||||
|
),
|
||||||
});
|
});
|
||||||
const formRule = createSchemaFieldRule(formSchema);
|
const formRule = createSchemaFieldRule(formSchema);
|
||||||
const { form: formInst, formProps } = useAntdForm({
|
const { form: formInst, formProps } = useAntdForm({
|
||||||
@ -570,7 +573,7 @@ const ApplyNodeConfigForm = forwardRef<ApplyNodeConfigFormInstance, ApplyNodeCon
|
|||||||
<InputNumber
|
<InputNumber
|
||||||
className="w-36"
|
className="w-36"
|
||||||
min={1}
|
min={1}
|
||||||
max={90}
|
max={365}
|
||||||
placeholder={t("workflow_node.apply.form.skip_before_expiry_days.placeholder")}
|
placeholder={t("workflow_node.apply.form.skip_before_expiry_days.placeholder")}
|
||||||
addonAfter={t("workflow_node.apply.form.skip_before_expiry_days.unit")}
|
addonAfter={t("workflow_node.apply.form.skip_before_expiry_days.unit")}
|
||||||
/>
|
/>
|
||||||
|
@ -10,7 +10,7 @@ type DeployNodeConfigFormAliyunCLBConfigFieldValues = Nullish<{
|
|||||||
resourceType: string;
|
resourceType: string;
|
||||||
region: string;
|
region: string;
|
||||||
loadbalancerId?: string;
|
loadbalancerId?: string;
|
||||||
listenerPort?: string | number;
|
listenerPort?: number;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@ -53,10 +53,13 @@ const DeployNodeConfigFormAliyunCLBConfig = ({
|
|||||||
.min(1, t("workflow_node.deploy.form.aliyun_clb_loadbalancer_id.placeholder"))
|
.min(1, t("workflow_node.deploy.form.aliyun_clb_loadbalancer_id.placeholder"))
|
||||||
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
||||||
.trim(),
|
.trim(),
|
||||||
listenerPort: z
|
listenerPort: z.preprocess(
|
||||||
.union([z.number(), z.string()])
|
(v) => (v == null || v === "" ? undefined : Number(v)),
|
||||||
.refine((v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v), t("workflow_node.deploy.form.aliyun_clb_listener_port.placeholder"))
|
z
|
||||||
.nullish(),
|
.number()
|
||||||
|
.nullish()
|
||||||
|
.refine((v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v!), t("workflow_node.deploy.form.aliyun_clb_listener_port.placeholder"))
|
||||||
|
),
|
||||||
domain: z
|
domain: z
|
||||||
.string()
|
.string()
|
||||||
.nullish()
|
.nullish()
|
||||||
|
@ -10,7 +10,7 @@ type DeployNodeConfigFormBaiduCloudAppBLBConfigFieldValues = Nullish<{
|
|||||||
resourceType: string;
|
resourceType: string;
|
||||||
region: string;
|
region: string;
|
||||||
loadbalancerId?: string;
|
loadbalancerId?: string;
|
||||||
listenerPort?: string | number;
|
listenerPort?: number;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@ -53,13 +53,16 @@ const DeployNodeConfigFormBaiduCloudAppBLBConfig = ({
|
|||||||
.min(1, t("workflow_node.deploy.form.baiducloud_appblb_loadbalancer_id.placeholder"))
|
.min(1, t("workflow_node.deploy.form.baiducloud_appblb_loadbalancer_id.placeholder"))
|
||||||
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
||||||
.trim(),
|
.trim(),
|
||||||
listenerPort: z
|
listenerPort: z.preprocess(
|
||||||
.union([z.number(), z.string()])
|
(v) => (v == null || v === "" ? undefined : Number(v)),
|
||||||
|
z
|
||||||
|
.number()
|
||||||
.refine(
|
.refine(
|
||||||
(v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v),
|
(v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v!),
|
||||||
t("workflow_node.deploy.form.baiducloud_appblb_listener_port.placeholder")
|
t("workflow_node.deploy.form.baiducloud_appblb_listener_port.placeholder")
|
||||||
)
|
)
|
||||||
.nullish(),
|
.nullish()
|
||||||
|
),
|
||||||
domain: z
|
domain: z
|
||||||
.string()
|
.string()
|
||||||
.nullish()
|
.nullish()
|
||||||
|
@ -10,7 +10,7 @@ type DeployNodeConfigFormBaiduCloudBLBConfigFieldValues = Nullish<{
|
|||||||
resourceType: string;
|
resourceType: string;
|
||||||
region: string;
|
region: string;
|
||||||
loadbalancerId?: string;
|
loadbalancerId?: string;
|
||||||
listenerPort?: string | number;
|
listenerPort?: number;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@ -53,13 +53,16 @@ const DeployNodeConfigFormBaiduCloudBLBConfig = ({
|
|||||||
.min(1, t("workflow_node.deploy.form.baiducloud_blb_loadbalancer_id.placeholder"))
|
.min(1, t("workflow_node.deploy.form.baiducloud_blb_loadbalancer_id.placeholder"))
|
||||||
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
.max(64, t("common.errmsg.string_max", { max: 64 }))
|
||||||
.trim(),
|
.trim(),
|
||||||
listenerPort: z
|
listenerPort: z.preprocess(
|
||||||
.union([z.number(), z.string()])
|
(v) => (v == null || v === "" ? undefined : Number(v)),
|
||||||
|
z
|
||||||
|
.number()
|
||||||
|
.nullish()
|
||||||
.refine(
|
.refine(
|
||||||
(v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v),
|
(v) => fieldResourceType === RESOURCE_TYPE_LISTENER && validPortNumber(v!),
|
||||||
t("workflow_node.deploy.form.baiducloud_blb_listener_port.placeholder")
|
t("workflow_node.deploy.form.baiducloud_blb_listener_port.placeholder")
|
||||||
)
|
)
|
||||||
.nullish(),
|
),
|
||||||
domain: z
|
domain: z
|
||||||
.string()
|
.string()
|
||||||
.nullish()
|
.nullish()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user