1030 lines
50 KiB
JavaScript
1030 lines
50 KiB
JavaScript
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 useProjectTitle from "@/lib/app/hooks/useProjectTitle";
|
|
import useActivityType from "@/lib/app/hooks/useActivityType";
|
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
|
import LegalPersonDatePicker from "@/core/components/LegalPersonDatePicker";
|
|
import PriceField from "@/core/components/PriceField";
|
|
import { useState } from "react";
|
|
|
|
const vehicle_amount = {
|
|
اتوبوس: parseInt(process.env.NEXT_PUBLIC_BUS_AMOUNT),
|
|
"مینی بوس": parseInt(process.env.NEXT_PUBLIC_MINIBUS_AMOUNT),
|
|
};
|
|
const LegalPersonForm = ({ setFinishLoanRequest }) => {
|
|
const t = useTranslations();
|
|
const router = useRouter();
|
|
const requestServer = useRequest();
|
|
const [vehicleType, setVehicleType] = useState("");
|
|
const { getUser, changeUser } = useUser();
|
|
const { cityTextField, cityList, setProvinceID, isLoadingCityList } = useCities();
|
|
const { provinceList, isLoadingProvinceList, errorProvinceList } = useLimitedProvince();
|
|
const { educationsList, isLoadingEducationsList, errorEducationsList } = UseEducations();
|
|
const { occupationsList, isLoadingOccupationsList, errorOccupationsList } = useOccupations();
|
|
const { activityType, isLoadingActivityType, errorActivityType } = useActivityType();
|
|
const { projectTitle, isLoadingProjectTitle, errorProjectTitle } = useProjectTitle();
|
|
|
|
const initialValues = {
|
|
person_type: "legal",
|
|
company_tel_number: "",
|
|
activity_type: "",
|
|
navgan_plan_id: "",
|
|
birthday: "",
|
|
investment: "",
|
|
requested_facilities: "",
|
|
applicant_payment: "",
|
|
user_existing_employment: "",
|
|
user_committed_employment: "",
|
|
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",
|
|
plate_part1: "",
|
|
plate_part2: "ع",
|
|
plate_part3: "",
|
|
plate_part4: "",
|
|
address: "",
|
|
company_register_date: "",
|
|
education_id: "",
|
|
occupation_id: "",
|
|
checkedBox: false,
|
|
history_facilities: 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")),
|
|
requested_facilities: Yup.mixed()
|
|
.test(
|
|
"max-amount",
|
|
`${t("LoanRequest.max_amount", {
|
|
value: parseInt(vehicle_amount[vehicleType]).toLocaleString("en"),
|
|
})}`,
|
|
(value) => value <= vehicle_amount[vehicleType]
|
|
)
|
|
.required(t("LoanRequest.error_message_requested_facilities")),
|
|
investment: Yup.string().required(t("LoanRequest.error_message_investment")),
|
|
user_committed_employment: Yup.string().required(t("LoanRequest.error_message_user_committed_employment")),
|
|
user_existing_employment: Yup.string().required(t("LoanRequest.error_message_user_existing_employment")),
|
|
activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")),
|
|
navgan_plan_id: Yup.string().required(t("LoanRequest.error_message_navgan_plan_id")),
|
|
register_number: Yup.string().required(t("LoanRequest.error_message_register_number")),
|
|
birthday: Yup.string().required(t("LoanRequest.error_message_boss_date_of_birth")),
|
|
company_name: Yup.string().required(t("LoanRequest.error_message_company_name")),
|
|
boss_gender: Yup.string().required(t("LoanRequest.error_message_boss_gender")),
|
|
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_register_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_father_name: Yup.string().required(t("LoanRequest.error_message_boss_father_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_boss_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
|
|
.test(
|
|
"max",
|
|
`${t("LoanRequest.boss_national_serial_number_max")}`,
|
|
(value) => value && value.toString().length === 10
|
|
)
|
|
.required(t("LoanRequest.error_message_boss_shenasname_serial"))
|
|
: schema;
|
|
}
|
|
),
|
|
boss_national_card_tracking_code: Yup.string().when(
|
|
"national_serial_number_or_tracking_code",
|
|
([national_serial_number_or_tracking_code], schema) => {
|
|
return national_serial_number_or_tracking_code === "national_card_tracking_code"
|
|
? schema
|
|
.test(
|
|
"max",
|
|
`${t("LoanRequest.national_boss_tracking_code_max")}`,
|
|
(value) => value && value.toString().length === 10
|
|
)
|
|
.required(t("LoanRequest.error_message_boss_national_card_tracking_code"))
|
|
: schema;
|
|
}
|
|
),
|
|
});
|
|
|
|
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.boss_national_serial_number,
|
|
}
|
|
: {
|
|
national_tracking_code: values.boss_national_card_tracking_code,
|
|
};
|
|
|
|
let _data = {
|
|
is_legal_person: 1,
|
|
telephone_number: values.company_tel_number,
|
|
register_number: values.register_number,
|
|
national_id: values.boss_national_code,
|
|
vehicle_type: values.vehicle_type,
|
|
company_name: values.company_name,
|
|
province_id: values.province_id,
|
|
city_id: values.city_id,
|
|
first_name: values.boss_first_name,
|
|
last_name: values.boss_last_name,
|
|
navgan_id: values.navgan_id,
|
|
activity_type_id: values.activity_type,
|
|
navgan_plan_id: values.navgan_plan_id,
|
|
postal_code: values.company_postal_code,
|
|
navgan_type: "عمومی",
|
|
requested_facility_amount: Number(values.requested_facilities),
|
|
investment_amount: Number(values.investment),
|
|
person_share: Number(values.applicant_payment),
|
|
user_committed_employment: Number(values.user_committed_employment),
|
|
user_existing_employment: Number(values.user_existing_employment),
|
|
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,
|
|
company_register_date: values.company_register_date.locale("en").format("YYYY-MM-DD"),
|
|
birthday: values.birthday.locale("en").format("YYYY-MM-DD"),
|
|
education_id: values.education_id,
|
|
occupation_id: values.occupation_id,
|
|
father_name: values.boss_father_name,
|
|
facility_usage_history: values.history_facilities === true ? 1 : 0,
|
|
..._national_card,
|
|
..._national_number,
|
|
};
|
|
|
|
await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {
|
|
auth: true,
|
|
notification: true,
|
|
data: _data,
|
|
})
|
|
.then(() => {
|
|
router.replace("/dashboard/followUp-loan");
|
|
getUser((data) => {
|
|
changeUser(data);
|
|
});
|
|
})
|
|
.catch(() => {})
|
|
.finally(() => {
|
|
props.setSubmitting(false);
|
|
});
|
|
};
|
|
|
|
const formik = useFormik({
|
|
initialValues,
|
|
validationSchema,
|
|
onSubmit: handleSubmit,
|
|
});
|
|
const handleAmountChange = (event) => {
|
|
if (!isNaN(event.target.value)) {
|
|
formik.setFieldValue("requested_facilities", event.target.value).then(() => {
|
|
formik.setFieldTouched("applicant_payment", false, false);
|
|
formik.setFieldValue("applicant_payment", Math.floor(event.target.value * 0.2));
|
|
});
|
|
} else {
|
|
formik.setFieldValue("requested_facilities", formik.values.requested_facilities);
|
|
}
|
|
};
|
|
return (
|
|
<>
|
|
<Grid container spacing={2} sx={{ p: 2 }}>
|
|
<Grid item xs={12} sm={6}>
|
|
<SelectBox
|
|
name="navgan_plan_id"
|
|
label={t("LoanRequest.text_field_navgan_plan_id")}
|
|
size="small"
|
|
selectType="navgan_plan_id"
|
|
isLoading={isLoadingProjectTitle}
|
|
errorEcured={errorProjectTitle}
|
|
selectors={projectTitle}
|
|
schema={{ value: "value", name: "name" }}
|
|
select={formik.values.navgan_plan_id}
|
|
value={formik.values.navgan_plan_id}
|
|
handleChange={(event) => {
|
|
formik.setFieldValue("navgan_plan_id", event.target.value);
|
|
}}
|
|
setFieldTouched={formik.setFieldTouched}
|
|
error={formik.touched.navgan_plan_id && Boolean(formik.errors.navgan_plan_id)}
|
|
helperText={formik.touched.navgan_plan_id && formik.errors.navgan_plan_id}
|
|
onBlur={formik.handleBlur("navgan_plan_id")}
|
|
/>
|
|
</Grid>
|
|
<Grid item xs={12} sm={6}>
|
|
<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>
|
|
<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_register_date && Boolean(formik.errors.company_register_date)}
|
|
helperText={formik.touched.company_register_date && formik.errors.company_register_date}
|
|
onBlur={formik.handleBlur("company_register_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.enter_province")}`
|
|
: 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: 0,
|
|
name: "زن",
|
|
},
|
|
{
|
|
id: 2,
|
|
value: 1,
|
|
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={4}>
|
|
<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={4}>
|
|
<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 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={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={(e) => {
|
|
const inputValue = e.target.value;
|
|
const regex = /^[A-Za-z0-9]*$/;
|
|
if (regex.test(inputValue)) {
|
|
formik.setFieldValue("boss_national_serial_number", inputValue);
|
|
}
|
|
}}
|
|
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"
|
|
inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }}
|
|
type={"tel"}
|
|
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={(event) => {
|
|
const inputValue = event.target.value;
|
|
if (isNaN(Number(inputValue))) {
|
|
return;
|
|
}
|
|
formik.handleChange({
|
|
target: {
|
|
name: "boss_national_card_tracking_code",
|
|
value: inputValue,
|
|
},
|
|
});
|
|
}}
|
|
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")}
|
|
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}
|
|
fullWidth
|
|
/>
|
|
</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) => {
|
|
setVehicleType(event.target.value);
|
|
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={4}>
|
|
<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 item xs={12} sm={4}>
|
|
<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={4}>
|
|
<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={{ p: 2 }}>
|
|
<Grid item xs={12} sm={6}>
|
|
<TextField
|
|
rows={4}
|
|
sx={{ width: "100%" }}
|
|
name="user_committed_employment"
|
|
variant="outlined"
|
|
value={formik.values.user_committed_employment}
|
|
size="small"
|
|
type={"tel"}
|
|
label={t("ShowLoan.user_committed_employment")}
|
|
error={!!(formik.touched.user_committed_employment && formik.errors.user_committed_employment)}
|
|
onChange={(event) => {
|
|
const inputValue = event.target.value;
|
|
if (isNaN(Number(inputValue))) {
|
|
return;
|
|
}
|
|
formik.handleChange({
|
|
target: {
|
|
name: "user_committed_employment",
|
|
value: inputValue,
|
|
},
|
|
});
|
|
}}
|
|
fullWidth
|
|
helperText={
|
|
formik.touched.user_committed_employment ? formik.errors.user_committed_employment : null
|
|
}
|
|
onBlur={formik.handleBlur("user_committed_employment")}
|
|
/>
|
|
</Grid>
|
|
<Grid item xs={12} sm={6}>
|
|
<TextField
|
|
rows={4}
|
|
sx={{ width: "100%" }}
|
|
name="user_existing_employment"
|
|
variant="outlined"
|
|
type={"tel"}
|
|
value={formik.values.user_existing_employment}
|
|
size="small"
|
|
label={t("ShowLoan.user_existing_employment")}
|
|
error={!!(formik.touched.user_existing_employment && formik.errors.user_existing_employment)}
|
|
onChange={(event) => {
|
|
const inputValue = event.target.value;
|
|
if (isNaN(Number(inputValue))) {
|
|
return;
|
|
}
|
|
formik.handleChange({
|
|
target: {
|
|
name: "user_existing_employment",
|
|
value: inputValue,
|
|
},
|
|
});
|
|
}}
|
|
fullWidth
|
|
helperText={
|
|
formik.touched.user_existing_employment ? formik.errors.user_existing_employment : null
|
|
}
|
|
onBlur={formik.handleBlur("user_existing_employment")}
|
|
/>
|
|
</Grid>
|
|
</Grid>
|
|
<Grid container spacing={2} sx={{ padding: 2 }}>
|
|
<Grid item xs={12} sm={4}>
|
|
<PriceField
|
|
name="investment"
|
|
label={t("LoanRequest.text_field_investment")}
|
|
type="text"
|
|
size="small"
|
|
inputProps={{
|
|
inputMode: "number",
|
|
min: 0,
|
|
pattern: "[0-9]*",
|
|
}}
|
|
variant="outlined"
|
|
value={formik.values.investment}
|
|
onChange={(event) => {
|
|
const inputValue = event.target.value;
|
|
if (isNaN(Number(inputValue))) {
|
|
return;
|
|
}
|
|
formik.setFieldValue("investment", event.target.value);
|
|
}}
|
|
onBlur={formik.handleBlur("investment")}
|
|
error={formik.touched.investment && Boolean(formik.errors.investment)}
|
|
helperText={formik.touched.investment && formik.errors.investment}
|
|
fullWidth
|
|
/>
|
|
</Grid>
|
|
<Grid item xs={12} sm={4}>
|
|
<PriceField
|
|
name="requested_facilities"
|
|
label={
|
|
formik.values.vehicle_type === ""
|
|
? t("LoanRequest.enter_vehicle_type")
|
|
: t("LoanRequest.text_field_requested_facilities")
|
|
}
|
|
type="text"
|
|
size="small"
|
|
inputProps={{
|
|
inputMode: "number",
|
|
min: 0,
|
|
pattern: "[0-9]*",
|
|
}}
|
|
variant="outlined"
|
|
value={formik.values.requested_facilities}
|
|
onChange={handleAmountChange}
|
|
disabled={formik.values.vehicle_type === ""}
|
|
onBlur={formik.handleBlur("requested_facilities")}
|
|
error={formik.touched.requested_facilities && Boolean(formik.errors.requested_facilities)}
|
|
helperText={formik.touched.requested_facilities && formik.errors.requested_facilities}
|
|
fullWidth
|
|
/>
|
|
</Grid>
|
|
<Grid item xs={12} sm={4}>
|
|
<PriceField
|
|
name="applicant_payment"
|
|
label={t("LoanRequest.text_field_applicant_payment")}
|
|
type="text"
|
|
size="small"
|
|
inputProps={{
|
|
inputMode: "number",
|
|
min: 0,
|
|
pattern: "[0-9]*",
|
|
}}
|
|
variant="outlined"
|
|
value={formik.values.applicant_payment}
|
|
disabled
|
|
fullWidth
|
|
/>
|
|
</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 sx={{ padding: 2 }}>
|
|
<Grid item xs={12}>
|
|
<FormControlLabel
|
|
color={"error.main"}
|
|
control={
|
|
<Checkbox
|
|
checked={formik.values.history_facilities}
|
|
onChange={(event) => {
|
|
formik.setFieldValue("history_facilities", event.target.checked);
|
|
}}
|
|
/>
|
|
}
|
|
label={`${t("LoanRequest.history_facilities")}`}
|
|
/>
|
|
</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 : true}
|
|
>
|
|
{formik.isSubmitting ? t("LoanRequest.button_while_submit") : t("LoanRequest.button_submit")}
|
|
</Button>
|
|
</Box>
|
|
</>
|
|
);
|
|
};
|
|
export default LegalPersonForm;
|