Merge branch 'main' into 'develop'
Amiriis - fixed bug navgan add request loan See merge request witel-front-end/loan-facilities/user!47
This commit is contained in:
@@ -6,6 +6,10 @@
|
||||
"message": "ثبت نام به زودی آغاز خواهد شد."
|
||||
}
|
||||
},
|
||||
"add_request_loan_birthday_range": {
|
||||
"min": 1327,
|
||||
"max": 1380
|
||||
},
|
||||
"deadlines": {
|
||||
"register": {
|
||||
"date": {
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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 (
|
||||
<Button
|
||||
sx={{width: "100%", padding: 0.8}}
|
||||
variant="outlined"
|
||||
color={props.slotProps.formik.touched.birthday && Boolean(props.slotProps.formik.errors.birthday) ? "error" : "primary"}
|
||||
id={id}
|
||||
disabled={disabled}
|
||||
ref={ref}
|
||||
aria-label={ariaLabel}
|
||||
onClick={() => setOpen?.((prev) => !prev)}
|
||||
>
|
||||
{label ? `${t("birthday")}: ${label}` : `${t("birthday")}`}
|
||||
</Button>
|
||||
);
|
||||
return (
|
||||
<Button
|
||||
sx={{ width: "100%", padding: 0.8 }}
|
||||
variant="outlined"
|
||||
color={
|
||||
props.slotProps.formik.touched.birthday &&
|
||||
Boolean(props.slotProps.formik.errors.birthday)
|
||||
? "error"
|
||||
: "primary"
|
||||
}
|
||||
id={id}
|
||||
disabled={disabled}
|
||||
ref={ref}
|
||||
aria-label={ariaLabel}
|
||||
onClick={() => setOpen?.((prev) => !prev)}
|
||||
>
|
||||
{label ? `${t("birthday")}: ${label}` : `${t("birthday")}`}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<DatePicker
|
||||
slots={{field: ButtonField, ...props.slots}}
|
||||
disableFuture
|
||||
disabled={props.disabled}
|
||||
slotProps={{
|
||||
formik: props.formik,
|
||||
field: {setOpen},
|
||||
textField: {
|
||||
helperText: props.formik.errors.birthday ? `${t("birthday_error")}` : null
|
||||
}
|
||||
}}
|
||||
{...props}
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
onOpen={() => setOpen(true)}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<DatePicker
|
||||
slots={{ field: ButtonField, ...props.slots }}
|
||||
disabled={props.disabled}
|
||||
slotProps={{
|
||||
formik: props.formik,
|
||||
field: { setOpen },
|
||||
textField: {
|
||||
helperText: props.formik.errors.birthday
|
||||
? `${t("birthday_error")}`
|
||||
: null,
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
open={open}
|
||||
minDate={dateRange.min}
|
||||
maxDate={dateRange.max}
|
||||
onClose={() => setOpen(false)}
|
||||
onOpen={() => setOpen(true)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PickerWithButtonField({formik, disabled}) {
|
||||
return (
|
||||
<FormControl
|
||||
variant={"outlined"}
|
||||
fullWidth
|
||||
size="small"
|
||||
error={true}
|
||||
>
|
||||
<LocalizationProvider
|
||||
dateAdapter={AdapterDateFnsJalali}
|
||||
localeText={
|
||||
{
|
||||
...faIR.components.MuiLocalizationProvider.defaultProps
|
||||
.localeText,
|
||||
okButtonLabel: 'تایید'
|
||||
}
|
||||
}
|
||||
>
|
||||
<ButtonDatePicker
|
||||
label={formik.values.birthday
|
||||
.locale("fa")
|
||||
.format("YYYY/MM/DD")}
|
||||
value={formik.values.birthday.toDate()}
|
||||
formik={formik}
|
||||
disabled={disabled}
|
||||
onChange={(newValue) => {
|
||||
formik.setFieldValue("birthday", moment(newValue))
|
||||
}}
|
||||
|
||||
/>
|
||||
</LocalizationProvider>
|
||||
<FormHelperText>{formik.touched.birthday && formik.errors.birthday}</FormHelperText>
|
||||
</FormControl>
|
||||
);
|
||||
export default function PickerWithButtonField({ formik, disabled }) {
|
||||
return (
|
||||
<FormControl variant={"outlined"} fullWidth size="small" error={true}>
|
||||
<LocalizationProvider
|
||||
dateAdapter={AdapterDateFnsJalali}
|
||||
localeText={{
|
||||
...faIR.components.MuiLocalizationProvider.defaultProps.localeText,
|
||||
okButtonLabel: "تایید",
|
||||
}}
|
||||
>
|
||||
<ButtonDatePicker
|
||||
label={
|
||||
formik.values.birthday !== "" &&
|
||||
formik.values.birthday.locale("fa").format("YYYY/MM/DD")
|
||||
}
|
||||
value={
|
||||
formik.values.birthday !== ""
|
||||
? formik.values.birthday.toDate()
|
||||
: null
|
||||
}
|
||||
formik={formik}
|
||||
disabled={disabled}
|
||||
onChange={(newValue) => {
|
||||
formik.setFieldValue("birthday", moment(newValue));
|
||||
}}
|
||||
/>
|
||||
</LocalizationProvider>
|
||||
<FormHelperText>
|
||||
{formik.touched.birthday && formik.errors.birthday}
|
||||
</FormHelperText>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user