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 DeployNodeConfigFormAliyunAPIGWConfigFieldValues = Nullish<{ serviceType: string; region: string; gatewayId?: string; groupId?: string; domain?: string; }>; export type DeployNodeConfigFormAliyunAPIGWConfigProps = { form: FormInstance; formName: string; disabled?: boolean; initialValues?: DeployNodeConfigFormAliyunAPIGWConfigFieldValues; onValuesChange?: (values: DeployNodeConfigFormAliyunAPIGWConfigFieldValues) => void; }; const SERVICE_TYPE_CLOUDNATIVE = "cloudnative" as const; const SERVICE_TYPE_TRADITIONAL = "traditional" as const; const initFormModel = (): DeployNodeConfigFormAliyunAPIGWConfigFieldValues => { return {}; }; const DeployNodeConfigFormAliyunAPIGWConfig = ({ form: formInst, formName, disabled, initialValues, onValuesChange, }: DeployNodeConfigFormAliyunAPIGWConfigProps) => { const { t } = useTranslation(); const formSchema = z.object({ serviceType: z.union([z.literal(SERVICE_TYPE_CLOUDNATIVE), z.literal(SERVICE_TYPE_TRADITIONAL)], { message: t("workflow_node.deploy.form.aliyun_apigw_service_type.placeholder"), }), region: z .string({ message: t("workflow_node.deploy.form.aliyun_apigw_region.placeholder") }) .nonempty(t("workflow_node.deploy.form.aliyun_apigw_region.placeholder")) .trim(), gatewayId: z .string() .nullish() .refine((v) => fieldServiceType !== SERVICE_TYPE_CLOUDNATIVE || !!v?.trim(), t("workflow_node.deploy.form.aliyun_apigw_gateway_id.placeholder")), groupId: z .string() .nullish() .refine((v) => fieldServiceType !== SERVICE_TYPE_TRADITIONAL || !!v?.trim(), t("workflow_node.deploy.form.aliyun_apigw_group_id.placeholder")), domain: z .string() .nonempty(t("workflow_node.deploy.form.aliyun_apigw_domain.placeholder")) .refine((v) => validDomainName(v!, { allowWildcard: true }), t("common.errmsg.domain_invalid")), }); const formRule = createSchemaFieldRule(formSchema); const fieldServiceType = Form.useWatch("serviceType", formInst); const handleFormChange = (_: unknown, values: z.infer) => { onValuesChange?.(values); }; return (
} > } > } > } >
); }; export default DeployNodeConfigFormAliyunAPIGWConfig;