53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
// PhysicalInfoForm.tsx
|
||
"use client";
|
||
|
||
import React from "react";
|
||
import { withFormik, type FormikBag } from "formik";
|
||
|
||
import InnerPhysicalInfoForm from "./InnerPhysicalInfoForm";
|
||
import { PhysicalInfoFormValues } from "./types";
|
||
import { PHYSICAL_INFO_EMPTY_VALUES } from "./constants";
|
||
import { PhysicalInfoValidationSchema } from "./validation";
|
||
|
||
/** این بخش را با ساختار اصلی WizardFormData پروژه خودت هماهنگ کن */
|
||
export interface WizardFormData {
|
||
physicalInfo: PhysicalInfoFormValues;
|
||
// ... بقیه step ها
|
||
}
|
||
|
||
export type PhysicalInfoFormProps = {
|
||
step: number;
|
||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
||
data: WizardFormData;
|
||
update: (patch: Partial<WizardFormData>) => void;
|
||
};
|
||
|
||
const PhysicalInfoForm = withFormik<
|
||
PhysicalInfoFormProps,
|
||
PhysicalInfoFormValues
|
||
>({
|
||
displayName: "PhysicalInfoForm",
|
||
|
||
enableReinitialize: true,
|
||
|
||
mapPropsToValues: (props) => {
|
||
return props.data?.physicalInfo ?? PHYSICAL_INFO_EMPTY_VALUES;
|
||
},
|
||
|
||
// validationSchema: PhysicalInfoValidationSchema,
|
||
|
||
handleSubmit: async (
|
||
values,
|
||
bag: FormikBag<PhysicalInfoFormProps, PhysicalInfoFormValues>,
|
||
) => {
|
||
const { props, setSubmitting } = bag;
|
||
|
||
props.update({ physicalInfo: values });
|
||
props.setStep((prev) => prev + 1);
|
||
|
||
setSubmitting(false);
|
||
},
|
||
})(InnerPhysicalInfoForm);
|
||
|
||
export default PhysicalInfoForm;
|