add education and occupation list hook

This commit is contained in:
2023-12-18 16:51:18 +03:30
parent c69aa4be89
commit 62670863a1
7 changed files with 202 additions and 63 deletions

View File

@@ -10,6 +10,8 @@ import useProvince from "@/lib/app/hooks/useProvince";
import useCities from "@/lib/app/hooks/useCities";
import PlateNumber from "@/core/components/PlateNumber";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import UseEducations from "@/lib/app/hooks/useEducations";
import useOccupations from "@/lib/app/hooks/useOccupations";
const AddFormComponent = () => {
const t = useTranslations();
@@ -17,28 +19,32 @@ const AddFormComponent = () => {
const requestServer = useRequest()
const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince()
const {cityTextField, cityList, setProvinceID} = useCities()
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations()
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations()
const initialValues = {
tel_number: "",
telephone_number: "",
vehicle_type: "",
plate_number: "",
province_id: "",
city_id: "",
navgan_id: "",
national_code: "",
national_id: "",
shenasname_serial: "",
postal_code: "",
navgan_type: "",
plate_part1: "",
plate_part2: "",
plate_part2: "الف",
plate_part3: "",
plate_part4: "",
address: "",
date_of_birth: "",
birthday: "",
education_id: "",
occupation_id: "",
};
const validationSchema = Yup.object().shape({
tel_number: Yup.mixed()
telephone_number: Yup.mixed()
.test("max", `${t("LoanRequest.tel_number_max")}`, (value) => value.toString().length === 11)
.required(t("LoanRequest.error_message_tel_number")),
vehicle_type: Yup.string().required(
@@ -47,10 +53,16 @@ const AddFormComponent = () => {
navgan_type: Yup.string().required(
t("LoanRequest.error_message_navgan_type")
),
occupation_id: Yup.string().required(
t("LoanRequest.error_message_occupation_id")
),
education_id: Yup.string().required(
t("LoanRequest.error_message_education_id")
),
address: Yup.string().required(
t("LoanRequest.error_message_address")
),
date_of_birth: Yup.string().required(
birthday: Yup.string().required(
t("LoanRequest.error_message_date_of_birth")
),
postal_code: Yup.mixed()
@@ -59,35 +71,32 @@ const AddFormComponent = () => {
t("LoanRequest.error_message_postal_code")
),
plate_part1: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part1_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part1")
t("LoanRequest.error_message_plate_number")
),
plate_part2: Yup.mixed()
.required(
t("LoanRequest.error_message_plate_part2")
t("LoanRequest.error_message_plate_number")
),
plate_part3: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part3")
t("LoanRequest.error_message_plate_number")
),
plate_part4: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part3")
t("LoanRequest.error_message_plate_number")
),
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
national_code: Yup.mixed()
national_id: Yup.mixed()
.test("is-number", `${t("LoanRequest.national_code_number")}`,
(value) => !isNaN(value))
.test("positive", `${t("LoanRequest.national_code_positive")}`, (value) => value >= 0)
.test("max", `${t("LoanRequest.national_code_max")}`, (value) => value.toString().length === 10)
.required(t("LoanRequest.error_message_national_id")),
shenasname_serial: Yup.mixed()
.test("max", `${t("LoanRequest.shenasname_serial_max")}`, (value) => value.toString().length === 11)
.test("max", `${t("LoanRequest.shenasname_serial_max")}`, (value) => value.toString().length === 10)
.required(t("LoanRequest.error_message_shenasname_serial")
),
});
@@ -95,7 +104,7 @@ const AddFormComponent = () => {
const handleSubmit = async (values, props) => {
const formData = new FormData();
formData.append("tel_number", values.tel_number);
formData.append("telephone_number", values.telephone_number);
formData.append("navgan_type", values.navgan_type);
formData.append("postal_code", values.postal_code);
formData.append("vehicle_type", values.vehicle_type);
@@ -104,9 +113,11 @@ const AddFormComponent = () => {
formData.append("city_id", values.city_id);
formData.append("address", values.address);
formData.append("navgan_id", values.navgan_id);
formData.append("national_code", values.national_code);
formData.append("date_of_birth", values.date_of_birth);
formData.append("national_id", values.national_id);
formData.append("birthday", values.birthday);
formData.append("shenasname_serial", values.shenasname_serial);
formData.append("education_id", values.education_id);
formData.append("occupation_id", values.occupation_id);
requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {auth: true, notification: true}).then().catch(() => {
props.setSubmitting(false)
@@ -124,7 +135,7 @@ const AddFormComponent = () => {
>
<TextField
sx={{width: "100%"}}
name="national_code"
name="national_id"
variant="outlined"
size="small"
type={"number"}
@@ -133,9 +144,9 @@ const AddFormComponent = () => {
placeholder={t(
"LoanRequest.text_field_enter_your_national_code"
)}
onBlur={formik.handleBlur("national_code")}
error={formik.touched.national_code && Boolean(formik.errors.national_code)}
helperText={formik.touched.national_code && formik.errors.national_code}
onBlur={formik.handleBlur("national_id")}
error={formik.touched.national_id && Boolean(formik.errors.national_id)}
helperText={formik.touched.national_id && formik.errors.national_id}
fullWidth
/>
</Grid>
@@ -159,9 +170,9 @@ const AddFormComponent = () => {
<Grid item xs={12} sm={4}>
<MuiDatePicker
formik={formik}
error={formik.touched.date_of_birth && Boolean(formik.errors.date_of_birth)}
helperText={formik.touched.date_of_birth && formik.errors.date_of_birth}
onBlur={formik.handleBlur("date_of_birth")}
error={formik.touched.birthday && Boolean(formik.errors.birthday)}
helperText={formik.touched.birthday && formik.errors.birthday}
onBlur={formik.handleBlur("birthday")}
/>
</Grid>
</Grid>
@@ -185,7 +196,7 @@ const AddFormComponent = () => {
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="tel_number"
name="telephone_number"
variant="outlined"
type={'number'}
size="small"
@@ -195,9 +206,9 @@ const AddFormComponent = () => {
"LoanRequest.text_field_enter_your_tel_number"
)}
fullWidth
onBlur={formik.handleBlur("tel_number")}
error={formik.touched.tel_number && Boolean(formik.errors.tel_number)}
helperText={formik.touched.tel_number && formik.errors.tel_number}
onBlur={formik.handleBlur("telephone_number")}
error={formik.touched.telephone_number && Boolean(formik.errors.telephone_number)}
helperText={formik.touched.telephone_number && formik.errors.telephone_number}
/>
</Grid>
</Grid>
@@ -208,11 +219,7 @@ const AddFormComponent = () => {
label={t("LoanRequest.text_field_navgan_type")}
size="small"
selectType="navgan_type"
selectors={[{id: 1, value: 1, name: "مسافری"}, {id: 2, value: 2, name: "عمومی"}, {
id: 3,
value: 3,
name: "روستایی"
}]}
selectors={[{id: 1, value: 1, name: "روستایی"}, {id: 2, value: 2, name: "عمومی"}]}
select={formik.values.navgan_type}
handleChange={(event) => {
formik.setFieldValue('navgan_type', event.target.value)
@@ -287,8 +294,8 @@ const AddFormComponent = () => {
label={t("LoanRequest.text_field_vehicle_type")}
size="small"
selectType="vehicle_type"
selectors={[{id: 0, value: 0, name: "اتوبوس"},
{id: 1, value: 1, name: "مینی بوس"}]}
selectors={[{id: 0, value: "اتوبوس", name: "اتوبوس"},
{id: 1, value: "مینی بوس", name: "مینی بوس"}]}
select={formik.values.vehicle_type}
handleChange={(event) => formik.setFieldValue('vehicle_type', event.target.value)}
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
@@ -300,6 +307,46 @@ const AddFormComponent = () => {
<PlateNumber formik={formik}/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="education_id"
label={t("LoanRequest.text_field_education_id")}
size="small"
isLoading={isLoadingEducationsList}
errorEcured={errorEducationsList}
selectType="education_id"
selectors={educationsList}
select={formik.values.education_id}
handleChange={(event) => {
formik.setFieldValue('education_id', event.target.value)
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.education_id && Boolean(formik.errors.education_id)}
helperText={formik.touched.education_id && formik.errors.education_id}
onBlur={formik.handleBlur("education_id")}
/>
</Grid>
<Grid item xs={12} sm={6}>
<SelectBox
name="occupation_id"
label={t("LoanRequest.text_field_occupation_id")}
size="small"
isLoading={isLoadingOccupationsList}
errorEcured={errorOccupationsList}
selectType="occupation_id"
selectors={occupationsList}
select={formik.values.occupation_id}
handleChange={(event) => {
formik.setFieldValue('occupation_id', event.target.value)
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.occupation_id && Boolean(formik.errors.occupation_id)}
helperText={formik.touched.occupation_id && formik.errors.occupation_id}
onBlur={formik.handleBlur("occupation_id")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12}>
<TextField