import { Box, Button, MenuItem, Paper, TextField, Typography, } from "@mui/material"; import { ErrorMessage, Form, FormikProps } from "formik"; import { IdentityFormValues } from "@/core/types"; import { IdentityFormProps } from "./IdentityForm"; import { UploadFile } from "@mui/icons-material"; import { genderOptions, religionOptions } from "@/core/constant"; import { useState } from "react"; export default function InnerIdentityForm( props: FormikProps & IdentityFormProps, ) { console.log(props.data) const handleBack = () => { // قبل از رفتن به عقب، مقادیر فعلی فرم را در استیت والد ذخیره کن props.update({ identity: props.values }); props.setStep(props.step - 1); }; const [profilePhoto, setProfilePhoto] = useState(null); const [profilePhotoError, setProfilePhotoError] = useState(""); const handleProfilePhotoChange = ( event: React.ChangeEvent, ) => { const file = event.target.files?.[0]; if (!file) return; if (!file.type.startsWith("image/")) { setProfilePhoto(null); setProfilePhotoError("فقط فایل تصویری مجاز است"); return; } const maxSize = 500 * 1024; // 500KB if (file.size > maxSize) { setProfilePhoto(null); setProfilePhotoError("حجم عکس باید حداکثر ۵۰۰ کیلوبایت باشد"); return; } setProfilePhoto(file); setProfilePhotoError(""); }; return (
props.setFieldValue("firstName", e.target.value) } error={!!props.errors.firstName} helperText={props.errors.firstName} fullWidth required />
props.setFieldValue("lastName", e.target.value)} error={!!props.errors.lastName} helperText={props.errors.lastName} fullWidth required /> props.setFieldValue("fatherName", e.target.value) } fullWidth /> props.setFieldValue("nationalCode", e.target.value) } error={!!props.errors.nationalCode} helperText={props.errors.nationalCode} fullWidth required /> {/* props.setFieldValue("birthDate", newValue) } slotProps={{ textField: { fullWidth: true, error: !!props.errors.birthDate, helperText: props.errors.birthDate, }, }} /> */} props.setFieldValue("birthPlace", e.target.value) } fullWidth /> props.setFieldValue("gender", e.target.value)} error={!!props.errors.gender} helperText={props.errors.gender} fullWidth required > {genderOptions.map((item) => ( {item.label} ))} props.setFieldValue("religion", e.target.value)} fullWidth > {religionOptions.map((item) => ( {item} ))} props.setFieldValue("nationality", e.target.value) } error={!!props.errors.nationality} helperText={props.errors.nationality} fullWidth required /> عکس پرسنلی فقط فایل تصویری مجاز است و حجم آن باید حداکثر ۵۰۰ کیلوبایت باشد. {profilePhoto && ( فایل انتخاب‌شده: {profilePhoto.name} )} {profilePhotoError && ( {profilePhotoError} )}
); }