Files
hounam-submit-form-frontend/ui/forms/personal/PersonalInfoForm.tsx
2026-06-02 17:08:52 +03:30

50 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// PersonalInfoForm.tsx
"use client";
import React from "react";
import { withFormik, type FormikBag } from "formik";
import InnerPersonalInfoForm from "./InnerPersonalInfoForm";
import { PersonalInfoFormValues } from "./types";
import { PERSONAL_INFO_EMPTY_VALUES } from "./constants";
import { PersonalInfoValidationSchema } from "./validation/PersonalInfoFormValidation";
/** اینا رو با Wizard خودت هماهنگ کن */
export interface WizardFormData {
personalInfo: PersonalInfoFormValues;
// ... بقیه step ها
}
export type PersonalInfoFormProps = {
step: number;
setStep: React.Dispatch<React.SetStateAction<number>>;
data: WizardFormData;
update: (patch: Partial<WizardFormData>) => void;
};
const PersonalInfoForm = withFormik<PersonalInfoFormProps, PersonalInfoFormValues>({
displayName: "PersonalInfoForm",
enableReinitialize: true,
mapPropsToValues: (props) => {
return props.data?.personalInfo ?? PERSONAL_INFO_EMPTY_VALUES;
},
// validationSchema: PersonalInfoValidationSchema,
handleSubmit: async (values, bag: FormikBag<PersonalInfoFormProps, PersonalInfoFormValues>) => {
const { props, setSubmitting } = bag;
props.update({ personalInfo: values });
// برو مرحله بعد
props.setStep((prev) => prev + 1);
setSubmitting(false);
},
})(InnerPersonalInfoForm);
export default PersonalInfoForm;