Merge branch 'feature/mohammad_update_form_refactor' into 'develop'
Feature/mohammad update form refactor See merge request witel-front-end/loan-facilities/user!49
This commit is contained in:
@@ -238,9 +238,11 @@
|
||||
"text_field_navgan_id": "کد ناوگان",
|
||||
"text_field_province_id": "استان",
|
||||
"text_field_education_id": "تحصیلات",
|
||||
"text_field_national_tracking_code": "کد رهگیری کارت ملی",
|
||||
"text_field_occupation_id": "شغل",
|
||||
"text_field_name": "نام کامل مالک",
|
||||
"text_field_navgan_type": "نوع ناوگان",
|
||||
"text_field_shenase_meli": "شناسه ملی",
|
||||
"text_field_vehicle_type": "نوع وسیله",
|
||||
"text_field_tel_number": "شماره ثابت (با پیش شماره استان)",
|
||||
"text_field_enter_your_national_id": "کد ملی را وارد کنید",
|
||||
@@ -251,6 +253,8 @@
|
||||
"text_field_enter_your_birthday": "تاریخ تولد را وارد کنید",
|
||||
"text_field_enter_your_navgan_id": "کد ناوگان را وارد کنید",
|
||||
"text_field_enter_your_name": "نام کامل مالک را وارد کنید",
|
||||
"text_field_enter_your_shenase_meli": "شناسه ملی را وارد کنید",
|
||||
"text_field_enter_your_national_tracking_code": "کد رهگیری کارت ملی را وارد کنید",
|
||||
"postal_code_max": "کد پستی می بایست 10 رقم باشد",
|
||||
"error_message_postal_code": "لطفا کد پستی را وارد کنید!",
|
||||
"error_message_national_serial_number": "لطفا سریال پشت کارت ملی را وارد کنید!",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import StyledForm from "@/core/components/StyledForm";
|
||||
import {Box, Button, Chip, Divider, Stack, TextField} from "@mui/material";
|
||||
import {Box, Chip, Divider, Stack, TextField} from "@mui/material";
|
||||
import {Field, Formik} from "formik";
|
||||
import {useTranslations} from "next-intl";
|
||||
import EditIcon from '@mui/icons-material/Edit';
|
||||
import * as Yup from "yup";
|
||||
import SelectBox from "@/core/components/SelectBox";
|
||||
import PlateNumber from "@/core/components/PlateNumber";
|
||||
@@ -26,11 +25,20 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
const occupationStates = useOccupations();
|
||||
const requestServer = useRequest();
|
||||
|
||||
let _shenase_meli = LoanDetails.is_legal_person === 1 ? {
|
||||
shenase_meli: LoanDetails.shenase_meli
|
||||
} : {}
|
||||
|
||||
const _national_card = LoanDetails.national_serial_number ? {
|
||||
national_serial_number: LoanDetails.national_serial_number
|
||||
} : {
|
||||
national_tracking_code: LoanDetails.national_card_tracking_code
|
||||
}
|
||||
// initial values
|
||||
const initialValues = {
|
||||
is_legal_person: LoanDetails.is_legal_person,
|
||||
national_id: LoanDetails.national_id,
|
||||
postal_code: LoanDetails.postal_code,
|
||||
national_serial_number: LoanDetails.national_serial_number,
|
||||
address: LoanDetails.address,
|
||||
birthday: moment(LoanDetails.birthday),
|
||||
navgan_id: LoanDetails.navgan_id,
|
||||
@@ -45,7 +53,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
plate_part3: LoanDetails.plate_number.split("-")[2],
|
||||
plate_part4: LoanDetails.plate_number.split("-")[3],
|
||||
education_id: LoanDetails.education_id,
|
||||
occupation_id: LoanDetails.occupation_id,
|
||||
occupation_id: LoanDetails.occupation_id, ..._national_card, ..._shenase_meli,
|
||||
};
|
||||
// end initial values
|
||||
|
||||
@@ -72,8 +80,24 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
occupation_id: Yup.string().required(t("ShowLoan.error_message_occupation_id")),
|
||||
education_id: Yup.string().required(t("ShowLoan.error_message_education_id")),
|
||||
birthday: Yup.string().required(t("ShowLoan.error_message_date_of_birth")),
|
||||
national_serial_number: Yup.string().required(t("ShowLoan.error_message_national_serial_number")),
|
||||
|
||||
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")),
|
||||
shenase_meli: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => {
|
||||
return is_legal_person === 1 ? schema
|
||||
.test("is-number", `${t("LoanRequest.national_number_number")}`, (value) => !isNaN(value))
|
||||
.test("positive", `${t("LoanRequest.national_number_positive")}`, (value) => value >= 0)
|
||||
.test("max", `${t("LoanRequest.national_number_max")}`, (value) => value && value.toString().length === 11)
|
||||
.required(t("LoanRequest.error_message_national_number")) : schema;
|
||||
}),
|
||||
national_serial_number: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === 'national_serial_number' ? schema.required(t("LoanRequest.error_message_shenasname_serial")) : schema
|
||||
}),
|
||||
national_card_tracking_code: Yup.string().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => {
|
||||
return national_serial_number_or_tracking_code === 'national_card_tracking_code' ? schema.required(t("LoanRequest.error_message_tracking_code")) : schema
|
||||
})
|
||||
});
|
||||
// end validation
|
||||
|
||||
@@ -185,6 +209,36 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
{
|
||||
initialValues.is_legal_person === 1 && (
|
||||
<Box
|
||||
sx={{
|
||||
mx: {xs: 0, sm: 2},
|
||||
my: 2,
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
name="shenase_meli"
|
||||
disabled
|
||||
variant="standard"
|
||||
size="small"
|
||||
label={t("ShowLoan.text_field_shenase_meli")}
|
||||
placeholder={t("ShowLoan.text_field_enter_your_shenase_meli")}
|
||||
type={"text"}
|
||||
error={!!(props.touched.shenase_meli && props.errors.shenase_meli)}
|
||||
fullWidth
|
||||
helperText={
|
||||
props.touched.shenase_meli
|
||||
? props.errors.shenase_meli
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
@@ -335,6 +389,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
{
|
||||
initialValues.national_serial_number ? (
|
||||
<Box
|
||||
sx={{
|
||||
mx: {xs: 0, sm: 2},
|
||||
@@ -347,10 +403,10 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
sx={{width: "100%"}}
|
||||
name="national_serial_number"
|
||||
size="small"
|
||||
disabled
|
||||
variant="standard"
|
||||
label={t("ShowLoan.text_field_national_serial_number")}
|
||||
placeholder={t(
|
||||
"ShowLoan.text_field_enter_your_national_serial_number"
|
||||
)}
|
||||
placeholder={t("ShowLoan.text_field_enter_your_national_serial_number")}
|
||||
type={"text"}
|
||||
error={!!(props.touched.national_serial_number && props.errors.national_serial_number)}
|
||||
fullWidth
|
||||
@@ -361,6 +417,35 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Box
|
||||
sx={{
|
||||
mx: {xs: 0, sm: 2},
|
||||
my: 2,
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
name="national_tracking_code"
|
||||
size="small"
|
||||
disabled
|
||||
variant="standard"
|
||||
label={t("ShowLoan.text_field_national_tracking_code")}
|
||||
placeholder={t("ShowLoan.text_field_enter_your_national_tracking_code")}
|
||||
type={"text"}
|
||||
error={!!(props.touched.national_tracking_code && props.errors.national_tracking_code)}
|
||||
fullWidth
|
||||
helperText={
|
||||
props.touched.national_tracking_code
|
||||
? props.errors.national_tracking_code
|
||||
: null
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
<Box
|
||||
sx={{
|
||||
mx: {xs: 0, sm: 2},
|
||||
@@ -370,6 +455,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
>
|
||||
<MuiDatePicker
|
||||
formik={props}
|
||||
disabled
|
||||
disableFuture={true}
|
||||
error={props.touched.birthday && Boolean(props.errors.birthday)}
|
||||
helperText={props.touched.birthday && props.errors.birthday}
|
||||
@@ -387,8 +473,9 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
name="postal_code"
|
||||
variant="outlined"
|
||||
variant="standard"
|
||||
size="small"
|
||||
disabled
|
||||
label={t("ShowLoan.text_field_postal_code")}
|
||||
placeholder={t(
|
||||
"ShowLoan.text_field_enter_your_postal_code"
|
||||
@@ -438,6 +525,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
name="province_id"
|
||||
label={t("ShowLoan.text_field_province_id")}
|
||||
size="small"
|
||||
disabled
|
||||
variant="standard"
|
||||
selectType="province_id"
|
||||
schema={{value: "value", name: "name"}}
|
||||
isLoading={provinceStates.isLoadingProvinceList}
|
||||
@@ -457,7 +546,6 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
/> : <Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
variant="outlined"
|
||||
disabled
|
||||
size="small"
|
||||
label={t("ShowLoan.text_field_province_id")}
|
||||
@@ -479,7 +567,9 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
label={citiesStates.cityList.length === 0 ? `${t("ShowLoan.cityList_empty")}` : citiesStates.cityTextField}
|
||||
size="small"
|
||||
selectType="city_id"
|
||||
disabled={citiesStates.cityList.length === 0}
|
||||
// disabled={citiesStates.cityList.length === 0}
|
||||
disabled
|
||||
variant="standard"
|
||||
selectors={citiesStates.cityList}
|
||||
select={props.values.city_id}
|
||||
schema={{value: "value", name: "name"}}
|
||||
@@ -491,7 +581,6 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
/> : <Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
variant="outlined"
|
||||
disabled
|
||||
size="small"
|
||||
label={t("ShowLoan.cityList_empty")}
|
||||
@@ -509,8 +598,9 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
<TextField
|
||||
sx={{width: "100%"}}
|
||||
name="telephone_number"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
variant="standard"
|
||||
disabled
|
||||
type={'tel'}
|
||||
value={props.values.telephone_number}
|
||||
onChange={(event) => {
|
||||
@@ -557,6 +647,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
name="education_id"
|
||||
label={t("ShowLoan.text_field_education_id")}
|
||||
size="small"
|
||||
variant="standard"
|
||||
disabled
|
||||
isLoading={educationStates.isLoadingEducationsList}
|
||||
errorEcured={educationStates.errorEducationsList}
|
||||
selectType="education_id"
|
||||
@@ -573,7 +665,6 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
/> : <Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
variant="outlined"
|
||||
disabled
|
||||
size="small"
|
||||
label={t("ShowLoan.text_field_education_id")}
|
||||
@@ -593,6 +684,8 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
name="occupation_id"
|
||||
label={t("ShowLoan.text_field_occupation_id")}
|
||||
size="small"
|
||||
disabled
|
||||
variant="standard"
|
||||
isLoading={occupationStates.isLoadingOccupationsList}
|
||||
errorEcured={occupationStates.errorOccupationsList}
|
||||
selectType="occupation_id"
|
||||
@@ -609,7 +702,6 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
/> : <Field
|
||||
as={TextField}
|
||||
sx={{width: "100%"}}
|
||||
variant="outlined"
|
||||
disabled
|
||||
size="small"
|
||||
label={t("ShowLoan.text_field_occupation_id")}
|
||||
@@ -640,8 +732,9 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
rows={4}
|
||||
sx={{width: "100%"}}
|
||||
name="address"
|
||||
variant="outlined"
|
||||
variant="standard"
|
||||
size="small"
|
||||
disabled
|
||||
label={t("ShowLoan.text_field_address")}
|
||||
placeholder={t("ShowLoan.text_field_enter_your_address")}
|
||||
type={"text"}
|
||||
@@ -660,17 +753,17 @@ const UpdateForm = ({LoanDetails, LoanId}) => {
|
||||
width: {xs: "100%", sm: "30%", md: "25%"},
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
fullWidth
|
||||
type="submit"
|
||||
variant="contained"
|
||||
size="large"
|
||||
sx={{mt: 2}}
|
||||
endIcon={<EditIcon/>}
|
||||
disabled={props.isSubmitting || !props.dirty || !props.isValid}
|
||||
>
|
||||
{t("ShowLoan.button_submit")}
|
||||
</Button>
|
||||
{/*<Button*/}
|
||||
{/* fullWidth*/}
|
||||
{/* type="submit"*/}
|
||||
{/* variant="contained"*/}
|
||||
{/* size="large"*/}
|
||||
{/* sx={{mt: 2}}*/}
|
||||
{/* endIcon={<EditIcon/>}*/}
|
||||
{/* disabled={props.isSubmitting || !props.dirty || !props.isValid}*/}
|
||||
{/*>*/}
|
||||
{/* {t("ShowLoan.button_submit")}*/}
|
||||
{/*</Button>*/}
|
||||
</Box>
|
||||
</StyledForm>
|
||||
</Stack>
|
||||
|
||||
@@ -21,8 +21,8 @@ function SelectBox({
|
||||
return (
|
||||
<FormControl
|
||||
disabled={disabled || false}
|
||||
variant={variant}
|
||||
fullWidth
|
||||
variant={variant}
|
||||
size="small"
|
||||
error={error}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user