From 27e5f65c0580e6ef8635d2eb3f7cde4910fa4adf Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Wed, 17 Apr 2024 16:46:52 +0330 Subject: [PATCH 1/5] get api --- src/components/dashboard/first/index.jsx | 2 +- .../forms/LegalPersonForm.jsx | 53 ++++++++++--------- .../add-request-loan/forms/RealPersonForm.jsx | 53 +++++++++++-------- src/lib/app/hooks/useProjectTitle.jsx | 3 +- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/components/dashboard/first/index.jsx b/src/components/dashboard/first/index.jsx index 826380e..7b42ef9 100644 --- a/src/components/dashboard/first/index.jsx +++ b/src/components/dashboard/first/index.jsx @@ -18,7 +18,7 @@ const FirstComponent = () => { {t("Dashboard.go_to_add_request_loan")} - ) -} -export default LegalPersonForm \ No newline at end of file + ); +}; +export default LegalPersonForm; diff --git a/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx index 4ef40ed..fb32069 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx @@ -1,15 +1,24 @@ -import {Box, Button, Checkbox, FormControlLabel, Grid, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material"; +import { + Box, + Button, + Checkbox, + FormControlLabel, + Grid, + TextField, + ToggleButton, + ToggleButtonGroup, +} from "@mui/material"; import SelectBox from "@/core/components/SelectBox"; import MuiDatePicker from "@/core/components/MuiDatePicker"; -import {useTranslations} from "next-intl"; +import { useTranslations } from "next-intl"; import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; import useCities from "@/lib/app/hooks/useCities"; -import {useFormik} from "formik"; +import { useFormik } from "formik"; import * as Yup from "yup"; import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; -import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes"; -import {useRequest, useUser} from "@witel/webapp-builder"; -import {useRouter} from "next/router"; +import { SEND_LOAN_REQUEST_NAVGAN } from "@/core/data/apiRoutes"; +import { useRequest, useUser } from "@witel/webapp-builder"; +import { useRouter } from "next/router"; import PlateNumber from "@/core/components/PlateNumber"; import * as React from "react"; import UseEducations from "@/lib/app/hooks/useEducations"; @@ -18,22 +27,22 @@ import useActivityType from "@/lib/app/hooks/useActivityType"; import usePriorityLists from "@/lib/app/hooks/usePriorityLists"; import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; -const RealPersonForm = ({setFinishLoanRequest}) => { +const RealPersonForm = ({ setFinishLoanRequest }) => { const t = useTranslations(); - const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince() - const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities() - const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations() - const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations() - const {activityType, isLoadingActivityType, errorActivityType} = useActivityType() - const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists() - const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle() - const requestServer = useRequest() - const {getUser, changeUser} = useUser() - const router = useRouter() + const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); + const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities(); + const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations(); + const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations(); + const { activityType, isLoadingActivityType, errorActivityType } = useActivityType(); + const { priorityLists, isLoadingPriorityLists, errorPriorityLists } = usePriorityLists(); + const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle(); + const requestServer = useRequest(); + const { getUser, changeUser } = useUser(); + const router = useRouter(); const initialValues = { - person_type : "real", - vehicle_type : "", + person_type: "real", + vehicle_type: "", telephone_number: "", activity_type: "", project_title: "", @@ -66,7 +75,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => { telephone_number: Yup.mixed() .test("max", `${t("LoanRequest.tel_number_max")}`, (value) => { const stringValue = String(value); - return stringValue.length === 11 + return stringValue.length === 11; }) .required(t("LoanRequest.error_message_tel_number")), father_name: Yup.string().required(t("LoanRequest.error_message_father_name")), @@ -88,48 +97,75 @@ const RealPersonForm = ({setFinishLoanRequest}) => { city_id: Yup.string().required(t("LoanRequest.error_message_city_id")), first_name: Yup.string().required(t("LoanRequest.error_message_first_name")), last_name: Yup.string().required(t("LoanRequest.error_message_last_name")), - plate_part1: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) + plate_part1: Yup.mixed() + .test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) .required(t("LoanRequest.error_message_plate_number")), - plate_part2: Yup.mixed() + plate_part2: Yup.mixed().required(t("LoanRequest.error_message_plate_number")), + plate_part3: Yup.mixed() + .test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3) .required(t("LoanRequest.error_message_plate_number")), - plate_part3: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3) - .required(t("LoanRequest.error_message_plate_number")), - plate_part4: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) + plate_part4: Yup.mixed() + .test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2) .required(t("LoanRequest.error_message_plate_number")), national_code: 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")), - national_number: Yup.mixed().when('person_type', ([person_type], schema) => { - return person_type === 'legal' ? schema - .test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value)) - .test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0) - .test("max", `${t("LoanRequest.national_number_max")}`, (value) => value && value.toString().length === 11) - .required(t("LoanRequest.error_message_national_number")) : schema; - }), - national_serial_number: Yup.string().test("max", `${t("LoanRequest.national_serial_number_max")}`, (value) => value && value.toString().length === 10).when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'national_serial_number' ? schema.required(t("LoanRequest.error_message_shenasname_serial")) : schema - }), - national_card_tracking_code: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'national_card_tracking_code' ? schema.required(t("LoanRequest.error_message_tracking_code")) : schema + national_number: Yup.mixed().when("person_type", ([person_type], schema) => { + return person_type === "legal" + ? schema + .test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value)) + .test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0) + .test( + "max", + `${t("LoanRequest.national_number_max")}`, + (value) => value && value.toString().length === 11 + ) + .required(t("LoanRequest.error_message_national_number")) + : schema; }), + national_serial_number: Yup.string() + .test( + "max", + `${t("LoanRequest.national_serial_number_max")}`, + (value) => value && value.toString().length === 10 + ) + .when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "national_serial_number" + ? schema.required(t("LoanRequest.error_message_shenasname_serial")) + : schema; + }), + national_card_tracking_code: Yup.string().when( + "national_serial_number_or_tracking_code", + ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "national_card_tracking_code" + ? schema.required(t("LoanRequest.error_message_tracking_code")) + : schema; + } + ), }); const handleSubmit = async (values, props) => { - props.setSubmitting(true) - let _national_number = values.person_type === "legal" ? { - shenase_meli: values.national_number - } : {} + props.setSubmitting(true); + let _national_number = + values.person_type === "legal" + ? { + shenase_meli: values.national_number, + } + : {}; - const _national_card = values.national_serial_number_or_tracking_code === "national_serial_number" ? { - national_serial_number: values.national_serial_number - } : { - national_tracking_code: values.national_card_tracking_code - } + const _national_card = + values.national_serial_number_or_tracking_code === "national_serial_number" + ? { + national_serial_number: values.national_serial_number, + } + : { + national_tracking_code: values.national_card_tracking_code, + }; let _data = { - is_legal_person: 0, + is_legal_person: 0, telephone_number: values.telephone_number, national_id: values.national_code, vehicle_type: values.vehicle_type, @@ -145,32 +181,44 @@ const RealPersonForm = ({setFinishLoanRequest}) => { address: values.address, education_id: values.education_id, occupation_id: values.occupation_id, - activity_type: values.activity_type, + activity_type_id: values.activity_type, project_title: values.project_title, - priority_list: values.priority_list, - birthday: values.birthday.locale('en').format("YYYY-MM-DD"), ..._national_card, ..._national_number - } + activity_priority_id: values.priority_list, + plate_part1: values.plate_part1, + plate_part2: values.plate_part2, + plate_part3: values.plate_part3, + plate_part4: values.plate_part4, + birthday: values.birthday.locale("en").format("YYYY-MM-DD"), + ..._national_card, + ..._national_number, + }; await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", { - auth: true, notification: true, data: _data - }).then(() => { - router.replace('/dashboard/navgan/followUp-loan') - getUser((data) => { - changeUser(data); - }); - }).catch(() => { - }).finally(() => { - props.setSubmitting(false) + auth: true, + notification: true, + data: _data, }) + .then(() => { + router.replace("/dashboard/navgan/followUp-loan"); + getUser((data) => { + changeUser(data); + }); + }) + .catch(() => {}) + .finally(() => { + props.setSubmitting(false); + }); }; const formik = useFormik({ - initialValues, validationSchema, onSubmit: handleSubmit - }) + initialValues, + validationSchema, + onSubmit: handleSubmit, + }); return ( <> - + { isLoading={isLoadingProjectTitle} errorEcured={errorProjectTitle} selectors={projectTitle} - schema={{value: 'value', name: 'name'}} + schema={{ value: "name", name: "name" }} select={formik.values.project_title} value={formik.values.project_title} handleChange={(event) => { - formik.setFieldValue('project_title', event.target.value) + formik.setFieldValue("project_title", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.project_title && Boolean(formik.errors.project_title)} @@ -201,11 +249,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingActivityType} errorEcured={errorActivityType} selectors={activityType} - schema={{value: 'value', name: 'name'}} + schema={{ value: "value", name: "name" }} select={formik.values.activity_type} value={formik.values.activity_type} handleChange={(event) => { - formik.setFieldValue('activity_type', event.target.value) + formik.setFieldValue("activity_type", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} @@ -222,11 +270,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingPriorityLists} errorEcured={errorPriorityLists} selectors={priorityLists} - schema={{value: 'value', name: 'name'}} + schema={{ value: "value", name: "name" }} select={formik.values.priority_list} value={formik.values.priority_list} handleChange={(event) => { - formik.setFieldValue('priority_list', event.target.value) + formik.setFieldValue("priority_list", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} @@ -235,21 +283,22 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + { - if (value === null) return + if (value === null) return; formik.handleChange({ target: { - name: "national_serial_number_or_tracking_code", value: value, + name: "national_serial_number_or_tracking_code", + value: value, }, - }) + }); }} > @@ -260,11 +309,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => { - {formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? ( - + {formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? ( + { fullWidth onChange={formik.handleChange} onBlur={formik.handleBlur("national_serial_number")} - error={formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number)} + error={ + formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number) + } helperText={formik.touched.national_serial_number && formik.errors.national_serial_number} /> - ) : ( + + ) : ( { fullWidth onChange={formik.handleChange} onBlur={formik.handleBlur("national_card_tracking_code")} - error={formik.touched.national_card_tracking_code && Boolean(formik.errors.national_card_tracking_code)} - helperText={formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code} + error={ + formik.touched.national_card_tracking_code && + Boolean(formik.errors.national_card_tracking_code) + } + helperText={ + formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code + } /> )} { const inputValue = event.target.value; if (isNaN(Number(inputValue))) { @@ -311,7 +367,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "national_code", value: inputValue, + name: "national_code", + value: inputValue, }, }); }} @@ -324,10 +381,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + { { /> - + { size="small" value={formik.values.gender} selectType="gender" - selectors={[{ - id: 1, value: 1, name: "زن" - }, { - id: 2, value: 0, name: "مرد" - }]} - schema={{value: 'value', name: 'name'}} + selectors={[ + { + id: 1, + value: 1, + name: "زن", + }, + { + id: 2, + value: 0, + name: "مرد", + }, + ]} + schema={{ value: "value", name: "name" }} select={formik.values.gender} handleChange={(event) => { - formik.setFieldValue('gender', event.target.value) + formik.setFieldValue("gender", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.gender && Boolean(formik.errors.gender)} @@ -407,15 +471,15 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + { const inputValue = event.target.value; if (isNaN(Number(inputValue))) { @@ -423,7 +487,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "postal_code", value: inputValue, + name: "postal_code", + value: inputValue, }, }); }} @@ -438,12 +503,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => { { const inputValue = event.target.value; @@ -452,7 +517,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => { } formik.handleChange({ target: { - name: "telephone_number", value: inputValue, + name: "telephone_number", + value: inputValue, }, }); }} @@ -465,7 +531,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + { size="small" value={formik.values.navgan_type} selectType="navgan_type" - selectors={[{ - id: 1, value: "روستایی", name: "روستایی" - }, { - id: 2, value: "عمومی", name: "عمومی" - }, { - id: 3, value: "منطقه آزاد", name: "منطقه آزاد" - }]} - schema={{value: 'value', name: 'name'}} + selectors={[ + { + id: 1, + value: "روستایی", + name: "روستایی", + }, + { + id: 2, + value: "عمومی", + name: "عمومی", + }, + { + id: 3, + value: "منطقه آزاد", + name: "منطقه آزاد", + }, + ]} + schema={{ value: "value", name: "name" }} select={formik.values.navgan_type} handleChange={(event) => { - formik.setFieldValue('navgan_type', event.target.value) + formik.setFieldValue("navgan_type", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} @@ -493,11 +569,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => { { /> - + { isLoading={isLoadingProvinceList} errorEcured={errorProvinceList} selectors={provinceList} - schema={{value: 'value', name: 'name'}} + schema={{ value: "value", name: "name" }} select={formik.values.province_id} value={formik.values.province_id} handleChange={(event) => { - formik.setFieldValue('province_id', event.target.value); - setProvinceID(event.target.value) + formik.setFieldValue("province_id", event.target.value); + setProvinceID(event.target.value); formik.setFieldTouched("city_id", false, false); - formik.setFieldValue("city_id", "") + formik.setFieldValue("city_id", ""); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.province_id && Boolean(formik.errors.province_id)} @@ -538,15 +614,21 @@ const RealPersonForm = ({setFinishLoanRequest}) => { formik.setFieldValue('city_id', event.target.value)} + handleChange={(event) => formik.setFieldValue("city_id", event.target.value)} setFieldTouched={formik.setFieldTouched} error={formik.touched.city_id && Boolean(formik.errors.city_id)} helperText={formik.touched.city_id && formik.errors.city_id} @@ -554,32 +636,39 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + formik.setFieldValue('vehicle_type', event.target.value)} + handleChange={(event) => formik.setFieldValue("vehicle_type", event.target.value)} error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)} helperText={formik.touched.vehicle_type && formik.errors.vehicle_type} onBlur={formik.handleBlur("vehicle_type")} /> - + - + { selectors={educationsList} select={formik.values.education_id} value={formik.values.education_id} - schema={{value: 'id', name: 'title'}} + schema={{ value: "id", name: "title" }} handleChange={(event) => { - formik.setFieldValue('education_id', event.target.value) + formik.setFieldValue("education_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.education_id && Boolean(formik.errors.education_id)} @@ -609,12 +698,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => { isLoading={isLoadingOccupationsList} errorEcured={errorOccupationsList} selectType="occupation_id" - schema={{value: 'id', name: 'title'}} + schema={{ value: "id", name: "title" }} selectors={occupationsList} select={formik.values.occupation_id} value={formik.values.occupation_id} handleChange={(event) => { - formik.setFieldValue('occupation_id', event.target.value) + formik.setFieldValue("occupation_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)} @@ -623,12 +712,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => { /> - + { /> - + { - formik.setFieldValue("checkedBox", event.target.checked) - }} - />} - label={`${t("LoanRequest.checkbox")}`}/> - + color={"error.main"} + control={ + { + formik.setFieldValue("checkedBox", event.target.checked); + }} + /> + } + label={`${t("LoanRequest.checkbox")}`} + /> - ) -} -export default RealPersonForm \ No newline at end of file + ); +}; +export default RealPersonForm; diff --git a/src/lib/app/hooks/useProjectTitle.jsx b/src/lib/app/hooks/useProjectTitle.jsx index bef25e1..31cbb35 100644 --- a/src/lib/app/hooks/useProjectTitle.jsx +++ b/src/lib/app/hooks/useProjectTitle.jsx @@ -1,34 +1,36 @@ -import {GET_PROJECT_TITLE} from "@/core/data/apiRoutes"; -import {useRequest} from "@witel/webapp-builder"; -import {useEffect, useState} from "react"; +import { GET_PROJECT_TITLE } from "@/core/data/apiRoutes"; +import { useRequest } from "@witel/webapp-builder"; +import { useEffect, useState } from "react"; const useProjectTitle = () => { - const [isLoadingProjectTitle, setIsLoadingProjectTitle] = useState(false) - const [errorProjectTitle, setErrorProjectTitle] = useState(false) - const [projectTitle, setProjectTitle] = useState([]) - const requestServer = useRequest({auth: true, notification: false}) + const [isLoadingProjectTitle, setIsLoadingProjectTitle] = useState(false); + const [errorProjectTitle, setErrorProjectTitle] = useState(false); + const [projectTitle, setProjectTitle] = useState([]); + const requestServer = useRequest({ auth: true, notification: false }); useEffect(() => { - setIsLoadingProjectTitle(true) - requestServer(GET_PROJECT_TITLE, 'get', {auth: true, notification: false}).then(({data}) => { - const formattedData = data.data.map((projectTitle, index) => ({ - id: index, - name: projectTitle.title, - value: projectTitle.id, - })); - setIsLoadingProjectTitle(false) - setProjectTitle(formattedData); - }).catch(() => { - setIsLoadingProjectTitle(false) - setErrorProjectTitle(true) - }) - }, []) + setIsLoadingProjectTitle(true); + requestServer(GET_PROJECT_TITLE, "get", { auth: true, notification: false }) + .then(({ data }) => { + const formattedData = data.data.map((projectTitle, index) => ({ + id: index, + name: projectTitle.title, + value: projectTitle.id, + })); + setIsLoadingProjectTitle(false); + setProjectTitle(formattedData); + }) + .catch(() => { + setIsLoadingProjectTitle(false); + setErrorProjectTitle(true); + }); + }, []); return { projectTitle, isLoadingProjectTitle, - errorProjectTitle - } + errorProjectTitle, + }; }; -export default useProjectTitle; \ No newline at end of file +export default useProjectTitle; From ce4ef177041056b9ed17975b07eada1fd28ece33 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sat, 20 Apr 2024 10:07:04 +0330 Subject: [PATCH 3/5] validation on national traking code --- public/locales/fa/app.json | 4 + .../forms/LegalPersonForm.jsx | 173 +++++++++--------- .../add-request-loan/forms/RealPersonForm.jsx | 161 ++++++++-------- 3 files changed, 176 insertions(+), 162 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 5486303..e03dc76 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -161,6 +161,9 @@ "national_number_number": "شناسه ملی شرکت می بایست شامل اعداد باشد", "national_code_max": "کد ملی می بایست 10 رقم باشد", "national_serial_number_max": "سریال پشت کارت ملی می بایست 10 رقم باشد", + "boss_national_serial_number_max": "سریال پشت کارت ملی مدیر عامل می بایست 10 رقم باشد", + "national_tracking_code_max": "کد رهگیری کارت ملی می بایست 10 رقم باشد", + "national_boss_tracking_code_max": "کد رهگیری کارت ملی مدیر عامل می بایست 10 رقم باشد", "boss_national_code_max": "کد ملی مدیر عامل می بایست 10 رقم باشد", "national_number_max": "شناسه ملی شرکت می بایست 11 رقم باشد", "shenasname_serial_max": "سریال پشت کارت ملی می بایست شامل 10 بخش باشد", @@ -196,6 +199,7 @@ "error_message_national_number": "لطفا شناسه ملی شرکت خود را وارد کنید!", "error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!", "error_message_shenasname_serial": "لطفا سریال پشت کارت ملی خود را وارد کنید!", + "error_message_boss_shenasname_serial": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", "error_message_boss_national_serial_number": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", "error_message_tracking_code": "لطفا کد رهگیری کارت ملی خود را وارد کنید!", "error_message_boss_national_card_tracking_code": "لطفا کد رهگیری کارت ملی مدیر عامل را وارد کنید!", diff --git a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx index 2c5065d..33368d8 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx @@ -8,7 +8,7 @@ import { ToggleButton, ToggleButtonGroup, } from "@mui/material"; -import { useTranslations } from "next-intl"; +import {useTranslations} from "next-intl"; import useCities from "@/lib/app/hooks/useCities"; import UseEducations from "@/lib/app/hooks/useEducations"; import useOccupations from "@/lib/app/hooks/useOccupations"; @@ -16,29 +16,29 @@ import * as React from "react"; import SelectBox from "@/core/components/SelectBox"; import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince"; import PlateNumber from "@/core/components/PlateNumber"; -import { useRouter } from "next/router"; -import { useRequest, useUser } from "@witel/webapp-builder"; +import {useRouter} from "next/router"; +import {useRequest, useUser} from "@witel/webapp-builder"; import * as Yup from "yup"; -import { SEND_LOAN_REQUEST_NAVGAN } from "@/core/data/apiRoutes"; +import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes"; import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; -import { useFormik } from "formik"; +import {useFormik} from "formik"; import LegalPersonDatePicker from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker"; import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; import useActivityType from "@/lib/app/hooks/useActivityType"; import usePriorityLists from "@/lib/app/hooks/usePriorityLists"; -const LegalPersonForm = ({ setFinishLoanRequest }) => { +const LegalPersonForm = ({setFinishLoanRequest}) => { const t = useTranslations(); const router = useRouter(); const requestServer = useRequest(); - const { getUser, changeUser } = useUser(); - const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities(); - const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince(); - const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations(); - const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations(); - const { activityType, isLoadingActivityType, errorActivityType } = useActivityType(); - const { priorityLists, isLoadingPriorityLists, errorPriorityLists } = usePriorityLists(); - const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle(); + const {getUser, changeUser} = useUser(); + const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities(); + const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince(); + const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations(); + const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations(); + const {activityType, isLoadingActivityType, errorActivityType} = useActivityType(); + const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists(); + const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle(); const initialValues = { person_type: "legal", @@ -120,32 +120,35 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { national_number: Yup.mixed().when("person_type", ([person_type], schema) => { return person_type === "legal" ? schema - .test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value)) - .test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0) - .test( - "max", - `${t("LoanRequest.national_number_max")}`, - (value) => value && value.toString().length === 11 - ) - .required(t("LoanRequest.error_message_national_number")) + .test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value)) + .test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0) + .test( + "max", + `${t("LoanRequest.national_number_max")}`, + (value) => value && value.toString().length === 11 + ) + .required(t("LoanRequest.error_message_national_number")) : schema; }), boss_national_serial_number: Yup.string() - .test( - "max", - `${t("LoanRequest.national_serial_number_max")}`, - (value) => value && value.toString().length === 10 - ) .when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => { return national_serial_number_or_tracking_code === "national_serial_number" - ? schema.required(t("LoanRequest.error_message_shenasname_serial")) + ? schema.test( + "max", + `${t("LoanRequest.boss_national_serial_number_max")}`, + (value) => value && value.toString().length === 10 + ).required(t("LoanRequest.error_message_boss_shenasname_serial")) : schema; }), boss_national_card_tracking_code: Yup.string().when( "national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => { return national_serial_number_or_tracking_code === "national_card_tracking_code" - ? schema.required(t("LoanRequest.error_message_boss_national_card_tracking_code")) + ? schema.test( + "max", + `${t("LoanRequest.national_boss_tracking_code_max")}`, + (value) => value && value.toString().length === 10 + ).required(t("LoanRequest.error_message_boss_national_card_tracking_code")) : schema; } ), @@ -156,18 +159,18 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { let _national_number = values.person_type === "legal" ? { - shenase_meli: values.national_number, - } + shenase_meli: values.national_number, + } : {}; const _national_card = values.national_serial_number_or_tracking_code === "national_serial_number" ? { - national_serial_number: values.boss_national_serial_number, - } + national_serial_number: values.boss_national_serial_number, + } : { - national_tracking_code: values.boss_national_card_tracking_code, - }; + national_tracking_code: values.boss_national_card_tracking_code, + }; let _data = { is_legal_person: 1, @@ -194,6 +197,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { plate_part4: values.plate_part4, address: values.address, company_register_date: values.company_date.locale("en").format("YYYY-MM-DD"), + birthday: values.company_date.locale("en").format("YYYY-MM-DD"), education_id: values.education_id, occupation_id: values.occupation_id, ..._national_card, @@ -211,7 +215,8 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { changeUser(data); }); }) - .catch(() => {}) + .catch(() => { + }) .finally(() => { props.setSubmitting(false); }); @@ -224,7 +229,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { }); return ( <> - + { isLoading={isLoadingProjectTitle} errorEcured={errorProjectTitle} selectors={projectTitle} - schema={{ value: "name", name: "name" }} + schema={{value: "name", name: "name"}} select={formik.values.project_title} value={formik.values.project_title} handleChange={(event) => { @@ -255,7 +260,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { isLoading={isLoadingActivityType} errorEcured={errorActivityType} selectors={activityType} - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} select={formik.values.activity_type} value={formik.values.activity_type} handleChange={(event) => { @@ -276,7 +281,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { isLoading={isLoadingPriorityLists} errorEcured={errorPriorityLists} selectors={priorityLists} - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} select={formik.values.priority_list} value={formik.values.priority_list} handleChange={(event) => { @@ -289,15 +294,15 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { const inputValue = event.target.value; @@ -321,7 +326,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { { { const inputValue = event.target.value; @@ -365,14 +370,14 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { const inputValue = event.target.value; @@ -397,11 +402,11 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { { @@ -433,7 +438,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { isLoading={isLoadingProvinceList} errorEcured={errorProvinceList} selectors={provinceList} - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} select={formik.values.province_id} value={formik.values.province_id} handleChange={(event) => { @@ -465,12 +470,12 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : cityList.length === 0 - ? `${t("LoanRequest.cityList_empty")}` - : cityTextField + ? `${t("LoanRequest.cityList_empty")}` + : cityTextField } size="small" selectType="city_id" - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} disabled={cityList.length === 0} selectors={cityList} select={formik.values.city_id} @@ -483,15 +488,15 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { const inputValue = event.target.value; @@ -532,7 +537,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { name: "مرد", }, ]} - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} select={formik.values.boss_gender} handleChange={(event) => { formik.setFieldValue("boss_gender", event.target.value); @@ -544,10 +549,10 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { { /> - + { {formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? ( { ) : ( { )} { /> - + { name: "منطقه آزاد", }, ]} - schema={{ value: "value", name: "name" }} + schema={{value: "value", name: "name"}} select={formik.values.navgan_type} handleChange={(event) => { formik.setFieldValue("navgan_type", event.target.value); @@ -705,10 +710,10 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { { /> - + { /> - + - + { selectors={educationsList} select={formik.values.education_id} value={formik.values.education_id} - schema={{ value: "id", name: "title" }} + schema={{value: "id", name: "title"}} handleChange={(event) => { formik.setFieldValue("education_id", event.target.value); }} @@ -784,7 +789,7 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { isLoading={isLoadingOccupationsList} errorEcured={errorOccupationsList} selectType="occupation_id" - schema={{ value: "id", name: "title" }} + schema={{value: "id", name: "title"}} selectors={occupationsList} select={formik.values.occupation_id} value={formik.values.occupation_id} @@ -798,12 +803,12 @@ const LegalPersonForm = ({ setFinishLoanRequest }) => { /> - + { /> - + {