import { useTranslation } from "react-i18next"; import { Form, type FormInstance, Input, Select } from "antd"; import { createSchemaFieldRule } from "antd-zod"; import { z } from "zod"; import Show from "@/components/Show"; import { validDomainName } from "@/utils/validators"; type DeployNodeConfigFormAliyunGAConfigFieldValues = Nullish<{ resourceType: string; acceleratorId?: string; listenerId?: string; domain?: string; }>; export type DeployNodeConfigFormAliyunGAConfigProps = { form: FormInstance; formName: string; disabled?: boolean; initialValues?: DeployNodeConfigFormAliyunGAConfigFieldValues; onValuesChange?: (values: DeployNodeConfigFormAliyunGAConfigFieldValues) => void; }; const RESOURCE_TYPE_ACCELERATOR = "accelerator" as const; const RESOURCE_TYPE_LISTENER = "listener" as const; const initFormModel = (): DeployNodeConfigFormAliyunGAConfigFieldValues => { return {}; }; const DeployNodeConfigFormAliyunGAConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange }: DeployNodeConfigFormAliyunGAConfigProps) => { const { t } = useTranslation(); const formSchema = z.object({ resourceType: z.union([z.literal(RESOURCE_TYPE_ACCELERATOR), z.literal(RESOURCE_TYPE_LISTENER)], { message: t("workflow_node.deploy.form.aliyun_ga_resource_type.placeholder"), }), acceleratorId: z .string() .max(64, t("common.errmsg.string_max", { max: 64 })) .trim(), listenerId: z .string() .max(64, t("common.errmsg.string_max", { max: 64 })) .trim() .nullish() .refine((v) => fieldResourceType !== RESOURCE_TYPE_LISTENER || !!v?.trim(), t("workflow_node.deploy.form.aliyun_ga_listener_id.placeholder")), domain: z .string() .nullish() .refine((v) => { if (![RESOURCE_TYPE_ACCELERATOR, RESOURCE_TYPE_LISTENER].includes(fieldResourceType)) return true; return !v || validDomainName(v!); }, t("common.errmsg.domain_invalid")), }); const formRule = createSchemaFieldRule(formSchema); const fieldResourceType = Form.useWatch("resourceType", formInst); const handleFormChange = (_: unknown, values: z.infer) => { onValuesChange?.(values); }; return (
} > } > } >
); }; export default DeployNodeConfigFormAliyunGAConfig;