use some api
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import {Box, Button, Checkbox, FormControlLabel, Grid, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
|
||||
import {useTranslations} from "next-intl";
|
||||
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";
|
||||
@@ -7,29 +16,29 @@ import * as React from "react";
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||
import PlateNumber from "@/core/components/PlateNumber";
|
||||
import {useRouter} from "next/router";
|
||||
import {useRequest, useUser} from "@witel/webapp-builder";
|
||||
import { useRouter } from "next/router";
|
||||
import { useRequest, useUser } from "@witel/webapp-builder";
|
||||
import * as Yup from "yup";
|
||||
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||
import { SEND_LOAN_REQUEST_NAVGAN } from "@/core/data/apiRoutes";
|
||||
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
|
||||
import {useFormik} from "formik";
|
||||
import { useFormik } from "formik";
|
||||
import LegalPersonDatePicker from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker";
|
||||
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
|
||||
import useActivityType from "@/lib/app/hooks/useActivityType";
|
||||
import usePriorityLists from "@/lib/app/hooks/usePriorityLists";
|
||||
|
||||
const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
const LegalPersonForm = ({ setFinishLoanRequest }) => {
|
||||
const t = useTranslations();
|
||||
const router = useRouter()
|
||||
const requestServer = useRequest()
|
||||
const {getUser, changeUser} = useUser()
|
||||
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
||||
const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince()
|
||||
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
||||
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
||||
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType()
|
||||
const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists()
|
||||
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle()
|
||||
const router = useRouter();
|
||||
const requestServer = useRequest();
|
||||
const { getUser, changeUser } = useUser();
|
||||
const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities();
|
||||
const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince();
|
||||
const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations();
|
||||
const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations();
|
||||
const { activityType, isLoadingActivityType, errorActivityType } = useActivityType();
|
||||
const { priorityLists, isLoadingPriorityLists, errorPriorityLists } = usePriorityLists();
|
||||
const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle();
|
||||
|
||||
const initialValues = {
|
||||
person_type: "legal",
|
||||
@@ -40,7 +49,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
vehicle_type: "",
|
||||
province_id: "",
|
||||
boss_father_name: "",
|
||||
company_postal_code : "",
|
||||
company_postal_code: "",
|
||||
register_number: "",
|
||||
boss_gender: "",
|
||||
boss_first_name: "",
|
||||
@@ -69,7 +78,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
company_tel_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.company_tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
return stringValue.length === 11
|
||||
return stringValue.length === 11;
|
||||
})
|
||||
.required(t("LoanRequest.error_message_company_tel_number")),
|
||||
vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")),
|
||||
@@ -88,13 +97,15 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
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)
|
||||
plate_part1: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part2: Yup.mixed()
|
||||
plate_part2: Yup.mixed().required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part3: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part3: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part4: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
plate_part4: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
|
||||
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
|
||||
@@ -106,35 +117,60 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
.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;
|
||||
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
|
||||
})
|
||||
boss_national_serial_number: Yup.string()
|
||||
.test(
|
||||
"max",
|
||||
`${t("LoanRequest.national_serial_number_max")}`,
|
||||
(value) => value && value.toString().length === 10
|
||||
)
|
||||
.when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === "national_serial_number"
|
||||
? schema.required(t("LoanRequest.error_message_shenasname_serial"))
|
||||
: schema;
|
||||
}),
|
||||
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
|
||||
} : {}
|
||||
props.setSubmitting(true);
|
||||
let _national_number =
|
||||
values.person_type === "legal"
|
||||
? {
|
||||
shenase_meli: values.national_number,
|
||||
}
|
||||
: {};
|
||||
|
||||
const _national_card = values.national_serial_number_or_tracking_code === "national_serial_number" ? {
|
||||
national_serial_number: values.national_serial_number
|
||||
} : {
|
||||
national_tracking_code: values.national_card_tracking_code
|
||||
}
|
||||
const _national_card =
|
||||
values.national_serial_number_or_tracking_code === "national_serial_number"
|
||||
? {
|
||||
national_serial_number: values.boss_national_serial_number,
|
||||
}
|
||||
: {
|
||||
national_tracking_code: values.boss_national_card_tracking_code,
|
||||
};
|
||||
|
||||
let _data = {
|
||||
is_legal_person: 1 ,
|
||||
is_legal_person: 1,
|
||||
telephone_number: values.company_tel_number,
|
||||
register_number: values.register_number,
|
||||
national_id: values.boss_national_code,
|
||||
@@ -146,38 +182,49 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
first_name: values.boss_first_name,
|
||||
last_name: values.boss_last_name,
|
||||
navgan_id: values.navgan_id,
|
||||
postal_code: values.postal_code,
|
||||
activity_type_id: values.activity_type,
|
||||
project_title: values.project_title,
|
||||
activity_priority_id: values.priority_list,
|
||||
postal_code: values.company_postal_code,
|
||||
navgan_type: values.navgan_type,
|
||||
gender: values.gender,
|
||||
gender: values.boss_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"),
|
||||
company_register_date: values.company_date.locale("en").format("YYYY-MM-DD"),
|
||||
education_id: values.education_id,
|
||||
occupation_id: values.occupation_id, ..._national_card, ..._national_number
|
||||
}
|
||||
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)
|
||||
auth: true,
|
||||
notification: true,
|
||||
data: _data,
|
||||
})
|
||||
.then(() => {
|
||||
router.replace("/dashboard/navgan/followUp-loan");
|
||||
getUser((data) => {
|
||||
changeUser(data);
|
||||
});
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
props.setSubmitting(false);
|
||||
});
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
initialValues,
|
||||
validationSchema,
|
||||
onSubmit: handleSubmit,
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
<Grid container spacing={2} sx={{ p: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="project_title"
|
||||
@@ -187,11 +234,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingProjectTitle}
|
||||
errorEcured={errorProjectTitle}
|
||||
selectors={projectTitle}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "name", name: "name" }}
|
||||
select={formik.values.project_title}
|
||||
value={formik.values.project_title}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('project_title', event.target.value)
|
||||
formik.setFieldValue("project_title", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.project_title && Boolean(formik.errors.project_title)}
|
||||
@@ -208,11 +255,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingActivityType}
|
||||
errorEcured={errorActivityType}
|
||||
selectors={activityType}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.activity_type}
|
||||
value={formik.values.activity_type}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('activity_type', event.target.value)
|
||||
formik.setFieldValue("activity_type", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.activity_type && Boolean(formik.errors.activity_type)}
|
||||
@@ -229,11 +276,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingPriorityLists}
|
||||
errorEcured={errorPriorityLists}
|
||||
selectors={priorityLists}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.priority_list}
|
||||
value={formik.values.priority_list}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('priority_list', event.target.value)
|
||||
formik.setFieldValue("priority_list", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.priority_list && Boolean(formik.errors.priority_list)}
|
||||
@@ -242,16 +289,16 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
<Grid container spacing={2} sx={{ p: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="national_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -259,7 +306,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_number", value: inputValue,
|
||||
name: "national_number",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -273,7 +321,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="company_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -289,13 +337,13 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="register_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.register_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -303,7 +351,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "register_number", value: inputValue,
|
||||
name: "register_number",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -316,15 +365,15 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="company_postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.company_postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -332,7 +381,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "company_postal_code", value: inputValue,
|
||||
name: "company_postal_code",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -347,12 +397,12 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="company_tel_number"
|
||||
variant="outlined"
|
||||
value={formik.values.company_tel_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
@@ -361,7 +411,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "company_tel_number", value: inputValue,
|
||||
name: "company_tel_number",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -382,7 +433,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
@@ -392,14 +443,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.province_id}
|
||||
value={formik.values.province_id}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('province_id', event.target.value);
|
||||
setProvinceID(event.target.value)
|
||||
formik.setFieldValue("province_id", event.target.value);
|
||||
setProvinceID(event.target.value);
|
||||
formik.setFieldTouched("city_id", false, false);
|
||||
formik.setFieldValue("city_id", "")
|
||||
formik.setFieldValue("city_id", "");
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.province_id && Boolean(formik.errors.province_id)}
|
||||
@@ -410,15 +461,21 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
label={
|
||||
isLoadingCityList
|
||||
? `${t("LoanRequest.cityList_loading")}`
|
||||
: cityList.length === 0
|
||||
? `${t("LoanRequest.cityList_empty")}`
|
||||
: cityTextField
|
||||
}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
handleChange={(event) => formik.setFieldValue('city_id', event.target.value)}
|
||||
handleChange={(event) => formik.setFieldValue("city_id", event.target.value)}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.city_id && Boolean(formik.errors.city_id)}
|
||||
helperText={formik.touched.city_id && formik.errors.city_id}
|
||||
@@ -426,16 +483,16 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
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'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -443,7 +500,8 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "boss_national_code", value: inputValue,
|
||||
name: "boss_national_code",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -462,15 +520,22 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
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'}}
|
||||
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)
|
||||
formik.setFieldValue("boss_gender", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.boss_gender && Boolean(formik.errors.boss_gender)}
|
||||
@@ -479,10 +544,10 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="boss_first_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -498,7 +563,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="boss_last_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -513,21 +578,22 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
size={"small"}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
if (value === null) return;
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
name: "national_serial_number_or_tracking_code",
|
||||
value: value,
|
||||
},
|
||||
})
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
@@ -538,11 +604,10 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
{formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="boss_national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -552,13 +617,19 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
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}
|
||||
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>
|
||||
) : (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="boss_national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -568,14 +639,20 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
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}
|
||||
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%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="boss_father_name"
|
||||
variant="outlined"
|
||||
value={formik.values.boss_father_name}
|
||||
@@ -590,7 +667,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
@@ -598,17 +675,27 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
size="small"
|
||||
value={formik.values.navgan_type}
|
||||
selectType="navgan_type"
|
||||
selectors={[{
|
||||
id: 1, value: "روستایی", name: "روستایی"
|
||||
}, {
|
||||
id: 2, value: "عمومی", name: "عمومی"
|
||||
}, {
|
||||
id: 3, value: "منطقه آزاد", name: "منطقه آزاد"
|
||||
}]}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectors={[
|
||||
{
|
||||
id: 1,
|
||||
value: "روستایی",
|
||||
name: "روستایی",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
value: "عمومی",
|
||||
name: "عمومی",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
value: "منطقه آزاد",
|
||||
name: "منطقه آزاد",
|
||||
},
|
||||
]}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('navgan_type', event.target.value)
|
||||
formik.setFieldValue("navgan_type", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)}
|
||||
@@ -618,11 +705,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
@@ -635,32 +722,39 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<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'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
selectors={[
|
||||
{
|
||||
id: 0,
|
||||
value: "اتوبوس",
|
||||
name: "اتوبوس",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: "مینی بوس",
|
||||
name: "مینی بوس",
|
||||
},
|
||||
]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
handleChange={(event) => formik.setFieldValue("vehicle_type", event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
<PlateNumber formik={formik} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
@@ -672,9 +766,9 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
schema={{ value: "id", name: "title" }}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('education_id', event.target.value)
|
||||
formik.setFieldValue("education_id", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.education_id && Boolean(formik.errors.education_id)}
|
||||
@@ -690,12 +784,12 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
schema={{ value: "id", name: "title" }}
|
||||
selectors={occupationsList}
|
||||
select={formik.values.occupation_id}
|
||||
value={formik.values.occupation_id}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('occupation_id', event.target.value)
|
||||
formik.setFieldValue("occupation_id", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)}
|
||||
@@ -704,12 +798,12 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={4}
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -724,27 +818,29 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<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")}`}/>
|
||||
|
||||
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"},
|
||||
flexDirection: { xs: "column", sm: "row" },
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
width: { xs: "100%", sm: "30%", md: "25%" },
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
@@ -753,14 +849,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
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
|
||||
);
|
||||
};
|
||||
export default LegalPersonForm;
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
import {Box, Button, Checkbox, FormControlLabel, Grid, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Checkbox,
|
||||
FormControlLabel,
|
||||
Grid,
|
||||
TextField,
|
||||
ToggleButton,
|
||||
ToggleButtonGroup,
|
||||
} from "@mui/material";
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||
import {useTranslations} from "next-intl";
|
||||
import { useTranslations } from "next-intl";
|
||||
import useLimitedProvince from "@/lib/app/hooks/useLimitedProvince";
|
||||
import useCities from "@/lib/app/hooks/useCities";
|
||||
import {useFormik} from "formik";
|
||||
import { useFormik } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
|
||||
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
|
||||
import {useRequest, useUser} from "@witel/webapp-builder";
|
||||
import {useRouter} from "next/router";
|
||||
import { SEND_LOAN_REQUEST_NAVGAN } from "@/core/data/apiRoutes";
|
||||
import { useRequest, useUser } from "@witel/webapp-builder";
|
||||
import { useRouter } from "next/router";
|
||||
import PlateNumber from "@/core/components/PlateNumber";
|
||||
import * as React from "react";
|
||||
import UseEducations from "@/lib/app/hooks/useEducations";
|
||||
@@ -18,22 +27,22 @@ import useActivityType from "@/lib/app/hooks/useActivityType";
|
||||
import usePriorityLists from "@/lib/app/hooks/usePriorityLists";
|
||||
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
|
||||
|
||||
const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
const RealPersonForm = ({ setFinishLoanRequest }) => {
|
||||
const t = useTranslations();
|
||||
const {provinceList, isLoadingProvinceList, errorProvinceList} = useLimitedProvince()
|
||||
const {cityTextField, cityList, setProvinceID, isLoadingCityList} = useCities()
|
||||
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
|
||||
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
|
||||
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType()
|
||||
const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists()
|
||||
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle()
|
||||
const requestServer = useRequest()
|
||||
const {getUser, changeUser} = useUser()
|
||||
const router = useRouter()
|
||||
const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince();
|
||||
const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities();
|
||||
const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations();
|
||||
const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations();
|
||||
const { activityType, isLoadingActivityType, errorActivityType } = useActivityType();
|
||||
const { priorityLists, isLoadingPriorityLists, errorPriorityLists } = usePriorityLists();
|
||||
const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle();
|
||||
const requestServer = useRequest();
|
||||
const { getUser, changeUser } = useUser();
|
||||
const router = useRouter();
|
||||
|
||||
const initialValues = {
|
||||
person_type : "real",
|
||||
vehicle_type : "",
|
||||
person_type: "real",
|
||||
vehicle_type: "",
|
||||
telephone_number: "",
|
||||
activity_type: "",
|
||||
project_title: "",
|
||||
@@ -66,7 +75,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
telephone_number: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.tel_number_max")}`, (value) => {
|
||||
const stringValue = String(value);
|
||||
return stringValue.length === 11
|
||||
return stringValue.length === 11;
|
||||
})
|
||||
.required(t("LoanRequest.error_message_tel_number")),
|
||||
father_name: Yup.string().required(t("LoanRequest.error_message_father_name")),
|
||||
@@ -88,48 +97,75 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
|
||||
first_name: Yup.string().required(t("LoanRequest.error_message_first_name")),
|
||||
last_name: Yup.string().required(t("LoanRequest.error_message_last_name")),
|
||||
plate_part1: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
plate_part1: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part2: Yup.mixed()
|
||||
plate_part2: Yup.mixed().required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part3: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part3: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 3)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
plate_part4: Yup.mixed().test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
plate_part4: Yup.mixed()
|
||||
.test("max", `${t("LoanRequest.error_message_plate_number")}`, (value) => value.toString().length === 2)
|
||||
.required(t("LoanRequest.error_message_plate_number")),
|
||||
national_code: Yup.mixed()
|
||||
.test("is-number", `${t("LoanRequest.national_code_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10)
|
||||
.required(t("LoanRequest.error_message_national_id")),
|
||||
national_number: Yup.mixed().when('person_type', ([person_type], schema) => {
|
||||
return person_type === 'legal' ? schema
|
||||
.test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.national_number_max")}`, (value) => value && value.toString().length === 11)
|
||||
.required(t("LoanRequest.error_message_national_number")) : schema;
|
||||
}),
|
||||
national_serial_number: Yup.string().test("max", `${t("LoanRequest.national_serial_number_max")}`, (value) => value && value.toString().length === 10).when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === 'national_serial_number' ? schema.required(t("LoanRequest.error_message_shenasname_serial")) : schema
|
||||
}),
|
||||
national_card_tracking_code: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === 'national_card_tracking_code' ? schema.required(t("LoanRequest.error_message_tracking_code")) : schema
|
||||
national_number: Yup.mixed().when("person_type", ([person_type], schema) => {
|
||||
return person_type === "legal"
|
||||
? schema
|
||||
.test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0)
|
||||
.test(
|
||||
"max",
|
||||
`${t("LoanRequest.national_number_max")}`,
|
||||
(value) => value && value.toString().length === 11
|
||||
)
|
||||
.required(t("LoanRequest.error_message_national_number"))
|
||||
: schema;
|
||||
}),
|
||||
national_serial_number: Yup.string()
|
||||
.test(
|
||||
"max",
|
||||
`${t("LoanRequest.national_serial_number_max")}`,
|
||||
(value) => value && value.toString().length === 10
|
||||
)
|
||||
.when("national_serial_number_or_tracking_code", ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === "national_serial_number"
|
||||
? schema.required(t("LoanRequest.error_message_shenasname_serial"))
|
||||
: schema;
|
||||
}),
|
||||
national_card_tracking_code: Yup.string().when(
|
||||
"national_serial_number_or_tracking_code",
|
||||
([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === "national_card_tracking_code"
|
||||
? schema.required(t("LoanRequest.error_message_tracking_code"))
|
||||
: schema;
|
||||
}
|
||||
),
|
||||
});
|
||||
|
||||
const handleSubmit = async (values, props) => {
|
||||
props.setSubmitting(true)
|
||||
let _national_number = values.person_type === "legal" ? {
|
||||
shenase_meli: values.national_number
|
||||
} : {}
|
||||
props.setSubmitting(true);
|
||||
let _national_number =
|
||||
values.person_type === "legal"
|
||||
? {
|
||||
shenase_meli: values.national_number,
|
||||
}
|
||||
: {};
|
||||
|
||||
const _national_card = values.national_serial_number_or_tracking_code === "national_serial_number" ? {
|
||||
national_serial_number: values.national_serial_number
|
||||
} : {
|
||||
national_tracking_code: values.national_card_tracking_code
|
||||
}
|
||||
const _national_card =
|
||||
values.national_serial_number_or_tracking_code === "national_serial_number"
|
||||
? {
|
||||
national_serial_number: values.national_serial_number,
|
||||
}
|
||||
: {
|
||||
national_tracking_code: values.national_card_tracking_code,
|
||||
};
|
||||
|
||||
let _data = {
|
||||
is_legal_person: 0,
|
||||
is_legal_person: 0,
|
||||
telephone_number: values.telephone_number,
|
||||
national_id: values.national_code,
|
||||
vehicle_type: values.vehicle_type,
|
||||
@@ -145,32 +181,44 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
address: values.address,
|
||||
education_id: values.education_id,
|
||||
occupation_id: values.occupation_id,
|
||||
activity_type: values.activity_type,
|
||||
activity_type_id: values.activity_type,
|
||||
project_title: values.project_title,
|
||||
priority_list: values.priority_list,
|
||||
birthday: values.birthday.locale('en').format("YYYY-MM-DD"), ..._national_card, ..._national_number
|
||||
}
|
||||
activity_priority_id: values.priority_list,
|
||||
plate_part1: values.plate_part1,
|
||||
plate_part2: values.plate_part2,
|
||||
plate_part3: values.plate_part3,
|
||||
plate_part4: values.plate_part4,
|
||||
birthday: values.birthday.locale("en").format("YYYY-MM-DD"),
|
||||
..._national_card,
|
||||
..._national_number,
|
||||
};
|
||||
|
||||
await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {
|
||||
auth: true, notification: true, data: _data
|
||||
}).then(() => {
|
||||
router.replace('/dashboard/navgan/followUp-loan')
|
||||
getUser((data) => {
|
||||
changeUser(data);
|
||||
});
|
||||
}).catch(() => {
|
||||
}).finally(() => {
|
||||
props.setSubmitting(false)
|
||||
auth: true,
|
||||
notification: true,
|
||||
data: _data,
|
||||
})
|
||||
.then(() => {
|
||||
router.replace("/dashboard/navgan/followUp-loan");
|
||||
getUser((data) => {
|
||||
changeUser(data);
|
||||
});
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
props.setSubmitting(false);
|
||||
});
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
initialValues, validationSchema, onSubmit: handleSubmit
|
||||
})
|
||||
initialValues,
|
||||
validationSchema,
|
||||
onSubmit: handleSubmit,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<Grid container spacing={2} sx={{p: 2}}>
|
||||
<Grid container spacing={2} sx={{ p: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<SelectBox
|
||||
name="project_title"
|
||||
@@ -180,11 +228,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingProjectTitle}
|
||||
errorEcured={errorProjectTitle}
|
||||
selectors={projectTitle}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "name", name: "name" }}
|
||||
select={formik.values.project_title}
|
||||
value={formik.values.project_title}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('project_title', event.target.value)
|
||||
formik.setFieldValue("project_title", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.project_title && Boolean(formik.errors.project_title)}
|
||||
@@ -201,11 +249,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingActivityType}
|
||||
errorEcured={errorActivityType}
|
||||
selectors={activityType}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.activity_type}
|
||||
value={formik.values.activity_type}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('activity_type', event.target.value)
|
||||
formik.setFieldValue("activity_type", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.activity_type && Boolean(formik.errors.activity_type)}
|
||||
@@ -222,11 +270,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingPriorityLists}
|
||||
errorEcured={errorPriorityLists}
|
||||
selectors={priorityLists}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.priority_list}
|
||||
value={formik.values.priority_list}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('priority_list', event.target.value)
|
||||
formik.setFieldValue("priority_list", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.priority_list && Boolean(formik.errors.priority_list)}
|
||||
@@ -235,21 +283,22 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<ToggleButtonGroup
|
||||
color="primary"
|
||||
fullWidth
|
||||
size={'small'}
|
||||
size={"small"}
|
||||
value={formik.values.national_serial_number_or_tracking_code}
|
||||
exclusive
|
||||
onChange={(e, value) => {
|
||||
if (value === null) return
|
||||
if (value === null) return;
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_serial_number_or_tracking_code", value: value,
|
||||
name: "national_serial_number_or_tracking_code",
|
||||
value: value,
|
||||
},
|
||||
})
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ToggleButton value="national_serial_number">
|
||||
@@ -260,11 +309,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</Grid>
|
||||
{formik.values.national_serial_number_or_tracking_code === 'national_serial_number' ? (
|
||||
<Grid item xs={12} sm={4}
|
||||
>
|
||||
{formik.values.national_serial_number_or_tracking_code === "national_serial_number" ? (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="national_serial_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -274,13 +322,16 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("national_serial_number")}
|
||||
error={formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number)}
|
||||
error={
|
||||
formik.touched.national_serial_number && Boolean(formik.errors.national_serial_number)
|
||||
}
|
||||
helperText={formik.touched.national_serial_number && formik.errors.national_serial_number}
|
||||
/>
|
||||
</Grid>) : (
|
||||
</Grid>
|
||||
) : (
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="national_card_tracking_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -290,20 +341,25 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
fullWidth
|
||||
onChange={formik.handleChange}
|
||||
onBlur={formik.handleBlur("national_card_tracking_code")}
|
||||
error={formik.touched.national_card_tracking_code && Boolean(formik.errors.national_card_tracking_code)}
|
||||
helperText={formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code}
|
||||
error={
|
||||
formik.touched.national_card_tracking_code &&
|
||||
Boolean(formik.errors.national_card_tracking_code)
|
||||
}
|
||||
helperText={
|
||||
formik.touched.national_card_tracking_code && formik.errors.national_card_tracking_code
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="national_code"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
value={formik.values.national_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -311,7 +367,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "national_code", value: inputValue,
|
||||
name: "national_code",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -324,10 +381,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="first_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -343,7 +400,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="last_name"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -358,10 +415,10 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={4}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="father_name"
|
||||
variant="outlined"
|
||||
value={formik.values.father_name}
|
||||
@@ -382,15 +439,22 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
size="small"
|
||||
value={formik.values.gender}
|
||||
selectType="gender"
|
||||
selectors={[{
|
||||
id: 1, value: 1, name: "زن"
|
||||
}, {
|
||||
id: 2, value: 0, name: "مرد"
|
||||
}]}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectors={[
|
||||
{
|
||||
id: 1,
|
||||
value: 1,
|
||||
name: "زن",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
value: 0,
|
||||
name: "مرد",
|
||||
},
|
||||
]}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.gender}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('gender', event.target.value)
|
||||
formik.setFieldValue("gender", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.gender && Boolean(formik.errors.gender)}
|
||||
@@ -407,15 +471,15 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="postal_code"
|
||||
variant="outlined"
|
||||
value={formik.values.postal_code}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
if (isNaN(Number(inputValue))) {
|
||||
@@ -423,7 +487,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "postal_code", value: inputValue,
|
||||
name: "postal_code",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -438,12 +503,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="telephone_number"
|
||||
variant="outlined"
|
||||
value={formik.values.telephone_number}
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
size="small"
|
||||
onChange={(event) => {
|
||||
const inputValue = event.target.value;
|
||||
@@ -452,7 +517,8 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
}
|
||||
formik.handleChange({
|
||||
target: {
|
||||
name: "telephone_number", value: inputValue,
|
||||
name: "telephone_number",
|
||||
value: inputValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -465,7 +531,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="navgan_type"
|
||||
@@ -473,17 +539,27 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
size="small"
|
||||
value={formik.values.navgan_type}
|
||||
selectType="navgan_type"
|
||||
selectors={[{
|
||||
id: 1, value: "روستایی", name: "روستایی"
|
||||
}, {
|
||||
id: 2, value: "عمومی", name: "عمومی"
|
||||
}, {
|
||||
id: 3, value: "منطقه آزاد", name: "منطقه آزاد"
|
||||
}]}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
selectors={[
|
||||
{
|
||||
id: 1,
|
||||
value: "روستایی",
|
||||
name: "روستایی",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
value: "عمومی",
|
||||
name: "عمومی",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
value: "منطقه آزاد",
|
||||
name: "منطقه آزاد",
|
||||
},
|
||||
]}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.navgan_type}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('navgan_type', event.target.value)
|
||||
formik.setFieldValue("navgan_type", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)}
|
||||
@@ -493,11 +569,11 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="navgan_id"
|
||||
variant="outlined"
|
||||
inputProps={{inputMode: 'numeric', pattern: '[0-9]*'}}
|
||||
type={'tel'}
|
||||
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
||||
type={"tel"}
|
||||
value={formik.values.navgan_id}
|
||||
onChange={formik.handleChange}
|
||||
size="small"
|
||||
@@ -510,7 +586,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="province_id"
|
||||
@@ -520,14 +596,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingProvinceList}
|
||||
errorEcured={errorProvinceList}
|
||||
selectors={provinceList}
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
select={formik.values.province_id}
|
||||
value={formik.values.province_id}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('province_id', event.target.value);
|
||||
setProvinceID(event.target.value)
|
||||
formik.setFieldValue("province_id", event.target.value);
|
||||
setProvinceID(event.target.value);
|
||||
formik.setFieldTouched("city_id", false, false);
|
||||
formik.setFieldValue("city_id", "")
|
||||
formik.setFieldValue("city_id", "");
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.province_id && Boolean(formik.errors.province_id)}
|
||||
@@ -538,15 +614,21 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="city_id"
|
||||
label={isLoadingCityList ? `${t("LoanRequest.cityList_loading")}` : (cityList.length === 0 ? `${t("LoanRequest.cityList_empty")}` : cityTextField)}
|
||||
label={
|
||||
isLoadingCityList
|
||||
? `${t("LoanRequest.cityList_loading")}`
|
||||
: cityList.length === 0
|
||||
? `${t("LoanRequest.cityList_empty")}`
|
||||
: cityTextField
|
||||
}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
schema={{value: 'value', name: 'name'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
disabled={cityList.length === 0}
|
||||
selectors={cityList}
|
||||
select={formik.values.city_id}
|
||||
value={formik.values.city_id}
|
||||
handleChange={(event) => formik.setFieldValue('city_id', event.target.value)}
|
||||
handleChange={(event) => formik.setFieldValue("city_id", event.target.value)}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.city_id && Boolean(formik.errors.city_id)}
|
||||
helperText={formik.touched.city_id && formik.errors.city_id}
|
||||
@@ -554,32 +636,39 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<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'}}
|
||||
schema={{ value: "value", name: "name" }}
|
||||
selectType="vehicle_type"
|
||||
selectors={[{
|
||||
id: 0, value: "اتوبوس", name: "اتوبوس"
|
||||
}, {
|
||||
id: 1, value: "مینی بوس", name: "مینی بوس"
|
||||
}]}
|
||||
selectors={[
|
||||
{
|
||||
id: 0,
|
||||
value: "اتوبوس",
|
||||
name: "اتوبوس",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
value: "مینی بوس",
|
||||
name: "مینی بوس",
|
||||
},
|
||||
]}
|
||||
select={formik.values.vehicle_type}
|
||||
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
|
||||
handleChange={(event) => formik.setFieldValue("vehicle_type", event.target.value)}
|
||||
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
|
||||
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
|
||||
onBlur={formik.handleBlur("vehicle_type")}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<PlateNumber formik={formik}/>
|
||||
<PlateNumber formik={formik} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12} sm={6}>
|
||||
<SelectBox
|
||||
name="education_id"
|
||||
@@ -591,9 +680,9 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
selectors={educationsList}
|
||||
select={formik.values.education_id}
|
||||
value={formik.values.education_id}
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
schema={{ value: "id", name: "title" }}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('education_id', event.target.value)
|
||||
formik.setFieldValue("education_id", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.education_id && Boolean(formik.errors.education_id)}
|
||||
@@ -609,12 +698,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
isLoading={isLoadingOccupationsList}
|
||||
errorEcured={errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
schema={{value: 'id', name: 'title'}}
|
||||
schema={{ value: "id", name: "title" }}
|
||||
selectors={occupationsList}
|
||||
select={formik.values.occupation_id}
|
||||
value={formik.values.occupation_id}
|
||||
handleChange={(event) => {
|
||||
formik.setFieldValue('occupation_id', event.target.value)
|
||||
formik.setFieldValue("occupation_id", event.target.value);
|
||||
}}
|
||||
setFieldTouched={formik.setFieldTouched}
|
||||
error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)}
|
||||
@@ -623,12 +712,12 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<Grid container spacing={2} sx={{ padding: 2 }}>
|
||||
<Grid item xs={12}>
|
||||
<TextField
|
||||
multiline
|
||||
rows={4}
|
||||
sx={{width: "100%"}}
|
||||
sx={{ width: "100%" }}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
@@ -643,27 +732,29 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid container spacing={2} sx={{padding: 2}}>
|
||||
<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")}`}/>
|
||||
|
||||
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"},
|
||||
flexDirection: { xs: "column", sm: "row" },
|
||||
alignItems: "center",
|
||||
mx: "auto",
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
width: { xs: "100%", sm: "30%", md: "25%" },
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
@@ -672,15 +763,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{my: 4}}
|
||||
endIcon={<DataSaverOnIcon/>}
|
||||
disabled={formik.values.checkedBox ? (formik.isSubmitting || !formik.dirty || !formik.isValid) : true}
|
||||
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
|
||||
);
|
||||
};
|
||||
export default RealPersonForm;
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
import {GET_PROJECT_TITLE} from "@/core/data/apiRoutes";
|
||||
import {useRequest} from "@witel/webapp-builder";
|
||||
import {useEffect, useState} from "react";
|
||||
import { GET_PROJECT_TITLE } from "@/core/data/apiRoutes";
|
||||
import { useRequest } from "@witel/webapp-builder";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const useProjectTitle = () => {
|
||||
const [isLoadingProjectTitle, setIsLoadingProjectTitle] = useState(false)
|
||||
const [errorProjectTitle, setErrorProjectTitle] = useState(false)
|
||||
const [projectTitle, setProjectTitle] = useState([])
|
||||
const requestServer = useRequest({auth: true, notification: false})
|
||||
const [isLoadingProjectTitle, setIsLoadingProjectTitle] = useState(false);
|
||||
const [errorProjectTitle, setErrorProjectTitle] = useState(false);
|
||||
const [projectTitle, setProjectTitle] = useState([]);
|
||||
const requestServer = useRequest({ auth: true, notification: false });
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoadingProjectTitle(true)
|
||||
requestServer(GET_PROJECT_TITLE, 'get', {auth: true, notification: false}).then(({data}) => {
|
||||
const formattedData = data.data.map((projectTitle, index) => ({
|
||||
id: index,
|
||||
name: projectTitle.title,
|
||||
value: projectTitle.id,
|
||||
}));
|
||||
setIsLoadingProjectTitle(false)
|
||||
setProjectTitle(formattedData);
|
||||
}).catch(() => {
|
||||
setIsLoadingProjectTitle(false)
|
||||
setErrorProjectTitle(true)
|
||||
})
|
||||
}, [])
|
||||
setIsLoadingProjectTitle(true);
|
||||
requestServer(GET_PROJECT_TITLE, "get", { auth: true, notification: false })
|
||||
.then(({ data }) => {
|
||||
const formattedData = data.data.map((projectTitle, index) => ({
|
||||
id: index,
|
||||
name: projectTitle.title,
|
||||
value: projectTitle.id,
|
||||
}));
|
||||
setIsLoadingProjectTitle(false);
|
||||
setProjectTitle(formattedData);
|
||||
})
|
||||
.catch(() => {
|
||||
setIsLoadingProjectTitle(false);
|
||||
setErrorProjectTitle(true);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return {
|
||||
projectTitle,
|
||||
isLoadingProjectTitle,
|
||||
errorProjectTitle
|
||||
}
|
||||
errorProjectTitle,
|
||||
};
|
||||
};
|
||||
|
||||
export default useProjectTitle;
|
||||
export default useProjectTitle;
|
||||
|
||||
Reference in New Issue
Block a user