Merge branch 'feature/amin_loan_request' into 'develop'
Feature/amin loan request See merge request witel-front-end/loan-facilities/user-v2!1
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-toastify": "^9.1.3",
|
||||
"react-transition-group": "^4.4.5",
|
||||
"sass": "^1.62.0",
|
||||
"stylis": "^4.1.3",
|
||||
"stylis-plugin-rtl": "^2.1.1",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"app_name": "سامانه جامع تسهیلات",
|
||||
"app_short_name": "سامانه تسهیلات",
|
||||
"birthday": "تاریخ تولد",
|
||||
"company_date": "تاریخ ثبت شرکت",
|
||||
"birthday_error": "تاریخ تولد خود را وارد کنید!",
|
||||
"dashboard": "داشبورد",
|
||||
"text_field_city_id": "شهر",
|
||||
@@ -156,39 +157,77 @@
|
||||
"real_person": "شخص حقیقی",
|
||||
"legal_person": "شخص حقوقی",
|
||||
"national_code_number": "کد ملی می بایست شامل اعداد باشد",
|
||||
"national_number_number": "شناسه ملی می بایست شامل اعداد باشد",
|
||||
"boss_national_code_number": "کد ملی مدیر عامل می بایست شامل اعداد باشد",
|
||||
"national_number_number": "شناسه ملی شرکت می بایست شامل اعداد باشد",
|
||||
"national_code_max": "کد ملی می بایست 10 رقم باشد",
|
||||
"national_number_max": "شناسه ملی می بایست 11 رقم باشد",
|
||||
"national_serial_number_max": "سریال پشت کارت ملی می بایست 10 رقم باشد",
|
||||
"boss_national_code_max": "کد ملی مدیر عامل می بایست 10 رقم باشد",
|
||||
"national_number_max": "شناسه ملی شرکت می بایست 11 رقم باشد",
|
||||
"shenasname_serial_max": "سریال پشت کارت ملی می بایست شامل 10 بخش باشد",
|
||||
"postal_code_max": "کد پستی می بایست 10 رقم باشد",
|
||||
"tel_number_max": "شماره ثابت می بایست 11 رقم باشد",
|
||||
"company_tel_number_max": "شماره ثابت شرکت می بایست 11 رقم باشد",
|
||||
"national_code_positive": "کد ملی می بایست مثبت باشد",
|
||||
"national_number_positive": "شناسه ملی می بایست مثبت باشد",
|
||||
"boss_national_code_positive": "کد ملی مدیر عامل می بایست مثبت باشد",
|
||||
"national_number_positive": "شناسه ملی شرکت می بایست مثبت باشد",
|
||||
"uploading_documents": "اسناد",
|
||||
"error_message_person_type": "نوع شخص خود را وارد کنید!",
|
||||
"error_message_name": "لطفا نام خود را وارد کنید!",
|
||||
"error_message_company_name": "لطفا نام شرکت خود را وارد کنید!",
|
||||
"error_message_first_name": "لطفا نام خود را وارد کنید!",
|
||||
"error_message_boss_first_name": "لطفا نام مدیر عامل را وارد کنید!",
|
||||
"error_message_last_name": "لطفا نام خانوادگی خود را وارد کنید!",
|
||||
"error_message_boss_last_name": "لطفا نام خانوادگی مدیر عامل را وارد کنید!",
|
||||
"error_message_gender": "لطفا جنسیت خود را وارد کنید!",
|
||||
"error_message_boss_gender": "لطفا جنسیت مدیر عامل را وارد کنید!",
|
||||
"error_message_father_name": "لطفا نام پدر خود را وارد کنید!",
|
||||
"error_message_boss_father_name": "لطفا نام پدر مدیر عامل را وارد کنید!",
|
||||
"error_message_register_number": "لطفا شماره ثبت شرکت خود را وارد کنید!",
|
||||
"error_message_plate_number": "لطفا شماره پلاک را به درستی وارد کنید!",
|
||||
"error_message_occupation_id": "لطفا کد شغل را به درستی وارد کنید!",
|
||||
"error_message_education_id": "لطفا تحصیلات را به درستی وارد کنید!",
|
||||
"error_message_company_postal_code": "لطفا کد پستی شرکت را وارد کنید!",
|
||||
"error_message_education_id": "لطفا مدرک تحصیلی را به درستی وارد کنید!",
|
||||
"error_message_tel_number": "لطفا شماره ثابت (با پیش شماره استان) خود را وارد کنید!",
|
||||
"error_message_company_tel_number": "لطفا شماره ثابت شرکت (با پیش شماره استان) خود را وارد کنید!",
|
||||
"error_message_vehicle_type": "لطفا نوع وسیله نقلیه خود را وارد کنید!",
|
||||
"error_message_navgan_id": "لطفا کد هوشمند ناوگان خود را وارد کنید!",
|
||||
"error_message_province_id": "لطفا استان خود را وارد کنید!",
|
||||
"error_message_national_id": "لطفا کد ملی خود را وارد کنید!",
|
||||
"error_message_national_number": "لطفا شناسه ملی خود را وارد کنید!",
|
||||
"error_message_national_number": "لطفا شناسه ملی شرکت خود را وارد کنید!",
|
||||
"error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!",
|
||||
"error_message_shenasname_serial": "لطفا سریال پشت کارت ملی خود را وارد کنید!",
|
||||
"error_message_boss_national_serial_number": "لطفا سریال پشت کارت ملی مدیر عامل را وارد کنید!",
|
||||
"error_message_tracking_code": "لطفا کد رهگیری کارت ملی خود را وارد کنید!",
|
||||
"error_message_boss_national_card_tracking_code": "لطفا کد رهگیری کارت ملی مدیر عامل را وارد کنید!",
|
||||
"error_message_postal_code": "لطفا کد پستی خود را وارد کنید!",
|
||||
"error_message_national_code": "لطفا کد ملی خود را وارد کنید!",
|
||||
"error_message_checkedBox": "لطفا کد صحت اطلاعات خود را تایید کنید!",
|
||||
"error_message_navgan_type": "لطفا نوع ناوگان خود را وارد کنید!",
|
||||
"error_message_address": "لطفا آدرس خود را وارد کنید!",
|
||||
"error_message_activity_type": "لطفا نوع فعالیت خود را وارد کنید!",
|
||||
"error_message_priority_list": "لطفا اولویت فعالیت خود را وارد کنید!",
|
||||
"error_message_project_title": "لطفا عنوان پروژه خود را وارد کنید!",
|
||||
"text_field_tel_number": "شماره ثابت (با پیش شماره استان)",
|
||||
"text_field_education_id": "تحصیلات",
|
||||
"text_field_company_tel_number": "شماره ثابت شرکت (با پیش شماره استان)",
|
||||
"text_field_education_id": "مدرک تحصیلی",
|
||||
"text_field_company_postal_code": "کد پستی شرکت",
|
||||
"text_field_occupation_id": "شغل",
|
||||
"company_postal_code_max": "کد پستی شرکت می بایست 10 رقم باشد",
|
||||
"text_field_enter_your_tel_number": "شماره ثابت (با پیش شماره استان) خود را وارد کنید",
|
||||
"text_field_name": "نام",
|
||||
"text_field_company_name": "نام شرکت",
|
||||
"text_field_first_name": "نام",
|
||||
"text_field_project_title": "عنوان پروژه",
|
||||
"text_field_boss_first_name": "نام مدیر عامل",
|
||||
"text_field_last_name": "نام خانوادگی",
|
||||
"text_field_boss_last_name": "نام خانوادگی مدیر عامل",
|
||||
"text_field_gender": "جنسیت",
|
||||
"text_field_activity_type": "نوع فعالیت",
|
||||
"text_field_priority_list": "اولویت فعالیت",
|
||||
"text_field_boss_gender": "جنسیت مدیر عامل",
|
||||
"text_field_register_number": "شماره ثبت شرکت",
|
||||
"text_field_father_name": "نام پدر",
|
||||
"text_field_boss_father_name": "نام پدر مدیر عامل",
|
||||
"text_field_plate_part4": "بخش چهارم",
|
||||
"text_field_plate_part3": "بخش سوم",
|
||||
"text_field_plate_part2": "بخش دوم",
|
||||
@@ -200,27 +239,43 @@
|
||||
"text_field_enter_your_plate_part2": "بخش دوم پلاک را وارد کنید",
|
||||
"text_field_enter_your_plate_part3": "بخش سوم پلاک را وارد کنید",
|
||||
"text_field_enter_your_plate_part4": "بخش چهارم پلاک راوارد کنید",
|
||||
"text_field_enter_your_first_name": "نام خود راوارد کنید",
|
||||
"text_field_enter_your_boss_first_name": "نام مدیر عامل راوارد کنید",
|
||||
"text_field_enter_your_company_name": "نام شرکت خود راوارد کنید",
|
||||
"text_field_enter_your_last_name": "نام خانوادگی خود راوارد کنید",
|
||||
"text_field_enter_your_boss_last_name": "نام خانوادگی مدیر عامل راوارد کنید",
|
||||
"text_field_enter_your_address": "آدرس خود راوارد کنید",
|
||||
"text_field_enter_your_name": "نام خود را وارد کنید",
|
||||
"text_field_enter_your_company_postal_code": "کد پستی شرکت را وارد کنید",
|
||||
"text_field_enter_your_register_number": "شماره ثبت شرکت خود را وارد کنید",
|
||||
"text_field_enter_your_father_name": "نام پدر خود را وارد کنید",
|
||||
"text_field_enter_your_boss_father_name": "نام پدر مدیر عامل را وارد کنید",
|
||||
"text_field_enter_your_postal_code": "کد پستی خود را وارد کنید",
|
||||
"text_field_enter_your_company_tel_number": "تلفن ثابت شرکت خود را وارد کنید",
|
||||
"text_field_vehicle_type": "نوع وسیله نقلیه",
|
||||
"text_field_enter_your_vehicle_type": "نوع وسیله نقلیه خود را وارد کنید",
|
||||
"text_field_province_id": "استان",
|
||||
"text_field_loading_provinces_list": "درحال دریافت استان ها ...",
|
||||
"text_field_error_fetching_provinces": "خطا در دریافت استان ها",
|
||||
"text_field_enter_your_national_code": "کد ملی خود را وارد کنید",
|
||||
"text_field_enter_your_boss_national_code": "کد ملی مدیر عامل را وارد کنید",
|
||||
"text_field_enter_your_province_id": "استان خود را وارد کنید",
|
||||
"text_field_enter_your_city_id": "شهر خود را وارد کنید",
|
||||
"text_field_navgan_id": "کد هوشمند ناوگان",
|
||||
"text_field_enter_your_navgan_id": "کد هوشمند ناوگان خود را وارد کنید",
|
||||
"text_field_national_code": "کد ملی",
|
||||
"text_field_national_number": "شناسه ملی",
|
||||
"text_field_boss_national_code": "کد ملی مدیر عامل",
|
||||
"text_field_national_number": "شناسه ملی شرکت",
|
||||
"text_field_enter_your_national_id": "کد ملی خود را وارد کنید",
|
||||
"text_field_enter_your_national_number": "شناسه ملی خود را وارد کنید",
|
||||
"text_field_enter_your_national_number": "شناسه ملی شرکت خود را وارد کنید",
|
||||
"text_field_shenasname_serial": "سریال پشت کارت ملی",
|
||||
"text_field_boss_national_serial_number": "سریال پشت کارت ملی مدیر عامل",
|
||||
"text_field_enter_your_shenasname_serial": "سریال پشت کارت ملی خود را وارد کنید",
|
||||
"text_field_enter_your_boss_national_serial_number": "سریال پشت کارت ملی مدیر عامل را وارد کنید",
|
||||
"text_field_national_trackin_code": "کد رهگیری کارت ملی",
|
||||
"text_field_boss_national_card_tracking_code": "کد رهگیری کارت ملی مدیر عامل",
|
||||
"text_field_enter_your_trackin_code": "کد رهگیری کارت ملی خود را وارد کنید",
|
||||
"text_field_enter_your_boss_national_card_tracking_code": "کد رهگیری کارت ملی مدیر عامل را وارد کنید",
|
||||
"text_field_plate_number": "شماره پلاک",
|
||||
"text_field_enter_your_plate_number": "شماره پلاک خود را وارد کنید",
|
||||
"button_submit": "ثبت درخواست",
|
||||
@@ -261,6 +316,7 @@
|
||||
"text_field_tel_number": "شماره ثابت (با پیش شماره استان)",
|
||||
"text_field_enter_your_national_id": "کد ملی را وارد کنید",
|
||||
"text_field_enter_your_postal_code": "کد پستی را وارد کنید",
|
||||
"text_field_enter_your_company_postal_code": "کد پستی شرکت را وارد کنید",
|
||||
"text_field_enter_your_national_serial_number": "سریال پشت کارت ملی را وارد کنید",
|
||||
"text_field_enter_your_address": "آدرس را وارد کنید",
|
||||
"text_field_enter_your_tel_number": "شماره ثابت (با پیش شماره استان) خود را وارد کنید",
|
||||
@@ -270,7 +326,8 @@
|
||||
"text_field_enter_your_shenase_meli": "شناسه ملی را وارد کنید",
|
||||
"text_field_enter_your_national_tracking_code": "کد رهگیری کارت ملی را وارد کنید",
|
||||
"postal_code_max": "کد پستی می بایست 10 رقم باشد",
|
||||
"error_message_postal_code": "لطفا کد پستی را وارد کنید!",
|
||||
"company_postal_code_max": "کد پستی شرکت می بایست 10 رقم باشد",
|
||||
"error_message_company_postal_code": "لطفا کد پستی شرکت را وارد کنید!",
|
||||
"error_message_national_serial_number": "لطفا سریال پشت کارت ملی را وارد کنید!",
|
||||
"error_message_address": "لطفا آدرس را وارد کنید!",
|
||||
"error_message_birthday": "لطفا تاریخ تولد را وارد کنید!",
|
||||
@@ -284,7 +341,7 @@
|
||||
"error_message_fixed_number": "لطفا تلفن ثابت را وارد کنید!",
|
||||
"error_message_tel_number": "لطفا شماره ثابت (با پیش شماره استان) خود را وارد کنید!",
|
||||
"error_message_occupation_id": "لطفا کد شغل (با توجه به مستندات ارائه شده) را به درستی وارد کنید!",
|
||||
"error_message_education_id": "لطفا تحصیلات (با توجه به مستندات ارائه شده) را به درستی وارد کنید!",
|
||||
"error_message_education_id": "لطفا مدرک تحصیلی (با توجه به مستندات ارائه شده) را به درستی وارد کنید!",
|
||||
"cityList_empty": "شهر یافت نشد",
|
||||
"button_submit": "ویرایش",
|
||||
"error_message_not_show_state": "شما دسترسی لازم به دریافت اطلاعات را ندارید!"
|
||||
|
||||
@@ -18,7 +18,7 @@ const FirstComponent = () => {
|
||||
<Typography>{t("Dashboard.go_to_add_request_loan")}</Typography>
|
||||
<Button
|
||||
component={NextLinkComposed}
|
||||
to={{ pathname: "/dashboard/navgan/add-request-loan" }}
|
||||
to={{ pathname: "/dashboard/navgan/past-add-request-loan" }}
|
||||
variant={"contained"}
|
||||
size={"large"}
|
||||
>
|
||||
|
||||
@@ -1,169 +1,24 @@
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Checkbox,
|
||||
Fade,
|
||||
FormControlLabel,
|
||||
Grid,
|
||||
Stack,
|
||||
TextField,
|
||||
ToggleButton,
|
||||
ToggleButtonGroup,
|
||||
Typography
|
||||
} from "@mui/material";
|
||||
import {useFormik} from "formik";
|
||||
import {useTranslations} from "next-intl";
|
||||
import * as Yup from "yup";
|
||||
import {CenterLayout, useRequest, useUser} from "@witel/webapp-builder";
|
||||
import useCities from "@/lib/app/hooks/useCities";
|
||||
import PlateNumber from "@/core/components/PlateNumber";
|
||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||
import UseEducations from "@/lib/app/hooks/useEducations";
|
||||
import useOccupations from "@/lib/app/hooks/useOccupations";
|
||||
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 {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||
import {useRouter} from "next/router";
|
||||
import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||
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 router = useRouter()
|
||||
const {getUser, changeUser} = useUser()
|
||||
const t = useTranslations();
|
||||
const [finishLoanRequest, setFinishLoanRequest] = useState(false)
|
||||
const [checked, setChecked] = useState(false);
|
||||
const requestServer = useRequest()
|
||||
const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince()
|
||||
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
||||
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
||||
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
||||
|
||||
const initialValues = {
|
||||
person_type: "real",
|
||||
telephone_number: "",
|
||||
vehicle_type: "",
|
||||
province_id: "",
|
||||
city_id: "",
|
||||
navgan_id: "",
|
||||
national_id: "",
|
||||
national_number: "",
|
||||
national_serial_number: "",
|
||||
national_card_tracking_code: "",
|
||||
national_serial_number_or_tracking_code: "national_serial_number",
|
||||
postal_code: "",
|
||||
navgan_type: "",
|
||||
plate_part1: "",
|
||||
plate_part2: "الف",
|
||||
plate_part3: "",
|
||||
plate_part4: "",
|
||||
address: "",
|
||||
birthday: "",
|
||||
education_id: "",
|
||||
occupation_id: "",
|
||||
checkedBox: false,
|
||||
};
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
person_type: Yup.string().required(t("LoanRequest.error_message_person_type")),
|
||||
telephone_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
return stringValue.length === 11
|
||||
})
|
||||
.required(t("LoanRequest.error_message_tel_number")),
|
||||
vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")),
|
||||
navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")),
|
||||
occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")),
|
||||
education_id: Yup.string().required(t("LoanRequest.error_message_education_id")),
|
||||
address: Yup.string().required(t("LoanRequest.error_message_address")),
|
||||
birthday: Yup.string().required(t("LoanRequest.error_message_date_of_birth")),
|
||||
postal_code: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.postal_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_postal_code")),
|
||||
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()
|
||||
.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)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
|
||||
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
|
||||
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
|
||||
national_id: Yup.mixed()
|
||||
.test("is-number", `${t("LoanRequest.national_code_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_national_id")),
|
||||
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().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
|
||||
} : {}
|
||||
|
||||
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: values.person_type === 'legal' ? 1 : 0,
|
||||
telephone_number: values.telephone_number,
|
||||
national_id: values.national_id,
|
||||
vehicle_type: values.vehicle_type,
|
||||
province_id: values.province_id,
|
||||
city_id: values.city_id,
|
||||
navgan_id: values.navgan_id,
|
||||
postal_code: values.postal_code,
|
||||
navgan_type: values.navgan_type,
|
||||
plate_part1: values.plate_part1,
|
||||
plate_part2: values.plate_part2,
|
||||
plate_part3: values.plate_part3,
|
||||
plate_part4: values.plate_part4,
|
||||
address: values.address,
|
||||
birthday: values.birthday.locale('en').format("YYYY-MM-DD"),
|
||||
education_id: values.education_id,
|
||||
occupation_id: values.occupation_id, ..._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)
|
||||
})
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
const [personType, setPersonType] = useState("real")
|
||||
|
||||
return (<>
|
||||
{finishLoanRequest ? (<CenterLayout>
|
||||
@@ -177,24 +32,16 @@ const AddFormComponent = () => {
|
||||
to={'/dashboard/navgan/followUp-loan'}>
|
||||
{t("LoanRequest.back_to_dashboard")}
|
||||
</Button>
|
||||
</CenterLayout>) : (<>
|
||||
<Grid container spacing={2} sx={{padding: 2}}
|
||||
>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
</CenterLayout>) : (
|
||||
<>
|
||||
<Stack sx={{width: "100%", my : 3}} justifyContent={'center'} alignItems={'center'}>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.person_type}
|
||||
value={personType}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "person_type", value: value,
|
||||
},
|
||||
})
|
||||
setPersonType(value)
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="real">
|
||||
@@ -204,412 +51,13 @@ const AddFormComponent = () => {
|
||||
{t("LoanRequest.legal_person")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_id"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_id}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_id", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_code")}
|
||||
onBlur={formik.handleBlur("national_id")}
|
||||
error={formik.touched.national_id && Boolean(formik.errors.national_id)}
|
||||
helperText={formik.touched.national_id && formik.errors.national_id}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
<Fade in={formik.values.person_type === 'legal'}>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_number")}
|
||||
onBlur={formik.handleBlur("national_number")}
|
||||
error={formik.touched.national_number && Boolean(formik.errors.national_number)}
|
||||
helperText={formik.touched.national_number && formik.errors.national_number}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
</Fade>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}
|
||||
>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
{t("LoanRequest.text_field_shenasname_serial")}
|
||||
</ToggleButton>
|
||||
<ToggleButton value="national_card_tracking_code">
|
||||
{t("LoanRequest.text_field_national_trackin_code")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_serial_number}
|
||||
label={t("LoanRequest.text_field_shenasname_serial")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_shenasname_serial")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("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}
|
||||
/>
|
||||
</Grid>) : (<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_card_tracking_code}
|
||||
label={t("LoanRequest.text_field_national_trackin_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_trackin_code")}
|
||||
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}
|
||||
/>
|
||||
</Grid>)}
|
||||
|
||||
<Grid item xs={12} sm={4}>
|
||||
<MuiDatePicker
|
||||
formik={formik}
|
||||
error={formik.touched.birthday && Boolean(formik.errors.birthday)}
|
||||
helperText={formik.touched.birthday && formik.errors.birthday}
|
||||
onBlur={formik.handleBlur("birthday")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "postal_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_postal_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_postal_code")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("postal_code")}
|
||||
error={formik.touched.postal_code && Boolean(formik.errors.postal_code)}
|
||||
helperText={formik.touched.postal_code && formik.errors.postal_code}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="telephone_number"
|
||||
variant="outlined"
|
||||
value={formik.values.telephone_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "telephone_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_tel_number")}
|
||||
placeholder={t("LoanRequest.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}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
label={t("LoanRequest.text_field_navgan_type")}
|
||||
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'}}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_navgan_id")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_navgan_id")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("navgan_id")}
|
||||
error={formik.touched.navgan_id && Boolean(formik.errors.navgan_id)}
|
||||
helperText={formik.touched.navgan_id && formik.errors.navgan_id}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
label={t("LoanRequest.text_field_province_id")}
|
||||
size="small"
|
||||
selectType="province_id"
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
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.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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
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}
|
||||
onBlur={formik.handleBlur("city_id")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="vehicle_type"
|
||||
label={t("LoanRequest.text_field_vehicle_type")}
|
||||
size="small"
|
||||
value={formik.values.vehicle_type}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
label={t("LoanRequest.text_field_education_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingEducationsList}
|
||||
errorEcured={errorEducationsList}
|
||||
selectType="education_id"
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="occupation_id"
|
||||
label={t("LoanRequest.text_field_occupation_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
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)
|
||||
}}
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={8}
|
||||
sx={{width: "100%"}}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_address")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_address")}
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("address")}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<FormControlLabel
|
||||
color={'error.main'}
|
||||
control={<Checkbox
|
||||
checked={formik.values.checkedBox}
|
||||
onChange={(event) => {
|
||||
formik.setFieldValue("checkedBox", event.target.checked)
|
||||
}}
|
||||
/>}
|
||||
label={`${t("LoanRequest.checkbox")}`}/>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: {xs: "column", sm: "row"},
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
>
|
||||
{formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")}
|
||||
</Button>
|
||||
</Box>
|
||||
</>)}
|
||||
</Stack>
|
||||
{
|
||||
personType === "real" ? <RealPersonForm setFinishLoanRequest={setFinishLoanRequest}/> :
|
||||
<LegalPersonForm setFinishLoanRequest={setFinishLoanRequest}/>
|
||||
}
|
||||
</>
|
||||
)}
|
||||
</>);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import {FormControl, FormHelperText} from "@mui/material";
|
||||
import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
|
||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||
import {faIR} from "@mui/x-date-pickers/locales";
|
||||
import moment from "jalali-moment";
|
||||
import * as React from "react";
|
||||
import {useTranslations} from "next-intl";
|
||||
import Button from "@mui/material/Button";
|
||||
import {useConfig} from "@witel/webapp-builder";
|
||||
import {useMemo, useState} from "react";
|
||||
import {DatePicker} from "@mui/x-date-pickers/DatePicker";
|
||||
|
||||
function ButtonField(props) {
|
||||
const t = useTranslations();
|
||||
const {
|
||||
setOpen,
|
||||
label,
|
||||
id,
|
||||
disabled,
|
||||
InputProps: { ref } = {},
|
||||
inputProps: { "aria-label": ariaLabel } = {},
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<Button
|
||||
sx={{ width: "100%", padding: 0.8 }}
|
||||
variant="outlined"
|
||||
color={
|
||||
props.slotProps.formik.touched.company_date &&
|
||||
Boolean(props.slotProps.formik.errors.company_date)
|
||||
? "error"
|
||||
: "primary"
|
||||
}
|
||||
id={id}
|
||||
disabled={disabled}
|
||||
ref={ref}
|
||||
aria-label={ariaLabel}
|
||||
onClick={() => setOpen?.((prev) => !prev)}
|
||||
>
|
||||
{label ? `${t("company_date")}: ${label}` : `${t("company_date")}`}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonDatePicker(props) {
|
||||
const t = useTranslations();
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<DatePicker
|
||||
slots={{ field: ButtonField, ...props.slots }}
|
||||
disabled={props.disabled}
|
||||
slotProps={{
|
||||
formik: props.formik,
|
||||
field: { setOpen },
|
||||
textField: {
|
||||
helperText: props.formik.errors.birthday
|
||||
? `${t("birthday_error")}`
|
||||
: null,
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
open={open}
|
||||
disableFuture
|
||||
onClose={() => setOpen(false)}
|
||||
onOpen={() => setOpen(true)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const LegalPersonDatePicker = ({ formik, disabled }) => {
|
||||
return (
|
||||
<FormControl variant={"outlined"} fullWidth size="small" error={true}>
|
||||
<LocalizationProvider
|
||||
dateAdapter={AdapterDateFnsJalali}
|
||||
localeText={{
|
||||
...faIR.components.MuiLocalizationProvider.defaultProps.localeText,
|
||||
okButtonLabel: "تایید",
|
||||
}}
|
||||
>
|
||||
<ButtonDatePicker
|
||||
label={
|
||||
formik.values.company_date !== "" &&
|
||||
formik.values.company_date.locale("fa").format("YYYY/MM/DD")
|
||||
}
|
||||
value={
|
||||
formik.values.company_date !== ""
|
||||
? formik.values.company_date.toDate()
|
||||
: null
|
||||
}
|
||||
formik={formik}
|
||||
disabled={disabled}
|
||||
onChange={(newValue) => {
|
||||
formik.setFieldValue("company_date", moment(newValue));
|
||||
}}
|
||||
/>
|
||||
</LocalizationProvider>
|
||||
<FormHelperText>
|
||||
{formik.touched.company_date && formik.errors.company_date}
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
||||
export default LegalPersonDatePicker
|
||||
@@ -0,0 +1,765 @@
|
||||
import {Box, Button, Checkbox, FormControlLabel, Grid, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
|
||||
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";
|
||||
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 * as Yup from "yup";
|
||||
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
|
||||
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 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 initialValues = {
|
||||
person_type: "legal",
|
||||
company_tel_number: "",
|
||||
activity_type: "",
|
||||
project_title: "",
|
||||
priority_list: "",
|
||||
vehicle_type: "",
|
||||
province_id: "",
|
||||
boss_father_name: "",
|
||||
company_postal_code : "",
|
||||
register_number: "",
|
||||
boss_gender: "",
|
||||
boss_first_name: "",
|
||||
boss_last_name: "",
|
||||
city_id: "",
|
||||
navgan_id: "",
|
||||
boss_national_code: "",
|
||||
national_number: "",
|
||||
company_name: "",
|
||||
boss_national_serial_number: "",
|
||||
boss_national_card_tracking_code: "",
|
||||
national_serial_number_or_tracking_code: "national_serial_number",
|
||||
navgan_type: "",
|
||||
plate_part1: "",
|
||||
plate_part2: "الف",
|
||||
plate_part3: "",
|
||||
plate_part4: "",
|
||||
address: "",
|
||||
company_date: "",
|
||||
education_id: "",
|
||||
occupation_id: "",
|
||||
checkedBox: false,
|
||||
};
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
company_tel_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.company_tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
return stringValue.length === 11
|
||||
})
|
||||
.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")),
|
||||
register_number: Yup.string().required(t("LoanRequest.error_message_register_number")),
|
||||
boss_father_name: Yup.string().required(t("LoanRequest.error_message_boss_father_name")),
|
||||
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")),
|
||||
occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")),
|
||||
education_id: Yup.string().required(t("LoanRequest.error_message_education_id")),
|
||||
address: Yup.string().required(t("LoanRequest.error_message_address")),
|
||||
company_date: Yup.string().required(t("LoanRequest.error_message_date_of_birth")),
|
||||
company_postal_code: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.company_postal_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_company_postal_code")),
|
||||
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()
|
||||
.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)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
|
||||
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
|
||||
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
|
||||
boss_first_name: Yup.string().required(t("LoanRequest.error_message_boss_first_name")),
|
||||
boss_last_name: Yup.string().required(t("LoanRequest.error_message_boss_last_name")),
|
||||
boss_national_code: Yup.mixed()
|
||||
.test("is-number", `${t("LoanRequest.boss_national_code_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.boss_national_code_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.boss_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;
|
||||
}),
|
||||
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.required(t("LoanRequest.error_message_boss_national_serial_number")) : 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
|
||||
})
|
||||
});
|
||||
|
||||
const handleSubmit = async (values, props) => {
|
||||
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
|
||||
}
|
||||
|
||||
let _data = {
|
||||
is_legal_person: values.person_type === 'legal' ? 1 : 0,
|
||||
telephone_number: values.company_tel_number,
|
||||
register_number: values.register_number,
|
||||
national_code: values.boss_national_code,
|
||||
vehicle_type: values.vehicle_type,
|
||||
company_name: values.company_name,
|
||||
province_id: values.province_id,
|
||||
father_name: values.father_name,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
city_id: values.city_id,
|
||||
navgan_id: values.navgan_id,
|
||||
postal_code: values.postal_code,
|
||||
navgan_type: values.navgan_type,
|
||||
gender: values.gender,
|
||||
plate_part1: values.plate_part1,
|
||||
plate_part2: values.plate_part2,
|
||||
plate_part3: values.plate_part3,
|
||||
plate_part4: values.plate_part4,
|
||||
address: values.address,
|
||||
birthday: values.birthday.locale('en').format("YYYY-MM-DD"),
|
||||
education_id: values.education_id,
|
||||
occupation_id: values.occupation_id, ..._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)
|
||||
})
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
return (
|
||||
<>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
{/*<Grid item xs={12} sm={4}>*/}
|
||||
{/* <SelectBox*/}
|
||||
{/* name="project_title"*/}
|
||||
{/* label={t("LoanRequest.text_field_project_title")}*/}
|
||||
{/* size="small"*/}
|
||||
{/* selectType="project_title"*/}
|
||||
{/* isLoading={isLoadingProjectTitle}*/}
|
||||
{/* errorEcured={errorProjectTitle}*/}
|
||||
{/* selectors={projectTitle}*/}
|
||||
{/* schema={{value: 'value', name: 'name'}}*/}
|
||||
{/* select={formik.values.project_title}*/}
|
||||
{/* value={formik.values.project_title}*/}
|
||||
{/* handleChange={(event) => {*/}
|
||||
{/* formik.setFieldValue('project_title', 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")}*/}
|
||||
{/* />*/}
|
||||
{/*</Grid>*/}
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="activity_type"
|
||||
label={t("LoanRequest.text_field_activity_type")}
|
||||
size="small"
|
||||
selectType="activity_type"
|
||||
isLoading={isLoadingActivityType}
|
||||
errorEcured={errorActivityType}
|
||||
selectors={activityType}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
select={formik.values.activity_type}
|
||||
value={formik.values.activity_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="priority_list"
|
||||
label={t("LoanRequest.text_field_priority_list")}
|
||||
size="small"
|
||||
selectType="priority_list"
|
||||
isLoading={isLoadingPriorityLists}
|
||||
errorEcured={errorPriorityLists}
|
||||
selectors={priorityLists}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
select={formik.values.priority_list}
|
||||
value={formik.values.priority_list}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_number")}
|
||||
onBlur={formik.handleBlur("national_number")}
|
||||
error={formik.touched.national_number && Boolean(formik.errors.national_number)}
|
||||
helperText={formik.touched.national_number && formik.errors.national_number}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="company_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.company_name}
|
||||
label={t("LoanRequest.text_field_company_name")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_company_name")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("company_name")}
|
||||
error={formik.touched.company_name && Boolean(formik.errors.company_name)}
|
||||
helperText={formik.touched.company_name && formik.errors.company_name}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="register_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.register_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "register_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_register_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_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
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="company_postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.company_postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "company_postal_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_company_postal_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_company_postal_code")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("company_postal_code")}
|
||||
error={formik.touched.company_postal_code && Boolean(formik.errors.company_postal_code)}
|
||||
helperText={formik.touched.company_postal_code && formik.errors.company_postal_code}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="company_tel_number"
|
||||
variant="outlined"
|
||||
value={formik.values.company_tel_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "company_tel_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_company_tel_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_company_tel_number")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("company_tel_number")}
|
||||
error={formik.touched.company_tel_number && Boolean(formik.errors.company_tel_number)}
|
||||
helperText={formik.touched.company_tel_number && formik.errors.company_tel_number}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<LegalPersonDatePicker
|
||||
formik={formik}
|
||||
error={formik.touched.company_date && Boolean(formik.errors.company_date)}
|
||||
helperText={formik.touched.company_date && formik.errors.company_date}
|
||||
onBlur={formik.handleBlur("company_date")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
label={t("LoanRequest.text_field_province_id")}
|
||||
size="small"
|
||||
selectType="province_id"
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
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.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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
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}
|
||||
onBlur={formik.handleBlur("city_id")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_national_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.boss_national_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "boss_national_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_boss_national_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_boss_national_code")}
|
||||
onBlur={formik.handleBlur("boss_national_code")}
|
||||
error={formik.touched.boss_national_code && Boolean(formik.errors.boss_national_code)}
|
||||
helperText={formik.touched.boss_national_code && formik.errors.boss_national_code}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="boss_gender"
|
||||
label={t("LoanRequest.text_field_boss_gender")}
|
||||
size="small"
|
||||
value={formik.values.boss_gender}
|
||||
selectType="boss_gender"
|
||||
selectors={[{
|
||||
id: 1, value: 1, name: "زن"
|
||||
}, {
|
||||
id: 2, value: 0, name: "مرد"
|
||||
}]}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
select={formik.values.boss_gender}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('boss_gender', event.target.value)
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.boss_gender && Boolean(formik.errors.boss_gender)}
|
||||
helperText={formik.touched.boss_gender && formik.errors.boss_gender}
|
||||
onBlur={formik.handleBlur("boss_gender")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_first_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.boss_first_name}
|
||||
label={t("LoanRequest.text_field_boss_first_name")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_boss_first_name")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("boss_first_name")}
|
||||
error={formik.touched.boss_first_name && Boolean(formik.errors.boss_first_name)}
|
||||
helperText={formik.touched.boss_first_name && formik.errors.boss_first_name}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_last_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.boss_last_name}
|
||||
label={t("LoanRequest.text_field_boss_last_name")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_boss_last_name")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("boss_last_name")}
|
||||
error={formik.touched.boss_last_name && Boolean(formik.errors.boss_last_name)}
|
||||
helperText={formik.touched.boss_last_name && formik.errors.boss_last_name}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
{t("LoanRequest.text_field_shenasname_serial")}
|
||||
</ToggleButton>
|
||||
<ToggleButton value="national_card_tracking_code">
|
||||
{t("LoanRequest.text_field_national_trackin_code")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.boss_national_serial_number}
|
||||
label={t("LoanRequest.text_field_boss_national_serial_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_boss_national_serial_number")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("boss_national_serial_number")}
|
||||
error={formik.touched.boss_national_serial_number && Boolean(formik.errors.boss_national_serial_number)}
|
||||
helperText={formik.touched.boss_national_serial_number && formik.errors.boss_national_serial_number}
|
||||
/>
|
||||
</Grid>) : (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.boss_national_card_tracking_code}
|
||||
label={t("LoanRequest.text_field_boss_national_card_tracking_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_boss_national_card_tracking_code")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("boss_national_card_tracking_code")}
|
||||
error={formik.touched.boss_national_card_tracking_code && Boolean(formik.errors.boss_national_card_tracking_code)}
|
||||
helperText={formik.touched.boss_national_card_tracking_code && formik.errors.boss_national_card_tracking_code}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="boss_father_name"
|
||||
variant="outlined"
|
||||
value={formik.values.boss_father_name}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
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}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
label={t("LoanRequest.text_field_navgan_type")}
|
||||
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'}}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_navgan_id")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_navgan_id")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("navgan_id")}
|
||||
error={formik.touched.navgan_id && Boolean(formik.errors.navgan_id)}
|
||||
helperText={formik.touched.navgan_id && formik.errors.navgan_id}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="vehicle_type"
|
||||
label={t("LoanRequest.text_field_vehicle_type")}
|
||||
size="small"
|
||||
value={formik.values.vehicle_type}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
label={t("LoanRequest.text_field_education_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingEducationsList}
|
||||
errorEcured={errorEducationsList}
|
||||
selectType="education_id"
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="occupation_id"
|
||||
label={t("LoanRequest.text_field_occupation_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
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)
|
||||
}}
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={4}
|
||||
sx={{width: "100%"}}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_address")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_address")}
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("address")}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<FormControlLabel
|
||||
color={'error.main'}
|
||||
control={<Checkbox
|
||||
checked={formik.values.checkedBox}
|
||||
onChange={(event) => {
|
||||
formik.setFieldValue("checkedBox", event.target.checked)
|
||||
}}
|
||||
/>}
|
||||
label={`${t("LoanRequest.checkbox")}`}/>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: {xs: "column", sm: "row"},
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
>
|
||||
{formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")}
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
export default LegalPersonForm
|
||||
@@ -0,0 +1,679 @@
|
||||
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 useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||
import useCities from "@/lib/app/hooks/useCities";
|
||||
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 PlateNumber from "@/core/components/PlateNumber";
|
||||
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";
|
||||
|
||||
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 requestServer = useRequest()
|
||||
const {getUser, changeUser} = useUser()
|
||||
const router = useRouter()
|
||||
|
||||
const initialValues = {
|
||||
person_type : "real",
|
||||
vehicle_type : "",
|
||||
telephone_number: "",
|
||||
activity_type: "",
|
||||
project_title: "",
|
||||
priority_list: "",
|
||||
father_name: "",
|
||||
gender: "",
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
city_id: "",
|
||||
province_id: "",
|
||||
education_id: "",
|
||||
occupation_id: "",
|
||||
navgan_id: "",
|
||||
national_code: "",
|
||||
national_serial_number: "",
|
||||
national_card_tracking_code: "",
|
||||
national_serial_number_or_tracking_code: "national_serial_number",
|
||||
postal_code: "",
|
||||
navgan_type: "",
|
||||
address: "",
|
||||
plate_part1: "",
|
||||
plate_part2: "الف",
|
||||
plate_part3: "",
|
||||
plate_part4: "",
|
||||
birthday: "",
|
||||
checkedBox: false,
|
||||
};
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
telephone_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
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")),
|
||||
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")),
|
||||
navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")),
|
||||
address: Yup.string().required(t("LoanRequest.error_message_address")),
|
||||
birthday: Yup.string().required(t("LoanRequest.error_message_date_of_birth")),
|
||||
postal_code: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.postal_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_postal_code")),
|
||||
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
|
||||
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
|
||||
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
|
||||
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)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
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_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
|
||||
}),
|
||||
});
|
||||
|
||||
const handleSubmit = async (values, props) => {
|
||||
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
|
||||
}
|
||||
|
||||
let _data = {
|
||||
is_legal_person: 0,
|
||||
telephone_number: values.telephone_number,
|
||||
national_code: values.national_code,
|
||||
vehicle_type: values.vehicle_type,
|
||||
province_id: values.province_id,
|
||||
father_name: values.father_name,
|
||||
first_name: values.first_name,
|
||||
last_name: values.last_name,
|
||||
city_id: values.city_id,
|
||||
navgan_id: values.navgan_id,
|
||||
postal_code: values.postal_code,
|
||||
navgan_type: values.navgan_type,
|
||||
gender: values.gender,
|
||||
address: values.address,
|
||||
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)
|
||||
})
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
{/*<Grid item xs={12} sm={4}>*/}
|
||||
{/* <SelectBox*/}
|
||||
{/* name="project_title"*/}
|
||||
{/* label={t("LoanRequest.text_field_project_title")}*/}
|
||||
{/* size="small"*/}
|
||||
{/* selectType="project_title"*/}
|
||||
{/* isLoading={isLoadingProjectTitle}*/}
|
||||
{/* errorEcured={errorProjectTitle}*/}
|
||||
{/* selectors={projectTitle}*/}
|
||||
{/* schema={{value: 'value', name: 'name'}}*/}
|
||||
{/* select={formik.values.project_title}*/}
|
||||
{/* value={formik.values.project_title}*/}
|
||||
{/* handleChange={(event) => {*/}
|
||||
{/* formik.setFieldValue('project_title', 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")}*/}
|
||||
{/* />*/}
|
||||
{/*</Grid>*/}
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="activity_type"
|
||||
label={t("LoanRequest.text_field_activity_type")}
|
||||
size="small"
|
||||
selectType="activity_type"
|
||||
isLoading={isLoadingActivityType}
|
||||
errorEcured={errorActivityType}
|
||||
selectors={activityType}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
select={formik.values.activity_type}
|
||||
value={formik.values.activity_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="priority_list"
|
||||
label={t("LoanRequest.text_field_priority_list")}
|
||||
size="small"
|
||||
selectType="priority_list"
|
||||
isLoading={isLoadingPriorityLists}
|
||||
errorEcured={errorPriorityLists}
|
||||
selectors={priorityLists}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
select={formik.values.priority_list}
|
||||
value={formik.values.priority_list}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
{t("LoanRequest.text_field_shenasname_serial")}
|
||||
</ToggleButton>
|
||||
<ToggleButton value="national_card_tracking_code">
|
||||
{t("LoanRequest.text_field_national_trackin_code")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_serial_number}
|
||||
label={t("LoanRequest.text_field_shenasname_serial")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_shenasname_serial")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("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}
|
||||
/>
|
||||
</Grid>) : (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_card_tracking_code}
|
||||
label={t("LoanRequest.text_field_national_trackin_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_trackin_code")}
|
||||
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}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_code")}
|
||||
onBlur={formik.handleBlur("national_code")}
|
||||
error={formik.touched.national_code && Boolean(formik.errors.national_code)}
|
||||
helperText={formik.touched.national_code && formik.errors.national_code}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="first_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.first_name}
|
||||
label={t("LoanRequest.text_field_first_name")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_first_name")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("first_name")}
|
||||
error={formik.touched.first_name && Boolean(formik.errors.first_name)}
|
||||
helperText={formik.touched.first_name && formik.errors.first_name}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="last_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.last_name}
|
||||
label={t("LoanRequest.text_field_last_name")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_last_name")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("last_name")}
|
||||
error={formik.touched.last_name && Boolean(formik.errors.last_name)}
|
||||
helperText={formik.touched.last_name && formik.errors.last_name}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="father_name"
|
||||
variant="outlined"
|
||||
value={formik.values.father_name}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
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}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="gender"
|
||||
label={t("LoanRequest.text_field_gender")}
|
||||
size="small"
|
||||
value={formik.values.gender}
|
||||
selectType="gender"
|
||||
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)
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.gender && Boolean(formik.errors.gender)}
|
||||
helperText={formik.touched.gender && formik.errors.gender}
|
||||
onBlur={formik.handleBlur("gender")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<MuiDatePicker
|
||||
formik={formik}
|
||||
error={formik.touched.birthday && Boolean(formik.errors.birthday)}
|
||||
helperText={formik.touched.birthday && formik.errors.birthday}
|
||||
onBlur={formik.handleBlur("birthday")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "postal_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_postal_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_postal_code")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("postal_code")}
|
||||
error={formik.touched.postal_code && Boolean(formik.errors.postal_code)}
|
||||
helperText={formik.touched.postal_code && formik.errors.postal_code}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="telephone_number"
|
||||
variant="outlined"
|
||||
value={formik.values.telephone_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "telephone_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_tel_number")}
|
||||
placeholder={t("LoanRequest.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}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
label={t("LoanRequest.text_field_navgan_type")}
|
||||
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'}}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_navgan_id")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_navgan_id")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("navgan_id")}
|
||||
error={formik.touched.navgan_id && Boolean(formik.errors.navgan_id)}
|
||||
helperText={formik.touched.navgan_id && formik.errors.navgan_id}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
label={t("LoanRequest.text_field_province_id")}
|
||||
size="small"
|
||||
selectType="province_id"
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
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.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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
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}
|
||||
onBlur={formik.handleBlur("city_id")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="vehicle_type"
|
||||
label={t("LoanRequest.text_field_vehicle_type")}
|
||||
size="small"
|
||||
value={formik.values.vehicle_type}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
label={t("LoanRequest.text_field_education_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingEducationsList}
|
||||
errorEcured={errorEducationsList}
|
||||
selectType="education_id"
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="occupation_id"
|
||||
label={t("LoanRequest.text_field_occupation_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
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)
|
||||
}}
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={4}
|
||||
sx={{width: "100%"}}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_address")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_address")}
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("address")}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<FormControlLabel
|
||||
color={'error.main'}
|
||||
control={<Checkbox
|
||||
checked={formik.values.checkedBox}
|
||||
onChange={(event) => {
|
||||
formik.setFieldValue("checkedBox", event.target.checked)
|
||||
}}
|
||||
/>}
|
||||
label={`${t("LoanRequest.checkbox")}`}/>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: {xs: "column", sm: "row"},
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
>
|
||||
|
||||
{formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")}
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
export default RealPersonForm
|
||||
@@ -1,22 +1,13 @@
|
||||
import {Box, Chip, Divider} from "@mui/material";
|
||||
import {useTranslations} from "next-intl";
|
||||
import AddFormComponent from "@/components/dashboard/navgan/add-request-loan/forms/AddForm";
|
||||
import {CenterLayout, useUser} from "@witel/webapp-builder";
|
||||
|
||||
const LoanRequestComponent = () => {
|
||||
const t = useTranslations();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box>
|
||||
<Divider>
|
||||
<Chip
|
||||
label={`${t("LoanRequest.loan_request_page")} | ${t("user_navy")} `}
|
||||
/>
|
||||
</Divider>
|
||||
</Box>
|
||||
<AddFormComponent/>
|
||||
</>
|
||||
<>
|
||||
<AddFormComponent/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,616 @@
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Checkbox,
|
||||
Fade,
|
||||
FormControlLabel,
|
||||
Grid,
|
||||
Stack,
|
||||
TextField,
|
||||
ToggleButton,
|
||||
ToggleButtonGroup,
|
||||
Typography
|
||||
} from "@mui/material";
|
||||
import {useFormik} from "formik";
|
||||
import {useTranslations} from "next-intl";
|
||||
import * as Yup from "yup";
|
||||
import {CenterLayout, useRequest, useUser} from "@witel/webapp-builder";
|
||||
import useCities from "@/lib/app/hooks/useCities";
|
||||
import PlateNumber from "@/core/components/PlateNumber";
|
||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||
import UseEducations from "@/lib/app/hooks/useEducations";
|
||||
import useOccupations from "@/lib/app/hooks/useOccupations";
|
||||
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 {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||
import {useRouter} from "next/router";
|
||||
import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||
|
||||
const AddFormComponent = () => {
|
||||
const router = useRouter()
|
||||
const {getUser, changeUser} = useUser()
|
||||
const t = useTranslations();
|
||||
const [finishLoanRequest, setFinishLoanRequest] = useState(false)
|
||||
const [checked, setChecked] = useState(false);
|
||||
const requestServer = useRequest()
|
||||
const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince()
|
||||
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
||||
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
||||
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
||||
|
||||
const initialValues = {
|
||||
person_type: "real",
|
||||
telephone_number: "",
|
||||
vehicle_type: "",
|
||||
province_id: "",
|
||||
city_id: "",
|
||||
navgan_id: "",
|
||||
national_id: "",
|
||||
national_number: "",
|
||||
national_serial_number: "",
|
||||
national_card_tracking_code: "",
|
||||
national_serial_number_or_tracking_code: "national_serial_number",
|
||||
postal_code: "",
|
||||
navgan_type: "",
|
||||
plate_part1: "",
|
||||
plate_part2: "الف",
|
||||
plate_part3: "",
|
||||
plate_part4: "",
|
||||
address: "",
|
||||
birthday: "",
|
||||
education_id: "",
|
||||
occupation_id: "",
|
||||
checkedBox: false,
|
||||
};
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
person_type: Yup.string().required(t("LoanRequest.error_message_person_type")),
|
||||
telephone_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
return stringValue.length === 11
|
||||
})
|
||||
.required(t("LoanRequest.error_message_tel_number")),
|
||||
vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")),
|
||||
navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")),
|
||||
occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")),
|
||||
education_id: Yup.string().required(t("LoanRequest.error_message_education_id")),
|
||||
address: Yup.string().required(t("LoanRequest.error_message_address")),
|
||||
birthday: Yup.string().required(t("LoanRequest.error_message_date_of_birth")),
|
||||
postal_code: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.postal_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_postal_code")),
|
||||
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()
|
||||
.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)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
|
||||
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
|
||||
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
|
||||
national_id: Yup.mixed()
|
||||
.test("is-number", `${t("LoanRequest.national_code_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_national_id")),
|
||||
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().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
|
||||
} : {}
|
||||
|
||||
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: values.person_type === 'legal' ? 1 : 0,
|
||||
telephone_number: values.telephone_number,
|
||||
national_id: values.national_id,
|
||||
vehicle_type: values.vehicle_type,
|
||||
province_id: values.province_id,
|
||||
city_id: values.city_id,
|
||||
navgan_id: values.navgan_id,
|
||||
postal_code: values.postal_code,
|
||||
navgan_type: values.navgan_type,
|
||||
plate_part1: values.plate_part1,
|
||||
plate_part2: values.plate_part2,
|
||||
plate_part3: values.plate_part3,
|
||||
plate_part4: values.plate_part4,
|
||||
address: values.address,
|
||||
birthday: values.birthday.locale('en').format("YYYY-MM-DD"),
|
||||
education_id: values.education_id,
|
||||
occupation_id: values.occupation_id, ..._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)
|
||||
})
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
|
||||
return (<>
|
||||
{finishLoanRequest ? (<CenterLayout>
|
||||
<SvgDone width={200} height={200}/>
|
||||
<Stack direction={'row'} spacing={0.7} sx={{mb: 4}}>
|
||||
<Typography variant={'h5'}
|
||||
align={'center'}>{t("LoanRequest.finish_loan_request")}</Typography>
|
||||
<DoneIcon color={'success'}/>
|
||||
</Stack>
|
||||
<Button variant={'contained'} component={NextLinkComposed}
|
||||
to={'/dashboard/navgan/followUp-loan'}>
|
||||
{t("LoanRequest.back_to_dashboard")}
|
||||
</Button>
|
||||
</CenterLayout>) : (<>
|
||||
<Grid container spacing={2} sx={{padding: 2}}
|
||||
>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.person_type}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "person_type", value: value,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="real">
|
||||
{t("LoanRequest.real_person")}
|
||||
</ToggleButton>
|
||||
<ToggleButton value="legal">
|
||||
{t("LoanRequest.legal_person")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_id"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_id}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_id", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_code")}
|
||||
onBlur={formik.handleBlur("national_id")}
|
||||
error={formik.touched.national_id && Boolean(formik.errors.national_id)}
|
||||
helperText={formik.touched.national_id && formik.errors.national_id}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
<Fade in={formik.values.person_type === 'legal'}>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_national_number")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_national_number")}
|
||||
onBlur={formik.handleBlur("national_number")}
|
||||
error={formik.touched.national_number && Boolean(formik.errors.national_number)}
|
||||
helperText={formik.touched.national_number && formik.errors.national_number}
|
||||
fullWidth
|
||||
/>
|
||||
</Grid>
|
||||
</Fade>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}
|
||||
>
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
},
|
||||
})
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
{t("LoanRequest.text_field_shenasname_serial")}
|
||||
</ToggleButton>
|
||||
<ToggleButton value="national_card_tracking_code">
|
||||
{t("LoanRequest.text_field_national_trackin_code")}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_serial_number}
|
||||
label={t("LoanRequest.text_field_shenasname_serial")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_shenasname_serial")}
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("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}
|
||||
/>
|
||||
</Grid>) : (<Grid item xs={12} sm={4}
|
||||
>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_card_tracking_code}
|
||||
label={t("LoanRequest.text_field_national_trackin_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_trackin_code")}
|
||||
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}
|
||||
/>
|
||||
</Grid>)}
|
||||
|
||||
<Grid item xs={12} sm={4}>
|
||||
<MuiDatePicker
|
||||
formik={formik}
|
||||
error={formik.touched.birthday && Boolean(formik.errors.birthday)}
|
||||
helperText={formik.touched.birthday && formik.errors.birthday}
|
||||
onBlur={formik.handleBlur("birthday")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "postal_code", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_postal_code")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_postal_code")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("postal_code")}
|
||||
error={formik.touched.postal_code && Boolean(formik.errors.postal_code)}
|
||||
helperText={formik.touched.postal_code && formik.errors.postal_code}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="telephone_number"
|
||||
variant="outlined"
|
||||
value={formik.values.telephone_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
return;
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "telephone_number", value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
label={t("LoanRequest.text_field_tel_number")}
|
||||
placeholder={t("LoanRequest.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}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
label={t("LoanRequest.text_field_navgan_type")}
|
||||
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'}}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_navgan_id")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_navgan_id")}
|
||||
fullWidth
|
||||
onBlur={formik.handleBlur("navgan_id")}
|
||||
error={formik.touched.navgan_id && Boolean(formik.errors.navgan_id)}
|
||||
helperText={formik.touched.navgan_id && formik.errors.navgan_id}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
label={t("LoanRequest.text_field_province_id")}
|
||||
size="small"
|
||||
selectType="province_id"
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
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.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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
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}
|
||||
onBlur={formik.handleBlur("city_id")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="vehicle_type"
|
||||
label={t("LoanRequest.text_field_vehicle_type")}
|
||||
size="small"
|
||||
value={formik.values.vehicle_type}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
label={t("LoanRequest.text_field_education_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingEducationsList}
|
||||
errorEcured={errorEducationsList}
|
||||
selectType="education_id"
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
handleChange={(event) => {
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="occupation_id"
|
||||
label={t("LoanRequest.text_field_occupation_id")}
|
||||
size="small"
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
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)
|
||||
}}
|
||||
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")}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={8}
|
||||
sx={{width: "100%"}}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
label={t("LoanRequest.text_field_address")}
|
||||
placeholder={t("LoanRequest.text_field_enter_your_address")}
|
||||
fullWidth
|
||||
value={formik.values.address}
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("address")}
|
||||
error={formik.touched.address && Boolean(formik.errors.address)}
|
||||
helperText={formik.touched.address && formik.errors.address}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid item xs={12}>
|
||||
<FormControlLabel
|
||||
color={'error.main'}
|
||||
control={<Checkbox
|
||||
checked={formik.values.checkedBox}
|
||||
onChange={(event) => {
|
||||
formik.setFieldValue("checkedBox", event.target.checked)
|
||||
}}
|
||||
/>}
|
||||
label={`${t("LoanRequest.checkbox")}`}/>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: {xs: "column", sm: "row"},
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
fullWidth
|
||||
onClick={formik.handleSubmit}
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
>
|
||||
{formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")}
|
||||
</Button>
|
||||
</Box>
|
||||
</>)}
|
||||
</>);
|
||||
};
|
||||
|
||||
export default AddFormComponent;
|
||||
@@ -0,0 +1,23 @@
|
||||
import {Box, Chip, Divider} from "@mui/material";
|
||||
import {useTranslations} from "next-intl";
|
||||
import AddFormComponent from "@/components/dashboard/navgan/past-add-request-loan/forms/AddForm";
|
||||
import {CenterLayout, useUser} from "@witel/webapp-builder";
|
||||
|
||||
const LoanRequestComponent = () => {
|
||||
const t = useTranslations();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box>
|
||||
<Divider>
|
||||
<Chip
|
||||
label={`${t("LoanRequest.loan_request_page")} | ${t("user_navy")} `}
|
||||
/>
|
||||
</Divider>
|
||||
</Box>
|
||||
<AddFormComponent/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoanRequestComponent;
|
||||
@@ -184,7 +184,7 @@ const PlateNumber = ({formik, disabled}) => {
|
||||
disabled={disabled}
|
||||
fullWidth
|
||||
>
|
||||
{plate_words.find(p => p.value === formik.values.plate_part2).name}
|
||||
{plate_words.find(p => p.value === formik.values.plate_part2)?.name}
|
||||
</Button>
|
||||
</Box>
|
||||
<Drawer
|
||||
|
||||
@@ -24,4 +24,8 @@ export const GET_OCCUPATIONS_LIST = BASE_URL + "/occupations";
|
||||
export const GET_LOAN_DETAILS = BASE_URL + "/navgan/loan/details/"
|
||||
export const UPDATE_LOAN = BASE_URL + "/navgan/loan/update/"
|
||||
|
||||
export const GET_PROJECT_TITLE = BASE_URL + "/navgan_plans"
|
||||
export const GET_ACTIVITY_LIST = BASE_URL + "/activity_types"
|
||||
export const GET_PRIORITY_LIST = BASE_URL + "/activity_priorities"
|
||||
|
||||
|
||||
|
||||
34
src/lib/app/hooks/useActivityType.jsx
Normal file
34
src/lib/app/hooks/useActivityType.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import {GET_ACTIVITY_LIST} from "@/core/data/apiRoutes";
|
||||
import {useRequest} from "@witel/webapp-builder";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
const useActivityType = () => {
|
||||
const [isLoadingActivityType, setIsLoadingActivityType] = useState(false)
|
||||
const [errorActivityType, setErrorActivityType] = useState(false)
|
||||
const [activityType, setActivityType] = useState([])
|
||||
const requestServer = useRequest({auth: true, notification: false})
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoadingActivityType(true)
|
||||
requestServer(GET_ACTIVITY_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
|
||||
const formattedData = data.data.map((activityList, index) => ({
|
||||
id: index,
|
||||
name: activityList.name,
|
||||
value: activityList.id,
|
||||
}));
|
||||
setIsLoadingActivityType(false)
|
||||
setActivityType(formattedData);
|
||||
}).catch(() => {
|
||||
setIsLoadingActivityType(false)
|
||||
setErrorActivityType(true)
|
||||
})
|
||||
}, [])
|
||||
|
||||
return {
|
||||
activityType,
|
||||
isLoadingActivityType,
|
||||
errorActivityType
|
||||
}
|
||||
};
|
||||
|
||||
export default useActivityType;
|
||||
34
src/lib/app/hooks/usePriorityLists.jsx
Normal file
34
src/lib/app/hooks/usePriorityLists.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
35
src/lib/app/hooks/useProjectTitle.jsx
Normal file
35
src/lib/app/hooks/useProjectTitle.jsx
Normal file
@@ -0,0 +1,35 @@
|
||||
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})
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoadingProjectTitle(true)
|
||||
requestServer(GET_PROJECT_TITLE, 'get', {auth: true, notification: false}).then(({data}) => {
|
||||
console.log(data)
|
||||
const formattedData = data.data.map((projectTitle, index) => ({
|
||||
id: index,
|
||||
name: projectTitle.name,
|
||||
value: projectTitle.id,
|
||||
}));
|
||||
setIsLoadingProjectTitle(false)
|
||||
setProjectTitle(formattedData);
|
||||
}).catch(() => {
|
||||
setIsLoadingProjectTitle(false)
|
||||
setErrorProjectTitle(true)
|
||||
})
|
||||
}, [])
|
||||
|
||||
return {
|
||||
projectTitle,
|
||||
isLoadingProjectTitle,
|
||||
errorProjectTitle
|
||||
}
|
||||
};
|
||||
|
||||
export default useProjectTitle;
|
||||
@@ -1,6 +1,6 @@
|
||||
import LoanRequestComponent from "@/components/dashboard/navgan/add-request-loan";
|
||||
import {globalServerProps} from "@/core/utils/globalServerProps";
|
||||
import DeadlineMiddleware from "@/middlewares/Deadline";
|
||||
import LoanRequestComponent from "@/components/dashboard/navgan/add-request-loan";
|
||||
|
||||
export default function AddLoanRequest(props) {
|
||||
return (<DeadlineMiddleware serverToday={props.today} type={'register'} withMessage={true}>
|
||||
|
||||
19
src/pages/dashboard/navgan/past-add-request-loan/index.jsx
Normal file
19
src/pages/dashboard/navgan/past-add-request-loan/index.jsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import LoanRequestComponent from "src/components/dashboard/navgan/past-add-request-loan";
|
||||
import {globalServerProps} from "@/core/utils/globalServerProps";
|
||||
import DeadlineMiddleware from "@/middlewares/Deadline";
|
||||
|
||||
export default function AddLoanRequest(props) {
|
||||
return (<DeadlineMiddleware serverToday={props.today} type={'register'} withMessage={true}>
|
||||
<LoanRequestComponent/>
|
||||
</DeadlineMiddleware>);
|
||||
}
|
||||
|
||||
export async function getServerSideProps({req, locale}) {
|
||||
return {
|
||||
props: {
|
||||
...await globalServerProps({req, locale}),
|
||||
title: "LoanRequest.loan_request_page",
|
||||
layout: {name: 'DashboardLayout', props: {permissions: ["can_request_navgan_loan"]}}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user