From b7181ab764d2b39bace55830d3dc9303ad759e2f Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Tue, 2 Jan 2024 15:43:10 +0330 Subject: [PATCH 1/3] add new inputs and disable all item and stop ability of updating(just show data) --- .../dashboard/navgan/show/form/UpdateForm.jsx | 83 +++++++++++++------ src/core/components/SelectBox.jsx | 2 +- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/components/dashboard/navgan/show/form/UpdateForm.jsx b/src/components/dashboard/navgan/show/form/UpdateForm.jsx index 871c9a2..8be307a 100644 --- a/src/components/dashboard/navgan/show/form/UpdateForm.jsx +++ b/src/components/dashboard/navgan/show/form/UpdateForm.jsx @@ -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,19 @@ const UpdateForm = ({LoanDetails, LoanId}) => { const occupationStates = useOccupations(); const requestServer = useRequest(); + let _national_number = 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 = { 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 +52,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, ..._national_number, }; // end initial values @@ -72,8 +79,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")), + // national_number: Yup.mixed().when('person_type', ([person_type], schema) => { + // return person_type === 'legal' ? 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 @@ -347,6 +370,8 @@ 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" @@ -370,6 +395,7 @@ 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 +465,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 +486,6 @@ 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 +521,6 @@ const UpdateForm = ({LoanDetails, LoanId}) => { /> : { { @@ -557,6 +587,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 +605,6 @@ 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 +642,6 @@ 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 +693,17 @@ const UpdateForm = ({LoanDetails, LoanId}) => { width: {xs: "100%", sm: "30%", md: "25%"}, }} > - + {/*}*/} + {/* disabled={props.isSubmitting || !props.dirty || !props.isValid}*/} + {/*>*/} + {/* {t("ShowLoan.button_submit")}*/} + {/**/} diff --git a/src/core/components/SelectBox.jsx b/src/core/components/SelectBox.jsx index 6fc787c..e9fb2e0 100644 --- a/src/core/components/SelectBox.jsx +++ b/src/core/components/SelectBox.jsx @@ -21,8 +21,8 @@ function SelectBox({ return ( From 2ee13f0131fdd24b9ac5c3381683b505c3869d84 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Sat, 6 Jan 2024 15:25:18 +0330 Subject: [PATCH 2/3] complete show part and disabled update for while --- public/locales/fa/app.json | 4 + .../dashboard/navgan/show/form/UpdateForm.jsx | 156 ++++++++++++------ 2 files changed, 112 insertions(+), 48 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 119b0b0..1d5d12e 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -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": "لطفا سریال پشت کارت ملی را وارد کنید!", diff --git a/src/components/dashboard/navgan/show/form/UpdateForm.jsx b/src/components/dashboard/navgan/show/form/UpdateForm.jsx index 8be307a..edddcc1 100644 --- a/src/components/dashboard/navgan/show/form/UpdateForm.jsx +++ b/src/components/dashboard/navgan/show/form/UpdateForm.jsx @@ -25,7 +25,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => { const occupationStates = useOccupations(); const requestServer = useRequest(); - let _national_number = LoanDetails.is_legal_person === 1 ? { + let _shenase_meli = LoanDetails.is_legal_person === 1 ? { shenase_meli: LoanDetails.shenase_meli } : {} @@ -36,6 +36,7 @@ const UpdateForm = ({LoanDetails, LoanId}) => { } // initial values const initialValues = { + is_legal_person: LoanDetails.is_legal_person, national_id: LoanDetails.national_id, postal_code: LoanDetails.postal_code, address: LoanDetails.address, @@ -52,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, ..._national_card, ..._national_number, + occupation_id: LoanDetails.occupation_id, ..._national_card, ..._shenase_meli, }; // end initial values @@ -79,24 +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_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")), - // national_number: Yup.mixed().when('person_type', ([person_type], schema) => { - // return person_type === 'legal' ? 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 - // }) + 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 @@ -208,6 +209,36 @@ const UpdateForm = ({LoanDetails, LoanId}) => { } /> + { + initialValues.is_legal_person === 1 && ( + + + + ) + } { width: "100%", }} > - - - + { + initialValues.national_serial_number ? ( + + + + ) : ( + + + + ) + } Date: Sat, 6 Jan 2024 15:27:21 +0330 Subject: [PATCH 3/3] edit fa of national tracking code --- public/locales/fa/app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 1d5d12e..5c4d71d 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -238,7 +238,7 @@ "text_field_navgan_id": "کد ناوگان", "text_field_province_id": "استان", "text_field_education_id": "تحصیلات", - "text_field_national_tracking_code": "کد رهگیری", + "text_field_national_tracking_code": "کد رهگیری کارت ملی", "text_field_occupation_id": "شغل", "text_field_name": "نام کامل مالک", "text_field_navgan_type": "نوع ناوگان", @@ -254,7 +254,7 @@ "text_field_enter_your_navgan_id": "کد ناوگان را وارد کنید", "text_field_enter_your_name": "نام کامل مالک را وارد کنید", "text_field_enter_your_shenase_meli": "شناسه ملی را وارد کنید", - "text_field_enter_your_national_tracking_code": "کد رهگیری را وارد کنید", + "text_field_enter_your_national_tracking_code": "کد رهگیری کارت ملی را وارد کنید", "postal_code_max": "کد پستی می بایست 10 رقم باشد", "error_message_postal_code": "لطفا کد پستی را وارد کنید!", "error_message_national_serial_number": "لطفا سریال پشت کارت ملی را وارد کنید!",