diff --git a/src/components/dashboard/roadPatrols/operator/OperatorList.jsx b/src/components/dashboard/roadPatrols/operator/OperatorList.jsx index f9e144d..52bb4b4 100644 --- a/src/components/dashboard/roadPatrols/operator/OperatorList.jsx +++ b/src/components/dashboard/roadPatrols/operator/OperatorList.jsx @@ -7,9 +7,10 @@ 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/MachinePerformanceContent.jsx b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinePerformanceContent.jsx index 8570f58..ead48ff 100644 --- a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinePerformanceContent.jsx +++ b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinePerformanceContent.jsx @@ -2,11 +2,11 @@ import { Box, Chip, DialogContent, Divider, Grid, Stack, Typography } from "@mui import React, { useEffect, useState, useRef } from "react"; import { Marker, useMap } from "react-leaflet"; import AzmayeshActiveIcon from "@/assets/images/examine_marker_active.png"; -import StopsInfo from "@/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/StopsInfo"; import MapLayer from "@/core/components/MapLayer"; import PinDropIcon from "@mui/icons-material/PinDrop"; import AccessAlarmsIcon from "@mui/icons-material/AccessAlarms"; import { formatSecondsToHHMMSS } from "@/core/utils/formatSecondsToHHMMSS"; +import StopsInfo from "./StopsInfo"; const defaultIconSize = [35, 35]; const MachinePerformanceContent = ({ machinesLists }) => { const [selectedPoint, setSelectedPoint] = useState(null); diff --git a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx new file mode 100644 index 0000000..0eb47d2 --- /dev/null +++ b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/MachinesCodeFetch.jsx @@ -0,0 +1,49 @@ +import DialogLoading from "@/core/components/DialogLoading"; +import { GET_CMMS_MACHINE_ROAD_PATROL } from "@/core/utils/routes"; +import useRequest from "@/lib/hooks/useRequest"; +import { DialogContent, Typography } from "@mui/material"; +import { useEffect, useState } from "react"; +import MachinePerformanceContent from "./MachinePerformanceContent"; + +const MachinePerformanceFetch = ({ row }) => { + const [loading, setLoading] = useState(true); + const [data, setData] = useState(null); + const request = useRequest(); + + useEffect(() => { + const fetchData = async () => { + try { + setLoading(true); + const response = await request(`${GET_CMMS_MACHINE_ROAD_PATROL}/${row.getValue('id')}`); + setData(response.data.data); + } catch (error) { + } finally { + setLoading(false); + } + }; + + fetchData(); + }, []); + + return ( + <> + + {loading ? ( + + ) : data && row.original?.stop_points?.length > 0 ? ( + + ) : ( + عملکرد خودرویی در سامانه یافت نشد + )} + + + ) +} +export default MachinePerformanceFetch \ No newline at end of file diff --git a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx index 8269166..c8dcb9e 100644 --- a/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx +++ b/src/components/dashboard/roadPatrols/operator/RowActions/MachinePerformanceForm/index.jsx @@ -1,18 +1,10 @@ -import { Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip, Typography } from "@mui/material"; import DirectionsCarIcon from "@mui/icons-material/DirectionsCar"; -import MachinePerformanceContent from "./MachinePerformanceContent"; +import { Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip } from "@mui/material"; import { useState } from "react"; +import MachinePerformanceFetch from "./MachinesCodeFetch"; const MachinePerformanceForm = ({ row }) => { const [openMachinesCodeDialog, setOpenMachinesCodeDialog] = useState(false); - const machineData = { - cmms_machine_code: row.original?.cmms_machines[0], - resultCode: 0, - mileage: row.original?.distance, - accOnDuration: row.original?.vehicle_runtime, - fuelConsumption: row.original?.fuel_consumption, - stopPoints: row.original?.stop_points, - }; return ( <> @@ -33,10 +25,8 @@ const MachinePerformanceForm = ({ row }) => { maxWidth={"md"} > عملکرد خودرو - {row.original?.stop_points ? ( - - ) : ( - عملکردی در سامانه ثبت نشده است. + {openMachinesCodeDialog && ( + )}