submit api

This commit is contained in:
2024-04-22 14:23:49 +03:30
parent 603708b165
commit 586252edb8
7 changed files with 163 additions and 241 deletions

View File

@@ -53,8 +53,8 @@ function ButtonDatePicker(props) {
formik: props.formik,
field: { setOpen },
textField: {
helperText: props.formik.errors.birthday
? `${t("birthday_error")}`
helperText: props.formik.errors.company_date
? `${t("company_date")}`
: null,
},
}}

View File

@@ -25,7 +25,7 @@ import {useFormik} from "formik";
import LegalPersonDatePicker from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker";
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
import useActivityType from "@/lib/app/hooks/useActivityType";
import usePriorityLists from "@/lib/app/hooks/usePriorityLists";
import MuiDatePicker from "@/core/components/MuiDatePicker";
const LegalPersonForm = ({setFinishLoanRequest}) => {
const t = useTranslations();
@@ -37,15 +37,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations();
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations();
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType();
const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists();
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle();
const initialValues = {
person_type: "legal",
company_tel_number: "",
activity_type: "",
project_title: "",
priority_list: "",
navgan_plan_id: "",
birthday: "",
vehicle_type: "",
province_id: "",
boss_father_name: "",
@@ -83,10 +82,9 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
.required(t("LoanRequest.error_message_company_tel_number")),
vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")),
activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")),
project_title: Yup.string().required(t("LoanRequest.error_message_project_title")),
priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")),
navgan_plan_id: Yup.string().required(t("LoanRequest.error_message_navgan_plan_id")),
register_number: Yup.string().required(t("LoanRequest.error_message_register_number")),
boss_father_name: Yup.string().required(t("LoanRequest.error_message_boss_father_name")),
birthday: Yup.string().required(t("LoanRequest.error_message_boss_date_of_birth")),
company_name: Yup.string().required(t("LoanRequest.error_message_company_name")),
boss_gender: Yup.string().required(t("LoanRequest.error_message_boss_gender")),
navgan_type: Yup.string().required(t("LoanRequest.error_message_navgan_type")),
@@ -171,6 +169,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
: {
national_tracking_code: values.boss_national_card_tracking_code,
};
const _father_name = values.boss_father_name !== "" ? {father_name: values.boss_father_name} : {}
let _data = {
is_legal_person: 1,
@@ -181,13 +180,11 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
company_name: values.company_name,
province_id: values.province_id,
city_id: values.city_id,
father_name: values.boss_father_name,
first_name: values.boss_first_name,
last_name: values.boss_last_name,
navgan_id: values.navgan_id,
activity_type_id: values.activity_type,
project_title: values.project_title,
activity_priority_id: values.priority_list,
navgan_plan_id: values.navgan_plan_id,
postal_code: values.company_postal_code,
navgan_type: values.navgan_type,
gender: values.boss_gender,
@@ -197,10 +194,12 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
plate_part4: values.plate_part4,
address: values.address,
company_register_date: values.company_date.locale("en").format("YYYY-MM-DD"),
birthday: values.birthday.locale("en").format("YYYY-MM-DD"),
education_id: values.education_id,
occupation_id: values.occupation_id,
..._national_card,
..._national_number,
..._father_name
};
await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {
@@ -229,28 +228,28 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
return (
<>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={4}>
<Grid item xs={12} sm={6}>
<SelectBox
name="project_title"
label={t("LoanRequest.text_field_project_title")}
name="navgan_plan_id"
label={t("LoanRequest.text_field_navgan_plan_id")}
size="small"
selectType="project_title"
selectType="navgan_plan_id"
isLoading={isLoadingProjectTitle}
errorEcured={errorProjectTitle}
selectors={projectTitle}
schema={{value: "name", name: "name"}}
select={formik.values.project_title}
value={formik.values.project_title}
schema={{value: "value", name: "name"}}
select={formik.values.navgan_plan_id}
value={formik.values.navgan_plan_id}
handleChange={(event) => {
formik.setFieldValue("project_title", event.target.value);
formik.setFieldValue("navgan_plan_id", event.target.value);
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.project_title && Boolean(formik.errors.project_title)}
helperText={formik.touched.project_title && formik.errors.project_title}
onBlur={formik.handleBlur("project_title")}
error={formik.touched.navgan_plan_id && Boolean(formik.errors.navgan_plan_id)}
helperText={formik.touched.navgan_plan_id && formik.errors.navgan_plan_id}
onBlur={formik.handleBlur("navgan_plan_id")}
/>
</Grid>
<Grid item xs={12} sm={4}>
<Grid item xs={12} sm={6}>
<SelectBox
name="activity_type"
label={t("LoanRequest.text_field_activity_type")}
@@ -271,27 +270,6 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
onBlur={formik.handleBlur("activity_type")}
/>
</Grid>
<Grid item xs={12} sm={4}>
<SelectBox
name="priority_list"
label={t("LoanRequest.text_field_priority_list")}
size="small"
selectType="priority_list"
isLoading={isLoadingPriorityLists}
errorEcured={errorPriorityLists}
selectors={priorityLists}
schema={{value: "value", name: "name"}}
select={formik.values.priority_list}
value={formik.values.priority_list}
handleChange={(event) => {
formik.setFieldValue("priority_list", event.target.value);
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.priority_list && Boolean(formik.errors.priority_list)}
helperText={formik.touched.priority_list && formik.errors.priority_list}
onBlur={formik.handleBlur("priority_list")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={4}>
@@ -549,7 +527,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="boss_first_name"
@@ -565,7 +543,7 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
helperText={formik.touched.boss_first_name && formik.errors.boss_first_name}
/>
</Grid>
<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="boss_last_name"
@@ -581,6 +559,14 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
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}>
@@ -665,9 +651,6 @@ const LegalPersonForm = ({setFinishLoanRequest}) => {
label={t("LoanRequest.text_field_boss_father_name")}
placeholder={t("LoanRequest.text_field_enter_your_boss_father_name")}
fullWidth
onBlur={formik.handleBlur("boss_father_name")}
error={formik.touched.boss_father_name && Boolean(formik.errors.boss_father_name)}
helperText={formik.touched.boss_father_name && formik.errors.boss_father_name}
/>
</Grid>
</Grid>

View File

@@ -24,7 +24,6 @@ import * as React from "react";
import UseEducations from "@/lib/app/hooks/useEducations";
import useOccupations from "@/lib/app/hooks/useOccupations";
import useActivityType from "@/lib/app/hooks/useActivityType";
import usePriorityLists from "@/lib/app/hooks/usePriorityLists";
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
const RealPersonForm = ({setFinishLoanRequest}) => {
@@ -34,7 +33,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
const {educationsList, isLoadingEducationsList, errorEducationsList} = UseEducations();
const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations();
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType();
const {priorityLists, isLoadingPriorityLists, errorPriorityLists} = usePriorityLists();
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle();
const requestServer = useRequest();
const {getUser, changeUser} = useUser();
@@ -45,8 +43,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
vehicle_type: "",
telephone_number: "",
activity_type: "",
project_title: "",
priority_list: "",
navgan_plan_id: "",
father_name: "",
gender: "",
first_name: "",
@@ -78,11 +75,9 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
return stringValue.length === 11;
})
.required(t("LoanRequest.error_message_tel_number")),
father_name: Yup.string().required(t("LoanRequest.error_message_father_name")),
vehicle_type: Yup.string().required(t("LoanRequest.error_message_vehicle_type")),
activity_type: Yup.string().required(t("LoanRequest.error_message_activity_type")),
project_title: Yup.string().required(t("LoanRequest.error_message_project_title")),
priority_list: Yup.string().required(t("LoanRequest.error_message_priority_list")),
navgan_plan_id: Yup.string().required(t("LoanRequest.error_message_navgan_plan_id")),
gender: Yup.string().required(t("LoanRequest.error_message_gender")),
occupation_id: Yup.string().required(t("LoanRequest.error_message_occupation_id")),
education_id: Yup.string().required(t("LoanRequest.error_message_education_id")),
@@ -147,6 +142,7 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
: {
national_tracking_code: values.national_card_tracking_code,
};
const _father_name = values.father_name !== "" ? {father_name: values.father_name} : {}
let _data = {
is_legal_person: 0,
@@ -155,7 +151,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
vehicle_type: values.vehicle_type,
province_id: values.province_id,
city_id: values.city_id,
father_name: values.father_name,
first_name: values.first_name,
last_name: values.last_name,
navgan_id: values.navgan_id,
@@ -166,14 +161,14 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
education_id: values.education_id,
occupation_id: values.occupation_id,
activity_type_id: values.activity_type,
project_title: values.project_title,
activity_priority_id: values.priority_list,
navgan_plan_id: values.navgan_plan_id,
plate_part1: values.plate_part1,
plate_part2: values.plate_part2,
plate_part3: values.plate_part3,
plate_part4: values.plate_part4,
birthday: values.birthday.locale("en").format("YYYY-MM-DD"),
..._national_card,
..._father_name
};
await requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {
@@ -204,28 +199,28 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
return (
<>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={4}>
<Grid item xs={12} sm={6}>
<SelectBox
name="project_title"
label={t("LoanRequest.text_field_project_title")}
name="navgan_plan_id"
label={t("LoanRequest.text_field_navgan_plan_id")}
size="small"
selectType="project_title"
selectType="navgan_plan_id"
isLoading={isLoadingProjectTitle}
errorEcured={errorProjectTitle}
selectors={projectTitle}
schema={{value: "name", name: "name"}}
select={formik.values.project_title}
value={formik.values.project_title}
schema={{value: "value", name: "name"}}
select={formik.values.navgan_plan_id}
value={formik.values.navgan_plan_id}
handleChange={(event) => {
formik.setFieldValue("project_title", event.target.value);
formik.setFieldValue("navgan_plan_id", event.target.value);
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.project_title && Boolean(formik.errors.project_title)}
helperText={formik.touched.project_title && formik.errors.project_title}
onBlur={formik.handleBlur("project_title")}
error={formik.touched.navgan_plan_id && Boolean(formik.errors.navgan_plan_id)}
helperText={formik.touched.navgan_plan_id && formik.errors.navgan_plan_id}
onBlur={formik.handleBlur("navgan_plan_id")}
/>
</Grid>
<Grid item xs={12} sm={4}>
<Grid item xs={12} sm={6}>
<SelectBox
name="activity_type"
label={t("LoanRequest.text_field_activity_type")}
@@ -246,27 +241,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
onBlur={formik.handleBlur("activity_type")}
/>
</Grid>
<Grid item xs={12} sm={4}>
<SelectBox
name="priority_list"
label={t("LoanRequest.text_field_priority_list")}
size="small"
selectType="priority_list"
isLoading={isLoadingPriorityLists}
errorEcured={errorPriorityLists}
selectors={priorityLists}
schema={{value: "value", name: "name"}}
select={formik.values.priority_list}
value={formik.values.priority_list}
handleChange={(event) => {
formik.setFieldValue("priority_list", event.target.value);
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.priority_list && Boolean(formik.errors.priority_list)}
helperText={formik.touched.priority_list && formik.errors.priority_list}
onBlur={formik.handleBlur("priority_list")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={4}>
@@ -412,9 +386,6 @@ const RealPersonForm = ({setFinishLoanRequest}) => {
label={t("LoanRequest.text_field_father_name")}
placeholder={t("LoanRequest.text_field_enter_your_father_name")}
fullWidth
onBlur={formik.handleBlur("father_name")}
error={formik.touched.father_name && Boolean(formik.errors.father_name)}
helperText={formik.touched.father_name && formik.errors.father_name}
/>
</Grid>
<Grid item xs={12} sm={4}>