From b64a1c93e912300ebc00d77cbcfc41d5d18041bb Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 5 Nov 2024 07:09:13 +0000 Subject: [PATCH] Feature/update api --- .eslintrc.json | 2 +- .prettierrc | 12 + package.json | 6 +- public/locales/fa/app.json | 2 +- src/components/dashboard/first/index.jsx | 75 +- .../navgan/add-request-loan/forms/AddForm.jsx | 102 +- .../forms/LegalPersonForm.jsx | 183 +-- .../add-request-loan/forms/RealPersonForm.jsx | 152 +- .../navgan/add-request-loan/index.jsx | 4 +- .../navgan/followUp-loan/RequestCard.jsx | 154 +- .../dashboard/navgan/followUp-loan/index.jsx | 38 +- .../navgan/show/form/UpdateFormLegal.jsx | 1391 +++++++++-------- .../navgan/show/form/UpdateFormReal.jsx | 1252 ++++++++------- .../dashboard/navgan/show/form/index.jsx | 37 +- .../dashboard/navgan/show/index.jsx | 8 +- src/components/errors/403.jsx | 15 +- src/components/errors/404.jsx | 15 +- src/components/errors/500.jsx | 15 +- src/components/first/Banner.jsx | 20 +- src/components/first/FooterDetails.jsx | 42 +- src/components/first/HeaderDetails.jsx | 12 +- src/components/first/LoanCondition.jsx | 75 +- .../first/LoanDescription/TimeLineDetails.jsx | 51 +- .../first/LoanDescription/index.jsx | 61 +- src/components/first/LoanRegister.jsx | 49 +- src/components/first/index.jsx | 18 +- src/components/login/SendToken.jsx | 74 +- src/components/login/SendUserData.jsx | 74 +- src/components/login/index.jsx | 2 +- src/core/components/AutoSubmit.jsx | 6 +- src/core/components/Config.jsx | 44 +- src/core/components/GlobalHead.jsx | 54 +- src/core/components/LegalPersonDatePicker.jsx | 21 +- src/core/components/PasswordField.jsx | 10 +- src/core/components/PlateNumber.jsx | 179 +-- src/core/components/ResendToken.jsx | 30 +- src/core/components/SelectBox.jsx | 48 +- src/core/components/StyledForm.jsx | 4 +- src/core/components/StyledImage.jsx | 2 +- src/core/components/TitlePage.jsx | 8 +- src/core/components/UploadSystem.jsx | 98 +- src/core/components/svgs/Svg403.jsx | 384 +++-- src/core/components/svgs/Svg404.jsx | 158 +- src/core/components/svgs/Svg500.jsx | 159 +- src/core/components/svgs/SvgDashboard.jsx | 179 ++- src/core/components/svgs/SvgDone.jsx | 237 ++- src/core/components/svgs/SvgLoading.jsx | 394 +++-- src/core/components/svgs/SvgLogin.jsx | 117 +- src/core/components/svgs/SvgMaintenance.jsx | 190 ++- src/core/components/svgs/SvgRegister.jsx | 173 +- .../components/timelines/DoneTimeLine.jsx | 37 +- .../timelines/InProgressTimeLine.jsx | 36 +- .../components/timelines/OpenTimeLine.jsx | 34 +- .../components/timelines/timelineManager.jsx | 16 +- src/core/data/apiRoutes.js | 12 +- src/core/data/headerItems.js | 18 +- src/core/data/languageList.js | 10 +- src/core/data/sidebarMenu.js | 12 +- src/core/utils/globalServerProps.js | 12 +- src/core/utils/isValidJson.js | 9 +- src/core/utils/theme-rtl.jsx | 4 +- src/core/utils/theme.jsx | 2 +- src/layouts/dashboard.jsx | 24 +- src/layouts/index.jsx | 20 +- src/layouts/list.jsx | 4 +- src/lib/app/hooks/useActivityType.jsx | 50 +- src/lib/app/hooks/useCities.jsx | 45 +- src/lib/app/hooks/useEducations.jsx | 40 +- src/lib/app/hooks/useLimitedProvince.jsx | 50 +- src/lib/app/hooks/useOccupations.jsx | 40 +- src/lib/app/hooks/useProjectTitle.jsx | 2 +- src/lib/app/hooks/useProvince.jsx | 50 +- src/middlewares/UserInfo.jsx | 8 +- src/pages/403.jsx | 22 +- src/pages/404.jsx | 23 +- src/pages/500.jsx | 22 +- src/pages/_app.jsx | 66 +- src/pages/_document.jsx | 24 +- src/pages/dashboard/index.jsx | 12 +- .../dashboard/navgan/[id]/show/index.jsx | 16 +- .../dashboard/navgan/followUp-loan/index.jsx | 12 +- src/pages/index.jsx | 9 +- src/pages/login.jsx | 12 +- 83 files changed, 4066 insertions(+), 3123 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc.json b/.eslintrc.json index bffb357..121cefd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,3 @@ { - "extends": "next/core-web-vitals" + "extends": ["next/core-web-vitals","prettier"] } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..434e674 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,12 @@ +{ + "printWidth": 120, + "tabWidth": 4, + "useTabs": false, + "semi": true, + "singleQuote": false, + "trailingComma": "es5", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "always", + "endOfLine": "crlf" +} diff --git a/package.json b/package.json index 14fe115..7044cfd 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build:publish": "npm i && npm run build && pm2 restart ecosystem.config.js", "start": "next start", "publish-3001": "next start -p 3001", - "lint": "next lint" + "lint": "next lint", + "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"" }, "dependencies": { "@emotion/react": "^11.10.6", @@ -32,6 +33,7 @@ "next-intl": "^2.13.1", "next-useragent": "^2.8.0", "nextjs-progressbar": "^0.0.16", + "prettier": "^3.3.3", "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -47,4 +49,4 @@ "@faker-js/faker": "^7.6.0", "eslint-config-next": "^13.3.0" } -} \ No newline at end of file +} diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 8460e70..33ac84b 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -320,7 +320,7 @@ "text_field_shenasname_serial": "سریال پشت کارت ملی", "text_field_national_trackin_code": "کد رهگیری کارت ملی", "text_field_national_id": "کد ملی", - "text_field_boss_national_id": "کد ملی رییس شرکت", + "text_field_boss_national_id": "کد ملی مدیر عامل", "text_field_register_number": "شماره ثبت شرکت", "text_field_postal_code": "کد پستی", "text_field_national_serial_number": "سریال پشت کارت ملی", diff --git a/src/components/dashboard/first/index.jsx b/src/components/dashboard/first/index.jsx index 7b42ef9..9d39d5e 100644 --- a/src/components/dashboard/first/index.jsx +++ b/src/components/dashboard/first/index.jsx @@ -1,46 +1,41 @@ -import { - CenterLayout, - FullPageLayout, - NextLinkComposed, - useUser, -} from "@witel/webapp-builder"; +import { CenterLayout, FullPageLayout, NextLinkComposed, useUser } from "@witel/webapp-builder"; import { Button, Typography } from "@mui/material"; import { useTranslations } from "next-intl"; const FirstComponent = () => { - const { user } = useUser(); - const t = useTranslations(); - return ( - - - {user.permissions.includes("can_request_navgan_loan") ? ( - <> - {t("Dashboard.go_to_add_request_loan")} - - - ) : ( - <> - {t("Dashboard.go_to_followUp-loan")} - - - )} - - - ); + const { user } = useUser(); + const t = useTranslations(); + return ( + + + {user.permissions.includes("can_request_navgan_loan") ? ( + <> + {t("Dashboard.go_to_add_request_loan")} + + + ) : ( + <> + {t("Dashboard.go_to_followUp-loan")} + + + )} + + + ); }; -export default FirstComponent; \ No newline at end of file +export default FirstComponent; 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 f83a954..74cf7a8 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx @@ -1,64 +1,58 @@ -import { - Button, - Grid, - Stack, - ToggleButton, - ToggleButtonGroup, - Typography -} from "@mui/material"; -import {useTranslations} from "next-intl"; -import {CenterLayout} from "@witel/webapp-builder"; -import {useState} from "react"; -import DoneIcon from '@mui/icons-material/Done'; -import {NextLinkComposed} from "@witel/webapp-builder/dist/utils/linkRouting"; +import { Button, Grid, Stack, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; +import { CenterLayout } from "@witel/webapp-builder"; +import { useState } from "react"; +import DoneIcon from "@mui/icons-material/Done"; +import { NextLinkComposed } from "@witel/webapp-builder/dist/utils/linkRouting"; import SvgDone from "@/core/components/svgs/SvgDone"; import RealPersonForm from "@/components/dashboard/navgan/add-request-loan/forms/RealPersonForm"; import LegalPersonForm from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm"; const AddFormComponent = () => { const t = useTranslations(); - const [finishLoanRequest, setFinishLoanRequest] = useState(false) - const [personType, setPersonType] = useState("real") + const [finishLoanRequest, setFinishLoanRequest] = useState(false); + const [personType, setPersonType] = useState("real"); - return (<> - {finishLoanRequest ? ( - - - {t("LoanRequest.finish_loan_request")} - - - - ) : ( - <> - - { - if (value === null) return - setPersonType(value) - }} - > - - {t("LoanRequest.real_person")} - - - {t("LoanRequest.legal_person")} - - - - { - personType === "real" ? : - - } - - )} - ); + return ( + <> + {finishLoanRequest ? ( + + + + + {t("LoanRequest.finish_loan_request")} + + + + + + ) : ( + <> + + { + if (value === null) return; + setPersonType(value); + }} + > + {t("LoanRequest.real_person")} + {t("LoanRequest.legal_person")} + + + {personType === "real" ? ( + + ) : ( + + )} + + )} + + ); }; export default AddFormComponent; 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 3ed42a1..1d98b62 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,28 +16,28 @@ 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 useProjectTitle from "@/lib/app/hooks/useProjectTitle"; import useActivityType from "@/lib/app/hooks/useActivityType"; import MuiDatePicker from "@/core/components/MuiDatePicker"; import LegalPersonDatePicker from "@/core/components/LegalPersonDatePicker"; -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 {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 { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle(); const initialValues = { person_type: "legal", @@ -118,35 +118,41 @@ 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() - .when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => { + boss_national_serial_number: Yup.string().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.test( - "max", - `${t("LoanRequest.boss_national_serial_number_max")}`, - (value) => value && value.toString().length === 10 - ).required(t("LoanRequest.error_message_boss_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.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 + .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; } ), @@ -157,18 +163,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, @@ -213,8 +219,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { changeUser(data); }); }) - .catch(() => { - }) + .catch(() => {}) .finally(() => { props.setSubmitting(false); }); @@ -227,7 +232,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { }); return ( <> - + { isLoading={isLoadingProjectTitle} errorEcured={errorProjectTitle} selectors={projectTitle} - schema={{value: "value", name: "name"}} + schema={{ value: "value", name: "name" }} select={formik.values.navgan_plan_id} value={formik.values.navgan_plan_id} handleChange={(event) => { @@ -258,7 +263,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) => { @@ -271,15 +276,15 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { /> - + { const inputValue = event.target.value; @@ -303,7 +308,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { { { const inputValue = event.target.value; @@ -347,14 +352,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { /> - + { const inputValue = event.target.value; @@ -379,11 +384,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { { @@ -415,7 +420,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) => { @@ -447,12 +452,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} @@ -465,15 +470,15 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { /> - + { const inputValue = event.target.value; @@ -514,7 +519,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); @@ -526,10 +531,10 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { /> - + { { /> - + { {formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? ( { ) : ( { )} { /> - + { /> - + - + { 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); }} @@ -756,7 +761,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} @@ -770,12 +775,12 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { /> - + { /> - + { /> - + { - ) : ( - - ) - } + {item.state_id === 17 ? ( + + ) : ( + + )} ); }; -export default RequestCard; \ No newline at end of file +export default RequestCard; diff --git a/src/components/dashboard/navgan/followUp-loan/index.jsx b/src/components/dashboard/navgan/followUp-loan/index.jsx index 7f68be2..4494e20 100644 --- a/src/components/dashboard/navgan/followUp-loan/index.jsx +++ b/src/components/dashboard/navgan/followUp-loan/index.jsx @@ -1,55 +1,53 @@ -import {Grid} from "@mui/material"; -import {useEffect, useState} from "react"; -import {SHOW_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes"; +import { Grid } from "@mui/material"; +import { useEffect, useState } from "react"; +import { SHOW_LOAN_REQUEST_NAVGAN } from "@/core/data/apiRoutes"; import RequestCard from "@/components/dashboard/navgan/followUp-loan/RequestCard"; -import {FullPageLayout, LoadingHardPage, useRequest} from "@witel/webapp-builder"; +import { FullPageLayout, LoadingHardPage, useRequest } from "@witel/webapp-builder"; import sidebarMenu from "@/core/data/sidebarMenu"; import BookmarkAddedIcon from "@mui/icons-material/BookmarkAdded"; const LoanFollowUpComponent = () => { const requestServer = useRequest(); - const [isLoading, setIsLoading] = useState(false) + const [isLoading, setIsLoading] = useState(false); const [requestsList, setRequestsList] = useState([]); useEffect(() => { - setIsLoading(true) + setIsLoading(true); requestServer(SHOW_LOAN_REQUEST_NAVGAN, "get", { auth: true, pending: false, - success: {notification: {show: false}} + success: { notification: { show: false } }, }) - .then(function ({data}) { + .then(function ({ data }) { const items = data.data; setRequestsList(items); - setIsLoading(false) - }) - .catch(function (error) { + setIsLoading(false); }) + .catch(function (error) {}); }, []); - return ( } + loading={isLoading} + width={100} + height={100} + sx={{ position: "absolute", bgcolor: "#fffc" }} + icon={} > - + {requestsList.map((item) => ( - + ))} - - ); }; diff --git a/src/components/dashboard/navgan/show/form/UpdateFormLegal.jsx b/src/components/dashboard/navgan/show/form/UpdateFormLegal.jsx index 2b6703a..bf7fe2c 100644 --- a/src/components/dashboard/navgan/show/form/UpdateFormLegal.jsx +++ b/src/components/dashboard/navgan/show/form/UpdateFormLegal.jsx @@ -1,6 +1,6 @@ -import {Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material"; -import {useFormik} from "formik"; -import {useTranslations} from "next-intl"; +import { Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup } from "@mui/material"; +import { useFormik } from "formik"; +import { useTranslations } from "next-intl"; import * as Yup from "yup"; import SelectBox from "@/core/components/SelectBox"; import PlateNumber from "@/core/components/PlateNumber"; @@ -10,61 +10,61 @@ import useProvince from "@/lib/app/hooks/useProvince"; import useCities from "@/lib/app/hooks/useCities"; import UseEducations from "@/lib/app/hooks/useEducations"; import useOccupations from "@/lib/app/hooks/useOccupations"; -import {UPDATE_LOAN} from "@/core/data/apiRoutes"; -import {useRequest} from "@witel/webapp-builder"; -import {useRouter} from "next/router"; -import {useEffect} from "react"; -import EditIcon from '@mui/icons-material/Edit'; +import { UPDATE_LOAN } from "@/core/data/apiRoutes"; +import { useRequest } from "@witel/webapp-builder"; +import { useRouter } from "next/router"; +import { useEffect } from "react"; +import EditIcon from "@mui/icons-material/Edit"; import * as React from "react"; import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; import useActivityType from "@/lib/app/hooks/useActivityType"; import LegalPersonDatePicker from "@/core/components/LegalPersonDatePicker"; -const UpdateFormLegal = ({LoanDetails, LoanId}) => { +const UpdateFormLegal = ({ LoanDetails, LoanId }) => { const t = useTranslations(); const provinceStates = useProvince(); - const router = useRouter() - const citiesStates = useCities(); - const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle(); - const {activityType, isLoadingActivityType, errorActivityType} = useActivityType(); - const educationStates = UseEducations(); - const occupationStates = useOccupations(); + const router = useRouter(); + const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities(); + const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle(); + const { activityType, isLoadingActivityType, errorActivityType } = useActivityType(); + const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations(); + const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations(); const requestServer = useRequest(); const initialValues = { is_legal_person: 1, national_serial_number_or_tracking_code: LoanDetails.national_serial_number ? "serial_number" : "tracking_code", - national_id: LoanDetails.national_id, - activity_type: LoanDetails.activity_type_id, - navgan_plan_id: LoanDetails.navgan_plan_id, - postal_code: LoanDetails.postal_code, - address: LoanDetails.address, - company_name: LoanDetails.company_name, - register_number: LoanDetails.register_number, + national_id: LoanDetails.national_id || "", + activity_type: LoanDetails.activity_type_id || "", + navgan_plan_id: LoanDetails.navgan_plan_id || "", + postal_code: LoanDetails.postal_code || "", + address: LoanDetails.address || "", + company_name: LoanDetails.company_name || "", + register_number: LoanDetails.register_number || "", company_date: LoanDetails.company_register_date ? moment(LoanDetails.company_register_date) : "", birthday: LoanDetails.birthday ? moment(LoanDetails.birthday) : "", - navgan_id: LoanDetails.navgan_id, - province_id: LoanDetails.province_id, - city_id: LoanDetails.city_id, - boss_first_name: LoanDetails.first_name, - boss_last_name: LoanDetails.last_name, - boss_father_name: LoanDetails.father_name, - gender: LoanDetails.gender, - navgan_type: LoanDetails.navgan_type, - vehicle_type: LoanDetails.vehicle_type, - telephone_number: LoanDetails.telephone_number, - plate_part1: LoanDetails.plate_number.split("-")[0], - plate_part2: LoanDetails.plate_number.split("-")[1], - plate_part3: LoanDetails.plate_number.split("-")[2], - plate_part4: LoanDetails.plate_number.split("-")[3], - education_id: LoanDetails.education_id, - occupation_id: LoanDetails.occupation_id, - shenase_meli: LoanDetails.shenase_meli, + navgan_id: LoanDetails.navgan_id || "", + province_id: LoanDetails.province_id || "", + city_id: LoanDetails.city_id || "", + boss_first_name: LoanDetails.first_name || "", + boss_last_name: LoanDetails.last_name || "", + boss_father_name: LoanDetails.father_name || "", + gender: LoanDetails.gender || "", + navgan_type: LoanDetails.navgan_type || "", + vehicle_type: LoanDetails.vehicle_type || "", + telephone_number: LoanDetails.telephone_number || "", + plate_part1: LoanDetails.plate_number.split("-")[0] || "", + plate_part2: LoanDetails.plate_number.split("-")[1] || "", + plate_part3: LoanDetails.plate_number.split("-")[2] || "", + plate_part4: LoanDetails.plate_number.split("-")[3] || "", + education_id: LoanDetails.education_id || "", + occupation_id: LoanDetails.occupation_id || "", + shenase_meli: LoanDetails.shenase_meli || "", national_serial_number: LoanDetails.national_serial_number ?? "", - national_tracking_code: LoanDetails.national_tracking_code ?? "" + national_tracking_code: LoanDetails.national_tracking_code ?? "", }; useEffect(() => { - citiesStates.setProvinceID(LoanDetails.province_id) + setProvinceID(LoanDetails.province_id); }, [LoanDetails.province_id]); const validationSchema = Yup.object().shape({ @@ -79,7 +79,7 @@ const UpdateFormLegal = ({LoanDetails, LoanId}) => { telephone_number: Yup.mixed() .test("max", `${t("ShowLoan.tel_number_max")}`, (value) => { const stringValue = String(value); - return stringValue.length === 11 + return stringValue.length === 11; }) .required(t("ShowLoan.error_message_tel_number")), occupation_id: Yup.string().required(t("ShowLoan.error_message_occupation_id")), @@ -92,61 +92,100 @@ const UpdateFormLegal = ({LoanDetails, LoanId}) => { boss_father_name: Yup.string().required(t("ShowLoan.error_message_boss_father_name")), education_id: Yup.string().required(t("ShowLoan.error_message_education_id")), birthday: Yup.string().required(t("ShowLoan.error_message_date_of_birth")), - national_id: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => { - return is_legal_person === 1 ? schema - .test("is-number", `${t("ShowLoan.national_code_number")}`, (value) => !isNaN(value)) - .test("positive", `${t("ShowLoan.national_code_positive")}`, (value) => value >= 0) - .test("max", `${t("ShowLoan.national_code_max")}`, (value) => value && value.toString().length === 10) - .required(t("ShowLoan.error_message_national_id")) : schema; + national_id: Yup.mixed().when("is_legal_person", ([is_legal_person], schema) => { + return is_legal_person === 1 + ? schema + .test("is-number", `${t("ShowLoan.national_code_number")}`, (value) => !isNaN(value)) + .test("positive", `${t("ShowLoan.national_code_positive")}`, (value) => value >= 0) + .test( + "max", + `${t("ShowLoan.national_code_max")}`, + (value) => value && value.toString().length === 10 + ) + .required(t("ShowLoan.error_message_national_id")) + : schema; }), - shenase_meli: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => { - return is_legal_person === 1 ? schema - .test("is-number", `${t("ShowLoan.national_number_number")}`, (value) => !isNaN(value)) - .test("positive", `${t("ShowLoan.national_number_positive")}`, (value) => value >= 0) - .test("max", `${t("ShowLoan.national_number_max")}`, (value) => value && value.toString().length === 11) - .required(t("ShowLoan.error_message_national_number")) : schema; + shenase_meli: Yup.mixed().when("is_legal_person", ([is_legal_person], schema) => { + return is_legal_person === 1 + ? schema + .test("is-number", `${t("ShowLoan.national_number_number")}`, (value) => !isNaN(value)) + .test("positive", `${t("ShowLoan.national_number_positive")}`, (value) => value >= 0) + .test( + "max", + `${t("ShowLoan.national_number_max")}`, + (value) => value && value.toString().length === 11 + ) + .required(t("ShowLoan.error_message_national_number")) + : schema; }), - national_serial_number: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'serial_number' ? schema.required(t("ShowLoan.error_message_shenasname_serial")) : schema - }), - national_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 === 'tracking_code' ? schema.required(t("ShowLoan.error_message_tracking_code")) : schema - }) + national_serial_number: Yup.string().when( + "national_serial_number_or_tracking_code", + ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "serial_number" + ? schema + .test( + "max", + `${t("LoanRequest.boss_national_serial_number_max")}`, + (value) => value && value.toString().length === 10 + ) + .required(t("ShowLoan.error_message_shenasname_serial")) + : schema; + } + ), + national_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 === "tracking_code" + ? schema + .test( + "max", + `${t("LoanRequest.national_boss_tracking_code_max")}`, + (value) => value && value.toString().length === 10 + ) + .required(t("ShowLoan.error_message_tracking_code")) + : schema; + } + ), }); const handleSubmit = async (values) => { - formik.setSubmitting(true) + formik.setSubmitting(true); const formData = new FormData(); if (values.national_serial_number_or_tracking_code === "serial_number") { - formData.append("national_serial_number", values.national_serial_number) + formData.append("national_serial_number", values.national_serial_number); } else { formData.append("national_tracking_code", values.national_tracking_code); } formData.append("national_id", values.national_id); - formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD")); + formData.append("birthday", values.birthday.locale("en").format("YYYY-MM-DD")); formData.append("postal_code", values.postal_code); formData.append("navgan_plan_id", values.navgan_plan_id); - formData.append("activity_type", values.activity_type); - formData.append("boss_first_name", values.boss_first_name); - formData.append("boss_last_name", values.boss_last_name); - formData.append("boss_father_name", values.boss_father_name); + formData.append("activity_type_id", values.activity_type); + formData.append("first_name", values.boss_first_name); + formData.append("last_name", values.boss_last_name); + formData.append("father_name", values.boss_father_name); formData.append("gender", values.gender); - formData.append("province_id", LoanDetails.province_id); - formData.append("city_id", LoanDetails.city_id); + formData.append("city_id", values.city_id); formData.append("telephone_number", values.telephone_number); formData.append("education_id", values.education_id); formData.append("occupation_id", values.occupation_id); formData.append("address", values.address); + formData.append("company_name", values.company_name); + formData.append("company_register_date", values.company_date.locale("en").format("YYYY-MM-DD")); + formData.append("register_number", values.register_number); await requestServer(UPDATE_LOAN + LoanId, "post", { - auth: true, notification: true, data: formData - }).then(() => { - router.push("/dashboard/navgan/followUp-loan"); - }).catch(() => { - }).finally(() => { - props.setSubmitting(false); + auth: true, + notification: true, + data: formData, }) - + .then(() => { + router.push("/dashboard/navgan/followUp-loan"); + }) + .catch(() => {}) + .finally(() => { + props.setSubmitting(false); + }); }; const formik = useFormik({ @@ -154,575 +193,657 @@ const UpdateFormLegal = ({LoanDetails, LoanId}) => { validationSchema, onSubmit: handleSubmit, }); - return (<> - - - - - - - - - + + + + + + + + + + + + { + formik.setFieldValue("activity_type", event.target.value); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} + helperText={formik.touched.activity_type && formik.errors.activity_type} + onBlur={formik.handleBlur("activity_type")} + /> + - - { - formik.setFieldValue("activity_type", event.target.value); - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} - helperText={formik.touched.activity_type && formik.errors.activity_type} - onBlur={formik.handleBlur("activity_type")} - /> - - - - - - - - - - - - - - - - { - const inputValue = event.target.value; - if (isNaN(Number(inputValue))) { - return; - } - formik.handleChange({ - target: { - name: "register_number", - value: inputValue, - }, - }); - }} - label={t("ShowLoan.text_field_register_number")} - onBlur={formik.handleBlur("register_number")} - error={formik.touched.register_number && Boolean(formik.errors.register_number)} - helperText={formik.touched.register_number && formik.errors.register_number} - fullWidth - /> - - - - - - - - - - - - - - - - - - {initialValues.is_legal_person === 1 && ( + + + + + + + + + + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "register_number", + value: inputValue, + }, + }); + }} + label={t("ShowLoan.text_field_register_number")} + onBlur={formik.handleBlur("register_number")} + error={formik.touched.register_number && Boolean(formik.errors.register_number)} + helperText={formik.touched.register_number && formik.errors.register_number} + fullWidth + /> + + + + + + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "national_id", + value: inputValue, + }, + }); + }} + onBlur={formik.handleBlur("national_id")} + /> + + + + + + + + + + {initialValues.is_legal_person === 1 && ( + + + + )} + + + + + + { + formik.setFieldValue("navgan_type", event.target.value); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} + helperText={formik.touched.navgan_type && formik.errors.navgan_type} + onBlur={formik.handleBlur("navgan_type")} + /> + + + + + + + + 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")} + /> + + + + + { + if (value === null) return; + formik.handleChange({ + target: { + name: "national_serial_number_or_tracking_code", + value: value, + }, + }); + value === "serial_number" + ? formik.setFieldValue( + "national_tracking_code", + formik.initialValues.national_tracking_code, + false + ) + : formik.setFieldValue( + "national_serial_number", + formik.initialValues.national_serial_number, + false + ); + }} + > + + {t("ShowLoan.text_field_shenasname_serial")} + + + {t("ShowLoan.text_field_national_trackin_code")} + + + + + {formik.values.national_serial_number_or_tracking_code === "serial_number" ? ( + { + const inputValue = e.target.value; + const regex = /^[A-Za-z0-9]*$/; + if (regex.test(inputValue)) { + formik.setFieldValue("national_serial_number", inputValue); + } + }} + onBlur={formik.handleBlur("national_serial_number")} + /> + ) : ( + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "national_tracking_code", + value: inputValue, + }, + }); + }} + value={formik.values.national_tracking_code} + onBlur={formik.handleBlur("national_tracking_code")} + /> + )} + + + + + + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "postal_code", + value: inputValue, + }, + }); + }} + error={!!(formik.touched.postal_code && formik.errors.postal_code)} + fullWidth + helperText={formik.touched.postal_code ? formik.errors.postal_code : null} + onBlur={formik.handleBlur("postal_code")} + /> + + + { + formik.setFieldValue("province_id", event.target.value); + citiesStates.setProvinceID(event.target.value); + formik.setFieldTouched("city_id", false, false); + formik.setFieldValue("city_id", ""); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.province_id && Boolean(formik.errors.province_id)} + helperText={formik.touched.province_id && formik.errors.province_id} + onBlur={formik.handleBlur("province_id")} + /> + + + 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} + onBlur={formik.handleBlur("city_id")} + /> + + + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "telephone_number", + value: inputValue, + }, + }); + }} + label={t("ShowLoan.text_field_tel_number")} + placeholder={t("ShowLoan.text_field_enter_your_tel_number")} + fullWidth + onBlur={formik.handleBlur("telephone_number")} + error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)} + helperText={formik.touched.telephone_number && formik.errors.telephone_number} + /> + + + { + 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")} + /> + + + + + + + + {LoanDetails.state_id === 17 && ( + + + )} - - - - - - - { - formik.setFieldValue('navgan_type', event.target.value) - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} - helperText={formik.touched.navgan_type && formik.errors.navgan_type} - onBlur={formik.handleBlur("navgan_type")} - /> - - - - - - - - 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")} - /> - - - - - { - if (value === null) return - formik.handleChange({ - target: { - name: "national_serial_number_or_tracking_code", value: value, - }, - }) - value === "serial_number" ? formik.setFieldValue("national_tracking_code", formik.initialValues.national_tracking_code, false) : formik.setFieldValue("national_serial_number", formik.initialValues.national_serial_number, false) - }} - > - - {t("ShowLoan.text_field_shenasname_serial")} - - - {t("ShowLoan.text_field_national_trackin_code")} - - - - - {formik.values.national_serial_number_or_tracking_code === "serial_number" ? () : ()} - - - - - - - - { - const inputValue = event.target.value; - if (isNaN(Number(inputValue))) { - return; - } - formik.handleChange({ - target: { - name: "postal_code", value: inputValue, - }, - }); - }} - error={!!(formik.touched.postal_code && formik.errors.postal_code)} - fullWidth - helperText={formik.touched.postal_code ? formik.errors.postal_code : null} - /> - - - { - formik.setFieldValue('province_id', event.target.value); - citiesStates.setProvinceID(event.target.value) - formik.setFieldTouched("city_id", false, false); - formik.setFieldValue("city_id", "") - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.province_id && Boolean(formik.errors.province_id)} - helperText={formik.touched.province_id && formik.errors.province_id} - onBlur={formik.handleBlur("province_id")} - /> - - - 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} - onBlur={formik.handleBlur("city_id")} - /> - - - - - { - const inputValue = event.target.value; - if (isNaN(Number(inputValue))) { - return; - } - formik.handleChange({ - target: { - name: "telephone_number", value: inputValue, - }, - }); - }} - label={t("ShowLoan.text_field_tel_number")} - placeholder={t("ShowLoan.text_field_enter_your_tel_number")} - fullWidth - onBlur={formik.handleBlur("telephone_number")} - error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)} - helperText={formik.touched.telephone_number && formik.errors.telephone_number} - /> - - - { - 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")} - /> - - - - - - - - {LoanDetails.state_id === 17 && ( - - - - )} - - ); + + + ); }; -export default UpdateFormLegal; \ No newline at end of file +export default UpdateFormLegal; diff --git a/src/components/dashboard/navgan/show/form/UpdateFormReal.jsx b/src/components/dashboard/navgan/show/form/UpdateFormReal.jsx index 5aa30c4..0dbdbb0 100644 --- a/src/components/dashboard/navgan/show/form/UpdateFormReal.jsx +++ b/src/components/dashboard/navgan/show/form/UpdateFormReal.jsx @@ -1,6 +1,6 @@ -import {Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material"; -import {useFormik} from "formik"; -import {useTranslations} from "next-intl"; +import { Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup } from "@mui/material"; +import { useFormik } from "formik"; +import { useTranslations } from "next-intl"; import * as Yup from "yup"; import SelectBox from "@/core/components/SelectBox"; import PlateNumber from "@/core/components/PlateNumber"; @@ -10,54 +10,54 @@ import useProvince from "@/lib/app/hooks/useProvince"; import useCities from "@/lib/app/hooks/useCities"; import UseEducations from "@/lib/app/hooks/useEducations"; import useOccupations from "@/lib/app/hooks/useOccupations"; -import {UPDATE_LOAN} from "@/core/data/apiRoutes"; -import {useRequest} from "@witel/webapp-builder"; -import {useRouter} from "next/router"; -import {useEffect} from "react"; -import EditIcon from '@mui/icons-material/Edit'; +import { UPDATE_LOAN } from "@/core/data/apiRoutes"; +import { useRequest } from "@witel/webapp-builder"; +import { useRouter } from "next/router"; +import { useEffect } from "react"; +import EditIcon from "@mui/icons-material/Edit"; import * as React from "react"; import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; import useActivityType from "@/lib/app/hooks/useActivityType"; -const UpdateFormReal = ({LoanDetails, LoanId}) => { +const UpdateFormReal = ({ LoanDetails, LoanId }) => { const t = useTranslations(); const provinceStates = useProvince(); - const router = useRouter() + const router = useRouter(); const citiesStates = useCities(); - const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle(); - const {activityType, isLoadingActivityType, errorActivityType} = useActivityType(); + const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle(); + const { activityType, isLoadingActivityType, errorActivityType } = useActivityType(); const educationStates = UseEducations(); const occupationStates = useOccupations(); const requestServer = useRequest(); const initialValues = { national_serial_number_or_tracking_code: LoanDetails.national_serial_number ? "serial_number" : "tracking_code", - national_id: LoanDetails.national_id, - activity_type: LoanDetails.activity_type_id, - navgan_plan_id: LoanDetails.navgan_plan_id, - postal_code: LoanDetails.postal_code, - address: LoanDetails.address, + national_id: LoanDetails.national_id || "", + activity_type: LoanDetails.activity_type_id || "", + navgan_plan_id: LoanDetails.navgan_plan_id || "", + postal_code: LoanDetails.postal_code || "", + address: LoanDetails.address || "", birthday: LoanDetails.birthday ? moment(LoanDetails.birthday) : "", - navgan_id: LoanDetails.navgan_id, - province_id: LoanDetails.province_id, - city_id: LoanDetails.city_id, - first_name: LoanDetails.first_name, - last_name: LoanDetails.last_name, - father_name: LoanDetails.father_name, - gender: LoanDetails.gender, - occupation_id : LoanDetails.occupation_id, - navgan_type: LoanDetails.navgan_type, - vehicle_type: LoanDetails.vehicle_type, - telephone_number: LoanDetails.telephone_number, - plate_part1: LoanDetails.plate_number.split("-")[0], - plate_part2: LoanDetails.plate_number.split("-")[1], - plate_part3: LoanDetails.plate_number.split("-")[2], - plate_part4: LoanDetails.plate_number.split("-")[3], - education_id: LoanDetails.education_id, + navgan_id: LoanDetails.navgan_id || "", + province_id: LoanDetails.province_id || "", + city_id: LoanDetails.city_id || "", + first_name: LoanDetails.first_name || "", + last_name: LoanDetails.last_name || "", + father_name: LoanDetails.father_name || "", + gender: LoanDetails.gender || "", + occupation_id: LoanDetails.occupation_id || "", + navgan_type: LoanDetails.navgan_type || "", + vehicle_type: LoanDetails.vehicle_type || "", + telephone_number: LoanDetails.telephone_number || "", + plate_part1: LoanDetails.plate_number.split("-")[0] || "", + plate_part2: LoanDetails.plate_number.split("-")[1] || "", + plate_part3: LoanDetails.plate_number.split("-")[2] || "", + plate_part4: LoanDetails.plate_number.split("-")[3] || "", + education_id: LoanDetails.education_id || "", national_serial_number: LoanDetails.national_serial_number ?? "", - national_tracking_code: LoanDetails.national_tracking_code ?? "" + national_tracking_code: LoanDetails.national_tracking_code ?? "", }; useEffect(() => { - citiesStates.setProvinceID(LoanDetails.province_id) + citiesStates.setProvinceID(LoanDetails.province_id); }, [LoanDetails.province_id]); const validationSchema = Yup.object().shape({ @@ -72,7 +72,7 @@ const UpdateFormReal = ({LoanDetails, LoanId}) => { telephone_number: Yup.mixed() .test("max", `${t("ShowLoan.tel_number_max")}`, (value) => { const stringValue = String(value); - return stringValue.length === 11 + return stringValue.length === 11; }) .required(t("ShowLoan.error_message_tel_number")), occupation_id: Yup.string().required(t("ShowLoan.error_message_occupation_id")), @@ -82,46 +82,70 @@ const UpdateFormReal = ({LoanDetails, LoanId}) => { father_name: Yup.string().required(t("ShowLoan.error_message_father_name")), education_id: Yup.string().required(t("ShowLoan.error_message_education_id")), birthday: Yup.string().required(t("ShowLoan.error_message_date_of_birth")), - national_serial_number: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => { - return national_serial_number_or_tracking_code === 'serial_number' ? schema.required(t("ShowLoan.error_message_shenasname_serial")) : schema - }), - national_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 === 'tracking_code' ? schema.required(t("ShowLoan.error_message_tracking_code")) : schema - }) + national_serial_number: Yup.string().when( + "national_serial_number_or_tracking_code", + ([national_serial_number_or_tracking_code], schema) => { + return national_serial_number_or_tracking_code === "serial_number" + ? schema + .test( + "max", + `${t("LoanRequest.national_serial_number_max")}`, + (value) => value && value.toString().length === 10 + ) + .required(t("ShowLoan.error_message_shenasname_serial")) + : schema; + } + ), + national_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 === "tracking_code" + ? schema + .test( + "max", + `${t("LoanRequest.national_tracking_code_max")}`, + (value) => value && value.toString().length === 10 + ) + .required(t("ShowLoan.error_message_tracking_code")) + : schema; + } + ), }); const handleSubmit = async (values, props) => { - props.setSubmitting(true) + props.setSubmitting(true); const formData = new FormData(); if (values.national_serial_number_or_tracking_code === "serial_number") { - formData.append("national_serial_number", values.national_serial_number) + formData.append("national_serial_number", values.national_serial_number); } else { formData.append("national_tracking_code", values.national_tracking_code); } - formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD")); + formData.append("birthday", values.birthday.locale("en").format("YYYY-MM-DD")); formData.append("postal_code", values.postal_code); formData.append("navgan_plan_id", values.navgan_plan_id); - formData.append("activity_type", values.activity_type); + formData.append("activity_type_id", values.activity_type); formData.append("first_name", values.first_name); formData.append("last_name", values.last_name); formData.append("father_name", values.father_name); formData.append("gender", values.gender); - formData.append("province_id", LoanDetails.province_id); - formData.append("city_id", LoanDetails.city_id); + formData.append("city_id", values.city_id); formData.append("telephone_number", values.telephone_number); formData.append("education_id", values.education_id); formData.append("occupation_id", values.occupation_id); formData.append("address", values.address); await requestServer(UPDATE_LOAN + LoanId, "post", { - auth: true, notification: true, data: formData - }).then(() => { - router.push("/dashboard/navgan/followUp-loan"); - }).catch(() => { - }).finally(() => { - props.setSubmitting(false); + auth: true, + notification: true, + data: formData, }) - + .then(() => { + router.push("/dashboard/navgan/followUp-loan"); + }) + .catch(() => {}) + .finally(() => { + props.setSubmitting(false); + }); }; const formik = useFormik({ @@ -129,527 +153,619 @@ const UpdateFormReal = ({LoanDetails, LoanId}) => { validationSchema, onSubmit: handleSubmit, }); - - return (<> - - - - - - - - - { - formik.setFieldValue("activity_type", event.target.value); - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} - helperText={formik.touched.activity_type && formik.errors.activity_type} - onBlur={formik.handleBlur("activity_type")} + return ( + <> + + + + + + + + + { + formik.setFieldValue("activity_type", event.target.value); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.activity_type && Boolean(formik.errors.activity_type)} + helperText={formik.touched.activity_type && formik.errors.activity_type} + onBlur={formik.handleBlur("activity_type")} + /> + + + + - - + + + + + + + - - - - + + + + + + + - - - - - - - - - - - - - - - - - - { - const inputValue = event.target.value; - if (isNaN(Number(inputValue))) { - return; - } - formik.handleChange({ - target: { - name: "postal_code", value: inputValue, + + + - - - - - - - - { - formik.setFieldValue('navgan_type', event.target.value) - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} - helperText={formik.touched.navgan_type && formik.errors.navgan_type} - onBlur={formik.handleBlur("navgan_type")} - /> - - - - - - - - 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")} - /> - - - - - { - if (value === null) return - formik.handleChange({ - target: { - name: "national_serial_number_or_tracking_code", value: value, + { + id: 2, + value: 0, + name: "مرد", }, - }) - value === "serial_number" ? formik.setFieldValue("national_tracking_code", formik.initialValues.national_tracking_code, false) : formik.setFieldValue("national_serial_number", formik.initialValues.national_serial_number, false) + ]} + schema={{ value: "value", name: "name" }} + select={formik.values.gender} + isLoading={!formik.values.gender} + handleChange={formik.handleChange} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.gender && Boolean(formik.errors.gender)} + helperText={formik.touched.gender && formik.errors.gender} + onBlur={formik.handleBlur("gender")} + /> + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "postal_code", + value: inputValue, + }, + }); + }} + error={!!(formik.touched.postal_code && formik.errors.postal_code)} + fullWidth + onBlur={formik.handleBlur("postal_code")} + helperText={formik.touched.postal_code ? formik.errors.postal_code : null} + /> + + + + + + + + { + formik.setFieldValue("navgan_type", event.target.value); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)} + helperText={formik.touched.navgan_type && formik.errors.navgan_type} + onBlur={formik.handleBlur("navgan_type")} + /> + + + + + + + + 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")} + /> + + + + + { + if (value === null) return; + formik.handleChange({ + target: { + name: "national_serial_number_or_tracking_code", + value: value, + }, + }); + value === "serial_number" + ? formik.setFieldValue( + "national_tracking_code", + formik.initialValues.national_tracking_code, + false + ) + : formik.setFieldValue( + "national_serial_number", + formik.initialValues.national_serial_number, + false + ); + }} + > + + {t("ShowLoan.text_field_shenasname_serial")} + + + {t("ShowLoan.text_field_national_trackin_code")} + + + + + {formik.values.national_serial_number_or_tracking_code === "serial_number" ? ( + { + const inputValue = e.target.value; + const regex = /^[A-Za-z0-9]*$/; + if (regex.test(inputValue)) { + formik.setFieldValue("national_serial_number", inputValue); + } + }} + /> + ) : ( + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "national_tracking_code", + value: inputValue, + }, + }); + }} + /> + )} + + + + + + + + {provinceStates.provinceList.length !== 0 ? ( + { + formik.setFieldValue("province_id", event.target.value); + citiesStates.setProvinceID(event.target.value); + formik.setFieldTouched("city_id", false, false); + formik.setFieldValue("city_id", ""); + }} + setFieldTouched={formik.setFieldTouched} + error={formik.touched.province_id && Boolean(formik.errors.province_id)} + helperText={formik.touched.province_id && formik.errors.province_id} + onBlur={formik.handleBlur("province_id")} + /> + ) : ( + + )} + + + {citiesStates.cityList.length !== 0 ? ( + 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} + onBlur={formik.handleBlur("city_id")} + /> + ) : ( + + )} + + + + + { + const inputValue = event.target.value; + if (isNaN(Number(inputValue))) { + return; + } + formik.handleChange({ + target: { + name: "telephone_number", + value: inputValue, + }, + }); + }} + label={t("ShowLoan.text_field_tel_number")} + placeholder={t("ShowLoan.text_field_enter_your_tel_number")} + fullWidth + onBlur={formik.handleBlur("telephone_number")} + error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)} + helperText={formik.touched.telephone_number && formik.errors.telephone_number} + /> + + + {educationStates.educationsList.length !== 0 ? ( + { + 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")} + /> + ) : ( + + )} + + + {occupationStates.occupationsList.length !== 0 ? ( + { + 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")} + /> + ) : ( + + )} + + + + + + + + {LoanDetails.state_id === 17 && ( + - - {t("ShowLoan.text_field_shenasname_serial")} - - - {t("ShowLoan.text_field_national_trackin_code")} - - - - - {formik.values.national_serial_number_or_tracking_code === "serial_number" ? () : ()} - - - - - - - - {provinceStates.provinceList.length !== 0 ? { - formik.setFieldValue('province_id', event.target.value); - citiesStates.setProvinceID(event.target.value) - formik.setFieldTouched("city_id", false, false); - formik.setFieldValue("city_id", "") - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.province_id && Boolean(formik.errors.province_id)} - helperText={formik.touched.province_id && formik.errors.province_id} - onBlur={formik.handleBlur("province_id")} - /> : } - - - - {citiesStates.cityList.length !== 0 ? 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} - onBlur={formik.handleBlur("city_id")} - /> : } - - - - - { - const inputValue = event.target.value; - if (isNaN(Number(inputValue))) { - return; - } - formik.handleChange({ - target: { - name: "telephone_number", value: inputValue, - }, - }); - }} - label={t("ShowLoan.text_field_tel_number")} - placeholder={t("ShowLoan.text_field_enter_your_tel_number")} - fullWidth - onBlur={formik.handleBlur("telephone_number")} - error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)} - helperText={formik.touched.telephone_number && formik.errors.telephone_number} - /> - - - {educationStates.educationsList.length !== 0 ? { - 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")} - /> : } - - - {occupationStates.occupationsList.length !== 0 ? { - 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")} - /> : } - - - - - - - - {LoanDetails.state_id === 17 && ( - - - - )} - - ); + + + )} + + + ); }; export default UpdateFormReal; diff --git a/src/components/dashboard/navgan/show/form/index.jsx b/src/components/dashboard/navgan/show/form/index.jsx index 84d5b99..f626390 100644 --- a/src/components/dashboard/navgan/show/form/index.jsx +++ b/src/components/dashboard/navgan/show/form/index.jsx @@ -1,37 +1,38 @@ -import {useEffect, useState} from "react"; -import {GET_LOAN_DETAILS} from "@/core/data/apiRoutes"; -import {useRouter} from "next/router"; -import {SvgLoading, useRequest} from "@witel/webapp-builder"; -import {Stack, Typography} from "@mui/material"; -import {useTranslations} from "next-intl"; +import { useEffect, useState } from "react"; +import { GET_LOAN_DETAILS } from "@/core/data/apiRoutes"; +import { useRouter } from "next/router"; +import { SvgLoading, useRequest } from "@witel/webapp-builder"; +import { Stack, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; import UpdateFormReal from "@/components/dashboard/navgan/show/form/UpdateFormReal"; import UpdateFormLegal from "@/components/dashboard/navgan/show/form/UpdateFormLegal"; const ShowLoanForm = () => { const t = useTranslations(); - const {query} = useRouter(); - const requestServer = useRequest({auth: true, notification: false}); + const { query } = useRouter(); + const requestServer = useRequest({ auth: true, notification: false }); const [LoanDetails, setLoanDetails] = useState({}); useEffect(() => { - requestServer(GET_LOAN_DETAILS + query.id, 'get', {auth: true, notification: false}).then(({data}) => { - setLoanDetails(data.data); - }).catch(() => { - }) + requestServer(GET_LOAN_DETAILS + query.id, "get", { auth: true, notification: false }) + .then(({ data }) => { + setLoanDetails(data.data); + }) + .catch(() => {}); }, []); if (Object.keys(LoanDetails).length === 0) { return ( - - + + {t("ShowLoan.loading_show_component")} ); } return LoanDetails.is_legal_person === 1 ? ( - + ) : ( - - ) + + ); }; -export default ShowLoanForm; \ No newline at end of file +export default ShowLoanForm; diff --git a/src/components/dashboard/navgan/show/index.jsx b/src/components/dashboard/navgan/show/index.jsx index b9c73ed..6dfeda9 100644 --- a/src/components/dashboard/navgan/show/index.jsx +++ b/src/components/dashboard/navgan/show/index.jsx @@ -1,14 +1,14 @@ -import {useTranslations} from "next-intl"; -import {CenterLayout, useUser} from "@witel/webapp-builder"; +import { useTranslations } from "next-intl"; +import { CenterLayout, useUser } from "@witel/webapp-builder"; import ShowLoanForm from "@/components/dashboard/navgan/show/form"; const ShowLoan = () => { const t = useTranslations(); - const {user} = useUser(); + const { user } = useUser(); return ( - + ); }; diff --git a/src/components/errors/403.jsx b/src/components/errors/403.jsx index 8d410ed..c20f89d 100644 --- a/src/components/errors/403.jsx +++ b/src/components/errors/403.jsx @@ -1,18 +1,18 @@ -import {Button, Typography} from "@mui/material"; -import {useTranslations} from "next-intl"; +import { Button, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; import TitlePage from "@/core/components/TitlePage"; import Svg403 from "@/core/components/svgs/Svg403"; -import {CenterLayout, FullPageLayout, NextLinkComposed} from "@witel/webapp-builder"; +import { CenterLayout, FullPageLayout, NextLinkComposed } from "@witel/webapp-builder"; const UnAuthorizedComponent = () => { const t = useTranslations(); return ( <> - - + + - + {t("ErrorPage.custom_403")} @@ -23,8 +23,7 @@ const UnAuthorizedComponent = () => { pathname: "/", }} > - {t("ErrorPage.link_routing_back_to")}{" "} - {t("ErrorPage.link_routing_main_page")} + {t("ErrorPage.link_routing_back_to")} {t("ErrorPage.link_routing_main_page")} diff --git a/src/components/errors/404.jsx b/src/components/errors/404.jsx index 15a394c..25395e5 100644 --- a/src/components/errors/404.jsx +++ b/src/components/errors/404.jsx @@ -1,18 +1,18 @@ -import {Button, Typography} from "@mui/material"; -import {useTranslations} from "next-intl"; +import { Button, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; import TitlePage from "@/core/components/TitlePage"; import Svg404 from "@/core/components/svgs/Svg404"; -import {CenterLayout, FullPageLayout, NextLinkComposed} from "@witel/webapp-builder"; +import { CenterLayout, FullPageLayout, NextLinkComposed } from "@witel/webapp-builder"; const NotFoundComponent = () => { const t = useTranslations(); return ( <> - - + + - + {t("ErrorPage.custom_404")} @@ -23,8 +23,7 @@ const NotFoundComponent = () => { pathname: "/", }} > - {t("ErrorPage.link_routing_back_to")}{" "} - {t("ErrorPage.link_routing_main_page")} + {t("ErrorPage.link_routing_back_to")} {t("ErrorPage.link_routing_main_page")} diff --git a/src/components/errors/500.jsx b/src/components/errors/500.jsx index 5527a39..e9bd09c 100644 --- a/src/components/errors/500.jsx +++ b/src/components/errors/500.jsx @@ -1,18 +1,18 @@ -import {Button, Typography} from "@mui/material"; -import {useTranslations} from "next-intl"; +import { Button, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; import TitlePage from "@/core/components/TitlePage"; import Svg500 from "@/core/components/svgs/Svg500"; -import {CenterLayout, FullPageLayout, NextLinkComposed} from "@witel/webapp-builder"; +import { CenterLayout, FullPageLayout, NextLinkComposed } from "@witel/webapp-builder"; const ServerErrorComponent = () => { const t = useTranslations(); return ( <> - - + + - + {t("ErrorPage.custom_500")} @@ -23,8 +23,7 @@ const ServerErrorComponent = () => { pathname: "/", }} > - {t("ErrorPage.link_routing_back_to")}{" "} - {t("ErrorPage.link_routing_main_page")} + {t("ErrorPage.link_routing_back_to")} {t("ErrorPage.link_routing_main_page")} diff --git a/src/components/first/Banner.jsx b/src/components/first/Banner.jsx index 0c4ef35..ee60dcc 100644 --- a/src/components/first/Banner.jsx +++ b/src/components/first/Banner.jsx @@ -1,14 +1,18 @@ -import {Box, Container} from "@mui/material"; -import {useConfig} from "@witel/webapp-builder"; +import { Box, Container } from "@mui/material"; +import { useConfig } from "@witel/webapp-builder"; const Banner = () => { - const {config} = useConfig(); + const { config } = useConfig(); const bannerHTML = config.banner; - return ( - {config.banner && config.banner !== "" && ( -
- )} - ); + return ( + + {config.banner && config.banner !== "" && ( + +
+ + )} + + ); }; export default Banner; diff --git a/src/components/first/FooterDetails.jsx b/src/components/first/FooterDetails.jsx index f456c14..fa2ba17 100644 --- a/src/components/first/FooterDetails.jsx +++ b/src/components/first/FooterDetails.jsx @@ -1,37 +1,39 @@ -import {Box, Button, Container, Grid, Stack, Typography} from "@mui/material"; -import {useTranslations} from "next-intl"; -import {LinkRouting} from "@witel/webapp-builder"; +import { Box, Button, Container, Grid, Stack, Typography } from "@mui/material"; +import { useTranslations } from "next-intl"; +import { LinkRouting } from "@witel/webapp-builder"; const FooterDetails = () => { const t = useTranslations(); return ( - - - + + + - {t("powered_by_witel")}/ + {t("powered_by_witel")} {t("powered_by_witel")} - v{process.env.NEXT_PUBLIC_API_VERSION} @@ -40,6 +42,6 @@ const FooterDetails = () => { - ) -} -export default FooterDetails \ No newline at end of file + ); +}; +export default FooterDetails; diff --git a/src/components/first/HeaderDetails.jsx b/src/components/first/HeaderDetails.jsx index 5e5f8e9..74d8174 100644 --- a/src/components/first/HeaderDetails.jsx +++ b/src/components/first/HeaderDetails.jsx @@ -1,16 +1,16 @@ -import {Box, Button, Container, Grid} from "@mui/material"; +import { Box, Button, Container, Grid } from "@mui/material"; const HeaderDetails = () => { return ( - + - @@ -95,9 +86,7 @@ const SendTokenComponent = ({ name="verification_code" variant="outlined" label={t("LoginPage.text_field_verification_code")} - placeholder={t( - "LoginPage.text_field_enter_your_verification_code" - )} + placeholder={t("LoginPage.text_field_enter_your_verification_code")} value={props.values.verification_code} type={"tel"} onChange={(event) => { @@ -113,7 +102,10 @@ const SendTokenComponent = ({ }); }} error={ - !!(props.touched.verification_code && props.errors.verification_code) + !!( + props.touched.verification_code && + props.errors.verification_code + ) } fullWidth helperText={ @@ -122,7 +114,7 @@ const SendTokenComponent = ({ : null } /> - + - setPlateDrawer(false)} - > - + setPlateDrawer(false)}> + {plate_words.map((item) => ( ) : (