From 35a72414f016dfc2c1366c7fe48f73f21ab38ad0 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Tue, 4 Mar 2025 07:30:52 +0000 Subject: [PATCH] Resolve #86c2a6cz3 "Feature/road safety " --- .../dashboard/road-safety/report/page.js | 17 + .../dashboard/damages/report/ReportLists.jsx | 1 + .../complaintList/ComplaintListTable.jsx | 13 +- .../complaintList/RowActions/index.jsx | 6 +- .../fastReact/operator/OperatorList.jsx | 7 +- .../fastReact/supervisor/RowActions/index.jsx | 4 +- .../fastReact/supervisor/SupervisorList.jsx | 11 +- .../roadPatrols/operator/OperatorList.jsx | 3 +- .../MachinesCodeFetch.jsx | 25 +- .../MachinePerformanceForm/index.jsx | 4 +- .../roadPatrols/reports/ReportLists.jsx | 1 + .../MachinesCodeFetch.jsx | 25 +- .../MachinePerformanceForm/index.jsx | 4 +- .../roadPatrols/supervisor/SupervisorList.jsx | 4 +- .../roadSafety/report/ExcelPrint/index.jsx | 72 +++++ .../roadSafety/report/ReportLists.jsx | 302 ++++++++++++++++++ .../report/Search/FromDateController.jsx | 28 ++ .../report/Search/SearchReportField.jsx | 45 +++ .../report/Search/SelectProvince.jsx | 47 +++ .../report/Search/ToDateController.jsx | 30 ++ .../roadSafety/report/Search/index.jsx | 13 + .../dashboard/roadSafety/report/Toolbar.jsx | 11 + .../dashboard/roadSafety/report/index.jsx | 141 ++++++++ src/core/utils/pageMenu.js | 4 +- src/core/utils/routes.js | 4 + 25 files changed, 769 insertions(+), 53 deletions(-) create mode 100644 src/app/(withAuth)/dashboard/road-safety/report/page.js create mode 100644 src/components/dashboard/roadSafety/report/ExcelPrint/index.jsx create mode 100644 src/components/dashboard/roadSafety/report/ReportLists.jsx create mode 100644 src/components/dashboard/roadSafety/report/Search/FromDateController.jsx create mode 100644 src/components/dashboard/roadSafety/report/Search/SearchReportField.jsx create mode 100644 src/components/dashboard/roadSafety/report/Search/SelectProvince.jsx create mode 100644 src/components/dashboard/roadSafety/report/Search/ToDateController.jsx create mode 100644 src/components/dashboard/roadSafety/report/Search/index.jsx create mode 100644 src/components/dashboard/roadSafety/report/Toolbar.jsx create mode 100644 src/components/dashboard/roadSafety/report/index.jsx diff --git a/src/app/(withAuth)/dashboard/road-safety/report/page.js b/src/app/(withAuth)/dashboard/road-safety/report/page.js new file mode 100644 index 0000000..dc35268 --- /dev/null +++ b/src/app/(withAuth)/dashboard/road-safety/report/page.js @@ -0,0 +1,17 @@ +import ReportPage from "@/components/dashboard/roadSafety/report"; +import WithPermission from "@/core/middlewares/withPermission"; + +const Page = () => { + return ( + + + + ); +}; +export default Page; diff --git a/src/components/dashboard/damages/report/ReportLists.jsx b/src/components/dashboard/damages/report/ReportLists.jsx index c43c9bb..8b00828 100644 --- a/src/components/dashboard/damages/report/ReportLists.jsx +++ b/src/components/dashboard/damages/report/ReportLists.jsx @@ -232,6 +232,7 @@ const ReportLists = ({ data, specialFilter }) => { data={data.data} page_name={"receiptReport"} table_name={"receiptReportList"} + enablePagination={false} specialFilter={specialFilter} /> diff --git a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx index 90102fc..0f13f80 100644 --- a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx +++ b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx @@ -115,8 +115,8 @@ const ComplaintListTable = ({ open, setOpen, mutate }) => { props.dependencyFieldValue?.value === "" ? "empty" : loadingEdaratList - ? "loading" - : props.filterParameters.value + ? "loading" + : props.filterParameters.value } columnSelectOption={getColumnSelectOptions} /> @@ -237,7 +237,10 @@ const ComplaintListTable = ({ open, setOpen, mutate }) => { size: 100, }, { - accessorFn: (row) => moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A").locale("fa").format("HH:mm | yyyy/MM/DD"), + accessorFn: (row) => + moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A") + .locale("fa") + .format("HH:mm | yyyy/MM/DD"), header: "تاریخ ثبت", id: "StartTime_DateTime", enableColumnFilter: false, @@ -246,8 +249,8 @@ const ComplaintListTable = ({ open, setOpen, mutate }) => { grow: false, size: 100, }, - ] - } + ], + }, ]; }, []); diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx index e9972aa..1926241 100644 --- a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx +++ b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx @@ -6,12 +6,10 @@ import { usePermissions } from "@/lib/hooks/usePermissions"; const RowActions = ({ row, mutate }) => { const { data: userPermissions } = usePermissions(); - const hasActionPermission = userPermissions.includes("show-fast-react-edarate-shahri") + const hasActionPermission = userPermissions.includes("show-fast-react-edarate-shahri"); return ( - {hasActionPermission && ( - - )} + {hasActionPermission && } diff --git a/src/components/dashboard/fastReact/operator/OperatorList.jsx b/src/components/dashboard/fastReact/operator/OperatorList.jsx index 3ff010b..cc4991f 100644 --- a/src/components/dashboard/fastReact/operator/OperatorList.jsx +++ b/src/components/dashboard/fastReact/operator/OperatorList.jsx @@ -181,7 +181,10 @@ const OperatorList = () => { size: 100, }, { - accessorFn: (row) => moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A").locale("fa").format("HH:mm | yyyy/MM/DD"), + accessorFn: (row) => + moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A") + .locale("fa") + .format("HH:mm | yyyy/MM/DD"), header: "تاریخ ثبت", id: "StartTime_DateTime", enableColumnFilter: false, @@ -190,7 +193,7 @@ const OperatorList = () => { grow: false, size: 100, }, - ] + ], }, { accessorFn: (row) => { diff --git a/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx b/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx index f9947ab..37d03f4 100644 --- a/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx +++ b/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx @@ -18,7 +18,9 @@ const RowActions = ({ row, mutate }) => { {hasSupervisePermission && row.original?.status === 0 && ( )} - {hasRestorePermission && row.original?.status !== 0 && } + {hasRestorePermission && row.original?.status !== 0 && ( + + )} ); }; diff --git a/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx b/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx index 89eb53c..08d8524 100644 --- a/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx +++ b/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx @@ -125,8 +125,8 @@ const SupervisorList = () => { props.dependencyFieldValue?.value === "" ? "empty" : loadingEdaratList - ? "loading" - : props.filterParameters.value + ? "loading" + : props.filterParameters.value } columnSelectOption={getColumnSelectOptions} /> @@ -282,7 +282,10 @@ const SupervisorList = () => { size: 100, }, { - accessorFn: (row) => moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A").locale("fa").format("HH:mm | yyyy/MM/DD"), + accessorFn: (row) => + moment(row.StartTime_DateTime, "M/D/YYYY h:mm:ss A") + .locale("fa") + .format("HH:mm | yyyy/MM/DD"), header: "تاریخ ثبت", id: "StartTime_DateTime", enableColumnFilter: false, @@ -291,7 +294,7 @@ const SupervisorList = () => { grow: false, size: 100, }, - ] + ], }, { accessorFn: (row) => { diff --git a/src/components/dashboard/roadPatrols/operator/OperatorList.jsx b/src/components/dashboard/roadPatrols/operator/OperatorList.jsx index 52bb4b4..f9e144d 100644 --- a/src/components/dashboard/roadPatrols/operator/OperatorList.jsx +++ b/src/components/dashboard/roadPatrols/operator/OperatorList.jsx @@ -7,10 +7,9 @@ import { GET_ROAD_PATROL_OPERATOR_LIST } from "@/core/utils/routes"; import moment from "jalali-moment"; import RowActions from "./RowActions"; import ReportForm from "./RowActions/ReportForm"; -import RahdaranDialog from "./RowActions/RahdaranForm" +import RahdaranDialog from "./RowActions/RahdaranForm"; import MachinePerformanceForm from "./RowActions/MachinePerformanceForm"; - const OperatorList = () => { const columns = useMemo( () => [ diff --git a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx index 0eb47d2..0da7b28 100644 --- a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx +++ b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx @@ -14,7 +14,7 @@ const MachinePerformanceFetch = ({ row }) => { const fetchData = async () => { try { setLoading(true); - const response = await request(`${GET_CMMS_MACHINE_ROAD_PATROL}/${row.getValue('id')}`); + const response = await request(`${GET_CMMS_MACHINE_ROAD_PATROL}/${row.getValue("id")}`); setData(response.data.data); } catch (error) { } finally { @@ -31,19 +31,20 @@ const MachinePerformanceFetch = ({ row }) => { {loading ? ( ) : data && row.original?.stop_points?.length > 0 ? ( - + ) : ( عملکرد خودرویی در سامانه یافت نشد )} - ) -} -export default MachinePerformanceFetch \ No newline at end of file + ); +}; +export default MachinePerformanceFetch; diff --git a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx index c8dcb9e..168936e 100644 --- a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx +++ b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx @@ -25,9 +25,7 @@ const MachinePerformanceForm = ({ row }) => { maxWidth={"md"} > عملکرد خودرو - {openMachinesCodeDialog && ( - - )} + {openMachinesCodeDialog && } + )} + + ); +}; +export default PrintExcel; diff --git a/src/components/dashboard/roadSafety/report/ReportLists.jsx b/src/components/dashboard/roadSafety/report/ReportLists.jsx new file mode 100644 index 0000000..9d64db2 --- /dev/null +++ b/src/components/dashboard/roadSafety/report/ReportLists.jsx @@ -0,0 +1,302 @@ +"use client"; +import DataTableWithAuth from "@/core/components/DataTableWithAuth"; +import { Box } from "@mui/material"; +import { useMemo } from "react"; +import Toolbar from "./Toolbar"; + +const ReportLists = ({ data, specialFilter }) => { + const columns = useMemo(() => { + return [ + { + accessorKey: "edare_name", + header: "اداره کل", + id: "edare_name", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + }, + + { + accessorKey: "sum", + header: "تعداد کل", + id: "sum", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + header: "ساخت و ساز غیر مجاز", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + id: "id_89", + grow: false, + size: 50, + columns: [ + { + accessorFn: (row) => (row["89"] ? row["89"]["1"] : 0), + header: "گام اول (شناسایی)", + id: "id_89.1", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["89"] ? row["89"]["2"] : 0), + header: "گام دوم (مستندات قضایی)", + id: "id_89.2", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["89"] ? row["89"]["3"] : 0), + header: "گام سوم (برخورد)", + id: "id_89.3", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + ], + }, + { + header: "راه دسترسی غیر مجاز", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + id: "id_90", + grow: false, + size: 50, + columns: [ + { + accessorFn: (row) => (row["90"] ? row["90"]["1"] : 0), + header: "گام اول (شناسایی)", + id: "id_90.1", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["90"] ? row["90"]["2"] : 0), + header: "گام دوم (مستندات قضایی)", + id: "id_90.2", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["90"] ? row["90"]["3"] : 0), + header: "گام سوم (برخورد)", + id: "id_90.3", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + ], + }, + { + header: "عبور تاسیسات زیربنایی غیر مجاز", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + id: "id_91", + grow: false, + size: 50, + columns: [ + { + accessorFn: (row) => (row["91"] ? row["91"]["1"] : 0), + header: "گام اول (شناسایی)", + id: "id_91.1", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["91"] ? row["91"]["2"] : 0), + header: "گام دوم (مستندات قضایی)", + id: "id_91.2", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + { + accessorFn: (row) => (row["91"] ? row["91"]["3"] : 0), + header: "گام سوم (برخورد)", + id: "id_91.3", + enableColumnFilter: false, + enableSorting: false, + datatype: "text", + grow: false, + size: 50, + muiTableBodyCellProps: { + sx: { + textAlign: "center", + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ renderedCellValue }) => { + return (renderedCellValue / 1).toLocaleString(); + }, + }, + ], + }, + ]; + }, []); + + return ( + + + + ); +}; + +export default ReportLists; diff --git a/src/components/dashboard/roadSafety/report/Search/FromDateController.jsx b/src/components/dashboard/roadSafety/report/Search/FromDateController.jsx new file mode 100644 index 0000000..cc6226a --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Search/FromDateController.jsx @@ -0,0 +1,28 @@ +import { Controller } from "react-hook-form"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import React from "react"; +import moment from "jalali-moment"; + +const FromDateController = ({ control }) => { + return ( + ( + { + const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD"); + onChange(formattedDate); // Update the field value in react-hook-form + }} + helperText={error ? error.message : null} + /> + )} + /> + ); +}; +export default FromDateController; diff --git a/src/components/dashboard/roadSafety/report/Search/SearchReportField.jsx b/src/components/dashboard/roadSafety/report/Search/SearchReportField.jsx new file mode 100644 index 0000000..ab8442c --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Search/SearchReportField.jsx @@ -0,0 +1,45 @@ +import { Button, Grid, LinearProgress, Typography } from "@mui/material"; +import SearchIcon from "@mui/icons-material/Search"; +import React from "react"; +import FromDateController from "./FromDateController"; +import ToDateController from "./ToDateController"; +import SelectProvince from "./SelectProvince"; +import { Controller } from "react-hook-form"; + +const SearchReportField = ({ control, hasProvincesPermission }) => { + return ( + + + + + + + + {hasProvincesPermission && ( + + + + )} + + ( + + )} + /> + + + ); +}; + +export default SearchReportField; diff --git a/src/components/dashboard/roadSafety/report/Search/SelectProvince.jsx b/src/components/dashboard/roadSafety/report/Search/SelectProvince.jsx new file mode 100644 index 0000000..b1d8a39 --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Search/SelectProvince.jsx @@ -0,0 +1,47 @@ +import { Controller } from "react-hook-form"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import React from "react"; +import { FormControl, FormHelperText, InputLabel, LinearProgress, MenuItem, Select, Typography } from "@mui/material"; +import useProvinces from "@/lib/hooks/useProvince"; + +const SelectProvince = ({ control }) => { + const { provinces, loadingProvinces, errorProvinces } = useProvinces(); + return ( + ( + + استان + + {error && {error.message}} + + )} + /> + ); +}; +export default SelectProvince; diff --git a/src/components/dashboard/roadSafety/report/Search/ToDateController.jsx b/src/components/dashboard/roadSafety/report/Search/ToDateController.jsx new file mode 100644 index 0000000..ad7690a --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Search/ToDateController.jsx @@ -0,0 +1,30 @@ +import { Controller, useWatch } from "react-hook-form"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import React from "react"; +import moment from "jalali-moment"; + +const ToDateController = ({ control }) => { + const minDate = useWatch({ control, name: "from_date" }); + return ( + ( + { + const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD"); + onChange(formattedDate); // Update the field value in react-hook-form + }} + helperText={error ? error.message : null} + /> + )} + /> + ); +}; +export default ToDateController; diff --git a/src/components/dashboard/roadSafety/report/Search/index.jsx b/src/components/dashboard/roadSafety/report/Search/index.jsx new file mode 100644 index 0000000..f29d302 --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Search/index.jsx @@ -0,0 +1,13 @@ +import StyledForm from "@/core/components/StyledForm"; +import SearchReportField from "./SearchReportField"; + +const SearchReportList = ({ handleSubmit, onSearchSubmit, control, hasProvincesPermission }) => { + return ( + <> + + + + + ); +}; +export default SearchReportList; diff --git a/src/components/dashboard/roadSafety/report/Toolbar.jsx b/src/components/dashboard/roadSafety/report/Toolbar.jsx new file mode 100644 index 0000000..7dd930f --- /dev/null +++ b/src/components/dashboard/roadSafety/report/Toolbar.jsx @@ -0,0 +1,11 @@ +import PrintExcel from "./ExcelPrint"; +import { Box } from "@mui/material"; + +const Toolbar = ({ table, filterData, mutate }) => { + return ( + + + + ); +}; +export default Toolbar; diff --git a/src/components/dashboard/roadSafety/report/index.jsx b/src/components/dashboard/roadSafety/report/index.jsx new file mode 100644 index 0000000..c30f108 --- /dev/null +++ b/src/components/dashboard/roadSafety/report/index.jsx @@ -0,0 +1,141 @@ +"use client"; +import PageTitle from "@/core/components/PageTitle"; +import { LinearProgress, Stack } from "@mui/material"; +import SearchReportList from "./Search"; +import { useEffect, useState } from "react"; +import ReportLists from "./ReportLists"; +import useRequest from "@/lib/hooks/useRequest"; +import { GET_ROAD_SAFETY_CITY_ACTIVITY_REPORT, GET_ROAD_SAFETY_PROVINCE_ACTIVITY_REPORT } from "@/core/utils/routes"; +import moment from "jalali-moment"; +import * as yup from "yup"; +import { useForm } from "react-hook-form"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { usePermissions } from "@/lib/hooks/usePermissions"; +import { useAuth } from "@/lib/contexts/auth"; + +const ReportPage = () => { + const [data, setData] = useState(null); + const { data: userPermissions } = usePermissions(); + const { user } = useAuth(); + const requestServer = useRequest(); + const hasProvincesPermission = userPermissions.some((item) => + [ + "show-safety-and-privacy-operator-cartable-province", + "show-safety-and-privacy-operator-cartable-edarate-shahri", + ].includes(item) + ); + + const defaultValues = { + from_date: moment(new Date()).format("YYYY-MM-DD"), + date_to: moment(new Date()).format("YYYY-MM-DD"), + province_id: hasProvincesPermission ? "-1" : user.province_id, + }; + const defaultFilter = [ + { value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" }, + { value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" }, + { value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" }, + ]; + const [specialFilter, setSpecialFilter] = useState(defaultFilter); + + const onSearchSubmit = async (data) => { + const params = new URLSearchParams(); + params.set("from_date", `${data.from_date}`); + params.set("date_to", `${data.date_to}`); + setSpecialFilter([ + { value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" }, + { value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" }, + { value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" }, + ]); + if (data.province_id === "-1") { + try { + const response = await requestServer(`${GET_ROAD_SAFETY_PROVINCE_ACTIVITY_REPORT}?${params}`); + const result = response.data.data; + const nationalReportForItem = result.activities.find((report) => report.province_id === -1); + const nationalReport = { + edare_name: "کل کشور", + ...nationalReportForItem, + }; + + setData({ + data: [ + nationalReport, + ...result.provinces.map((province) => { + const filteredReports = result.activities.find( + (report) => report.province_id === province.id + ); + return { + ...filteredReports, + edare_name: province.name_fa, + }; + }), + ], + filters: data, + }); + } catch (e) {} + } else { + try { + params.set("province_id", `${data.province_id}`); + const response = await requestServer(`${GET_ROAD_SAFETY_CITY_ACTIVITY_REPORT}?${params}`); + const result = response.data.data; + const nationalReportForItem = result.activities.find((report) => report.edare_shahri_id == "-1"); + const nationalReport = { + ...nationalReportForItem, + edare_name: "کل استان", + }; + setData({ + data: [ + nationalReport, + ...result.edarateShahri.map((edare) => { + const filteredReports = result.activities.find( + (report) => report.edare_shahri_id == edare.id + ); + return { + edare_name: edare.name_fa, + ...filteredReports, + }; + }), + ], + filters: data, + }); + } catch (e) {} + } + }; + + useEffect(() => { + if (!userPermissions) return; + onSearchSubmit(defaultValues); + }, [userPermissions]); + + const validationSchema = yup.object().shape({ + from_date: yup + .string() + .required("تاریخ ثبت الزامی است!") + .matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ ثبت الزامی است!") + .test("is-valid-date", "تاریخ ثبت معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()), + date_to: yup + .string() + .required("تاریخ ثبت الزامی است!") + .matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ ثبت الزامی است!") + .test("is-valid-date", "تاریخ ثبت معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()), + province_id: yup.string().nullable(), + }); + + const { control, handleSubmit } = useForm({ + defaultValues, + resolver: yupResolver(validationSchema), + mode: "onBlur", + }); + return ( + + + + {!data ? : } + + ); +}; +export default ReportPage; diff --git a/src/core/utils/pageMenu.js b/src/core/utils/pageMenu.js index 1811e60..2b00efb 100644 --- a/src/core/utils/pageMenu.js +++ b/src/core/utils/pageMenu.js @@ -331,20 +331,18 @@ export const pageMenu = [ "show-safety-and-privacy-operator-cartable", "show-safety-and-privacy-operator-cartable-province", "show-safety-and-privacy-operator-cartable-edarate-shahri", - "add-safety-and-privacy", ], }, { id: "safetyAndPrivacyManagmentReport", label: "گزارش ها", type: "page", - route: process.env.NEXT_PUBLIC_API_URL + "/v2/safety_and_privacy/report", + route: "/dashboard/road-safety/report", icon: , permissions: [ "show-safety-and-privacy-operator-cartable", "show-safety-and-privacy-operator-cartable-province", "show-safety-and-privacy-operator-cartable-edarate-shahri", - "add-safety-and-privacy", ], }, ], diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index 6014c93..13da8ae 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -127,3 +127,7 @@ export const UPDATE_FAST_REACT = api + "/api/v3/road_observations/modify_registr export const EXPORT_FAST_REACT_SUPERVISOR_LIST = api + "/api/v3/road_observations/supervisor_report"; export const EXPORT_FAST_REACT_OPERATOR_LIST = api + "/api/v3/road_observations/operator_report"; export const EXPORT_FAST_REACT_COMPLAINT_LIST = api + "/api/v3/road_observations/complaints_report"; + +// road safety +export const GET_ROAD_SAFETY_PROVINCE_ACTIVITY_REPORT = api + "/api/v3/safety_and_privacy_report/country_activity"; +export const GET_ROAD_SAFETY_CITY_ACTIVITY_REPORT = api + "/api/v3/safety_and_privacy_report/province_activity";