import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useDeepCompareEffect } from "ahooks"; import { Form, Input, type FormInstance } from "antd"; import { createSchemaFieldRule } from "antd-zod"; import { z } from "zod"; import { type GoDaddyAccessConfig } from "@/domain/access"; type AccessEditFormGoDaddyConfigModelType = Partial; export type AccessEditFormGoDaddyConfigProps = { form: FormInstance; disabled?: boolean; loading?: boolean; model?: AccessEditFormGoDaddyConfigModelType; onModelChange?: (model: AccessEditFormGoDaddyConfigModelType) => void; }; const initModel = () => { return {} as AccessEditFormGoDaddyConfigModelType; }; const AccessEditFormGoDaddyConfig = ({ form, disabled, loading, model, onModelChange }: AccessEditFormGoDaddyConfigProps) => { const { t } = useTranslation(); const formSchema = z.object({ apiKey: z .string() .trim() .min(1, t("access.form.godaddy_api_key.placeholder")) .max(64, t("common.errmsg.string_max", { max: 64 })), apiSecret: z .string() .trim() .min(1, t("access.form.godaddy_api_secret.placeholder")) .max(64, t("common.errmsg.string_max", { max: 64 })), }); const formRule = createSchemaFieldRule(formSchema); const [initialValues, setInitialValues] = useState>>(model ?? initModel()); useDeepCompareEffect(() => { setInitialValues(model ?? initModel()); }, [model]); const handleFormChange = (_: unknown, fields: AccessEditFormGoDaddyConfigModelType) => { onModelChange?.(fields); }; return (
} > } >
); }; export default AccessEditFormGoDaddyConfig;