From 62670863a1a738dedce19451b715d37823fd2647 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 18 Dec 2023 16:51:18 +0330 Subject: [PATCH] add education and occupation list hook --- public/locales/fa/app.json | 4 +- .../navgan/add-request-loan/forms/AddForm.jsx | 119 ++++++++++++------ src/core/components/MuiDatePicker.jsx | 9 +- src/core/components/PlateNumber.jsx | 63 ++++++---- src/core/data/apiRoutes.js | 2 + src/lib/app/hooks/useEducations.jsx | 34 +++++ src/lib/app/hooks/useOccupations.jsx | 34 +++++ 7 files changed, 202 insertions(+), 63 deletions(-) create mode 100644 src/lib/app/hooks/useEducations.jsx create mode 100644 src/lib/app/hooks/useOccupations.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 2c0b598..d4ac905 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -145,11 +145,13 @@ "national_code_positive": "کد ملی می بایست مثبت باشد", "uploading_documents": "اسناد", "error_message_name": "لطفا نام خود را وارد کنید!", + "error_message_plate_number": "لطفا شماره پلاک را به درستی وارد کنید!", "error_message_tel_number": "لطفا شماره ثابت (با پیش شماره استان) خود را وارد کنید!", "error_message_vehicle_type": "لطفا نوع وسیله نقلیه خود را وارد کنید!", - "error_message_navgan_id": "لطفا کد هوشمند خود را وارد کنید!", + "error_message_navgan_id": "لطفا کد هوشمند ناوگان خود را وارد کنید!", "error_message_province_id": "لطفا استان خود را وارد کنید!", "error_message_national_id": "لطفا کد ملی خود را وارد کنید!", + "error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!", "error_message_shenasname_serial": "لطفا سریال پشت کارت ملی خود را وارد کنید!", "error_message_postal_code": "لطفا کد پستی خود را وارد کنید!", "error_message_national_code": "لطفا کد ملی خود را وارد کنید!", diff --git a/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx index cda3e80..9bce099 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx @@ -10,6 +10,8 @@ import useProvince from "@/lib/app/hooks/useProvince"; import useCities from "@/lib/app/hooks/useCities"; import PlateNumber from "@/core/components/PlateNumber"; import MuiDatePicker from "@/core/components/MuiDatePicker"; +import UseEducations from "@/lib/app/hooks/useEducations"; +import useOccupations from "@/lib/app/hooks/useOccupations"; const AddFormComponent = () => { const t = useTranslations(); @@ -17,28 +19,32 @@ const AddFormComponent = () => { const requestServer = useRequest() const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince() const {cityTextField, cityList, setProvinceID} = useCities() + const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations() + const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations() const initialValues = { - tel_number: "", + telephone_number: "", vehicle_type: "", plate_number: "", province_id: "", city_id: "", navgan_id: "", - national_code: "", + national_id: "", shenasname_serial: "", postal_code: "", navgan_type: "", plate_part1: "", - plate_part2: "", + plate_part2: "الف", plate_part3: "", plate_part4: "", address: "", - date_of_birth: "", + birthday: "", + education_id: "", + occupation_id: "", }; const validationSchema = Yup.object().shape({ - tel_number: Yup.mixed() + telephone_number: Yup.mixed() .test("max", `${t("LoanRequest.tel_number_max")}`, (value) => value.toString().length === 11) .required(t("LoanRequest.error_message_tel_number")), vehicle_type: Yup.string().required( @@ -47,10 +53,16 @@ const AddFormComponent = () => { navgan_type: Yup.string().required( t("LoanRequest.error_message_navgan_type") ), + occupation_id: Yup.string().required( + t("LoanRequest.error_message_occupation_id") + ), + education_id: Yup.string().required( + t("LoanRequest.error_message_education_id") + ), address: Yup.string().required( t("LoanRequest.error_message_address") ), - date_of_birth: Yup.string().required( + birthday: Yup.string().required( t("LoanRequest.error_message_date_of_birth") ), postal_code: Yup.mixed() @@ -59,35 +71,32 @@ const AddFormComponent = () => { t("LoanRequest.error_message_postal_code") ), plate_part1: Yup.mixed() - .test("max", `${t("LoanRequest.plate_part1_max")}`, (value) => value.toString().length === 2) .required( - t("LoanRequest.error_message_plate_part1") + t("LoanRequest.error_message_plate_number") ), plate_part2: Yup.mixed() .required( - t("LoanRequest.error_message_plate_part2") + t("LoanRequest.error_message_plate_number") ), plate_part3: Yup.mixed() - .test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2) .required( - t("LoanRequest.error_message_plate_part3") + t("LoanRequest.error_message_plate_number") ), plate_part4: Yup.mixed() - .test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2) .required( - t("LoanRequest.error_message_plate_part3") + t("LoanRequest.error_message_plate_number") ), navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")), province_id: Yup.string().required(t("LoanRequest.error_message_province_id")), city_id: Yup.string().required(t("LoanRequest.error_message_city_id")), - national_code: Yup.mixed() + national_id: Yup.mixed() .test("is-number", `${t("LoanRequest.national_code_number")}`, (value) => !isNaN(value)) .test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0) .test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10) .required(t("LoanRequest.error_message_national_id")), shenasname_serial: Yup.mixed() - .test("max", `${t("LoanRequest.shenasname_serial_max")}`, (value) => value.toString().length === 11) + .test("max", `${t("LoanRequest.shenasname_serial_max")}`, (value) => value.toString().length === 10) .required(t("LoanRequest.error_message_shenasname_serial") ), }); @@ -95,7 +104,7 @@ const AddFormComponent = () => { const handleSubmit = async (values, props) => { const formData = new FormData(); - formData.append("tel_number", values.tel_number); + formData.append("telephone_number", values.telephone_number); formData.append("navgan_type", values.navgan_type); formData.append("postal_code", values.postal_code); formData.append("vehicle_type", values.vehicle_type); @@ -104,9 +113,11 @@ const AddFormComponent = () => { formData.append("city_id", values.city_id); formData.append("address", values.address); formData.append("navgan_id", values.navgan_id); - formData.append("national_code", values.national_code); - formData.append("date_of_birth", values.date_of_birth); + formData.append("national_id", values.national_id); + formData.append("birthday", values.birthday); formData.append("shenasname_serial", values.shenasname_serial); + formData.append("education_id", values.education_id); + formData.append("occupation_id", values.occupation_id); requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {auth: true, notification: true}).then().catch(() => { props.setSubmitting(false) @@ -124,7 +135,7 @@ const AddFormComponent = () => { > { placeholder={t( "LoanRequest.text_field_enter_your_national_code" )} - onBlur={formik.handleBlur("national_code")} - error={formik.touched.national_code && Boolean(formik.errors.national_code)} - helperText={formik.touched.national_code && formik.errors.national_code} + onBlur={formik.handleBlur("national_id")} + error={formik.touched.national_id && Boolean(formik.errors.national_id)} + helperText={formik.touched.national_id && formik.errors.national_id} fullWidth /> @@ -159,9 +170,9 @@ const AddFormComponent = () => { @@ -185,7 +196,7 @@ const AddFormComponent = () => { { "LoanRequest.text_field_enter_your_tel_number" )} fullWidth - onBlur={formik.handleBlur("tel_number")} - error={formik.touched.tel_number && Boolean(formik.errors.tel_number)} - helperText={formik.touched.tel_number && formik.errors.tel_number} + onBlur={formik.handleBlur("telephone_number")} + error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)} + helperText={formik.touched.telephone_number && formik.errors.telephone_number} /> @@ -208,11 +219,7 @@ const AddFormComponent = () => { label={t("LoanRequest.text_field_navgan_type")} size="small" selectType="navgan_type" - selectors={[{id: 1, value: 1, name: "مسافری"}, {id: 2, value: 2, name: "عمومی"}, { - id: 3, - value: 3, - name: "روستایی" - }]} + selectors={[{id: 1, value: 1, name: "روستایی"}, {id: 2, value: 2, name: "عمومی"}]} select={formik.values.navgan_type} handleChange={(event) => { formik.setFieldValue('navgan_type', event.target.value) @@ -287,8 +294,8 @@ const AddFormComponent = () => { label={t("LoanRequest.text_field_vehicle_type")} size="small" selectType="vehicle_type" - selectors={[{id: 0, value: 0, name: "اتوبوس"}, - {id: 1, value: 1, name: "مینی بوس"}]} + selectors={[{id: 0, value: "اتوبوس", name: "اتوبوس"}, + {id: 1, value: "مینی بوس", name: "مینی بوس"}]} select={formik.values.vehicle_type} handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)} error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)} @@ -300,6 +307,46 @@ const AddFormComponent = () => { + + + { + formik.setFieldValue('education_id', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.education_id && Boolean(formik.errors.education_id)} + helperText={formik.touched.education_id && formik.errors.education_id} + onBlur={formik.handleBlur("education_id")} + /> + + + { + formik.setFieldValue('occupation_id', event.target.value) + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)} + helperText={formik.touched.occupation_id && formik.errors.occupation_id} + onBlur={formik.handleBlur("occupation_id")} + /> + + { - formik.setFieldValue("date_of_birth", newValue) + formik.setFieldValue("birthday", newValue) setValue(newValue) }} /> - {formik.touched.date_of_birth && formik.errors.date_of_birth} + {formik.touched.birthday && formik.errors.birthday} ); } \ No newline at end of file diff --git a/src/core/components/PlateNumber.jsx b/src/core/components/PlateNumber.jsx index 292b764..cbe0e7b 100644 --- a/src/core/components/PlateNumber.jsx +++ b/src/core/components/PlateNumber.jsx @@ -1,4 +1,4 @@ -import {Box, Button, Drawer, FormHelperText, InputBase, Stack} from "@mui/material"; +import {Box, Button, Drawer, FormHelperText, Stack, TextField} from "@mui/material"; import {useTranslations} from "next-intl"; import AccessibleIcon from '@mui/icons-material/Accessible'; import {useState} from "react"; @@ -123,36 +123,54 @@ const plate_words = [ const PlateNumber = ({formik}) => { const t = useTranslations(); const [plateDrawer, setPlateDrawer] = useState(false); - const [selectedWordName, setSelectedWordName] = useState("الف"); - const [selectedWordValue, setSelectedWordValue] = useState(""); - + const isValidPlate = Boolean(formik.errors.plate_part1 || formik.errors.plate_part3 || formik.errors.plate_part4) return ( <> - + event.target.value.length <= 2 ? formik.setFieldValue("plate_part4", event.target.value) : null} size={'small'} - placeholder={'xx'} sx={{flexGrow: 2}} - inputProps={{sx: {textAlign: 'center'}}}/> - + event.target.value.length <= 3 ? formik.setFieldValue("plate_part3", event.target.value) : null} - size={'small'} placeholder={'xxx'} sx={{ - flexGrow: 3, borderLeft: 1, borderRadius: 0, borderColor: 'divider' - }} inputProps={{sx: {textAlign: 'center'}}}/> + size={'small'} + placeholder={'xxx'} + sx={{ + flexGrow: 3, + borderLeft: 1, + borderRadius: 0, + borderColor: 'divider', + "& fieldset": {border: 'none'} + }} + inputProps={{sx: {textAlign: 'center'}}} + onChange={formik.handleChange} + onBlur={formik.handleBlur("plate_part3")} + error={formik.touched.plate_part3 && Boolean(formik.errors.plate_part3)} + /> {