import { useTranslation } from "react-i18next"; import { Form, type FormInstance, Input, Select } from "antd"; import { createSchemaFieldRule } from "antd-zod"; import { z } from "zod/v4"; import Show from "@/components/Show"; import { validDomainName } from "@/utils/validators"; type DeployNodeConfigFormTencentCloudCLBConfigFieldValues = Nullish<{ endpoint?: string; region: string; resourceType: string; loadbalancerId?: string; listenerId?: string; domain?: string; }>; export type DeployNodeConfigFormTencentCloudCLBConfigProps = { form: FormInstance; formName: string; disabled?: boolean; initialValues?: DeployNodeConfigFormTencentCloudCLBConfigFieldValues; onValuesChange?: (values: DeployNodeConfigFormTencentCloudCLBConfigFieldValues) => void; }; const RESOURCE_TYPE_LOADBALANCER = "loadbalancer" as const; const RESOURCE_TYPE_LISTENER = "listener" as const; const RESOURCE_TYPE_RULEDOMAIN = "ruledomain" as const; const RESOURCE_TYPE_VIA_SSLDEPLOY = "ssl-deploy" as const; const initFormModel = (): DeployNodeConfigFormTencentCloudCLBConfigFieldValues => { return { resourceType: RESOURCE_TYPE_LISTENER, }; }; const DeployNodeConfigFormTencentCloudCLBConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange, }: DeployNodeConfigFormTencentCloudCLBConfigProps) => { const { t } = useTranslation(); const formSchema = z.object({ endpoint: z.string().nullish(), resourceType: z.literal( [RESOURCE_TYPE_LOADBALANCER, RESOURCE_TYPE_LISTENER, RESOURCE_TYPE_RULEDOMAIN, RESOURCE_TYPE_VIA_SSLDEPLOY], t("workflow_node.deploy.form.tencentcloud_clb_resource_type.placeholder") ), region: z .string(t("workflow_node.deploy.form.tencentcloud_clb_region.placeholder")) .nonempty(t("workflow_node.deploy.form.tencentcloud_clb_region.placeholder")), loadbalancerId: z .string() .min(1, t("workflow_node.deploy.form.tencentcloud_clb_loadbalancer_id.placeholder")) .max(64, t("common.errmsg.string_max", { max: 64 })), listenerId: z .string() .max(64, t("common.errmsg.string_max", { max: 64 })) .nullish() .refine( (v) => ![RESOURCE_TYPE_LISTENER, RESOURCE_TYPE_RULEDOMAIN, RESOURCE_TYPE_VIA_SSLDEPLOY].includes(fieldResourceType) || !!v?.trim(), t("workflow_node.deploy.form.tencentcloud_clb_listener_id.placeholder") ), domain: z .string() .nullish() .refine((v) => RESOURCE_TYPE_RULEDOMAIN !== fieldResourceType || validDomainName(v!, { allowWildcard: true }), 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 DeployNodeConfigFormTencentCloudCLBConfig;