diff --git a/public/config.json.example b/public/config.json.example index fc45751..ac50d76 100644 --- a/public/config.json.example +++ b/public/config.json.example @@ -6,6 +6,10 @@ "message": "ثبت نام به زودی آغاز خواهد شد." } }, + "add_request_loan_birthday_range": { + "min": 1327, + "max": 1380 + }, "deadlines": { "register": { "date": { diff --git a/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx index 3392286..e58f890 100644 --- a/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx +++ b/src/components/dashboard/navgan/add-request-loan/forms/AddForm.jsx @@ -16,7 +16,6 @@ import DoneIcon from '@mui/icons-material/Done'; import {NextLinkComposed} from "@witel/webapp-builder/dist/utils/linkRouting"; import SvgDone from "@/core/components/svgs/SvgDone"; import {SEND_LOAN_REQUEST_NAVGAN} from "@/core/data/apiRoutes"; -import moment from "jalali-moment"; const AddFormComponent = () => { const t = useTranslations(); @@ -29,24 +28,24 @@ const AddFormComponent = () => { const {occupationsList, isLoadingOccupationsList, errorOccupationsList} = useOccupations() const initialValues = { - telephone_number: "", - vehicle_type: "", - province_id: "", - city_id: "", - navgan_id: "", - national_id: "", - national_serial_number: "", - postal_code: "", - navgan_type: "", - plate_part1: "", - plate_part2: "الف", - plate_part3: "", - plate_part4: "", - address: "", - birthday: moment(), - education_id: "", - occupation_id: "", - checkedBox: false + telephone_number: "", + vehicle_type: "", + province_id: "", + city_id: "", + navgan_id: "", + national_id: "", + national_serial_number: "", + postal_code: "", + navgan_type: "", + plate_part1: "", + plate_part2: "الف", + plate_part3: "", + plate_part4: "", + address: "", + birthday: "", + education_id: "", + occupation_id: "", + checkedBox: false, }; const validationSchema = Yup.object().shape({ @@ -402,11 +401,6 @@ const AddFormComponent = () => { id: 1, value: "مینی بوس", name: "مینی بوس" - }, - { - id: 2, - value: "سواری", - name: "سواری" } ]} select={formik.values.vehicle_type} diff --git a/src/core/components/MuiDatePicker.jsx b/src/core/components/MuiDatePicker.jsx index 7a01da3..bf2c947 100644 --- a/src/core/components/MuiDatePicker.jsx +++ b/src/core/components/MuiDatePicker.jsx @@ -1,97 +1,119 @@ -import * as React from 'react'; -import {useState} from 'react'; -import Button from '@mui/material/Button'; -import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali"; -import {LocalizationProvider} from '@mui/x-date-pickers/LocalizationProvider'; -import {DatePicker} from '@mui/x-date-pickers/DatePicker'; -import {faIR} from "@mui/x-date-pickers/locales"; -import {useTranslations} from "next-intl"; +import * as React from "react"; +import { useMemo, useState } from "react"; +import Button from "@mui/material/Button"; +import { AdapterDateFnsJalali } from "@mui/x-date-pickers/AdapterDateFnsJalali"; +import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; +import { DatePicker } from "@mui/x-date-pickers/DatePicker"; +import { faIR } from "@mui/x-date-pickers/locales"; +import { useTranslations } from "next-intl"; import moment from "jalali-moment"; -import {FormControl, FormHelperText} from "@mui/material"; +import { FormControl, FormHelperText } from "@mui/material"; +import { useConfig } from "@witel/webapp-builder"; function ButtonField(props) { - const t = useTranslations(); - const { - setOpen, - label, - id, - disabled, - InputProps: {ref} = {}, - inputProps: {'aria-label': ariaLabel} = {}, - } = props; + const t = useTranslations(); + const { + setOpen, + label, + id, + disabled, + InputProps: { ref } = {}, + inputProps: { "aria-label": ariaLabel } = {}, + } = props; - return ( - - ); + return ( + + ); } function ButtonDatePicker(props) { - const t = useTranslations(); - const [open, setOpen] = useState(false); + const { config } = useConfig(); + const t = useTranslations(); + const [open, setOpen] = useState(false); + const dateRange = useMemo(() => { + const today = moment(); + const min = moment( + `${config.add_request_loan_birthday_range.min}-01-01`, + "jYYYY-jMM-jDD" + ).toDate(); + const max = moment( + `${config.add_request_loan_birthday_range.max}-${today.format( + "jMM-jDD" + )}`, + "jYYYY-jMM-jDD" + ).toDate(); + return { min, max }; + }, [config.add_request_loan_birthday_range]); - return ( - setOpen(false)} - onOpen={() => setOpen(true)} - /> - ); + return ( + setOpen(false)} + onOpen={() => setOpen(true)} + /> + ); } -export default function PickerWithButtonField({formik, disabled}) { - return ( - - - { - formik.setFieldValue("birthday", moment(newValue)) - }} - - /> - - {formik.touched.birthday && formik.errors.birthday} - - ); +export default function PickerWithButtonField({ formik, disabled }) { + return ( + + + { + formik.setFieldValue("birthday", moment(newValue)); + }} + /> + + + {formik.touched.birthday && formik.errors.birthday} + + + ); } \ No newline at end of file