// InnerPersonalInfoForm.tsx "use client"; import React from "react"; import { Box, Button, MenuItem, TextField } from "@mui/material"; import { Form, type FormikProps } from "formik"; import { MilitaryStatus, PersonalInfoFormValues } from "./types"; import { EDUCATION_OPTIONS, HOUSING_OPTIONS, MILITARY_OPTIONS, } from "./constants"; import { PersonalInfoFormProps } from "./PersonalInfoForm"; import { handleBack } from "@/core/utils"; type Props = FormikProps & PersonalInfoFormProps; export default function InnerPersonalInfoForm(props: Props) { const { values, errors, touched, setFieldValue, handleChange } = props; const showSpouseFields = values.maritalStatus === "متاهل"; const showChildrenCount = ["متاهل", "متارکه", "فوت همسر"].includes( values.maritalStatus, ); const isPermanentExempt = values.militaryStatus === "معافیت دائم"; const handleMaritalStatusChange = ( e: React.ChangeEvent, ) => { const status = e.target.value; setFieldValue("maritalStatus", status); // پاکسازی شرطی‌ها const isMarried = status === "متاهل"; const hasChildren = ["متاهل", "متارکه", "فوت همسر"].includes(status); if (!isMarried) { setFieldValue("spouseName", ""); setFieldValue("spouseEducation", ""); setFieldValue("spouseJob", ""); setFieldValue("spouseWorkplace", ""); } if (!hasChildren) { setFieldValue("childrenCount", ""); } }; const handleMilitaryStatusChange = ( e: React.ChangeEvent, ) => { const ms = e.target.value as MilitaryStatus; setFieldValue("militaryStatus", ms); if (ms !== "معافیت دائم") { setFieldValue("permanentExemptionReason", ""); } }; const tf = (name: K) => ({ name: String(name), value: values[name] as any, onChange: handleChange, fullWidth: true, error: !!(touched as any)[name] && !!(errors as any)[name], helperText: (touched as any)[name] ? ((errors as any)[name] as string) : "", }); return (
{/* وضعیت تاهل */} انتخاب کنید مجرد متاهل متارکه فوت همسر {/* همسر (شرطی) */} {showSpouseFields && ( <> )} {/* تعداد فرزند (شرطی) */} {showChildrenCount && ( setFieldValue( "childrenCount", e.target.value === "" ? "" : Number(e.target.value), ) } fullWidth error={!!touched.childrenCount && !!errors.childrenCount} helperText={ touched.childrenCount ? (errors.childrenCount as string) : "" } /> )} {/* وضعیت نظام وظیفه */} انتخاب کنید {MILITARY_OPTIONS.map((opt) => ( {opt} ))} {/* علت معافیت دائم */} {isPermanentExempt && ( )} {/* تحصیلات پدر/مادر */} انتخاب کنید {EDUCATION_OPTIONS.map((opt) => ( {opt} ))} انتخاب کنید {EDUCATION_OPTIONS.map((opt) => ( {opt} ))} {/* وضعیت مسکن / شهر / آدرس */} انتخاب کنید {HOUSING_OPTIONS.map((opt) => ( {opt} ))} {" "} {/* تلفن‌ها */} {/* مدت سکونت */} setFieldValue( "residenceDuration", e.target.value === "" ? "" : Number(e.target.value), ) } fullWidth error={!!touched.residenceDuration && !!errors.residenceDuration} helperText={ touched.residenceDuration ? (errors.residenceDuration as string) : "" } /> {/* ایثارگر */} setFieldValue("isVeteran", e.target.value === "true") } fullWidth error={!!touched.isVeteran && !!errors.isVeteran} helperText={touched.isVeteran ? (errors.isVeteran as string) : ""} > خیر بله {/* سوءپیشینه */} { const next = e.target.value === "true"; setFieldValue("hasCriminalRecord", next); if (!next) setFieldValue("criminalDescription", ""); }} fullWidth error={!!touched.hasCriminalRecord && !!errors.hasCriminalRecord} helperText={ touched.hasCriminalRecord ? (errors.hasCriminalRecord as string) : "" } > خیر بله {values.hasCriminalRecord && ( )}
); }