Feature/edit followup

This commit is contained in:
2024-11-02 06:50:38 +00:00
committed by AmirHossein Mahmoodi
parent 94a6964f50
commit 36eb1b478a
9 changed files with 1534 additions and 788 deletions

View File

@@ -148,6 +148,11 @@
"loan_status": "وضعیت",
"loan_bank_branch": "اطلاعات شعبه",
"loan_details": "نمایش",
"loan_edit": "ویرایش",
"loan_cancel": "رد درخواست",
"loan_review": "درحال بررسی",
"loan_reserve": "در صف انتظار",
"loan_edit_info": "نیاز به ویرایش اطلاعات",
"loan_description": "توضیحات"
},
"LoanRequest": {
@@ -212,8 +217,6 @@
"error_message_tracking_code": "لطفا کد رهگیری کارت ملی خود را وارد کنید!",
"error_message_boss_national_card_tracking_code": "لطفا کد رهگیری کارت ملی مدیر عامل را وارد کنید!",
"error_message_postal_code": "لطفا کد پستی خود را وارد کنید!",
"error_message_father_name": "لطفا نام پدر خود را وارد کنید!",
"error_message_boss_father_name": "لطفا نام پدر مدیر عامل را وارد کنید!",
"error_message_national_code": "لطفا کد ملی خود را وارد کنید!",
"error_message_checkedBox": "لطفا کد صحت اطلاعات خود را تایید کنید!",
"error_message_navgan_type": "لطفا نوع ناوگان خود را وارد کنید!",
@@ -298,7 +301,10 @@
},
"ShowLoan": {
"show_loan_page": "نمایش وام | ناوگان",
"update_loan_page": "ویرایش وام | {person_type}",
"text_field_activity_type": "نوع فعالیت",
"text_field_navgan_plan_id": "عنوان پروژه",
"update_loan_page": "نمایش وام | {person_type} | کد یکتا {id}",
"edit_loan_page": "ویرایش وام | {person_type} | کد یکتا {id}",
"loading_show_component": "درحال دریافت اطلاعات درخواست...",
"tel_number_max": "شماره ثابت می بایست 11 رقم باشد",
"national_code_number": "کد ملی می بایست شامل اعداد باشد",
@@ -314,18 +320,27 @@
"text_field_shenasname_serial": "سریال پشت کارت ملی",
"text_field_national_trackin_code": "کد رهگیری کارت ملی",
"text_field_national_id": "کد ملی",
"text_field_boss_national_id": "کد ملی رییس شرکت",
"text_field_register_number": "شماره ثبت شرکت",
"text_field_postal_code": "کد پستی",
"text_field_national_serial_number": "سریال پشت کارت ملی",
"text_field_address": "آدرس",
"text_field_company_name": "نام شرکت",
"text_field_birthday": "تاریخ تولد",
"text_field_navgan_id": "کد ناوگان",
"text_field_province_id": "استان",
"text_field_boss_father_name": "نام پدر مدیر عامل",
"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_shenase_meli": "شناسه ملی شرکت",
"text_field_first_name": "نام",
"text_field_boss_first_name": "نام مدیر عامل",
"text_field_boss_last_name": "نام خانوادگی مدیر عامل",
"text_field_gender": "جنسیت",
"text_field_last_name": "نام خانوادگی",
"text_field_vehicle_type": "نوع وسیله",
"text_field_tel_number": "شماره ثابت (با پیش شماره استان)",
"text_field_enter_your_national_id": "کد ملی را وارد کنید",
@@ -337,6 +352,7 @@
"text_field_enter_your_birthday": "تاریخ تولد را وارد کنید",
"text_field_enter_your_navgan_id": "کد ناوگان را وارد کنید",
"text_field_enter_your_name": "نام کامل مالک را وارد کنید",
"text_field_father_name": "نام پدر",
"text_field_enter_your_shenase_meli": "شناسه ملی را وارد کنید",
"text_field_enter_your_national_tracking_code": "کد رهگیری کارت ملی را وارد کنید",
"postal_code_max": "کد پستی می بایست 10 رقم باشد",
@@ -345,13 +361,26 @@
"error_message_national_serial_number": "لطفا سریال پشت کارت ملی را وارد کنید!",
"error_message_address": "لطفا آدرس را وارد کنید!",
"error_message_birthday": "لطفا تاریخ تولد را وارد کنید!",
"error_message_activity_type": "لطفا نوع فعالیت خود را وارد کنید!",
"error_message_navgan_plan_id": "لطفا عنوان پروژه خود را وارد کنید!",
"error_message_boss_first_name": "لطفا نام مدیر عامل را وارد کنید!",
"error_message_navgan_id": "لطفا کد ناوگان را وارد کنید!",
"error_message_boss_last_name": "لطفا نام خانوادگی مدیر عامل را وارد کنید!",
"error_message_father_name": "لطفا نام پدر خود را وارد کنید!",
"error_message_first_name": "لطفا نام خود را وارد کنید!",
"error_message_province_id": "لطفا استان را وارد کنید!",
"error_message_city_id": "لطفا شهر خود را وارد کنید!",
"error_message_name": "لطفا نام کامل مالک را وارد کنید!",
"error_message_register_number": "لطفا شماره ثبت شرکت خود را وارد کنید!",
"error_message_boss_father_name": "لطفا نام پدر مدیر عامل را وارد کنید!",
"error_message_postal_code": "لطفا کد پستی خود را وارد کنید!",
"error_message_date_of_birth": "لطفا تاریخ تولد خود را وارد کنید!",
"error_message_company_date": "لطفا تاریخ ثبت شرکت را وارد کنید!",
"error_message_navgan_type": "لطفا نوع ناوگان را وارد کنید!",
"error_message_vehicle_type": "لطفا نوع وسیله را وارد کنید!",
"error_message_company_name": "لطفا نام شرکت خود را وارد کنید!",
"error_message_gender": "لطفا جنسیت خود را وارد کنید!",
"error_message_last_name": "لطفا نام خانوادگی خود را وارد کنید!",
"error_message_fixed_number": "لطفا تلفن ثابت را وارد کنید!",
"error_message_tel_number": "لطفا شماره ثابت (با پیش شماره استان) خود را وارد کنید!",
"error_message_occupation_id": "لطفا کد شغل (با توجه به مستندات ارائه شده) را به درستی وارد کنید!",

View File

@@ -78,11 +78,11 @@ const LegalPersonDatePicker = ({ formik, disabled }) => {
<ButtonDatePicker
label={
formik.values.company_date !== "" &&
formik.values.company_date.locale("fa").format("YYYY/MM/DD")
formik.values.company_date?.locale("fa").format("YYYY/MM/DD")
}
value={
formik.values.company_date !== ""
? formik.values.company_date.toDate()
? formik.values.company_date?.toDate()
: null
}
formik={formik}

View File

@@ -1,9 +1,11 @@
import {Box, Button, Card, CardContent, Grid, Typography} from "@mui/material";
import {Box, Button, Card, CardContent, Grid, Stack, Typography} from "@mui/material";
import {useTranslations} from "next-intl";
import moment from "jalali-moment";
import {LinkRouting} from "@witel/webapp-builder";
import AccessTimeFilledIcon from '@mui/icons-material/AccessTimeFilled';
import CancelIcon from '@mui/icons-material/Cancel';
import EditIcon from '@mui/icons-material/Edit';
import PendingIcon from '@mui/icons-material/Pending';
const RequestCard = ({item}) => {
const t = useTranslations();
@@ -11,82 +13,101 @@ const RequestCard = ({item}) => {
<Grid item xs={12} lg={6} xl={4}>
<Card sx={{
width: "100%",
height: "100%",
boxShadow: "rgba(0, 0, 0, 0.15) 0px 5px 15px 0px"
}}>
<CardContent sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'flex-start',
paddingBottom: '16px !important'
height: '100%',
justifyContent: "space-between"
}}>
<Box
sx={{
borderLeft: '6px solid',
borderColor: 'primary.main',
borderRadius: '6px 0px 0px 6px',
paddingLeft: '10px',
}}
>
<Typography variant="h6" sx={{lineHeight: 2, fontWeight: 'bold'}}>
{`${t("LoanFollowUp.loan_unique_code")}: ${item.id}`}
<Stack>
<Box
sx={{
borderLeft: '6px solid',
borderColor: 'primary.main',
borderRadius: '6px 0px 0px 6px',
paddingLeft: '10px',
}}
>
<Typography variant="h6" sx={{lineHeight: 2, fontWeight: 'bold'}}>
{`${t("LoanFollowUp.loan_unique_code")}: ${item.id}`}
</Typography>
</Box>
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_date")}: ${moment(item.created_at).locale("fa").format("HH:mm | YYYY/MM/DD")}`}
</Typography>
</Box>
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_date")}: ${moment(item.created_at).locale("fa").format("HH:mm | YYYY/MM/DD")}`}
</Typography>
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_bank_branch")}: ${item.branch_info === null ? '-' : item.branch_info}`}
</Typography>
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_status")}: `}
{item.loan_state}
{item.state_id >= 1 && item.state_id <= 6 &&
<AccessTimeFilledIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: '#48a4df'}}/>}
{item.state_id === 8 &&
<AccessTimeFilledIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: '#48a4df'}}/>}
{item.state_id === 7 &&
<CancelIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: 'red'}}/>}
</Typography>
{item.state_id === 7 && (
<Typography variant="body1" sx={{
lineHeight: 2,
paddingLeft: '20px',
wordWrap: 'break-word',
overflowWrap: 'break-word',
wordBreak: 'break-word'
}}>
{`${t("LoanFollowUp.loan_description")}: ${item.latestHistory.expert_description}`}
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_bank_branch")}: ${item.branch_info === null ? '-' : item.branch_info}`}
</Typography>
)}
{item.bank_status == 0 && (
<Typography variant="body1" sx={{
lineHeight: 2,
paddingLeft: '20px',
wordWrap: 'break-word',
overflowWrap: 'break-word',
wordBreak: 'break-word'
}}>
{`${t("LoanFollowUp.loan_description")}: درخواست وام توسط بانک تایید نشد (نیاز به اصلاح اطلاعات) `}
<Typography variant="body1" sx={{lineHeight: 2, paddingLeft: '20px'}}>
{`${t("LoanFollowUp.loan_status")}: `}
{item.state_id === 9 &&
<>
{t("LoanFollowUp.loan_reserve")}
<PendingIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: '#48a4df'}}/>
</>
}
{item.state_id === 17 &&
<>
{t("LoanFollowUp.loan_edit_info")}
<EditIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: '#ed6c02'}}/>
</>
}
{item.state_id === 7 &&
<>
{t("LoanFollowUp.loan_cancel")}
<CancelIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: 'red'}}/>
</>
}
{item.state_id !== 7 && item.state_id !== 17 && item.state_id !== 9 &&
<>
{t("LoanFollowUp.loan_review")}
<AccessTimeFilledIcon sx={{verticalAlign: 'middle', marginLeft: '4px', color: '#084070'}}/>
</>
}
</Typography>
)}
{item.bank_state == 8 && (
<Typography variant="body1" sx={{
lineHeight: 2,
paddingLeft: '20px',
wordWrap: 'break-word',
overflowWrap: 'break-word',
wordBreak: 'break-word'
}}>
{`${t("LoanFollowUp.loan_description")}: عدم تایید درخواست وام توسط بانک `}
</Typography>
)}
{item.state_id === 8 && item.bank_status == 0 && (
<Button variant="contained" color="primary" sx={{alignSelf: 'flex-end', mt: 2}}>
<LinkRouting underline="none" color="inherit" href={`/dashboard/navgan/${item.id}/show`}>
{t("LoanFollowUp.loan_details")}
</LinkRouting>
</Button>
)}
{item.state_id === 17 && (
<Typography variant="body1" sx={{
lineHeight: 2,
paddingLeft: '20px',
wordWrap: 'break-word',
overflowWrap: 'break-word',
wordBreak: 'break-word'
}}>
{`${t("LoanFollowUp.loan_description")}: ${item.latestHistory.expert_description}`}
</Typography>
)}
{item.state_id === 7 && (
<Typography variant="body1" sx={{
lineHeight: 2,
paddingLeft: '20px',
wordWrap: 'break-word',
overflowWrap: 'break-word',
wordBreak: 'break-word'
}}>
{`${t("LoanFollowUp.loan_description")}: درخواست وام توسط بانک تایید نشد (نیاز به اصلاح اطلاعات) `}
</Typography>
)}
</Stack>
{
item.state_id === 17 ? (
<Button variant="contained" color="warning" sx={{alignSelf: 'flex-end', mt: 2}}>
<LinkRouting underline="none" color="inherit"
href={`/dashboard/navgan/${item.id}/show`}>
{t("LoanFollowUp.loan_edit")}
</LinkRouting>
</Button>
) : (
<Button variant="contained" color="primary" sx={{alignSelf: 'flex-end', mt: 2}}>
<LinkRouting underline="none" color="inherit"
href={`/dashboard/navgan/${item.id}/show`}>
{t("LoanFollowUp.loan_details")}
</LinkRouting>
</Button>
)
}
</CardContent>
</Card>
</Grid>

View File

@@ -1,8 +1,10 @@
import { Grid } from "@mui/material";
import {Grid} from "@mui/material";
import {useEffect, useState} from "react";
import {SHOW_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
import RequestCard from "@/components/dashboard/navgan/followUp-loan/RequestCard";
import {FullPageLayout , useRequest} from "@witel/webapp-builder";
import {FullPageLayout, LoadingHardPage, useRequest} from "@witel/webapp-builder";
import sidebarMenu from "@/core/data/sidebarMenu";
import BookmarkAddedIcon from "@mui/icons-material/BookmarkAdded";
const LoanFollowUpComponent = () => {
const requestServer = useRequest();
@@ -12,8 +14,8 @@ const LoanFollowUpComponent = () => {
setIsLoading(true)
requestServer(SHOW_LOAN_REQUEST_NAVGAN, "get", {
auth: true,
pending:false,
success:{notification:{show:false}}
pending: false,
success: {notification: {show: false}}
})
.then(function ({data}) {
const items = data.data;
@@ -24,6 +26,7 @@ const LoanFollowUpComponent = () => {
})
}, []);
return (
<FullPageLayout>
<Grid
@@ -32,9 +35,17 @@ const LoanFollowUpComponent = () => {
rowSpacing={2}
sx={{alignItems: "start", justifyContent: "center", padding: "24px"}}
>
{requestsList.map((item) => (
<RequestCard item={item} key={item.id}/>
))}
<LoadingHardPage
loading={isLoading} width={100} height={100}
sx={{position: "absolute", bgcolor: "#fffc"}}
icon={<BookmarkAddedIcon sx={{width: 'inherit', height: 'inherit'}}/>}
>
<Grid container sx={{justifyContent : "center"}} spacing={2}>
{requestsList.map((item) => (
<RequestCard item={item} key={item.id}/>
))}
</Grid>
</LoadingHardPage>
</Grid>
</FullPageLayout>

View File

@@ -1,693 +0,0 @@
import StyledForm from "@/core/components/StyledForm";
import {Box, Button, Chip, Divider, Stack, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
import {Field, Formik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import SelectBox from "@/core/components/SelectBox";
import PlateNumber from "@/core/components/PlateNumber";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import moment from "jalali-moment";
import useProvince from "@/lib/app/hooks/useProvince";
import useCities from "@/lib/app/hooks/useCities";
import UseEducations from "@/lib/app/hooks/useEducations";
import useOccupations from "@/lib/app/hooks/useOccupations";
import {UPDATE_LOAN} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useRouter} from "next/router";
import {useEffect} from "react";
import EditIcon from '@mui/icons-material/Edit';
const UpdateForm = ({LoanDetails, LoanId}) => {
const t = useTranslations();
const provinceStates = useProvince();
const router = useRouter()
const citiesStates = useCities();
const educationStates = UseEducations();
const occupationStates = useOccupations();
const requestServer = useRequest();
let _shenase_meli = LoanDetails.is_legal_person === 1 ? {
shenase_meli: LoanDetails.shenase_meli
} : {}
// initial values
const initialValues = {
is_legal_person: LoanDetails.is_legal_person,
national_serial_number_or_tracking_code: LoanDetails.national_serial_number ? "serial_number" : "tracking_code",
national_id: LoanDetails.national_id,
postal_code: LoanDetails.postal_code,
address: LoanDetails.address,
birthday: moment(LoanDetails.birthday),
navgan_id: LoanDetails.navgan_id,
province_id: LoanDetails.province_id,
city_id: LoanDetails.city_id,
name: LoanDetails.name,
navgan_type: LoanDetails.navgan_type,
vehicle_type: LoanDetails.vehicle_type,
telephone_number: LoanDetails.telephone_number,
plate_part1: LoanDetails.plate_number.split("-")[0],
plate_part2: LoanDetails.plate_number.split("-")[1],
plate_part3: LoanDetails.plate_number.split("-")[2],
plate_part4: LoanDetails.plate_number.split("-")[3],
education_id: LoanDetails.education_id,
occupation_id: LoanDetails.occupation_id, ..._shenase_meli,
national_serial_number: LoanDetails.national_serial_number ?? "",
national_tracking_code: LoanDetails.national_tracking_code ?? ""
};
// end initial values
useEffect(() => {
citiesStates.setProvinceID(LoanDetails.province_id)
}, [LoanDetails.province_id]);
// validation
const validationSchema = Yup.object().shape({
postal_code: Yup.mixed()
.test("max", `${t("ShowLoan.postal_code_max")}`, (value) => value.toString().length === 10)
.required(t("ShowLoan.error_message_postal_code")),
address: Yup.string().required(t("ShowLoan.error_message_address")),
province_id: Yup.string().required(t("ShowLoan.error_message_province_id")),
city_id: Yup.string().required(t("ShowLoan.error_message_city_id")),
telephone_number: Yup.mixed()
.test("max", `${t("ShowLoan.tel_number_max")}`, (value) => {
const stringValue = String(value);
return stringValue.length === 11
})
.required(t("ShowLoan.error_message_tel_number")),
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_id: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => {
return is_legal_person === 1 ? schema
.test("is-number", `${t("ShowLoan.national_code_number")}`, (value) => !isNaN(value))
.test("positive", `${t("ShowLoan.national_code_positive")}`, (value) => value >= 0)
.test("max", `${t("ShowLoan.national_code_max")}`, (value) => value && value.toString().length === 10)
.required(t("ShowLoan.error_message_national_id")) : schema;
}),
shenase_meli: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => {
return is_legal_person === 1 ? schema
.test("is-number", `${t("ShowLoan.national_number_number")}`, (value) => !isNaN(value))
.test("positive", `${t("ShowLoan.national_number_positive")}`, (value) => value >= 0)
.test("max", `${t("ShowLoan.national_number_max")}`, (value) => value && value.toString().length === 11)
.required(t("ShowLoan.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 === 'serial_number' ? schema.required(t("ShowLoan.error_message_shenasname_serial")) : schema
}),
national_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 === 'tracking_code' ? schema.required(t("ShowLoan.error_message_tracking_code")) : schema
})
});
// end validation
// submit
const handleSubmit = async (values, props) => {
props.setSubmitting(true)
const formData = new FormData();
if (values.national_serial_number_or_tracking_code === "serial_number") {
formData.append("national_serial_number", values.national_serial_number)
} else {
formData.append("national_tracking_code", values.national_tracking_code);
}
if (values.is_legal_person === 1) {
formData.append("national_id", values.national_id);
}
formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD"));
formData.append("postal_code", values.postal_code);
formData.append("province_id", LoanDetails.province_id);
formData.append("city_id", LoanDetails.city_id);
formData.append("telephone_number", values.telephone_number);
formData.append("education_id", values.education_id);
formData.append("occupation_id", values.occupation_id);
formData.append("address", values.address);
await requestServer(UPDATE_LOAN + LoanId, "post", {
auth: true, notification: true, data: formData
}).then(() => {
router.push("/dashboard/navgan/followUp-loan");
}).catch(() => {
}).finally(() => {
props.setSubmitting(false);
})
};
// end submit
return (<>
<Box sx={{width: "80%", my: 2}}>
<Divider>
<Chip
label={t("ShowLoan.update_loan_page", {person_type: LoanDetails.is_legal_person === 1 ? "شخص حقوقی" : "شخص حقیقی"})}
/>
</Divider>
</Box>
<Formik
initialValues={initialValues}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
{(props) => (<Stack
spacing={2}
sx={{
p: 1, width: "100%",
}}
>
<StyledForm sx={{width: "100%"}}>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="national_id"
disabled={props.values.is_legal_person !== 1}
variant={props.values.is_legal_person !== 1 ? "standard" : "outlined"}
size="small"
label={t("ShowLoan.text_field_national_id")}
placeholder={t("ShowLoan.text_field_enter_your_national_id")}
type={'tel'}
error={!!(props.touched.national_id && props.errors.national_id)}
fullWidth
helperText={props.touched.national_id ? props.errors.national_id : null}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="name"
disabled
variant="standard"
size="small"
label={t("ShowLoan.text_field_name")}
placeholder={t("ShowLoan.text_field_enter_your_name")}
type={"text"}
error={!!(props.touched.name && props.errors.name)}
fullWidth
helperText={props.touched.name ? props.errors.name : null}
/>
</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={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="navgan_id"
disabled
variant="standard"
size="small"
label={t("ShowLoan.text_field_navgan_id")}
placeholder={t("ShowLoan.text_field_enter_your_navgan_id")}
type={'tel'}
error={!!(props.touched.navgan_id && props.errors.navgan_id)}
fullWidth
helperText={props.touched.navgan_id ? props.errors.navgan_id : null}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<SelectBox
name="navgan_type"
label={t("ShowLoan.text_field_navgan_type")}
size="small"
disabled
variant="standard"
selectType="navgan_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 1, value: "روستایی", name: "روستایی"
}, {
id: 2, value: "عمومی", name: "عمومی"
}, {
id: 3, value: "منطقه آزاد", name: "منطقه آزاد"
}]}
select={props.values.navgan_type}
handleChange={(event) => {
props.setFieldValue('navgan_type', event.target.value)
}}
setFieldTouched={props.setFieldTouched}
error={props.touched.navgan_type && Boolean(props.errors.navgan_type)}
helperText={props.touched.navgan_type && props.errors.navgan_type}
onBlur={props.handleBlur("navgan_type")}
/>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<PlateNumber formik={props} disabled={true}/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<SelectBox
name="vehicle_type"
label={t("ShowLoan.text_field_vehicle_type")}
size="small"
disabled
variant="standard"
selectType="vehicle_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 0, value: "اتوبوس", name: "اتوبوس"
}, {
id: 1, value: "مینی بوس", name: "مینی بوس"
}, {
id: 2, value: "سواری", name: "سواری"
}]}
select={props.values.vehicle_type}
handleChange={(event) => props.setFieldValue('vehicle_type', event.target.value)}
error={props.touched.vehicle_type && Boolean(props.errors.vehicle_type)}
helperText={props.touched.vehicle_type && props.errors.vehicle_type}
onBlur={props.handleBlur("vehicle_type")}
/>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<ToggleButtonGroup
color="primary"
fullWidth
size={'small'}
value={props.values.national_serial_number_or_tracking_code}
exclusive
onChange={(e, value) => {
if (value === null) return
props.handleChange({
target: {
name: "national_serial_number_or_tracking_code", value: value,
},
})
value === "serial_number" ? props.setFieldValue("national_tracking_code", props.initialValues.national_tracking_code, false) : props.setFieldValue("national_serial_number", props.initialValues.national_serial_number, false)
}}
>
<ToggleButton value="serial_number">
{t("ShowLoan.text_field_shenasname_serial")}
</ToggleButton>
<ToggleButton value="tracking_code">
{t("ShowLoan.text_field_national_trackin_code")}
</ToggleButton>
</ToggleButtonGroup>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
{props.values.national_serial_number_or_tracking_code === "serial_number" ? (<Field
as={TextField}
sx={{width: "100%"}}
name="national_serial_number"
size="small"
variant="outlined"
label={t("ShowLoan.text_field_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
helperText={props.touched.national_serial_number ? props.errors.national_serial_number : null}
/>) : (<Field
as={TextField}
sx={{width: "100%"}}
name="national_tracking_code"
size="small"
variant="outlined"
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}, my: 2, width: "100%",
}}
>
<MuiDatePicker
formik={props}
disableFuture={true}
error={props.touched.birthday && Boolean(props.errors.birthday)}
helperText={props.touched.birthday && props.errors.birthday}
onBlur={props.handleBlur("birthday")}
/>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<Field
as={TextField}
sx={{width: "100%"}}
name="postal_code"
variant="outlined"
size="small"
label={t("ShowLoan.text_field_postal_code")}
placeholder={t("ShowLoan.text_field_enter_your_postal_code")}
value={props.values.postal_code}
type={'tel'}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
props.handleChange({
target: {
name: "postal_code", value: inputValue,
},
});
}}
error={!!(props.touched.postal_code && props.errors.postal_code)}
fullWidth
helperText={props.touched.postal_code ? props.errors.postal_code : null}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
{provinceStates.provinceList.length !== 0 ? <SelectBox
name="province_id"
label={t("ShowLoan.text_field_province_id")}
size="small"
variant="standard"
disabled
selectType="province_id"
schema={{value: "value", name: "name"}}
isLoading={provinceStates.isLoadingProvinceList}
errorEcured={provinceStates.errorProvinceList}
selectors={provinceStates.provinceList}
select={props.values.province_id}
handleChange={(event) => {
props.setFieldValue('province_id', event.target.value);
citiesStates.setProvinceID(event.target.value)
props.setFieldTouched("city_id", false, false);
props.setFieldValue("city_id", "")
}}
setFieldTouched={props.setFieldTouched}
error={props.touched.province_id && Boolean(props.errors.province_id)}
helperText={props.touched.province_id && props.errors.province_id}
onBlur={props.handleBlur("province_id")}
/> : <Field
as={TextField}
sx={{width: "100%"}}
disabled
variant="standard"
size="small"
label={t("ShowLoan.text_field_province_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
{citiesStates.cityList.length !== 0 ? <SelectBox
name="city_id"
label={citiesStates.cityList.length === 0 ? `${t("ShowLoan.cityList_empty")}` : citiesStates.cityTextField}
size="small"
selectType="city_id"
// disabled={citiesStates.cityList.length === 0}
variant="standard"
disabled
selectors={citiesStates.cityList}
select={props.values.city_id}
schema={{value: "value", name: "name"}}
handleChange={(event) => props.setFieldValue('city_id', event.target.value)}
setFieldTouched={props.setFieldTouched}
error={props.touched.city_id && Boolean(props.errors.city_id)}
helperText={props.touched.city_id && props.errors.city_id}
onBlur={props.handleBlur("city_id")}
/> : <Field
as={TextField}
sx={{width: "100%"}}
disabled
variant="standard"
size="small"
label={t("ShowLoan.cityList_empty")}
value={t("text_field_loading")}
type={"text"}
/>}
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<TextField
sx={{width: "100%"}}
name="telephone_number"
size="small"
variant="outlined"
type={'tel'}
value={props.values.telephone_number}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
props.handleChange({
target: {
name: "telephone_number", value: inputValue,
},
});
}}
label={t("ShowLoan.text_field_tel_number")}
placeholder={t("ShowLoan.text_field_enter_your_tel_number")}
fullWidth
onBlur={props.handleBlur("telephone_number")}
error={props.touched.telephone_number && Boolean(props.errors.telephone_number)}
helperText={props.touched.telephone_number && props.errors.telephone_number}
/>
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
{educationStates.educationsList.length !== 0 ? <SelectBox
name="education_id"
label={t("ShowLoan.text_field_education_id")}
size="small"
variant="outlined"
isLoading={educationStates.isLoadingEducationsList}
errorEcured={educationStates.errorEducationsList}
selectType="education_id"
selectors={educationStates.educationsList}
select={props.values.education_id}
schema={{value: "id", name: "title"}}
handleChange={(event) => {
props.setFieldValue('education_id', event.target.value)
}}
setFieldTouched={props.setFieldTouched}
error={props.touched.education_id && Boolean(props.errors.education_id)}
helperText={props.touched.education_id && props.errors.education_id}
onBlur={props.handleBlur("education_id")}
/> : <Field
as={TextField}
sx={{width: "100%"}}
disabled
size="small"
label={t("ShowLoan.text_field_education_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Box>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
{occupationStates.occupationsList.length !== 0 ? <SelectBox
name="occupation_id"
label={t("ShowLoan.text_field_occupation_id")}
size="small"
variant="outlined"
isLoading={occupationStates.isLoadingOccupationsList}
errorEcured={occupationStates.errorOccupationsList}
selectType="occupation_id"
selectors={occupationStates.occupationsList}
select={props.values.occupation_id}
schema={{value: "id", name: "title"}}
handleChange={(event) => {
props.setFieldValue('occupation_id', event.target.value)
}}
setFieldTouched={props.setFieldTouched}
error={props.touched.occupation_id && Boolean(props.errors.occupation_id)}
helperText={props.touched.occupation_id && props.errors.occupation_id}
onBlur={props.handleBlur("occupation_id")}
/> : <Field
as={TextField}
sx={{width: "100%"}}
disabled
size="small"
label={t("ShowLoan.text_field_occupation_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "start",
justifyContent: "center",
width: "100%",
}}
>
<Box
sx={{
mx: {xs: 0, sm: 2}, my: 2, width: "100%",
}}
>
<Field
as={TextField}
multiline
rows={4}
sx={{width: "100%"}}
name="address"
variant="outlined"
size="small"
label={t("ShowLoan.text_field_address")}
placeholder={t("ShowLoan.text_field_enter_your_address")}
type={"text"}
error={!!(props.touched.address && props.errors.address)}
fullWidth
helperText={props.touched.address ? props.errors.address : null}
/>
</Box>
</Box>
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "center",
mx: "auto",
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>
</Box>
</StyledForm>
</Stack>)}
</Formik>
</>);
};
export default UpdateForm;

View File

@@ -0,0 +1,729 @@
import {Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
import {useFormik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import SelectBox from "@/core/components/SelectBox";
import PlateNumber from "@/core/components/PlateNumber";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import moment from "jalali-moment";
import useProvince from "@/lib/app/hooks/useProvince";
import useCities from "@/lib/app/hooks/useCities";
import UseEducations from "@/lib/app/hooks/useEducations";
import useOccupations from "@/lib/app/hooks/useOccupations";
import {UPDATE_LOAN} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useRouter} from "next/router";
import {useEffect} from "react";
import EditIcon from '@mui/icons-material/Edit';
import * as React from "react";
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
import LegalPersonDatePicker from "@/components/dashboard/navgan/add-request-loan/forms/LegalPersonDatePicker";
import useActivityType from "@/lib/app/hooks/useActivityType";
const UpdateFormLegal = ({LoanDetails, LoanId}) => {
const t = useTranslations();
const provinceStates = useProvince();
const router = useRouter()
const citiesStates = useCities();
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle();
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType();
const educationStates = UseEducations();
const occupationStates = useOccupations();
const requestServer = useRequest();
const initialValues = {
is_legal_person: 1,
national_serial_number_or_tracking_code: LoanDetails.national_serial_number ? "serial_number" : "tracking_code",
national_id: LoanDetails.national_id,
activity_type: LoanDetails.activity_type_id,
navgan_plan_id: LoanDetails.navgan_plan_id,
postal_code: LoanDetails.postal_code,
address: LoanDetails.address,
company_name: LoanDetails.company_name,
register_number: LoanDetails.register_number,
company_date: LoanDetails.company_register_date,
birthday: moment(LoanDetails.birthday),
navgan_id: LoanDetails.navgan_id,
province_id: LoanDetails.province_id,
city_id: LoanDetails.city_id,
boss_first_name: LoanDetails.first_name,
boss_last_name: LoanDetails.last_name,
boss_father_name: LoanDetails.father_name,
gender: LoanDetails.gender,
navgan_type: LoanDetails.navgan_type,
vehicle_type: LoanDetails.vehicle_type,
telephone_number: LoanDetails.telephone_number,
plate_part1: LoanDetails.plate_number.split("-")[0],
plate_part2: LoanDetails.plate_number.split("-")[1],
plate_part3: LoanDetails.plate_number.split("-")[2],
plate_part4: LoanDetails.plate_number.split("-")[3],
education_id: LoanDetails.education_id,
occupation_id: LoanDetails.occupation_id,
shenase_meli: LoanDetails.shenase_meli,
national_serial_number: LoanDetails.national_serial_number ?? "",
national_tracking_code: LoanDetails.national_tracking_code ?? ""
};
useEffect(() => {
citiesStates.setProvinceID(LoanDetails.province_id)
}, [LoanDetails.province_id]);
const validationSchema = Yup.object().shape({
postal_code: Yup.mixed()
.test("max", `${t("ShowLoan.postal_code_max")}`, (value) => value.toString().length === 10)
.required(t("ShowLoan.error_message_postal_code")),
address: Yup.string().required(t("ShowLoan.error_message_address")),
province_id: Yup.string().required(t("ShowLoan.error_message_province_id")),
activity_type: Yup.string().required(t("ShowLoan.error_message_activity_type")),
navgan_plan_id: Yup.string().required(t("ShowLoan.error_message_navgan_plan_id")),
city_id: Yup.string().required(t("ShowLoan.error_message_city_id")),
telephone_number: Yup.mixed()
.test("max", `${t("ShowLoan.tel_number_max")}`, (value) => {
const stringValue = String(value);
return stringValue.length === 11
})
.required(t("ShowLoan.error_message_tel_number")),
occupation_id: Yup.string().required(t("ShowLoan.error_message_occupation_id")),
company_date: Yup.string().required(t("ShowLoan.error_message_company_date")),
company_name: Yup.string().required(t("ShowLoan.error_message_company_name")),
register_number: Yup.string().required(t("ShowLoan.error_message_register_number")),
boss_first_name: Yup.string().required(t("ShowLoan.error_message_boss_first_name")),
boss_last_name: Yup.string().required(t("ShowLoan.error_message_boss_last_name")),
gender: Yup.string().required(t("ShowLoan.error_message_gender")),
boss_father_name: Yup.string().required(t("ShowLoan.error_message_boss_father_name")),
education_id: Yup.string().required(t("ShowLoan.error_message_education_id")),
birthday: Yup.string().required(t("ShowLoan.error_message_date_of_birth")),
national_id: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => {
return is_legal_person === 1 ? schema
.test("is-number", `${t("ShowLoan.national_code_number")}`, (value) => !isNaN(value))
.test("positive", `${t("ShowLoan.national_code_positive")}`, (value) => value >= 0)
.test("max", `${t("ShowLoan.national_code_max")}`, (value) => value && value.toString().length === 10)
.required(t("ShowLoan.error_message_national_id")) : schema;
}),
shenase_meli: Yup.mixed().when('is_legal_person', ([is_legal_person], schema) => {
return is_legal_person === 1 ? schema
.test("is-number", `${t("ShowLoan.national_number_number")}`, (value) => !isNaN(value))
.test("positive", `${t("ShowLoan.national_number_positive")}`, (value) => value >= 0)
.test("max", `${t("ShowLoan.national_number_max")}`, (value) => value && value.toString().length === 11)
.required(t("ShowLoan.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 === 'serial_number' ? schema.required(t("ShowLoan.error_message_shenasname_serial")) : schema
}),
national_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 === 'tracking_code' ? schema.required(t("ShowLoan.error_message_tracking_code")) : schema
})
});
const handleSubmit = async (values) => {
formik.setSubmitting(true)
const formData = new FormData();
if (values.national_serial_number_or_tracking_code === "serial_number") {
formData.append("national_serial_number", values.national_serial_number)
} else {
formData.append("national_tracking_code", values.national_tracking_code);
}
formData.append("national_id", values.national_id);
formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD"));
formData.append("postal_code", values.postal_code);
formData.append("navgan_plan_id", values.navgan_plan_id);
formData.append("activity_type", values.activity_type);
formData.append("boss_first_name", values.boss_first_name);
formData.append("boss_last_name", values.boss_last_name);
formData.append("boss_father_name", values.boss_father_name);
formData.append("gender", values.gender);
formData.append("province_id", LoanDetails.province_id);
formData.append("city_id", LoanDetails.city_id);
formData.append("telephone_number", values.telephone_number);
formData.append("education_id", values.education_id);
formData.append("occupation_id", values.occupation_id);
formData.append("address", values.address);
await requestServer(UPDATE_LOAN + LoanId, "post", {
auth: true, notification: true, data: formData
}).then(() => {
router.push("/dashboard/navgan/followUp-loan");
}).catch(() => {
}).finally(() => {
props.setSubmitting(false);
})
};
const formik = useFormik({
initialValues,
validationSchema,
onSubmit: handleSubmit,
});
console.log(formik.values.activity_type)
return (<>
<Box sx={{width: "80%", my: 2}}>
<Divider>
<Chip
label={
LoanDetails.state_id === 17 ?
t("ShowLoan.edit_loan_page", {person_type: "شخص حقوقی", id: LoanId}) :
t("ShowLoan.update_loan_page", {person_type: "شخص حقوقی", id: LoanId})
}
/>
</Divider>
</Box>
<Stack sx={{p: 1, width: "100%"}}>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="navgan_plan_id"
label={t("ShowLoan.text_field_navgan_plan_id")}
size="small"
selectType="navgan_plan_id"
value={formik.values.navgan_plan_id}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
selectors={projectTitle}
isLoading={isLoadingProjectTitle}
errorEcured={errorProjectTitle}
select={formik.values.navgan_plan_id}
schema={{value: "value", name: "name"}}
handleChange={formik.handleChange}
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("ShowLoan.text_field_activity_type")}
size="small"
selectType="activity_type"
isLoading={isLoadingActivityType}
errorEcured={errorActivityType}
disabled={LoanDetails.state_id !== 17}
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={{padding: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="boss_first_name"
variant="outlined"
size="small"
value={formik.values.boss_first_name}
label={t("ShowLoan.text_field_boss_first_name")}
disabled={LoanDetails.state_id !== 17}
fullWidth
onChange={formik.handleChange}
onBlur={formik.handleBlur("boss_first_name")}
error={!!(formik.touched.boss_first_name && formik.errors.boss_first_name)}
helperText={formik.touched.boss_first_name ? formik.errors.boss_first_name : null}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="boss_last_name"
variant="outlined"
size="small"
value={formik.values.boss_last_name}
label={t("ShowLoan.text_field_boss_last_name")}
disabled={LoanDetails.state_id !== 17}
fullWidth
onChange={formik.handleChange}
onBlur={formik.handleBlur("boss_last_name")}
error={!!(formik.touched.boss_last_name && formik.errors.boss_last_name)}
helperText={formik.touched.boss_last_name ? formik.errors.boss_last_name : null}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="company_name"
disabled={LoanDetails.state_id !== 17}
variant="outlined"
size="small"
value={formik.values.company_name}
label={t("ShowLoan.text_field_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"
disabled={LoanDetails.state_id !== 17}
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("ShowLoan.text_field_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 item xs={12} sm={4}>
<LegalPersonDatePicker
formik={formik}
disabled={LoanDetails.state_id !== 17}
error={formik.touched.company_date && Boolean(formik.errors.company_date)}
helperText={formik.touched.company_date && formik.errors.company_date}
onBlur={formik.handleBlur("company_date")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="national_id"
disabled={LoanDetails.state_id !== 17}
value={formik.values.national_id}
variant={"outlined"}
size="small"
label={t("ShowLoan.text_field_boss_national_id")}
type={'tel'}
error={!!(formik.touched.national_id && formik.errors.national_id)}
helperText={formik.touched.national_id ? formik.errors.national_id : null}
onChange={formik.handleChange}
fullWidth
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="boss_father_name"
value={formik.values.national_id}
disabled={LoanDetails.state_id !== 17}
variant={formik.values.is_legal_person !== 1 ? "standard" : "outlined"}
size="small"
label={t("ShowLoan.text_field_boss_father_name")}
type={'text'}
error={!!(formik.touched.boss_father_name && formik.errors.boss_father_name)}
onChange={formik.handleChange}
fullWidth
helperText={formik.touched.boss_father_name ? formik.errors.boss_father_name : null}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="gender"
label={t("ShowLoan.text_field_gender")}
size="small"
value={formik.values.gender}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
selectType="gender"
selectors={[
{
id: 1,
value: 1,
name: "زن",
},
{
id: 2,
value: 0,
name: "مرد",
},
]}
schema={{value: "value", name: "name"}}
select={formik.values.gender}
handleChange={formik.handleChange}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.gender && Boolean(formik.errors.gender)}
helperText={formik.touched.gender && formik.errors.gender}
onBlur={formik.handleBlur("gender")}
/>
</Grid>
{initialValues.is_legal_person === 1 && (
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="shenase_meli"
disabled
variant="outlined"
size="small"
label={t("ShowLoan.text_field_shenase_meli")}
type={"text"}
error={!!(formik.touched.shenase_meli && formik.errors.shenase_meli)}
fullWidth
helperText={formik.touched.shenase_meli ? formik.errors.shenase_meli : null}
onChange={formik.handleChange}
value={formik.values.shenase_meli}
/>
</Grid>
)}
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="navgan_id"
disabled
variant="outlined"
size="small"
label={t("ShowLoan.text_field_navgan_id")}
type={'tel'}
error={!!(formik.touched.navgan_id && formik.errors.navgan_id)}
fullWidth
helperText={formik.touched.navgan_id ? formik.errors.navgan_id : null}
onChange={formik.handleChange}
value={formik.values.shenase_meli}
/>
</Grid>
<Grid item xs={12} sm={6}>
<SelectBox
name="navgan_type"
label={t("ShowLoan.text_field_navgan_type")}
size="small"
disabled
variant="outlined"
selectType="navgan_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 1, value: "روستایی", name: "روستایی"
}, {
id: 2, value: "عمومی", name: "عمومی"
}, {
id: 3, value: "منطقه آزاد", name: "منطقه آزاد"
}]}
select={formik.values.navgan_type}
handleChange={(event) => {
formik.setFieldValue('navgan_type', event.target.value)
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)}
helperText={formik.touched.navgan_type && formik.errors.navgan_type}
onBlur={formik.handleBlur("navgan_type")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<PlateNumber formik={formik} disabled={true}/>
</Grid>
<Grid item xs={12} sm={6}>
<SelectBox
name="vehicle_type"
label={t("ShowLoan.text_field_vehicle_type")}
size="small"
disabled
variant="outlined"
selectType="vehicle_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 0, value: "اتوبوس", name: "اتوبوس"
}, {
id: 1, value: "مینی بوس", name: "مینی بوس"
}, {
id: 2, 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)}
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
onBlur={formik.handleBlur("vehicle_type")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 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,
},
})
value === "serial_number" ? formik.setFieldValue("national_tracking_code", formik.initialValues.national_tracking_code, false) : formik.setFieldValue("national_serial_number", formik.initialValues.national_serial_number, false)
}}
>
<ToggleButton value="serial_number">
{t("ShowLoan.text_field_shenasname_serial")}
</ToggleButton>
<ToggleButton value="tracking_code">
{t("ShowLoan.text_field_national_trackin_code")}
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item xs={12} sm={4}>
{formik.values.national_serial_number_or_tracking_code === "serial_number" ? (<TextField
sx={{width: "100%"}}
name="national_serial_number"
disabled={LoanDetails.state_id !== 17}
size="small"
variant="outlined"
label={t("ShowLoan.text_field_national_serial_number")}
placeholder={t("ShowLoan.text_field_enter_your_national_serial_number")}
type="text"
error={!!(formik.touched.national_serial_number && formik.errors.national_serial_number)}
fullWidth
helperText={formik.touched.national_serial_number ? formik.errors.national_serial_number : null}
onChange={formik.handleChange}
value={formik.values.shenase_meli}
/>) : (<TextField
sx={{width: "100%"}}
disabled={LoanDetails.state_id !== 17}
name="national_tracking_code"
size="small"
variant="outlined"
label={t("ShowLoan.text_field_national_tracking_code")}
placeholder={t("ShowLoan.text_field_enter_your_national_tracking_code")}
type="text"
error={!!(formik.touched.national_tracking_code && formik.errors.national_tracking_code)}
fullWidth
helperText={formik.touched.national_tracking_code ? formik.errors.national_tracking_code : null}
onChange={formik.handleChange}
value={formik.values.shenase_meli}
/>)}
</Grid>
<Grid item xs={12} sm={4}>
<MuiDatePicker
formik={formik}
disabled={LoanDetails.state_id !== 17}
disableFuture={true}
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={{p: 2}}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="postal_code"
disabled={LoanDetails.state_id !== 17}
variant="outlined"
size="small"
label={t("ShowLoan.text_field_postal_code")}
placeholder={t("ShowLoan.text_field_enter_your_postal_code")}
value={formik.values.postal_code}
type={'tel'}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
formik.handleChange({
target: {
name: "postal_code", value: inputValue,
},
});
}}
error={!!(formik.touched.postal_code && formik.errors.postal_code)}
fullWidth
helperText={formik.touched.postal_code ? formik.errors.postal_code : null}
/>
</Grid>
<Grid item xs={12} sm={4}>
<SelectBox
name="province_id"
label={t("ShowLoan.text_field_province_id")}
size="small"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
value={formik.values.province_id}
selectType="province_id"
schema={{value: "value", name: "name"}}
isLoading={provinceStates.isLoadingProvinceList}
errorEcured={provinceStates.errorProvinceList}
selectors={provinceStates.provinceList}
select={formik.values.province_id}
handleChange={(event) => {
formik.setFieldValue('province_id', event.target.value);
citiesStates.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={4}>
<SelectBox
name="city_id"
label={citiesStates.cityTextField}
size="small"
selectType="city_id"
value={formik.values.city_id}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
isLoading={citiesStates.isLoadingCityList}
selectors={citiesStates.cityList}
select={formik.values.city_id}
schema={{value: "value", name: "name"}}
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={{p: 2}}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="telephone_number"
size="small"
disabled={LoanDetails.state_id !== 17}
variant="outlined"
type={'tel'}
value={formik.values.telephone_number}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
formik.handleChange({
target: {
name: "telephone_number", value: inputValue,
},
});
}}
label={t("ShowLoan.text_field_tel_number")}
placeholder={t("ShowLoan.text_field_enter_your_tel_number")}
fullWidth
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 item xs={12} sm={4}>
<SelectBox
name="education_id"
label={t("ShowLoan.text_field_education_id")}
disabled={LoanDetails.state_id !== 17}
size="small"
variant="outlined"
isLoading={educationStates.isLoadingEducationsList}
errorEcured={educationStates.errorEducationsList}
selectType="education_id"
selectors={educationStates.educationsList}
select={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("ShowLoan.text_field_occupation_id")}
size="small"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
isLoading={occupationStates.isLoadingOccupationsList}
errorEcured={occupationStates.errorOccupationsList}
selectType="occupation_id"
selectors={occupationStates.occupationsList}
select={formik.values.occupation_id}
schema={{value: "id", name: "title"}}
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={12}>
<TextField
multiline
disabled={LoanDetails.state_id !== 17}
rows={4}
sx={{width: "100%"}}
name="address"
variant="outlined"
size="small"
label={t("ShowLoan.text_field_address")}
placeholder={t("ShowLoan.text_field_enter_your_address")}
type={"text"}
error={!!(formik.touched.address && formik.errors.address)}
fullWidth
helperText={formik.touched.address ? formik.errors.address : null}
onChange={formik.handleChange}
value={formik.values.address}
/>
</Grid>
</Grid>
{LoanDetails.state_id === 17 && (
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "center",
mx: "auto",
width: {xs: "100%", sm: "30%", md: "25%"},
}}
>
<Button
fullWidth
type="submit"
onClick={formik.handleSubmit}
variant="contained"
size="large"
sx={{mt: 2}}
endIcon={<EditIcon/>}
disabled={formik.isSubmitting || !formik.isValid}
>
{t("ShowLoan.button_submit")}
</Button>
</Box>
)}
</Stack>
</>);
};
export default UpdateFormLegal;

View File

@@ -0,0 +1,655 @@
import {Box, Button, Chip, Divider, Grid, Stack, TextField, ToggleButton, ToggleButtonGroup} from "@mui/material";
import {useFormik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
import SelectBox from "@/core/components/SelectBox";
import PlateNumber from "@/core/components/PlateNumber";
import MuiDatePicker from "@/core/components/MuiDatePicker";
import moment from "jalali-moment";
import useProvince from "@/lib/app/hooks/useProvince";
import useCities from "@/lib/app/hooks/useCities";
import UseEducations from "@/lib/app/hooks/useEducations";
import useOccupations from "@/lib/app/hooks/useOccupations";
import {UPDATE_LOAN} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useRouter} from "next/router";
import {useEffect} from "react";
import EditIcon from '@mui/icons-material/Edit';
import * as React from "react";
import useProjectTitle from "@/lib/app/hooks/useProjectTitle";
import useActivityType from "@/lib/app/hooks/useActivityType";
const UpdateFormReal = ({LoanDetails, LoanId}) => {
const t = useTranslations();
const provinceStates = useProvince();
const router = useRouter()
const citiesStates = useCities();
const {projectTitle, isLoadingProjectTitle, errorProjectTitle} = useProjectTitle();
const {activityType, isLoadingActivityType, errorActivityType} = useActivityType();
const educationStates = UseEducations();
const occupationStates = useOccupations();
const requestServer = useRequest();
const initialValues = {
national_serial_number_or_tracking_code: LoanDetails.national_serial_number ? "serial_number" : "tracking_code",
national_id: LoanDetails.national_id,
activity_type: LoanDetails.activity_type_id,
navgan_plan_id: LoanDetails.navgan_plan_id,
postal_code: LoanDetails.postal_code,
address: LoanDetails.address,
birthday: moment(LoanDetails.birthday),
navgan_id: LoanDetails.navgan_id,
province_id: LoanDetails.province_id,
city_id: LoanDetails.city_id,
first_name: LoanDetails.first_name,
last_name: LoanDetails.last_name,
father_name: LoanDetails.father_name,
gender: LoanDetails.gender,
occupation_id : LoanDetails.occupation_id,
navgan_type: LoanDetails.navgan_type,
vehicle_type: LoanDetails.vehicle_type,
telephone_number: LoanDetails.telephone_number,
plate_part1: LoanDetails.plate_number.split("-")[0],
plate_part2: LoanDetails.plate_number.split("-")[1],
plate_part3: LoanDetails.plate_number.split("-")[2],
plate_part4: LoanDetails.plate_number.split("-")[3],
education_id: LoanDetails.education_id,
national_serial_number: LoanDetails.national_serial_number ?? "",
national_tracking_code: LoanDetails.national_tracking_code ?? ""
};
useEffect(() => {
citiesStates.setProvinceID(LoanDetails.province_id)
}, [LoanDetails.province_id]);
const validationSchema = Yup.object().shape({
postal_code: Yup.mixed()
.test("max", `${t("ShowLoan.postal_code_max")}`, (value) => value.toString().length === 10)
.required(t("ShowLoan.error_message_postal_code")),
address: Yup.string().required(t("ShowLoan.error_message_address")),
province_id: Yup.string().required(t("ShowLoan.error_message_province_id")),
activity_type: Yup.string().required(t("ShowLoan.error_message_activity_type")),
navgan_plan_id: Yup.string().required(t("ShowLoan.error_message_navgan_plan_id")),
city_id: Yup.string().required(t("ShowLoan.error_message_city_id")),
telephone_number: Yup.mixed()
.test("max", `${t("ShowLoan.tel_number_max")}`, (value) => {
const stringValue = String(value);
return stringValue.length === 11
})
.required(t("ShowLoan.error_message_tel_number")),
occupation_id: Yup.string().required(t("ShowLoan.error_message_occupation_id")),
first_name: Yup.string().required(t("ShowLoan.error_message_first_name")),
last_name: Yup.string().required(t("ShowLoan.error_message_last_name")),
gender: Yup.string().required(t("ShowLoan.error_message_gender")),
father_name: Yup.string().required(t("ShowLoan.error_message_father_name")),
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().when('national_serial_number_or_tracking_code', ([national_serial_number_or_tracking_code], schema) => {
return national_serial_number_or_tracking_code === 'serial_number' ? schema.required(t("ShowLoan.error_message_shenasname_serial")) : schema
}),
national_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 === 'tracking_code' ? schema.required(t("ShowLoan.error_message_tracking_code")) : schema
})
});
const handleSubmit = async (values, props) => {
props.setSubmitting(true)
const formData = new FormData();
if (values.national_serial_number_or_tracking_code === "serial_number") {
formData.append("national_serial_number", values.national_serial_number)
} else {
formData.append("national_tracking_code", values.national_tracking_code);
}
formData.append("birthday", values.birthday.locale('en').format("YYYY-MM-DD"));
formData.append("postal_code", values.postal_code);
formData.append("navgan_plan_id", values.navgan_plan_id);
formData.append("activity_type", values.activity_type);
formData.append("first_name", values.first_name);
formData.append("last_name", values.last_name);
formData.append("father_name", values.father_name);
formData.append("gender", values.gender);
formData.append("province_id", LoanDetails.province_id);
formData.append("city_id", LoanDetails.city_id);
formData.append("telephone_number", values.telephone_number);
formData.append("education_id", values.education_id);
formData.append("occupation_id", values.occupation_id);
formData.append("address", values.address);
await requestServer(UPDATE_LOAN + LoanId, "post", {
auth: true, notification: true, data: formData
}).then(() => {
router.push("/dashboard/navgan/followUp-loan");
}).catch(() => {
}).finally(() => {
props.setSubmitting(false);
})
};
const formik = useFormik({
initialValues,
validationSchema,
onSubmit: handleSubmit,
});
return (<>
<Box sx={{width: "80%", my: 2}}>
<Divider>
<Chip
label={
LoanDetails.state_id === 17 ?
t("ShowLoan.edit_loan_page", {person_type: "شخص حقیقی", id: LoanId}) :
t("ShowLoan.update_loan_page", {person_type: "شخص حقیقی", id: LoanId})
}
/>
</Divider>
</Box>
<Stack sx={{p: 1, width: "100%"}}>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="activity_type"
label={t("ShowLoan.text_field_activity_type")}
size="small"
disabled={LoanDetails.state_id !== 17}
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 item xs={12} sm={6}>
<SelectBox
name="navgan_plan_id"
label={t("ShowLoan.text_field_navgan_plan_id")}
size="small"
selectType="navgan_plan_id"
value={formik.values.navgan_plan_id}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
selectors={projectTitle}
isLoading={isLoadingProjectTitle}
errorEcured={errorProjectTitle}
select={formik.values.navgan_plan_id}
schema={{value: "value", name: "name"}}
handleChange={formik.handleChange}
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>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="first_name"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
size="small"
value={formik.values.first_name}
label={t("ShowLoan.text_field_first_name")}
fullWidth
onChange={formik.handleChange}
onBlur={formik.handleBlur("first_name")}
error={!!(formik.touched.first_name && formik.errors.first_name)}
helperText={formik.touched.first_name ? formik.errors.first_name : null}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="last_name"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
size="small"
value={formik.values.last_name}
label={t("ShowLoan.text_field_last_name")}
fullWidth
onChange={formik.handleChange}
onBlur={formik.handleBlur("last_name")}
error={!!(formik.touched.last_name && formik.errors.last_name)}
helperText={formik.touched.last_name ? formik.errors.last_name : null}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="national_id"
disabled
variant={"outlined"}
size="small"
value={formik.values.national_id}
label={t("ShowLoan.text_field_national_id")}
type={'tel'}
error={!!(formik.touched.national_id && formik.errors.national_id)}
fullWidth
helperText={formik.touched.national_id ? formik.errors.national_id : null}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="father_name"
disabled={LoanDetails.state_id !== 17}
variant={"outlined"}
size="small"
value={formik.values.father_name}
label={t("ShowLoan.text_field_father_name")}
type={'text'}
error={!!(formik.touched.father_name && formik.errors.father_name)}
fullWidth
helperText={formik.touched.father_name ? formik.errors.father_name : null}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="gender"
label={t("ShowLoan.text_field_gender")}
size="small"
value={formik.values.gender}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
selectType="gender"
selectors={[
{
id: 1,
value: 1,
name: "زن",
},
{
id: 2,
value: 0,
name: "مرد",
},
]}
schema={{value: "value", name: "name"}}
select={formik.values.gender}
handleChange={formik.handleChange}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.gender && Boolean(formik.errors.gender)}
helperText={formik.touched.gender && formik.errors.gender}
onBlur={formik.handleBlur("gender")}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="postal_code"
disabled={LoanDetails.state_id !== 17}
variant="outlined"
size="small"
label={t("ShowLoan.text_field_postal_code")}
placeholder={t("ShowLoan.text_field_enter_your_postal_code")}
value={formik.values.postal_code}
type={'tel'}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
formik.handleChange({
target: {
name: "postal_code", value: inputValue,
},
});
}}
error={!!(formik.touched.postal_code && formik.errors.postal_code)}
fullWidth
helperText={formik.touched.postal_code ? formik.errors.postal_code : null}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
name="navgan_id"
disabled
variant="outlined"
value={formik.values.navgan_id}
size="small"
label={t("ShowLoan.text_field_navgan_id")}
placeholder={t("ShowLoan.text_field_enter_your_navgan_id")}
type={'tel'}
error={!!(formik.touched.navgan_id && formik.errors.navgan_id)}
fullWidth
helperText={formik.touched.navgan_id ? formik.errors.navgan_id : null}
/>
</Grid>
<Grid item xs={12} sm={6}>
<SelectBox
name="navgan_type"
label={t("ShowLoan.text_field_navgan_type")}
size="small"
disabled
variant="outlined"
selectType="navgan_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 1, value: "روستایی", name: "روستایی"
}, {
id: 2, value: "عمومی", name: "عمومی"
}, {
id: 3, value: "منطقه آزاد", name: "منطقه آزاد"
}]}
select={formik.values.navgan_type}
handleChange={(event) => {
formik.setFieldValue('navgan_type', event.target.value)
}}
setFieldTouched={formik.setFieldTouched}
error={formik.touched.navgan_type && Boolean(formik.errors.navgan_type)}
helperText={formik.touched.navgan_type && formik.errors.navgan_type}
onBlur={formik.handleBlur("navgan_type")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={6}>
<PlateNumber formik={formik} disabled={true}/>
</Grid>
<Grid item xs={12} sm={6}>
<SelectBox
name="vehicle_type"
label={t("ShowLoan.text_field_vehicle_type")}
size="small"
disabled
variant="outlined"
selectType="vehicle_type"
schema={{value: "value", name: "name"}}
selectors={[{
id: 0, value: "اتوبوس", name: "اتوبوس"
}, {
id: 1, value: "مینی بوس", name: "مینی بوس"
}, {
id: 2, 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)}
helperText={formik.touched.vehicle_type && formik.errors.vehicle_type}
onBlur={formik.handleBlur("vehicle_type")}
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 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,
},
})
value === "serial_number" ? formik.setFieldValue("national_tracking_code", formik.initialValues.national_tracking_code, false) : formik.setFieldValue("national_serial_number", formik.initialValues.national_serial_number, false)
}}
>
<ToggleButton value="serial_number">
{t("ShowLoan.text_field_shenasname_serial")}
</ToggleButton>
<ToggleButton value="tracking_code">
{t("ShowLoan.text_field_national_trackin_code")}
</ToggleButton>
</ToggleButtonGroup>
</Grid>
<Grid item xs={12} sm={4}>
{formik.values.national_serial_number_or_tracking_code === "serial_number" ? (<TextField
sx={{width: "100%"}}
name="national_serial_number"
disabled={LoanDetails.state_id !== 17}
size="small"
value={formik.values.national_serial_number}
variant="outlined"
label={t("ShowLoan.text_field_national_serial_number")}
placeholder={t("ShowLoan.text_field_enter_your_national_serial_number")}
type="text"
error={!!(formik.touched.national_serial_number && formik.errors.national_serial_number)}
fullWidth
helperText={formik.touched.national_serial_number ? formik.errors.national_serial_number : null}
/>) : (<TextField
sx={{width: "100%"}}
disabled={LoanDetails.state_id !== 17}
name="national_tracking_code"
size="small"
value={formik.values.national_tracking_code}
variant="outlined"
label={t("ShowLoan.text_field_national_tracking_code")}
placeholder={t("ShowLoan.text_field_enter_your_national_tracking_code")}
type="text"
error={!!(formik.touched.national_tracking_code && formik.errors.national_tracking_code)}
fullWidth
helperText={formik.touched.national_tracking_code ? formik.errors.national_tracking_code : null}
/>)}
</Grid>
<Grid item xs={12} sm={4}>
<MuiDatePicker
formik={formik}
disabled={LoanDetails.state_id !== 17}
disableFuture={true}
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={{p: 2}}>
<Grid item xs={12} sm={6}>
{provinceStates.provinceList.length !== 0 ? <SelectBox
name="province_id"
label={t("ShowLoan.text_field_province_id")}
size="small"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
value={formik.values.province_id}
selectType="province_id"
schema={{value: "value", name: "name"}}
isLoading={provinceStates.isLoadingProvinceList}
errorEcured={provinceStates.errorProvinceList}
selectors={provinceStates.provinceList}
select={formik.values.province_id}
handleChange={(event) => {
formik.setFieldValue('province_id', event.target.value);
citiesStates.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")}
/> : <TextField
sx={{width: "100%"}}
disabled
variant="outlined"
size="small"
label={t("ShowLoan.text_field_province_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Grid>
<Grid item xs={12} sm={6}>
{citiesStates.cityList.length !== 0 ? <SelectBox
name="city_id"
label={citiesStates.cityList.length === 0 ? `${t("ShowLoan.cityList_empty")}` : citiesStates.cityTextField}
size="small"
selectType="city_id"
value={formik.values.city_id}
disabled={LoanDetails.state_id !== 17}
variant="outlined"
selectors={citiesStates.cityList}
select={formik.values.city_id}
schema={{value: "value", name: "name"}}
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")}
/> : <TextField
sx={{width: "100%"}}
disabled
variant="outlined"
size="small"
label={t("ShowLoan.cityList_empty")}
value={t("text_field_loading")}
type={"text"}
/>}
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={4}>
<TextField
sx={{width: "100%"}}
name="telephone_number"
size="small"
disabled={LoanDetails.state_id !== 17}
variant="outlined"
type={'tel'}
value={formik.values.telephone_number}
onChange={(event) => {
const inputValue = event.target.value;
if (isNaN(Number(inputValue))) {
return;
}
formik.handleChange({
target: {
name: "telephone_number", value: inputValue,
},
});
}}
label={t("ShowLoan.text_field_tel_number")}
placeholder={t("ShowLoan.text_field_enter_your_tel_number")}
fullWidth
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 item xs={12} sm={4}>
{educationStates.educationsList.length !== 0 ? <SelectBox
name="education_id"
label={t("ShowLoan.text_field_education_id")}
disabled={LoanDetails.state_id !== 17}
size="small"
variant="outlined"
isLoading={educationStates.isLoadingEducationsList}
errorEcured={educationStates.errorEducationsList}
selectType="education_id"
selectors={educationStates.educationsList}
select={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")}
/> : <TextField
sx={{width: "100%"}}
disabled
size="small"
label={t("ShowLoan.text_field_education_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Grid>
<Grid item xs={12} sm={4}>
{occupationStates.occupationsList.length !== 0 ? <SelectBox
name="occupation_id"
label={t("ShowLoan.text_field_occupation_id")}
size="small"
variant="outlined"
disabled={LoanDetails.state_id !== 17}
isLoading={occupationStates.isLoadingOccupationsList}
errorEcured={occupationStates.errorOccupationsList}
selectType="occupation_id"
selectors={occupationStates.occupationsList}
select={formik.values.occupation_id}
schema={{value: "id", name: "title"}}
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")}
/> : <TextField
sx={{width: "100%"}}
disabled
size="small"
label={t("ShowLoan.text_field_occupation_id")}
value={t("text_field_loading")}
type={"text"}
/>}
</Grid>
</Grid>
<Grid container spacing={2} sx={{p: 2}}>
<Grid item xs={12} sm={12}>
<TextField
multiline
disabled={LoanDetails.state_id !== 17}
rows={4}
sx={{width: "100%"}}
name="address"
variant="outlined"
value={formik.values.address}
size="small"
label={t("ShowLoan.text_field_address")}
placeholder={t("ShowLoan.text_field_enter_your_address")}
type={"text"}
error={!!(formik.touched.address && formik.errors.address)}
fullWidth
helperText={formik.touched.address ? formik.errors.address : null}
/>
</Grid>
</Grid>
{LoanDetails.state_id === 17 && (
<Box
sx={{
display: "flex",
flexDirection: {xs: "column", sm: "row"},
alignItems: "center",
mx: "auto",
width: {xs: "100%", sm: "30%", md: "25%"},
}}
>
<Button
fullWidth
type="submit"
variant="contained"
size="large"
sx={{mt: 2}}
endIcon={<EditIcon/>}
disabled={formik.isSubmitting || !formik.isValid}
>
{t("ShowLoan.button_submit")}
</Button>
</Box>
)}
</Stack>
</>);
};
export default UpdateFormReal;

View File

@@ -1,10 +1,11 @@
import UpdateForm from "@/components/dashboard/navgan/show/form/UpdateForm";
import {useEffect, useState} from "react";
import {GET_LOAN_DETAILS} from "@/core/data/apiRoutes";
import {useRouter} from "next/router";
import {SvgLoading, useRequest} from "@witel/webapp-builder";
import {Stack, Typography} from "@mui/material";
import {useTranslations} from "next-intl";
import UpdateFormReal from "@/components/dashboard/navgan/show/form/UpdateFormReal";
import UpdateFormLegal from "@/components/dashboard/navgan/show/form/UpdateFormLegal";
const ShowLoanForm = () => {
const t = useTranslations();
@@ -26,16 +27,11 @@ const ShowLoanForm = () => {
<Typography>{t("ShowLoan.loading_show_component")}</Typography>
</Stack>
);
} else if (!(LoanDetails.state_id === 8 && LoanDetails.bank_status == 0)) {
return (
<Stack sx={{alignItems: "center", justifyContent: "center"}} spacing={3}>
<Typography>{t("ShowLoan.error_message_not_show_state")}</Typography>
</Stack>
);
}
return (
<UpdateForm LoanDetails={LoanDetails} LoanId={query.id}/>
);
return LoanDetails.is_legal_person === 1 ? (
<UpdateFormLegal LoanDetails={LoanDetails} LoanId={query.id}/>
) : (
<UpdateFormReal LoanDetails={LoanDetails} LoanId={query.id}/>
)
};
export default ShowLoanForm;
export default ShowLoanForm;

View File

@@ -31,8 +31,6 @@ const useCities = () => {
setCityTextField(t("text_field_error_fetching_cities"))
});
}, [provinceID])
return {cityTextField, cityList, setProvinceID, isLoadingCityList}
}
export default useCities