import React from "react"; import { Box, Paper, TextField, Typography, Switch, FormControlLabel, MenuItem, Grid, } from "@mui/material"; import { DatePicker } from "@mui/x-date-pickers"; import { format } from "date-fns-jalali"; // برای تبدیل تاریخ به رشته استاندارد // --- Types --- export interface JobInfoFormData { readyToWorkDate: string; // YYYY-MM-DD isCurrentEmployee: boolean; hasPastCooperation: boolean; isCurrentlyEmployed: boolean; dualJobInterest: boolean; retirementStatus: "None" | "Retired" | "Redeemed"; isMilitary: boolean; hasInsurance: boolean; insuranceType: string; totalInsuranceYears: string; } interface Props { value: JobInfoFormData; onChange: (next: JobInfoFormData) => void; } export default function JobInfoForm({ value, onChange }: Props) { const setField = (key: keyof JobInfoFormData) => (e: any) => { onChange({ ...value, [key]: e.target.value }); }; const setSwitch = (key: keyof JobInfoFormData) => (e: React.ChangeEvent) => { const checked = e.target.checked; const next = { ...value, [key]: checked }; // پاکسازی فیلدهای وابسته بیمه در صورت غیرفعال شدن if (key === "hasInsurance" && !checked) { next.insuranceType = ""; next.totalInsuranceYears = "0"; } onChange(next); }; const handleDateChange = (date: Date | null) => { if (date) { // تبدیل تاریخ جاوا اسکریپت به فرمت YYYY-MM-DD برای دیتابیس const formattedDate = format(date, "yyyy-MM-dd"); onChange({ ...value, readyToWorkDate: formattedDate }); } }; return ( {/* وضعیت بازنشستگی */} هیچکدام بازنشسته بازخرید {/* Switch Buttons */} } label="از پرسنل حال حاضر هستم" /> } label="سابقه همکاری در گذشته دارم" /> } label="در حال حاضر مشغول به کار هستم" /> } label="تمایل به شغل دوم دارم" /> } label="نظامی هستم" /> } label="دارای سابقه بیمه هستم" /> {/* Conditional Insurance Fields */} {value?.hasInsurance && ( <> )} ); }