From 586252edb8f51529bcf8e34912deab7e24710272 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 22 Apr 2024 14:23:49 +0330 Subject: [PATCH] submit api --- public/locales/fa/app.json | 9 +- .../forms/LegalPersonDatePicker.jsx | 4 +- .../forms/LegalPersonForm.jsx | 79 +++---- .../add-request-loan/forms/RealPersonForm.jsx | 63 ++---- src/core/components/MuiDatePicker.jsx | 214 +++++++++--------- src/lib/app/hooks/usePriorityLists.jsx | 34 --- src/lib/app/hooks/useProjectTitle.jsx | 1 - 7 files changed, 163 insertions(+), 241 deletions(-) delete mode 100644 src/lib/app/hooks/usePriorityLists.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index e03dc76..c9645ab 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -1,9 +1,9 @@ { "app_name": "سامانه جامع تسهیلات", "app_short_name": "سامانه تسهیلات", - "birthday": "تاریخ تولد", + "birthday": "تاریخ تولد {value}", "company_date": "تاریخ ثبت شرکت", - "birthday_error": "تاریخ تولد خود را وارد کنید!", + "birthday_error": "تاریخ تولد {value} را وارد کنید!", "dashboard": "داشبورد", "text_field_city_id": "شهر", "text_field_error_fetching_cities": "لطفا شهر خود را وارد کنید!", @@ -198,6 +198,7 @@ "error_message_national_id": "لطفا کد ملی خود را وارد کنید!", "error_message_national_number": "لطفا شناسه ملی شرکت خود را وارد کنید!", "error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!", + "error_message_boss_date_of_birth": "لطفا تاریخ تولد مدیر عامل را وارد کنید!", "error_message_shenasname_serial": "لطفا سریال پشت کارت ملی خود را وارد کنید!", "error_message_boss_shenasname_serial": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", "error_message_boss_national_serial_number": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!", @@ -210,7 +211,7 @@ "error_message_address": "لطفا آدرس خود را وارد کنید!", "error_message_activity_type": "لطفا نوع فعالیت خود را وارد کنید!", "error_message_priority_list": "لطفا اولویت فعالیت خود را وارد کنید!", - "error_message_project_title": "لطفا عنوان پروژه خود را وارد کنید!", + "error_message_navgan_plan_id": "لطفا عنوان پروژه خود را وارد کنید!", "text_field_tel_number": "شماره ثابت (با پیش شماره استان)", "text_field_company_tel_number": "شماره ثابت شرکت (با پیش شماره استان)", "text_field_education_id": "مدرک تحصیلی", @@ -221,7 +222,7 @@ "text_field_name": "نام", "text_field_company_name": "نام شرکت", "text_field_first_name": "نام", - "text_field_project_title": "عنوان پروژه", + "text_field_navgan_plan_id": "عنوان پروژه", "text_field_boss_first_name": "نام مدیر عامل", "text_field_last_name": "نام خانوادگی", "text_field_boss_last_name": "نام خانوادگی مدیر عامل", diff --git a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker.jsx b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker.jsx index 733e33a..2f9fcdb 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker.jsx @@ -53,8 +53,8 @@ function ButtonDatePicker(props) { formik: props.formik, field: { setOpen }, textField: { - helperText: props.formik.errors.birthday - ? `${t("birthday_error")}` + helperText: props.formik.errors.company_date + ? `${t("company_date")}` : null, }, }} 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 736a891..e3826d5 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/LegalPersonForm.jsx @@ -25,7 +25,7 @@ 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"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; const LegalPersonForm = ({setFinishLoanRequest}) => { const t = useTranslations(); @@ -37,15 +37,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { 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", company_tel_number: "", activity_type: "", - project_title: "", - priority_list: "", + navgan_plan_id: "", + birthday: "", vehicle_type: "", province_id: "", boss_father_name: "", @@ -83,10 +82,9 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { .required(t("LoanRequest.error_message_company_tel_number")), vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")), activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")), - project_title: Yup.string().required(t("LoanRequest.error_message_project_title")), - priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")), + navgan_plan_id: Yup.string().required(t("LoanRequest.error_message_navgan_plan_id")), register_number: Yup.string().required(t("LoanRequest.error_message_register_number")), - boss_father_name: Yup.string().required(t("LoanRequest.error_message_boss_father_name")), + birthday: Yup.string().required(t("LoanRequest.error_message_boss_date_of_birth")), company_name: Yup.string().required(t("LoanRequest.error_message_company_name")), boss_gender: Yup.string().required(t("LoanRequest.error_message_boss_gender")), navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")), @@ -171,6 +169,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { : { national_tracking_code: values.boss_national_card_tracking_code, }; + const _father_name = values.boss_father_name !== "" ? {father_name: values.boss_father_name} : {} let _data = { is_legal_person: 1, @@ -181,13 +180,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { company_name: values.company_name, province_id: values.province_id, city_id: values.city_id, - father_name: values.boss_father_name, first_name: values.boss_first_name, last_name: values.boss_last_name, navgan_id: values.navgan_id, activity_type_id: values.activity_type, - project_title: values.project_title, - activity_priority_id: values.priority_list, + navgan_plan_id: values.navgan_plan_id, postal_code: values.company_postal_code, navgan_type: values.navgan_type, gender: values.boss_gender, @@ -197,10 +194,12 @@ 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.birthday.locale("en").format("YYYY-MM-DD"), education_id: values.education_id, occupation_id: values.occupation_id, ..._national_card, ..._national_number, + ..._father_name }; await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", { @@ -229,28 +228,28 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { return ( <> - + { - formik.setFieldValue("project_title", event.target.value); + formik.setFieldValue("navgan_plan_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} - error={formik.touched.project_title && Boolean(formik.errors.project_title)} - helperText={formik.touched.project_title && formik.errors.project_title} - onBlur={formik.handleBlur("project_title")} + error={formik.touched.navgan_plan_id && Boolean(formik.errors.navgan_plan_id)} + helperText={formik.touched.navgan_plan_id && formik.errors.navgan_plan_id} + onBlur={formik.handleBlur("navgan_plan_id")} /> - + { onBlur={formik.handleBlur("activity_type")} /> - - { - formik.setFieldValue("priority_list", event.target.value); - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} - helperText={formik.touched.priority_list && formik.errors.priority_list} - onBlur={formik.handleBlur("priority_list")} - /> - @@ -549,7 +527,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { - + { helperText={formik.touched.boss_first_name && formik.errors.boss_first_name} /> - + { helperText={formik.touched.boss_last_name && formik.errors.boss_last_name} /> + + + @@ -665,9 +651,6 @@ const LegalPersonForm = ({setFinishLoanRequest}) => { label={t("LoanRequest.text_field_boss_father_name")} placeholder={t("LoanRequest.text_field_enter_your_boss_father_name")} fullWidth - onBlur={formik.handleBlur("boss_father_name")} - error={formik.touched.boss_father_name && Boolean(formik.errors.boss_father_name)} - helperText={formik.touched.boss_father_name && formik.errors.boss_father_name} /> 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 b0740af..d50fe47 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/RealPersonForm.jsx @@ -24,7 +24,6 @@ import * as React from "react"; import UseEducations from "@/lib/app/hooks/useEducations"; import useOccupations from "@/lib/app/hooks/useOccupations"; import useActivityType from "@/lib/app/hooks/useActivityType"; -import usePriorityLists from "@/lib/app/hooks/usePriorityLists"; import useProjectTitle from "@/lib/app/hooks/useProjectTitle"; const RealPersonForm = ({setFinishLoanRequest}) => { @@ -34,7 +33,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => { 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(); @@ -45,8 +43,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => { vehicle_type: "", telephone_number: "", activity_type: "", - project_title: "", - priority_list: "", + navgan_plan_id: "", father_name: "", gender: "", first_name: "", @@ -78,11 +75,9 @@ const RealPersonForm = ({setFinishLoanRequest}) => { return stringValue.length === 11; }) .required(t("LoanRequest.error_message_tel_number")), - father_name: Yup.string().required(t("LoanRequest.error_message_father_name")), vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")), activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")), - project_title: Yup.string().required(t("LoanRequest.error_message_project_title")), - priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")), + navgan_plan_id: Yup.string().required(t("LoanRequest.error_message_navgan_plan_id")), gender: Yup.string().required(t("LoanRequest.error_message_gender")), occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")), education_id: Yup.string().required(t("LoanRequest.error_message_education_id")), @@ -147,6 +142,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => { : { national_tracking_code: values.national_card_tracking_code, }; + const _father_name = values.father_name !== "" ? {father_name: values.father_name} : {} let _data = { is_legal_person: 0, @@ -155,7 +151,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => { vehicle_type: values.vehicle_type, province_id: values.province_id, city_id: values.city_id, - father_name: values.father_name, first_name: values.first_name, last_name: values.last_name, navgan_id: values.navgan_id, @@ -166,14 +161,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => { education_id: values.education_id, occupation_id: values.occupation_id, activity_type_id: values.activity_type, - project_title: values.project_title, - activity_priority_id: values.priority_list, + navgan_plan_id: values.navgan_plan_id, 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, + ..._father_name }; await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", { @@ -204,28 +199,28 @@ const RealPersonForm = ({setFinishLoanRequest}) => { return ( <> - + { - formik.setFieldValue("project_title", event.target.value); + formik.setFieldValue("navgan_plan_id", event.target.value); }} setFieldTouched={formik.setFieldTouched} - error={formik.touched.project_title && Boolean(formik.errors.project_title)} - helperText={formik.touched.project_title && formik.errors.project_title} - onBlur={formik.handleBlur("project_title")} + error={formik.touched.navgan_plan_id && Boolean(formik.errors.navgan_plan_id)} + helperText={formik.touched.navgan_plan_id && formik.errors.navgan_plan_id} + onBlur={formik.handleBlur("navgan_plan_id")} /> - + { onBlur={formik.handleBlur("activity_type")} /> - - { - formik.setFieldValue("priority_list", event.target.value); - }} - setFieldTouched={formik.setFieldTouched} - error={formik.touched.priority_list && Boolean(formik.errors.priority_list)} - helperText={formik.touched.priority_list && formik.errors.priority_list} - onBlur={formik.handleBlur("priority_list")} - /> - @@ -412,9 +386,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => { label={t("LoanRequest.text_field_father_name")} placeholder={t("LoanRequest.text_field_enter_your_father_name")} fullWidth - onBlur={formik.handleBlur("father_name")} - error={formik.touched.father_name && Boolean(formik.errors.father_name)} - helperText={formik.touched.father_name && formik.errors.father_name} /> diff --git a/src/core/components/MuiDatePicker.jsx b/src/core/components/MuiDatePicker.jsx index bf2c947..0551f0c 100644 --- a/src/core/components/MuiDatePicker.jsx +++ b/src/core/components/MuiDatePicker.jsx @@ -1,119 +1,121 @@ import * as React from "react"; -import { useMemo, useState } from "react"; +import {useMemo, useState} from "react"; import Button from "@mui/material/Button"; -import { AdapterDateFnsJalali } from "@mui/x-date-pickers/AdapterDateFnsJalali"; -import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; -import { DatePicker } from "@mui/x-date-pickers/DatePicker"; -import { faIR } from "@mui/x-date-pickers/locales"; -import { useTranslations } from "next-intl"; +import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali"; +import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider"; +import {DatePicker} from "@mui/x-date-pickers/DatePicker"; +import {faIR} from "@mui/x-date-pickers/locales"; +import {useTranslations} from "next-intl"; import moment from "jalali-moment"; -import { FormControl, FormHelperText } from "@mui/material"; -import { useConfig } from "@witel/webapp-builder"; +import {FormControl, FormHelperText} from "@mui/material"; +import {useConfig} from "@witel/webapp-builder"; function ButtonField(props) { - const t = useTranslations(); - const { - setOpen, - label, - id, - disabled, - InputProps: { ref } = {}, - inputProps: { "aria-label": ariaLabel } = {}, - } = props; + const t = useTranslations(); + const { + setOpen, + label, + id, + disabled, + InputProps: {ref} = {}, + inputProps: {"aria-label": ariaLabel} = {}, + } = props; - return ( - - ); + return ( + + ); } function ButtonDatePicker(props) { - const { config } = useConfig(); - const t = useTranslations(); - const [open, setOpen] = useState(false); - const dateRange = useMemo(() => { - const today = moment(); - const min = moment( - `${config.add_request_loan_birthday_range.min}-01-01`, - "jYYYY-jMM-jDD" - ).toDate(); - const max = moment( - `${config.add_request_loan_birthday_range.max}-${today.format( - "jMM-jDD" - )}`, - "jYYYY-jMM-jDD" - ).toDate(); - return { min, max }; - }, [config.add_request_loan_birthday_range]); + const {config} = useConfig(); + const t = useTranslations(); + const [open, setOpen] = useState(false); + const dateRange = useMemo(() => { + const today = moment(); + const min = moment( + `${config.add_request_loan_birthday_range.min}-01-01`, + "jYYYY-jMM-jDD" + ).toDate(); + const max = moment( + `${config.add_request_loan_birthday_range.max}-${today.format( + "jMM-jDD" + )}`, + "jYYYY-jMM-jDD" + ).toDate(); + return {min, max}; + }, [config.add_request_loan_birthday_range]); - return ( - setOpen(false)} - onOpen={() => setOpen(true)} - /> - ); + return ( + setOpen(false)} + onOpen={() => setOpen(true)} + /> + ); } -export default function PickerWithButtonField({ formik, disabled }) { - return ( - - - { - formik.setFieldValue("birthday", moment(newValue)); - }} - /> - - - {formik.touched.birthday && formik.errors.birthday} - - - ); +export default function PickerWithButtonField({formik, disabled}) { + return ( + + + { + formik.setFieldValue("birthday", moment(newValue)); + }} + /> + + + {formik.touched.birthday && formik.errors.birthday} + + + ); } \ No newline at end of file diff --git a/src/lib/app/hooks/usePriorityLists.jsx b/src/lib/app/hooks/usePriorityLists.jsx deleted file mode 100644 index 75a294e..0000000 --- a/src/lib/app/hooks/usePriorityLists.jsx +++ /dev/null @@ -1,34 +0,0 @@ -import {GET_PRIORITY_LIST} from "@/core/data/apiRoutes"; -import {useRequest} from "@witel/webapp-builder"; -import {useEffect, useState} from "react"; - -const usePriorityLists = () => { - const [isLoadingPriorityLists, setIsLoadingPriorityLists] = useState(false) - const [errorPriorityLists, setErrorPriorityLists] = useState(false) - const [priorityLists, setPriorityLists] = useState([]) - const requestServer = useRequest({auth: true, notification: false}) - - useEffect(() => { - setIsLoadingPriorityLists(true) - requestServer(GET_PRIORITY_LIST, 'get', {auth: true, notification: false}).then(({data}) => { - const formattedData = data.data.map((priorityList, index) => ({ - id: index, - name: priorityList.name, - value: priorityList.id, - })); - setIsLoadingPriorityLists(false) - setPriorityLists(formattedData); - }).catch(() => { - setIsLoadingPriorityLists(false) - setErrorPriorityLists(true) - }) - }, []) - - return { - priorityLists, - isLoadingPriorityLists, - errorPriorityLists - } -}; - -export default usePriorityLists; \ No newline at end of file diff --git a/src/lib/app/hooks/useProjectTitle.jsx b/src/lib/app/hooks/useProjectTitle.jsx index 31cbb35..3b8a643 100644 --- a/src/lib/app/hooks/useProjectTitle.jsx +++ b/src/lib/app/hooks/useProjectTitle.jsx @@ -25,7 +25,6 @@ const useProjectTitle = () => { setErrorProjectTitle(true); }); }, []); - return { projectTitle, isLoadingProjectTitle,