From 734bb153a0bfaea57627d950df794cffa9f1ec19 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Tue, 7 Nov 2023 17:36:05 +0330 Subject: [PATCH] LFFE-10 complete sending data part from filters to main page of it and start to sending request and showing witch items are filtering after this --- public/locales/fa/app.json | 3 + .../reports/Filter/ProvinceFilter.jsx | 55 ++++++ .../dashboard/reports/Filter/YearFilter.jsx | 47 +++++ .../dashboard/reports/Filter/index.jsx | 174 ++++++------------ .../reports/LoanDistribution/index.jsx | 18 +- .../dashboard/reports/LoanProgress/index.jsx | 11 +- 6 files changed, 185 insertions(+), 123 deletions(-) create mode 100644 src/components/dashboard/reports/Filter/ProvinceFilter.jsx create mode 100644 src/components/dashboard/reports/Filter/YearFilter.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index adbf89a..07463ed 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -471,5 +471,8 @@ "button-add": "ثبت" }, "reports": { + "loan_progress": "درصد پیشرفت تسویه وام", + "loan_distribution": "درصد توضیع وام ها در هر مرحله", + "filter_as": "فیلتر های اعمال شده" } } diff --git a/src/components/dashboard/reports/Filter/ProvinceFilter.jsx b/src/components/dashboard/reports/Filter/ProvinceFilter.jsx new file mode 100644 index 0000000..ead52f2 --- /dev/null +++ b/src/components/dashboard/reports/Filter/ProvinceFilter.jsx @@ -0,0 +1,55 @@ +import {Box, Chip, FormControl, InputLabel, MenuItem, OutlinedInput, Select} from "@mui/material"; + +const provinceList = [ + {name: "قزوین", id: 1}, + {name: "تبریز", id: 2}, + {name: "مشهد", id: 3} +] + +const ProvinceFilter = ({formik, multiple}) => { + const provinceChange = (event) => { + const {target: {value}} = event; + formik.handleChange(event); + formik.setFieldValue('province_id', value); + }; + return ( + + انتخاب استان + + + ) +}; + +export default ProvinceFilter; \ No newline at end of file diff --git a/src/components/dashboard/reports/Filter/YearFilter.jsx b/src/components/dashboard/reports/Filter/YearFilter.jsx new file mode 100644 index 0000000..c96d704 --- /dev/null +++ b/src/components/dashboard/reports/Filter/YearFilter.jsx @@ -0,0 +1,47 @@ +import {Box, Chip, FormControl, InputLabel, MenuItem, OutlinedInput, Select} from "@mui/material"; +import moment from "jalali-moment"; + +const currentShamsiYear = moment().format('jYYYY'); +const shamsiYearList = Array.from({length: currentShamsiYear - 1399}, (_, index) => (currentShamsiYear - index).toString()); + +const YearFilter = ({formik, multiple}) => { + const yearChange = (event) => { + const {target: {value}} = event; + formik.handleChange(event); + formik.setFieldValue('date', value); + }; + return ( + + انتخاب سال + + + ) +}; + +export default YearFilter; \ No newline at end of file diff --git a/src/components/dashboard/reports/Filter/index.jsx b/src/components/dashboard/reports/Filter/index.jsx index 3c8ec43..43b63bd 100644 --- a/src/components/dashboard/reports/Filter/index.jsx +++ b/src/components/dashboard/reports/Filter/index.jsx @@ -1,135 +1,79 @@ -import { - Accordion, - AccordionDetails, - AccordionSummary, - Box, - Button, - Chip, - FormControl, - InputLabel, - MenuItem, - OutlinedInput, - Select, - Stack, - Typography -} from "@mui/material"; +import {Accordion, AccordionDetails, AccordionSummary, Box, Button, Stack, Typography} from "@mui/material"; import {useFormik} from "formik"; -import {useState} from "react"; -import QueryStatsIcon from '@mui/icons-material/QueryStats'; +import ProvinceFilter from "./ProvinceFilter"; +import YearFilter from "./YearFilter"; +import FilterAltIcon from '@mui/icons-material/FilterAlt'; +import {useTranslations} from "next-intl"; +import TroubleshootIcon from '@mui/icons-material/Troubleshoot'; +import moment from "jalali-moment"; -const provinceList = [ - 'قزوین', - 'تبریز', - 'مشهد', -]; -const yearList = [ - '1401', - '1402', - '1403', -] +const periodOfYear = (year) => { + const isLeapYear = moment.jIsLeapYear(year); + const firstDayGeorgian = moment.from(`${year}/01/01`, 'fa').format('YYYY-MM-DD'); + const lastDayGeorgian = moment.from(`${year}/12/${isLeapYear ? '30' : '29'}`, 'fa').format('YYYY-MM-DD'); + return { + from: firstDayGeorgian, + to: lastDayGeorgian + } +} + +const Filter = ({title, filterItem, expanded}) => { + const t = useTranslations(); + + const filter_by_province = filterItem.find((item) => item.type === "province"); + const filter_by_year = filterItem.find((item) => item.type === "year"); -const Filter = ({title}) => { - const [province, setProvince] = useState([]); - const [year, setYear] = useState([]); - const provinceChange = (event) => { - const { - target: {value}, - } = event; - setProvince(typeof value === 'string' ? value.split(',') : value); - }; - const yearChange = (event) => { - const { - target: {value}, - } = event; - setYear(typeof value === 'string' ? value.split(',') : value); - }; const formik = useFormik({ initialValues: { - date: "", - province_id: "", + ...(filter_by_year && { + date: filter_by_year.multiple ? [] : "" + }), + ...(filter_by_province && { + province_id: filter_by_province.multiple ? [] : "" + }) }, onSubmit: (values, {setSubmitting}) => { - const formData = new FormData(); - formData.append("date", values.date); - formData.append("province_id", values.province_id); - + const dates = values.date + dates.map((date) => { + periodOfYear(date); + }) + console.log("val", values); }, }); - return ( - - - - {title} - - - + + + + {title} + + | {t("reports.filter_as")} : + + + - - - - انتخاب استان - - - - انتخاب سال - - + + + {filter_by_province ? + : "" + } + {filter_by_year ? + : "" + } + + + + ) }; diff --git a/src/components/dashboard/reports/LoanDistribution/index.jsx b/src/components/dashboard/reports/LoanDistribution/index.jsx index f90529a..2e67323 100644 --- a/src/components/dashboard/reports/LoanDistribution/index.jsx +++ b/src/components/dashboard/reports/LoanDistribution/index.jsx @@ -1,6 +1,8 @@ -import {Chip, Divider, Grid, Paper} from "@mui/material"; +import {Grid, Paper} from "@mui/material"; import PolarChart from "./PolarChart"; import Pie from "./PieChart"; +import {useTranslations} from "next-intl"; +import Filter from "@/components/dashboard/reports/Filter"; const fakeData = [ {name: "آذربایجان شرقی", data: 0}, @@ -36,12 +38,16 @@ const fakeData = [ {name: "یزد", data: 60} ]; -const LoanDistribution = (props) => { +const LoanDistribution = () => { + const t = useTranslations(); return ( - - - - + + diff --git a/src/components/dashboard/reports/LoanProgress/index.jsx b/src/components/dashboard/reports/LoanProgress/index.jsx index 54db36d..4f24949 100644 --- a/src/components/dashboard/reports/LoanProgress/index.jsx +++ b/src/components/dashboard/reports/LoanProgress/index.jsx @@ -1,6 +1,7 @@ import {Grid, Paper} from "@mui/material"; import BarChart from "./BarChart"; import Filter from "../Filter"; +import {useTranslations} from "next-intl"; const fakeData = [ {name: "آذربایجان شرقی", data: 0}, @@ -36,10 +37,16 @@ const fakeData = [ {name: "یزد", data: 60} ]; -const LoanProgress = (props) => { +const LoanProgress = () => { + const t = useTranslations(); return ( - +