mohammad | working on plate component

This commit is contained in:
2023-12-13 15:52:41 +03:30
parent 7feec0d209
commit 4a54f3a8d2
3 changed files with 189 additions and 181 deletions

View File

@@ -1,7 +1,7 @@
import SelectBox from "@/core/components/SelectBox";
import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes";
import DataSaverOnIcon from "@mui/icons-material/DataSaverOn";
import {Box, Button, FormControl, Grid, Stack, TextField} from "@mui/material";
import {Box, Button, Grid, TextField} from "@mui/material";
import {useFormik} from "formik";
import {useTranslations} from "next-intl";
import * as Yup from "yup";
@@ -14,8 +14,8 @@ const AddFormComponent = () => {
const t = useTranslations();
const {token} = useUser();
const requestServer = useRequest()
const{provinceList, isLoadingProvinceList, errorProvinceList} = useProvince()
const{cityTextField, cityList, setProvinceID}=useCities()
const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince()
const {cityTextField, cityList, setProvinceID} = useCities()
const initialValues = {
tel_number: "",
@@ -28,10 +28,10 @@ const AddFormComponent = () => {
shenasname_id: "",
postal_code: "",
navgan_type: "",
plate_part1 : "",
plate_part2 : "",
plate_part3 : "",
plate_part4 : "",
plate_part1: "",
plate_part2: "",
plate_part3: "",
plate_part4: "",
};
const validationSchema = Yup.object().shape({
@@ -44,36 +44,17 @@ const AddFormComponent = () => {
navgan_type: Yup.string().required(
t("LoanRequest.error_message_navgan_type")
),
postal_code : Yup.mixed()
postal_code: Yup.mixed()
.test("max", `${t("LoanRequest.postal_code_max")}`, (value) => value.toString().length === 10)
.required(
t("LoanRequest.error_message_postal_code")
),
plate_part1: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part1_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part1")
),
plate_part2: Yup.mixed()
.required(
t("LoanRequest.error_message_plate_part2")
),
plate_part3: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part3")
),
plate_part4: Yup.mixed()
.test("max", `${t("LoanRequest.plate_part3_max")}`, (value) => value.toString().length === 2)
.required(
t("LoanRequest.error_message_plate_part3")
),
navgan_id: Yup.mixed().required(t("LoanRequest.error_message_navgan_id")),
province_id: Yup.string().required(t("LoanRequest.error_message_province_id")),
city_id: Yup.string().required(t("LoanRequest.error_message_city_id")),
national_code: Yup.mixed()
.test("is-number", `${t("LoanRequest.national_code_number")}`,
(value) => !isNaN(value))
(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")),
@@ -96,7 +77,7 @@ const AddFormComponent = () => {
formData.append("national_code", values.national_code);
formData.append("shenasname_id", values.shenasname_id);
requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {auth : true, notification : true}).then().catch(() => {
requestServer(SEND_LOAN_REQUEST_NAVGAN, "post", {auth: true, notification: true}).then().catch(() => {
props.setSubmitting(false)
})
};
@@ -106,7 +87,7 @@ const AddFormComponent = () => {
})
return (
<>
<Grid container spacing={2} sx={{padding : 2}}
<Grid container spacing={2} sx={{padding: 2}}
>
<Grid item xs={12} sm={6}
>
@@ -147,15 +128,15 @@ const AddFormComponent = () => {
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding : 2}}>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="vehicle_type"
label={t("LoanRequest.text_field_vehicle_type")}
size="small"
selectType="vehicle_type"
selectors={[{id : 0, value : 0, name : "اتوبوس"},
{id : 1, value: 1, name : "مینی بوس"}]}
selectors={[{id: 0, value: 0, name: "اتوبوس"},
{id: 1, value: 1, name: "مینی بوس"}]}
select={formik.values.vehicle_type}
setFieldValue={formik.setFieldValue}
error={formik.touched.vehicle_type && Boolean(formik.errors.vehicle_type)}
@@ -203,9 +184,15 @@ const AddFormComponent = () => {
label={t("LoanRequest.text_field_navgan_type")}
size="small"
selectType="navgan_type"
selectors={[{id : 1, value : 1, name : "مسافری"},{id : 2, value : 2, name : "عمومی"},{id : 3, value : 3, name : "روستایی"}]}
selectors={[{id: 1, value: 1, name: "مسافری"}, {id: 2, value: 2, name: "عمومی"}, {
id: 3,
value: 3,
name: "روستایی"
}]}
select={formik.values.navgan_type}
handleChange={(event)=> {formik.setFieldValue('navgan_type', event.target.value)}}
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}
@@ -213,7 +200,7 @@ const AddFormComponent = () => {
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding : 2}}>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<SelectBox
name="province_id"
@@ -224,7 +211,9 @@ const AddFormComponent = () => {
errorEcured={errorProvinceList}
selectors={provinceList}
select={formik.values.province_id}
handleChange={(event)=> {formik.setFieldValue('province_id', event.target.value); setProvinceID(event.target.value)
handleChange={(event) => {
formik.setFieldValue('province_id', event.target.value);
setProvinceID(event.target.value)
formik.setFieldTouched("city_id", false, false);
formik.setFieldValue("city_id", "")
}}
@@ -243,7 +232,7 @@ const AddFormComponent = () => {
disabled={cityList.length === 0}
selectors={cityList}
select={formik.values.city_id}
handleChange={(event)=>formik.setFieldValue('city_id', event.target.value)}
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}
@@ -251,7 +240,7 @@ const AddFormComponent = () => {
/>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding : 2}}>
<Grid container spacing={2} sx={{padding: 2}}>
<Grid item xs={12} sm={6}>
<TextField
sx={{width: "100%"}}
@@ -268,11 +257,7 @@ const AddFormComponent = () => {
/>
</Grid>
<Grid item xs={12} sm={6}>
</Grid>
</Grid>
<Grid container spacing={2} sx={{padding : 2}}>
<Grid item xs={12}>
<PlateNumber formik={formik} />
<PlateNumber formik={formik}/>
</Grid>
</Grid>
<Box