import { withFormik } from "formik"; import * as yup from "yup"; import InnerRegistrationCenterForm from "./InnerRegistrationCenterForm"; import { CenterItem, IdentityFormValues } from "@/core/types"; export interface RegistrationCenterFormValues { selectedCenter: CenterItem | null; } export interface WizardFormData { applicantId: string; registrationCenter: { selectedCenter: CenterItem | null; }; identity: IdentityFormValues; } export interface RegistrationCenterFormProps { step: number; setStep: React.Dispatch>; data: WizardFormData; update: (patch: Partial) => void; } const EMPTY_VALUES: RegistrationCenterFormValues = { selectedCenter: null, }; const RegistrationCenterFormValidationSchema = yup.object({ selectedCenter: yup .mixed() .nullable() .required("لطفاً یک مرکز را انتخاب کنید"), }); const RegistrationCenterForm = withFormik< RegistrationCenterFormProps, RegistrationCenterFormValues >({ enableReinitialize: true, mapPropsToValues: (props) => ({ selectedCenter: props.data.registrationCenter.selectedCenter ?? null, }), validationSchema: RegistrationCenterFormValidationSchema, handleSubmit: (values, { props }) => { props.update({ registrationCenter: values, }); props.setStep((prev) => prev + 1); }, })(InnerRegistrationCenterForm); export default RegistrationCenterForm;