import React, { useContext, useState } from 'react' import { Box, Input, Radio, RadioGroup, Select, SimpleGrid, Stack, Textarea, FormControl, FormLabel, FormErrorMessage, InputGroup, InputLeftElement, InputRightElement } from '@chakra-ui/react' import { MDBBtn, MDBInputGroup, MDBInputGroupText, } from 'mdb-react-ui-kit' import { FiUser, FiPhone, FiCalendar, FiHome, FiBriefcase, FiHeart } from 'react-icons/fi' import { useForm, Controller } from 'react-hook-form' import { HandleFormReq } from '../../../../lib/HandleFormReq' import axios from 'axios' import { AppProduction } from '../../../../lib/api' // آیکون سفارشی const FieldIcon = ({ icon: Icon }) => ( ) // کامپوننت فیلد ورودی const FormField = ({ label, icon: Icon, error, children, isRequired = false, helpText }) => ( {label && ( {label} )} {Icon && ( )} {children} {error && ( {error} )} {helpText && !error && ( {helpText} )} ) // کامپوننت Select با Controller - حل مشکل theme const FormSelect = ({ label, options, error, name, control, placeholder = "انتخاب کنید", isRequired = false, defaultValue = "" }) => ( {label && ( {label} )} ( )} /> {error && ( {error} )} ) // کامپوننت Radio Group const FormRadioGroup = ({ label, options, name, control, error }) => ( {label && ( {label} )} ( {options.map(opt => ( {opt.label} ))} )} /> {error && ( {error} )} ) // آپشن‌های عددی const numberOptions = (min, max) => { const options = [] for (let i = min; i <= max; i++) { options.push({ value: String(i), label: String(i) }) } return options } const PersonData = () => { const { setPage, personData, setpersondata } = useContext(HandleFormReq) const [sex, setSex] = useState(personData.gender || '1') const [health, setHealth] = useState(personData.health || '1') const [isSubmitting, setIsSubmitting] = useState(false) const { register, handleSubmit, control, watch, setValue, formState: { errors } } = useForm({ defaultValues: { firstname: personData.firstname || '', lastname: personData.lastname || '', fatherName: personData.fatherName || '', wifeJob: personData.wifeJob || '', childIndex: personData.childIndex ?? 0, dependants: personData.dependants ?? 0, Insurance: personData.Insurance || '', national_code: personData.national_code || '', placenational: personData.placenational || '', phone: personData.phone || '', mobile_number: personData.mobile_number || '', birthday: personData.birthday || '', gender: personData.gender || '1', degree: personData.degree || '', marital: personData.marital || '', military: personData.military || '', health: personData.health || '1', healthreason: personData.healthreason || '', address: personData.address || '', } }) // گزینه‌ها const insuranceOptions = [ { value: '1', label: 'بیمه تامین اجتماعی' }, { value: '2', label: 'بیمه خدمات درمانی' }, { value: '3', label: 'بیمه سلامت' }, { value: '4', label: 'بیمه نیروهای مسلح' }, { value: '5', label: 'بدون بیمه' }, ] const educationOptions = [ { value: '0', label: 'زیر دیپلم' }, { value: '1', label: 'دیپلم' }, { value: '5', label: 'فوق دیپلم' }, { value: '2', label: 'لیسانس' }, { value: '3', label: 'فوق لیسانس' }, { value: '4', label: 'دکتری' }, ] const maritalOptions = [ { value: '1', label: 'مجرد' }, { value: '2', label: 'متاهل' }, ] const militaryOptions = [ { value: '1', label: 'معافیت' }, { value: '2', label: 'مشمول' }, { value: '3', label: 'پایان خدمت' }, ] const healthOptions = [ { value: '1', label: 'ندارم' }, { value: '2', label: 'دارم' }, ] const onSubmit = async data => { setIsSubmitting(true) try { const res = await axios.post(`${AppProduction}public/jobrequest/nationalcode`, { nationalcode: data.national_code }) if (res.data.status === false) { alert('کد ملی شما قبلاً ثبت شده است') } else { setpersondata(data) setPage(2) } } catch (err) { console.error('خطا در ارسال فرم:', err) alert('خطا در ارتباط با سرور. لطفاً دوباره تلاش کنید.') } finally { setIsSubmitting(false) } } return (
اطلاعات فردی
{/* ===== بخش اطلاعات شخصی ===== */}
اطلاعات شخصی
{/* ===== بخش شناسایی ===== */}
اطلاعات شناسایی
{/* ===== بخش وضعیت ===== */}
وضعیت شخصی
{/* جنسیت - با useState مدیریت می‌شود */} {/* نظام وظیفه - فقط برای مردان */} {sex === '1' && (
)}
{/* ===== بخش خانواده ===== */}
اطلاعات خانوادگی
{/* ===== بخش سلامت ===== */}
وضعیت سلامت
{health === '2' && (
)}
{/* ===== آدرس ===== */}
آدرس محل سکونت