build and format
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageLoading from "@/core/components/PageLoading";
|
import PageLoading from "@/core/components/PageLoading";
|
||||||
|
|
||||||
const Loading = () => {
|
const Loading = () => {
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
};
|
};
|
||||||
export default Loading;
|
export default Loading;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import MachinesPage from "@/components/dashboard/machines";
|
import MachinesPage from "@/components/dashboard/machines";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "کارتابل ماشینها",
|
title: "کارتابل ماشینها",
|
||||||
};
|
};
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WithPermission permission_name={["all"]}>
|
<WithPermission permission_name={["all"]}>
|
||||||
<MachinesPage />
|
<MachinesPage />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Page;
|
export default Page;
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import MissionsReportPage from "@/components/dashboard/roadMissions/reports/taradodReports";
|
import MissionsReportPage from "@/components/dashboard/roadMissions/reports/taradodReports";
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "کارتابل گزارش ترددها",
|
title: "کارتابل گزارش ترددها",
|
||||||
};
|
};
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission
|
<WithPermission
|
||||||
permission_name={[
|
permission_name={[
|
||||||
"all", // TODO : change permission
|
"all", // TODO : change permission
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<MissionsReportPage />
|
<MissionsReportPage />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Page;
|
export default Page;
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import ViolationsReportsPage from "@/components/dashboard/roadMissions/reports/violationsReports";
|
import ViolationsReportsPage from "@/components/dashboard/roadMissions/reports/violationsReports";
|
||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: "کارتابل گزارش تخلفات",
|
title: "کارتابل گزارش تخلفات",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<WithPermission
|
<WithPermission
|
||||||
permission_name={[
|
permission_name={[
|
||||||
"all", // TODO : change permission
|
"all", // TODO : change permission
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<ViolationsReportsPage />
|
<ViolationsReportsPage />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,134 +1,134 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
||||||
import { GET_MACHINES_LIST } from "@/core/utils/routes";
|
import { GET_MACHINES_LIST } from "@/core/utils/routes";
|
||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Typography } from "@mui/material";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import RowActions from "./RowActions";
|
import RowActions from "./RowActions";
|
||||||
|
|
||||||
const statusOptions = [
|
const statusOptions = [
|
||||||
{ value: "", label: "همه وضعیت ها" },
|
{ value: "", label: "همه وضعیت ها" },
|
||||||
{ value: 1, label: "آماده" },
|
{ value: 1, label: "آماده" },
|
||||||
{ value: 2, label: "رزرو" },
|
{ value: 2, label: "رزرو" },
|
||||||
{ value: 3, label: "در ماموریت" },
|
{ value: 3, label: "در ماموریت" },
|
||||||
{ value: 4, label: "خارج از رده" },
|
{ value: 4, label: "خارج از رده" },
|
||||||
{ value: 5, label: "در تعمیر" },
|
{ value: 5, label: "در تعمیر" },
|
||||||
{ value: 6, label: "فروخته شده" },
|
{ value: 6, label: "فروخته شده" },
|
||||||
{ value: 7, label: "نیاز به تعمیر" },
|
{ value: 7, label: "نیاز به تعمیر" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const MachinesList = () => {
|
const MachinesList = () => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "id",
|
accessorKey: "id",
|
||||||
header: "کد یکتا", // Unique Code
|
header: "کد یکتا", // Unique Code
|
||||||
id: "id",
|
id: "id",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: false,
|
sortDescFirst: false,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
header: "اطلاعات ماشینها",
|
header: "اطلاعات ماشینها",
|
||||||
id: "machines_info",
|
id: "machines_info",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
accessorKey: "car_name",
|
accessorKey: "car_name",
|
||||||
header: "نام ماشین",
|
header: "نام ماشین",
|
||||||
id: "car_name",
|
id: "car_name",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: false,
|
sortDescFirst: false,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "car_type",
|
accessorKey: "car_type",
|
||||||
header: "نوع ماشین",
|
header: "نوع ماشین",
|
||||||
id: "car_type",
|
id: "car_type",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: false,
|
sortDescFirst: false,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "machine_code",
|
accessorKey: "machine_code",
|
||||||
header: "کد ماشین",
|
header: "کد ماشین",
|
||||||
id: "machine_code",
|
id: "machine_code",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: false,
|
sortDescFirst: false,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "plak_number",
|
accessorKey: "plak_number",
|
||||||
header: "پلاک",
|
header: "پلاک",
|
||||||
id: "plak_number",
|
id: "plak_number",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: false,
|
sortDescFirst: false,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "status",
|
accessorKey: "status",
|
||||||
header: "وضعیت",
|
header: "وضعیت",
|
||||||
id: "status",
|
id: "status",
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
columnSelectOption: () => {
|
columnSelectOption: () => {
|
||||||
return statusOptions.map((status) => ({
|
return statusOptions.map((status) => ({
|
||||||
value: status.value,
|
value: status.value,
|
||||||
label: status.label,
|
label: status.label,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
Cell: ({ row }) => {
|
Cell: ({ row }) => {
|
||||||
const status = statusOptions.find((option) => option.value == row.original.status);
|
const status = statusOptions.find((option) => option.value == row.original.status);
|
||||||
return <Typography variant="body2">{status?.label || ""}</Typography>;
|
return <Typography variant="body2">{status?.label || ""}</Typography>;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
need_filter={true}
|
need_filter={true}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
table_url={GET_MACHINES_LIST}
|
table_url={GET_MACHINES_LIST}
|
||||||
page_name={"machines"}
|
page_name={"machines"}
|
||||||
table_name={"machinesList"}
|
table_name={"machinesList"}
|
||||||
sorting={[{ id: "id", desc: true }]}
|
sorting={[{ id: "id", desc: true }]}
|
||||||
enableRowActions
|
enableRowActions
|
||||||
positionActionsColumn={"first"}
|
positionActionsColumn={"first"}
|
||||||
RowActions={RowActions}
|
RowActions={RowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default MachinesList;
|
export default MachinesList;
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
|
import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { DELETE_TOLL_HOUSE_ITEM } from "@/core/utils/routes";
|
import { DELETE_TOLL_HOUSE_ITEM } from "@/core/utils/routes";
|
||||||
|
|
||||||
const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
|
const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
requestServer(`${DELETE_TOLL_HOUSE_ITEM}/${rowId}`, "delete")
|
requestServer(`${DELETE_TOLL_HOUSE_ITEM}/${rowId}`, "delete")
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate();
|
mutate();
|
||||||
setOpenDeleteDialog(false);
|
setOpenDeleteDialog(false);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Stack alignItems="center" spacing={2}>
|
<Stack alignItems="center" spacing={2}>
|
||||||
<Typography mt={2}>آیا از حذف راهدارخانه اطمینان دارید؟</Typography>
|
<Typography mt={2}>آیا از حذف راهدارخانه اطمینان دارید؟</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
|
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
|
||||||
<Button onClick={() => setOpenDeleteDialog(false)} variant="outlined" color="secondary">
|
<Button onClick={() => setOpenDeleteDialog(false)} variant="outlined" color="secondary">
|
||||||
خیر !
|
خیر !
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleClick} variant="contained" color="error" disabled={submitting}>
|
<Button onClick={handleClick} variant="contained" color="error" disabled={submitting}>
|
||||||
{submitting ? "درحال حذف..." : "بله اطمینان دارم"}
|
{submitting ? "درحال حذف..." : "بله اطمینان دارم"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default DeleteContent;
|
export default DeleteContent;
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import DeleteContent from "./DeleteContent";
|
import DeleteContent from "./DeleteContent";
|
||||||
const DeleteDialog = ({ rowId, mutate }) => {
|
const DeleteDialog = ({ rowId, mutate }) => {
|
||||||
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tooltip title="حذف">
|
<Tooltip title="حذف">
|
||||||
<IconButton color="error" onClick={() => setOpenDeleteDialog(true)}>
|
<IconButton color="error" onClick={() => setOpenDeleteDialog(true)}>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={openDeleteDialog}
|
open={openDeleteDialog}
|
||||||
onClose={() => setOpenDeleteDialog(false)}
|
onClose={() => setOpenDeleteDialog(false)}
|
||||||
PaperProps={{
|
PaperProps={{
|
||||||
sx: {
|
sx: {
|
||||||
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
dir="rtl"
|
dir="rtl"
|
||||||
maxWidth={"md"}
|
maxWidth={"md"}
|
||||||
>
|
>
|
||||||
<DialogTitle>حذف راهدارخانه</DialogTitle>
|
<DialogTitle>حذف راهدارخانه</DialogTitle>
|
||||||
{openDeleteDialog && (
|
{openDeleteDialog && (
|
||||||
<DeleteContent rowId={rowId} mutate={mutate} setOpenDeleteDialog={setOpenDeleteDialog} />
|
<DeleteContent rowId={rowId} mutate={mutate} setOpenDeleteDialog={setOpenDeleteDialog} />
|
||||||
)}
|
)}
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default DeleteDialog;
|
export default DeleteDialog;
|
||||||
|
|||||||
@@ -1,281 +1,281 @@
|
|||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import {
|
import {
|
||||||
GET_CITIES_LIST,
|
GET_CITIES_LIST,
|
||||||
GET_PROVINCES_LIST,
|
GET_PROVINCES_LIST,
|
||||||
GET_STATIONS_LIST,
|
GET_STATIONS_LIST,
|
||||||
UPDATE_MACHINE_STATUS_AND_LOCATION,
|
UPDATE_MACHINE_STATUS_AND_LOCATION,
|
||||||
} from "@/core/utils/routes";
|
} from "@/core/utils/routes";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { Beenhere, ExitToApp } from "@mui/icons-material";
|
import { Beenhere, ExitToApp } from "@mui/icons-material";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
CircularProgress,
|
CircularProgress,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
FormControl,
|
FormControl,
|
||||||
InputLabel,
|
InputLabel,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
Select,
|
Select,
|
||||||
Stack,
|
Stack,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { DialogHeader } from "next/dist/client/components/react-dev-overlay/internal/components/Dialog";
|
import { DialogHeader } from "next/dist/client/components/react-dev-overlay/internal/components/Dialog";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Controller, useForm, useWatch } from "react-hook-form";
|
import { Controller, useForm, useWatch } from "react-hook-form";
|
||||||
import { number, object } from "yup";
|
import { number, object } from "yup";
|
||||||
|
|
||||||
const statusOptions = [
|
const statusOptions = [
|
||||||
{ value: 1, label: "آماده" },
|
{ value: 1, label: "آماده" },
|
||||||
{ value: 2, label: "رزرو" },
|
{ value: 2, label: "رزرو" },
|
||||||
{ value: 3, label: "در ماموریت" },
|
{ value: 3, label: "در ماموریت" },
|
||||||
{ value: 4, label: "خارج از رده" },
|
{ value: 4, label: "خارج از رده" },
|
||||||
{ value: 5, label: "در تعمیر" },
|
{ value: 5, label: "در تعمیر" },
|
||||||
{ value: 6, label: "فروخته شده" },
|
{ value: 6, label: "فروخته شده" },
|
||||||
{ value: 7, label: "نیاز به تعمیر" },
|
{ value: 7, label: "نیاز به تعمیر" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const validationSchema = object({
|
const validationSchema = object({
|
||||||
status: number().required("انتخاب وضعیت الزامی است"),
|
status: number().required("انتخاب وضعیت الزامی است"),
|
||||||
province_id: number().required("انتخاب استان الزامی است"),
|
province_id: number().required("انتخاب استان الزامی است"),
|
||||||
city_id: number().required("انتخاب شهر الزامی است"),
|
city_id: number().required("انتخاب شهر الزامی است"),
|
||||||
station_id: number().required("انتخاب راهداری الزامی است"),
|
station_id: number().required("انتخاب راهداری الزامی است"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const EditFormContent = ({ row, rowId, mutate, setOpen }) => {
|
const EditFormContent = ({ row, rowId, mutate, setOpen }) => {
|
||||||
const requestServer = useRequest();
|
const requestServer = useRequest();
|
||||||
|
|
||||||
const [provinces, setProvinces] = useState([]);
|
const [provinces, setProvinces] = useState([]);
|
||||||
const [cities, setCities] = useState([]);
|
const [cities, setCities] = useState([]);
|
||||||
const [stations, setStations] = useState([]);
|
const [stations, setStations] = useState([]);
|
||||||
|
|
||||||
const [loadingProvinces, setLoadingProvinces] = useState(false);
|
const [loadingProvinces, setLoadingProvinces] = useState(false);
|
||||||
const [loadingCities, setLoadingCities] = useState(false);
|
const [loadingCities, setLoadingCities] = useState(false);
|
||||||
const [loadingStations, setLoadingStations] = useState(false);
|
const [loadingStations, setLoadingStations] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
setValue,
|
setValue,
|
||||||
formState: { isSubmitting },
|
formState: { isSubmitting },
|
||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
status: row.original.status,
|
status: row.original.status,
|
||||||
province_id: row.original.province_id,
|
province_id: row.original.province_id,
|
||||||
city_id: row.original.city_id,
|
city_id: row.original.city_id,
|
||||||
station_id: row.original.station_id,
|
station_id: row.original.station_id,
|
||||||
},
|
},
|
||||||
resolver: yupResolver(validationSchema),
|
resolver: yupResolver(validationSchema),
|
||||||
mode: "all",
|
mode: "all",
|
||||||
});
|
});
|
||||||
|
|
||||||
const provinceId = useWatch({
|
const provinceId = useWatch({
|
||||||
control,
|
control,
|
||||||
name: "province_id",
|
name: "province_id",
|
||||||
});
|
});
|
||||||
|
|
||||||
const cityId = useWatch({
|
const cityId = useWatch({
|
||||||
control,
|
control,
|
||||||
name: "city_id",
|
name: "city_id",
|
||||||
});
|
});
|
||||||
|
|
||||||
const loadProvinces = async () => {
|
const loadProvinces = async () => {
|
||||||
try {
|
try {
|
||||||
setLoadingProvinces(true);
|
setLoadingProvinces(true);
|
||||||
const response = await requestServer(GET_PROVINCES_LIST, "get");
|
const response = await requestServer(GET_PROVINCES_LIST, "get");
|
||||||
setProvinces(response.data?.data || []);
|
setProvinces(response.data?.data || []);
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingProvinces(false);
|
setLoadingProvinces(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadCities = async (provinceId) => {
|
const loadCities = async (provinceId) => {
|
||||||
if (!provinceId) return;
|
if (!provinceId) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoadingCities(true);
|
setLoadingCities(true);
|
||||||
const response = await requestServer(`${GET_CITIES_LIST}?province_id=${provinceId}`, "get");
|
const response = await requestServer(`${GET_CITIES_LIST}?province_id=${provinceId}`, "get");
|
||||||
setCities(response.data?.data || []);
|
setCities(response.data?.data || []);
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingCities(false);
|
setLoadingCities(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadStations = async (cityId) => {
|
const loadStations = async (cityId) => {
|
||||||
if (!cityId) return;
|
if (!cityId) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoadingStations(true);
|
setLoadingStations(true);
|
||||||
const response = await requestServer(`${GET_STATIONS_LIST}/search_by_city?city_id=${cityId}`, "get");
|
const response = await requestServer(`${GET_STATIONS_LIST}/search_by_city?city_id=${cityId}`, "get");
|
||||||
setStations(response.data?.data || []);
|
setStations(response.data?.data || []);
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingStations(false);
|
setLoadingStations(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadProvinces();
|
loadProvinces();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initial edit mode loading
|
* Initial edit mode loading
|
||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (row.original.province_id) {
|
if (row.original.province_id) {
|
||||||
loadCities(row.original.province_id);
|
loadCities(row.original.province_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row.original.city_id) {
|
if (row.original.city_id) {
|
||||||
loadStations(row.original.city_id);
|
loadStations(row.original.city_id);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!provinceId) return;
|
if (!provinceId) return;
|
||||||
|
|
||||||
loadCities(provinceId);
|
loadCities(provinceId);
|
||||||
|
|
||||||
if (provinceId !== row.original.province_id) {
|
if (provinceId !== row.original.province_id) {
|
||||||
setValue("city_id", "");
|
setValue("city_id", "");
|
||||||
setValue("station_id", "");
|
setValue("station_id", "");
|
||||||
setStations([]);
|
setStations([]);
|
||||||
}
|
}
|
||||||
}, [provinceId]);
|
}, [provinceId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!cityId) return;
|
if (!cityId) return;
|
||||||
|
|
||||||
loadStations(cityId);
|
loadStations(cityId);
|
||||||
|
|
||||||
if (cityId !== row.original.city_id) {
|
if (cityId !== row.original.city_id) {
|
||||||
setValue("station_id", "");
|
setValue("station_id", "");
|
||||||
}
|
}
|
||||||
}, [cityId]);
|
}, [cityId]);
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
formData.append("status", String(data.status));
|
formData.append("status", String(data.status));
|
||||||
formData.append("province_id", String(data.province_id));
|
formData.append("province_id", String(data.province_id));
|
||||||
formData.append("city_id", String(data.city_id));
|
formData.append("city_id", String(data.city_id));
|
||||||
formData.append("station_id", String(data.station_id));
|
formData.append("station_id", String(data.station_id));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await requestServer(`${UPDATE_MACHINE_STATUS_AND_LOCATION}/${rowId}`, "post", {
|
await requestServer(`${UPDATE_MACHINE_STATUS_AND_LOCATION}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
});
|
});
|
||||||
|
|
||||||
mutate();
|
mutate();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>ویرایش ماشین</DialogTitle>
|
<DialogTitle>ویرایش ماشین</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<StyledForm id="updateMachineForm" onSubmit={handleSubmit(onSubmit)}>
|
<StyledForm id="updateMachineForm" onSubmit={handleSubmit(onSubmit)}>
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<Controller
|
<Controller
|
||||||
name="province_id"
|
name="province_id"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl fullWidth size="small" error={!!error}>
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
<InputLabel>استان</InputLabel>
|
<InputLabel>استان</InputLabel>
|
||||||
|
|
||||||
<Select {...field} label="استان" disabled={loadingProvinces}>
|
<Select {...field} label="استان" disabled={loadingProvinces}>
|
||||||
{provinces.map((province) => (
|
{provinces.map((province) => (
|
||||||
<MenuItem key={province.id} value={province.id}>
|
<MenuItem key={province.id} value={province.id}>
|
||||||
{province.name_fa}
|
{province.name_fa}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="city_id"
|
name="city_id"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl fullWidth size="small" error={!!error}>
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
<InputLabel>شهر</InputLabel>
|
<InputLabel>شهر</InputLabel>
|
||||||
|
|
||||||
<Select {...field} label="شهر" disabled={!provinceId || loadingCities}>
|
<Select {...field} label="شهر" disabled={!provinceId || loadingCities}>
|
||||||
{cities.map((city) => (
|
{cities.map((city) => (
|
||||||
<MenuItem key={city.id} value={city.id}>
|
<MenuItem key={city.id} value={city.id}>
|
||||||
{city.name_fa}
|
{city.name_fa}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
name="station_id"
|
name="station_id"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl fullWidth size="small" error={!!error}>
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
<InputLabel>راهداری</InputLabel>
|
<InputLabel>راهداری</InputLabel>
|
||||||
|
|
||||||
<Select {...field} label="راهداری" disabled={!cityId || loadingStations}>
|
<Select {...field} label="راهداری" disabled={!cityId || loadingStations}>
|
||||||
{stations.map((station) => (
|
{stations.map((station) => (
|
||||||
<MenuItem key={station.id} value={station.id}>
|
<MenuItem key={station.id} value={station.id}>
|
||||||
{station.name}
|
{station.name}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
name="status"
|
name="status"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl fullWidth size="small" error={!!error}>
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
<InputLabel>وضعیت</InputLabel>
|
<InputLabel>وضعیت</InputLabel>
|
||||||
|
|
||||||
<Select {...field} label="وضعیت">
|
<Select {...field} label="وضعیت">
|
||||||
{statusOptions.map((item) => (
|
{statusOptions.map((item) => (
|
||||||
<MenuItem key={item.value} value={item.value}>
|
<MenuItem key={item.value} value={item.value}>
|
||||||
{item.label}
|
{item.label}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{(loadingCities || loadingStations) && (
|
{(loadingCities || loadingStations) && (
|
||||||
<Stack direction="row" justifyContent="center">
|
<Stack direction="row" justifyContent="center">
|
||||||
<CircularProgress size={24} />
|
<CircularProgress size={24} />
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={() => setOpen(false)} variant="outlined" color="secondary" startIcon={<ExitToApp />}>
|
<Button onClick={() => setOpen(false)} variant="outlined" color="secondary" startIcon={<ExitToApp />}>
|
||||||
بستن
|
بستن
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
type="submit"
|
type="submit"
|
||||||
form="updateMachineForm"
|
form="updateMachineForm"
|
||||||
endIcon={<Beenhere />}
|
endIcon={<Beenhere />}
|
||||||
>
|
>
|
||||||
{isSubmitting ? "در حال ویرایش" : "ویرایش ماشین"}
|
{isSubmitting ? "در حال ویرایش" : "ویرایش ماشین"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EditFormContent;
|
export default EditFormContent;
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
import { SwapHoriz } from "@mui/icons-material";
|
import { SwapHoriz } from "@mui/icons-material";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import { Dialog, IconButton, Tooltip } from "@mui/material";
|
import { Dialog, IconButton, Tooltip } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import EditFormContent from "./Form";
|
import EditFormContent from "./Form";
|
||||||
|
|
||||||
const Edit = ({ row, mutate, rowId }) => {
|
const Edit = ({ row, mutate, rowId }) => {
|
||||||
const [openEditDialog, setOpenEditDialog] = useState(false);
|
const [openEditDialog, setOpenEditDialog] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tooltip title="ویرایش" arrow placement="right">
|
<Tooltip title="ویرایش" arrow placement="right">
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
sx={{ textTransform: "unset", alignSelf: "center" }}
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpenEditDialog(true);
|
setOpenEditDialog(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<SwapHoriz />
|
<SwapHoriz />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog open={openEditDialog} fullWidth maxWidth="xs">
|
<Dialog open={openEditDialog} fullWidth maxWidth="xs">
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="close"
|
aria-label="close"
|
||||||
onClick={() => setOpenEditDialog(false)}
|
onClick={() => setOpenEditDialog(false)}
|
||||||
sx={(theme) => ({
|
sx={(theme) => ({
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
right: 8,
|
right: 8,
|
||||||
top: 8,
|
top: 8,
|
||||||
zIndex: 50,
|
zIndex: 50,
|
||||||
color: theme.palette.grey[500],
|
color: theme.palette.grey[500],
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<CloseIcon />
|
<CloseIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
{openEditDialog && (
|
{openEditDialog && (
|
||||||
<EditFormContent rowId={rowId} row={row} setOpen={setOpenEditDialog} mutate={mutate} />
|
<EditFormContent rowId={rowId} row={row} setOpen={setOpenEditDialog} mutate={mutate} />
|
||||||
)}
|
)}
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Edit;
|
export default Edit;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import Edit from "./Edit";
|
import Edit from "./Edit";
|
||||||
|
|
||||||
const RowActions = ({ row, mutate }) => {
|
const RowActions = ({ row, mutate }) => {
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const hasEditPermission = userPermissions.some((item) => ["update-machine"].includes(item));
|
const hasEditPermission = userPermissions.some((item) => ["update-machine"].includes(item));
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
{hasEditPermission && <Edit row={row} mutate={mutate} rowId={row.getValue("id")} />}
|
{hasEditPermission && <Edit row={row} mutate={mutate} rowId={row.getValue("id")} />}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default RowActions;
|
export default RowActions;
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { FeatureGroup, useMap } from "react-leaflet";
|
import { FeatureGroup, useMap } from "react-leaflet";
|
||||||
|
|
||||||
const ShowBound = ({ bound }) => {
|
const ShowBound = ({ bound }) => {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const featureRef = useRef(null);
|
const featureRef = useRef(null);
|
||||||
|
|
||||||
const safeFitBounds = (layer) => {
|
const safeFitBounds = (layer) => {
|
||||||
if (!layer || !map) return;
|
if (!layer || !map) return;
|
||||||
try {
|
try {
|
||||||
const latLngs = layer.getLatLngs();
|
const latLngs = layer.getLatLngs();
|
||||||
map.fitBounds(latLngs, {
|
map.fitBounds(latLngs, {
|
||||||
paddingTopLeft: [20, 20],
|
paddingTopLeft: [20, 20],
|
||||||
paddingBottomRight: [20, 20],
|
paddingBottomRight: [20, 20],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("fitBounds failed:", e);
|
console.warn("fitBounds failed:", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
bound?.editing?.disable();
|
bound?.editing?.disable();
|
||||||
featureRef.current.addLayer(bound);
|
featureRef.current.addLayer(bound);
|
||||||
safeFitBounds(bound);
|
safeFitBounds(bound);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <FeatureGroup ref={featureRef} />;
|
return <FeatureGroup ref={featureRef} />;
|
||||||
};
|
};
|
||||||
export default ShowBound;
|
export default ShowBound;
|
||||||
|
|||||||
@@ -1,65 +1,65 @@
|
|||||||
const { IconButton, Tooltip, Box, Dialog, DialogTitle, Typography, DialogContent } = require("@mui/material");
|
const { IconButton, Tooltip, Box, Dialog, DialogTitle, Typography, DialogContent } = require("@mui/material");
|
||||||
import MapLayer from "@/core/components/MapLayer";
|
import MapLayer from "@/core/components/MapLayer";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import LayersIcon from "@mui/icons-material/Layers";
|
import LayersIcon from "@mui/icons-material/Layers";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import ShowBound from "./ShowBound";
|
import ShowBound from "./ShowBound";
|
||||||
|
|
||||||
const ShowProjectArea = ({ primaryArea }) => {
|
const ShowProjectArea = ({ primaryArea }) => {
|
||||||
const [openShowAreaDialog, setOpenShowAreaDialog] = useState(false);
|
const [openShowAreaDialog, setOpenShowAreaDialog] = useState(false);
|
||||||
const bound = useMemo(() => {
|
const bound = useMemo(() => {
|
||||||
const coordinates = Object.values(primaryArea.coordinates);
|
const coordinates = Object.values(primaryArea.coordinates);
|
||||||
|
|
||||||
const latLngCoords = coordinates.map(([lat, lng]) => [parseFloat(lng), parseFloat(lat)]);
|
const latLngCoords = coordinates.map(([lat, lng]) => [parseFloat(lng), parseFloat(lat)]);
|
||||||
|
|
||||||
return primaryArea.type === "polygon"
|
return primaryArea.type === "polygon"
|
||||||
? L.polygon(latLngCoords, { color: "#ff5555" })
|
? L.polygon(latLngCoords, { color: "#ff5555" })
|
||||||
: L.polyline(latLngCoords);
|
: L.polyline(latLngCoords);
|
||||||
}, [primaryArea]);
|
}, [primaryArea]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Tooltip title="نمایش پلیگان" placement="right" arrow>
|
<Tooltip title="نمایش پلیگان" placement="right" arrow>
|
||||||
<IconButton size="small" color="primary" onClick={() => setOpenShowAreaDialog(true)}>
|
<IconButton size="small" color="primary" onClick={() => setOpenShowAreaDialog(true)}>
|
||||||
<LayersIcon />
|
<LayersIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={openShowAreaDialog}
|
open={openShowAreaDialog}
|
||||||
onClose={() => setOpenShowAreaDialog(false)}
|
onClose={() => setOpenShowAreaDialog(false)}
|
||||||
PaperProps={{
|
PaperProps={{
|
||||||
sx: {
|
sx: {
|
||||||
transition: "all .3s",
|
transition: "all .3s",
|
||||||
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
padding: 1,
|
padding: 1,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
maxWidth="sm"
|
maxWidth="sm"
|
||||||
fullWidth
|
fullWidth
|
||||||
dir="rtl"
|
dir="rtl"
|
||||||
>
|
>
|
||||||
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", padding: "16px 24px" }}>
|
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", padding: "16px 24px" }}>
|
||||||
<Typography variant="body1" sx={{ fontWeight: "bold", fontSize: "large" }}>
|
<Typography variant="body1" sx={{ fontWeight: "bold", fontSize: "large" }}>
|
||||||
محدوده طرح
|
محدوده طرح
|
||||||
</Typography>
|
</Typography>
|
||||||
<IconButton onClick={() => setOpenShowAreaDialog(false)} size="small">
|
<IconButton onClick={() => setOpenShowAreaDialog(false)} size="small">
|
||||||
<CloseIcon />
|
<CloseIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Box sx={{ flex: 1 }}>
|
<Box sx={{ flex: 1 }}>
|
||||||
<Box sx={{ width: "100%", height: "400px" }}>
|
<Box sx={{ width: "100%", height: "400px" }}>
|
||||||
<MapLayer style={{ borderRadius: "4px" }}>
|
<MapLayer style={{ borderRadius: "4px" }}>
|
||||||
<ShowBound bound={bound} />
|
<ShowBound bound={bound} />
|
||||||
</MapLayer>
|
</MapLayer>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowProjectArea;
|
export default ShowProjectArea;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import MachinesList from "./MachinesList";
|
import MachinesList from "./MachinesList";
|
||||||
|
|
||||||
const MachinesPage = () => {
|
const MachinesPage = () => {
|
||||||
return (
|
return (
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
<PageTitle title={"لیست ماشین ها"} />
|
<PageTitle title={"لیست ماشین ها"} />
|
||||||
<MachinesList />
|
<MachinesList />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default MachinesPage;
|
export default MachinesPage;
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Typography } from "@mui/material";
|
||||||
|
|
||||||
const AlarmText = ({ isSource }) => {
|
const AlarmText = ({ isSource }) => {
|
||||||
if (isSource) return null;
|
if (isSource) return null;
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: 5,
|
top: 5,
|
||||||
left: 5,
|
left: 5,
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
border: "1px solid #ed0f02",
|
border: "1px solid #ed0f02",
|
||||||
backgroundColor: "#f19898",
|
backgroundColor: "#f19898",
|
||||||
py: 0.5,
|
py: 0.5,
|
||||||
px: 1,
|
px: 1,
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
opacity: 0.8,
|
opacity: 0.8,
|
||||||
boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
|
boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="caption" sx={{ fontWeight: "bold" }} color="#ed0f02">
|
<Typography variant="caption" sx={{ fontWeight: "bold" }} color="#ed0f02">
|
||||||
با کلیک بر روی مارکر موقعیت را انتخاب کنید
|
با کلیک بر روی مارکر موقعیت را انتخاب کنید
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AlarmText;
|
export default AlarmText;
|
||||||
|
|||||||
@@ -1,53 +1,53 @@
|
|||||||
import { Box, Button, TextField } from "@mui/material";
|
import { Box, Button, TextField } from "@mui/material";
|
||||||
|
|
||||||
const DataBox = ({ isSource, isDest, sourcePosition, destPosition, editingTarget, onEditSource, onEditDest }) => {
|
const DataBox = ({ isSource, isDest, sourcePosition, destPosition, editingTarget, onEditSource, onEditDest }) => {
|
||||||
if (!isSource) return null;
|
if (!isSource) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
bottom: 5,
|
bottom: 5,
|
||||||
left: 5,
|
left: 5,
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
border: "1px solid #e1e1e1",
|
border: "1px solid #e1e1e1",
|
||||||
padding: 1,
|
padding: 1,
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
opacity: 0.8,
|
opacity: 0.8,
|
||||||
gap: 1,
|
gap: 1,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
||||||
<TextField
|
<TextField
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
size="small"
|
size="small"
|
||||||
readOnly
|
readOnly
|
||||||
value={sourcePosition ? `${sourcePosition.lat.toFixed(6)}, ${sourcePosition.lng.toFixed(6)}` : ""}
|
value={sourcePosition ? `${sourcePosition.lat.toFixed(6)}, ${sourcePosition.lng.toFixed(6)}` : ""}
|
||||||
/>
|
/>
|
||||||
{isSource && isDest && (
|
{isSource && isDest && (
|
||||||
<Button variant="contained" color="success" size="small" onClick={onEditSource}>
|
<Button variant="contained" color="success" size="small" onClick={onEditSource}>
|
||||||
ویرایش مبدا
|
ویرایش مبدا
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{isDest && (
|
{isDest && (
|
||||||
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
readOnly
|
readOnly
|
||||||
value={destPosition ? `${destPosition.lat.toFixed(6)}, ${destPosition.lng.toFixed(6)}` : ""}
|
value={destPosition ? `${destPosition.lat.toFixed(6)}, ${destPosition.lng.toFixed(6)}` : ""}
|
||||||
/>
|
/>
|
||||||
<Button variant="contained" color="error" size="small" onClick={onEditDest}>
|
<Button variant="contained" color="error" size="small" onClick={onEditDest}>
|
||||||
ویرایش مقصد
|
ویرایش مقصد
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DataBox;
|
export default DataBox;
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Marker, Polyline, useMap } from "react-leaflet";
|
import { Marker, Polyline, useMap } from "react-leaflet";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import polyline from "@mapbox/polyline";
|
import polyline from "@mapbox/polyline";
|
||||||
import SourceIcon from "@/assets/images/source-icon.svg";
|
import SourceIcon from "@/assets/images/source-icon.svg";
|
||||||
import DestIcon from "@/assets/images/destination-icon.svg";
|
import DestIcon from "@/assets/images/destination-icon.svg";
|
||||||
|
|
||||||
const ShowRoute = ({ area }) => {
|
const ShowRoute = ({ area }) => {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const defaultIconSize = [35, 35];
|
const defaultIconSize = [35, 35];
|
||||||
|
|
||||||
const createCustomIcon = (size, iconUrl) => {
|
const createCustomIcon = (size, iconUrl) => {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: iconUrl,
|
iconUrl: iconUrl,
|
||||||
iconSize: size,
|
iconSize: size,
|
||||||
iconAnchor: [size[0] / 2, size[1]],
|
iconAnchor: [size[0] / 2, size[1]],
|
||||||
popupAnchor: [0, -size[1]],
|
popupAnchor: [0, -size[1]],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
useEffect(() => {
|
||||||
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
if (coords.length > 0) {
|
||||||
|
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
||||||
if (!area) return null;
|
}
|
||||||
const coords = polyline.decode(area, 6);
|
}, [area]);
|
||||||
|
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
||||||
if (coords.length === 0) return null;
|
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
||||||
|
|
||||||
const sourcePosition = coords[0];
|
if (!area) return null;
|
||||||
const destPosition = coords[coords.length - 1];
|
const coords = polyline.decode(area, 6);
|
||||||
useEffect(() => {
|
|
||||||
if (coords.length > 0) {
|
if (coords.length === 0) return null;
|
||||||
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
|
||||||
}
|
const sourcePosition = coords[0];
|
||||||
}, [area]);
|
const destPosition = coords[coords.length - 1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
||||||
<Marker position={sourcePosition} icon={sourceIcon} />
|
<Marker position={sourcePosition} icon={sourceIcon} />
|
||||||
<Marker position={destPosition} icon={destIcon} />
|
<Marker position={destPosition} icon={destIcon} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowRoute;
|
export default ShowRoute;
|
||||||
|
|||||||
@@ -1,219 +1,219 @@
|
|||||||
import { Marker, Polyline, useMapEvents } from "react-leaflet";
|
import { Marker, Polyline, useMapEvents } from "react-leaflet";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import polyline from "@mapbox/polyline";
|
import polyline from "@mapbox/polyline";
|
||||||
import SourceIcon from "@/assets/images/source-icon.svg";
|
import SourceIcon from "@/assets/images/source-icon.svg";
|
||||||
import PrevSourceIcon from "@/assets/images/prev-source-icon.svg";
|
import PrevSourceIcon from "@/assets/images/prev-source-icon.svg";
|
||||||
import PrevDestIcon from "@/assets/images/prev-destination-icon.svg";
|
import PrevDestIcon from "@/assets/images/prev-destination-icon.svg";
|
||||||
import DestIcon from "@/assets/images/destination-icon.svg";
|
import DestIcon from "@/assets/images/destination-icon.svg";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import DataBox from "./DataBox";
|
import DataBox from "./DataBox";
|
||||||
import AlarmText from "./AlarmText";
|
import AlarmText from "./AlarmText";
|
||||||
|
|
||||||
const Routing = ({ setArea, setLocations, locations, area }) => {
|
const Routing = ({ setArea, setLocations, locations, area }) => {
|
||||||
const mapPrevSourceMarker = useRef();
|
const mapPrevSourceMarker = useRef();
|
||||||
const mapPrevDestMarker = useRef();
|
const mapPrevDestMarker = useRef();
|
||||||
const mapRef = useRef(null);
|
const mapRef = useRef(null);
|
||||||
const defaultIconSize = [35, 35];
|
const defaultIconSize = [35, 35];
|
||||||
const [isSource, setIsSource] = useState(false);
|
const [isSource, setIsSource] = useState(false);
|
||||||
const [sourcePosition, setSourcePosition] = useState(null);
|
const [sourcePosition, setSourcePosition] = useState(null);
|
||||||
const [isDest, setIsDest] = useState(false);
|
const [isDest, setIsDest] = useState(false);
|
||||||
const [destPosition, setDestPosition] = useState(null);
|
const [destPosition, setDestPosition] = useState(null);
|
||||||
const [routeCoords, setRouteCoords] = useState([]);
|
const [routeCoords, setRouteCoords] = useState([]);
|
||||||
const [alternateCoords, setAlternateCoords] = useState([]);
|
const [alternateCoords, setAlternateCoords] = useState([]);
|
||||||
const [editingTarget, setEditingTarget] = useState(null);
|
const [editingTarget, setEditingTarget] = useState(null);
|
||||||
const [selectedRoute, setSelectedRoute] = useState(null);
|
const [selectedRoute, setSelectedRoute] = useState(null);
|
||||||
|
|
||||||
const createCustomIcon = (size, iconUrl) => {
|
const createCustomIcon = (size, iconUrl) => {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: iconUrl,
|
iconUrl: iconUrl,
|
||||||
iconSize: size,
|
iconSize: size,
|
||||||
iconAnchor: [size[0] / 2, size[1]],
|
iconAnchor: [size[0] / 2, size[1]],
|
||||||
popupAnchor: [0, -size[1]],
|
popupAnchor: [0, -size[1]],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultIcon = createCustomIcon(
|
const defaultIcon = createCustomIcon(
|
||||||
defaultIconSize,
|
defaultIconSize,
|
||||||
isSource && editingTarget !== "source" ? SourceIcon.src : PrevSourceIcon.src
|
isSource && editingTarget !== "source" ? SourceIcon.src : PrevSourceIcon.src
|
||||||
);
|
);
|
||||||
|
|
||||||
const prevDestIcon = createCustomIcon(
|
const prevDestIcon = createCustomIcon(
|
||||||
defaultIconSize,
|
defaultIconSize,
|
||||||
isDest && editingTarget !== "dest" ? DestIcon.src : PrevDestIcon.src
|
isDest && editingTarget !== "dest" ? DestIcon.src : PrevDestIcon.src
|
||||||
);
|
);
|
||||||
|
|
||||||
const isMovingSource = !isSource || editingTarget === "source";
|
const isMovingSource = !isSource || editingTarget === "source";
|
||||||
const isMovingDest = isSource && (!isDest || editingTarget === "dest");
|
const isMovingDest = isSource && (!isDest || editingTarget === "dest");
|
||||||
|
|
||||||
const map = useMapEvents({
|
const map = useMapEvents({
|
||||||
move(e) {
|
move(e) {
|
||||||
if (isMovingSource) mapPrevSourceMarker.current.setLatLng(e.target.getCenter());
|
if (isMovingSource) mapPrevSourceMarker.current.setLatLng(e.target.getCenter());
|
||||||
if (isMovingDest && mapPrevDestMarker.current) mapPrevDestMarker.current.setLatLng(e.target.getCenter());
|
if (isMovingDest && mapPrevDestMarker.current) mapPrevDestMarker.current.setLatLng(e.target.getCenter());
|
||||||
},
|
},
|
||||||
movestart() {
|
movestart() {
|
||||||
if (isMovingSource) mapPrevSourceMarker.current.setIcon(createCustomIcon([45, 45], PrevSourceIcon.src));
|
if (isMovingSource) mapPrevSourceMarker.current.setIcon(createCustomIcon([45, 45], PrevSourceIcon.src));
|
||||||
if (isMovingDest && mapPrevDestMarker.current)
|
if (isMovingDest && mapPrevDestMarker.current)
|
||||||
mapPrevDestMarker.current.setIcon(createCustomIcon([45, 45], PrevDestIcon.src));
|
mapPrevDestMarker.current.setIcon(createCustomIcon([45, 45], PrevDestIcon.src));
|
||||||
},
|
},
|
||||||
moveend() {
|
moveend() {
|
||||||
if (isMovingSource)
|
if (isMovingSource)
|
||||||
mapPrevSourceMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevSourceIcon.src));
|
mapPrevSourceMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevSourceIcon.src));
|
||||||
if (isMovingDest && mapPrevDestMarker.current)
|
if (isMovingDest && mapPrevDestMarker.current)
|
||||||
mapPrevDestMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevDestIcon.src));
|
mapPrevDestMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevDestIcon.src));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mapRef.current = map;
|
mapRef.current = map;
|
||||||
}, [map]);
|
}, [map]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (locations.length < 2) return;
|
if (locations.length < 2) return;
|
||||||
const restoredSource = { lat: locations[0].lat, lng: locations[0].lon };
|
const restoredSource = { lat: locations[0].lat, lng: locations[0].lon };
|
||||||
const restoredDest = { lat: locations[1].lat, lng: locations[1].lon };
|
const restoredDest = { lat: locations[1].lat, lng: locations[1].lon };
|
||||||
setSourcePosition(restoredSource);
|
setSourcePosition(restoredSource);
|
||||||
setDestPosition(restoredDest);
|
setDestPosition(restoredDest);
|
||||||
setIsSource(true);
|
setIsSource(true);
|
||||||
setIsDest(true);
|
setIsDest(true);
|
||||||
if (area) {
|
if (area) {
|
||||||
const decoded = polyline.decode(area, 6);
|
const decoded = polyline.decode(area, 6);
|
||||||
setRouteCoords(decoded);
|
setRouteCoords(decoded);
|
||||||
setSelectedRoute({ index: "main", coords: decoded });
|
setSelectedRoute({ index: "main", coords: decoded });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
mapRef.current?.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
mapRef.current?.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
fetchRoute(restoredSource, restoredDest);
|
fetchRoute(restoredSource, restoredDest);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchRoute = async (source, dest) => {
|
const fetchRoute = async (source, dest) => {
|
||||||
const locs = [
|
const locs = [
|
||||||
{ lat: source.lat, lon: source.lng },
|
{ lat: source.lat, lon: source.lng },
|
||||||
{ lat: dest.lat, lon: dest.lng },
|
{ lat: dest.lat, lon: dest.lng },
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://jouya.141.ir/api/router/drive", {
|
const response = await fetch("https://jouya.141.ir/api/router/drive", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ locations: locs }),
|
body: JSON.stringify({ locations: locs }),
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const shape = data.trip.legs[0].shape;
|
const shape = data.trip.legs[0].shape;
|
||||||
setLocations(locs);
|
setLocations(locs);
|
||||||
setArea(shape);
|
setArea(shape);
|
||||||
const decoded = polyline.decode(shape, 6);
|
const decoded = polyline.decode(shape, 6);
|
||||||
setRouteCoords(decoded);
|
setRouteCoords(decoded);
|
||||||
setSelectedRoute({ index: "main", coords: decoded });
|
setSelectedRoute({ index: "main", coords: decoded });
|
||||||
|
|
||||||
if (data.alternates?.length > 0) {
|
if (data.alternates?.length > 0) {
|
||||||
const decodedAlternates = data.alternates.map((alt) => polyline.decode(alt.trip.legs[0].shape, 6));
|
const decodedAlternates = data.alternates.map((alt) => polyline.decode(alt.trip.legs[0].shape, 6));
|
||||||
setAlternateCoords(decodedAlternates);
|
setAlternateCoords(decodedAlternates);
|
||||||
} else {
|
} else {
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
}
|
}
|
||||||
map.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
map.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Routing error:", error);
|
console.error("Routing error:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMarkerClick = async () => {
|
const handleMarkerClick = async () => {
|
||||||
if (!isSource || editingTarget === "source") {
|
if (!isSource || editingTarget === "source") {
|
||||||
const clickedPosition = mapPrevSourceMarker.current.getLatLng();
|
const clickedPosition = mapPrevSourceMarker.current.getLatLng();
|
||||||
setSourcePosition(clickedPosition);
|
setSourcePosition(clickedPosition);
|
||||||
setIsSource(true);
|
setIsSource(true);
|
||||||
setEditingTarget(null);
|
setEditingTarget(null);
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
|
|
||||||
if (editingTarget === "source" && destPosition) {
|
if (editingTarget === "source" && destPosition) {
|
||||||
await fetchRoute(clickedPosition, destPosition);
|
await fetchRoute(clickedPosition, destPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDestMarkerClick = async () => {
|
const handleDestMarkerClick = async () => {
|
||||||
if (!isDest || editingTarget === "dest") {
|
if (!isDest || editingTarget === "dest") {
|
||||||
const clickedPosition = mapPrevDestMarker.current.getLatLng();
|
const clickedPosition = mapPrevDestMarker.current.getLatLng();
|
||||||
setDestPosition(clickedPosition);
|
setDestPosition(clickedPosition);
|
||||||
setIsDest(true);
|
setIsDest(true);
|
||||||
setEditingTarget(null);
|
setEditingTarget(null);
|
||||||
|
|
||||||
await fetchRoute(sourcePosition, clickedPosition);
|
await fetchRoute(sourcePosition, clickedPosition);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditSource = () => {
|
const handleEditSource = () => {
|
||||||
setEditingTarget("source");
|
setEditingTarget("source");
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditDest = () => {
|
const handleEditDest = () => {
|
||||||
setEditingTarget("dest");
|
setEditingTarget("dest");
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectRoute = (index, coords) => {
|
const handleSelectRoute = (index, coords) => {
|
||||||
setSelectedRoute({ index, coords });
|
setSelectedRoute({ index, coords });
|
||||||
const encoded = polyline.encode(coords, 6);
|
const encoded = polyline.encode(coords, 6);
|
||||||
setArea(encoded);
|
setArea(encoded);
|
||||||
map.flyToBounds(coords, { padding: [50, 50], duration: 0.3 });
|
map.flyToBounds(coords, { padding: [50, 50], duration: 0.3 });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DataBox
|
<DataBox
|
||||||
isSource={isSource}
|
isSource={isSource}
|
||||||
isDest={isDest}
|
isDest={isDest}
|
||||||
sourcePosition={sourcePosition}
|
sourcePosition={sourcePosition}
|
||||||
destPosition={destPosition}
|
destPosition={destPosition}
|
||||||
editingTarget={editingTarget}
|
editingTarget={editingTarget}
|
||||||
onEditSource={handleEditSource}
|
onEditSource={handleEditSource}
|
||||||
onEditDest={handleEditDest}
|
onEditDest={handleEditDest}
|
||||||
/>
|
/>
|
||||||
<AlarmText isSource={isSource} />
|
<AlarmText isSource={isSource} />
|
||||||
<Marker
|
<Marker
|
||||||
position={sourcePosition || map.getCenter()}
|
position={sourcePosition || map.getCenter()}
|
||||||
ref={mapPrevSourceMarker}
|
ref={mapPrevSourceMarker}
|
||||||
eventHandlers={{ click: handleMarkerClick }}
|
eventHandlers={{ click: handleMarkerClick }}
|
||||||
icon={defaultIcon}
|
icon={defaultIcon}
|
||||||
/>
|
/>
|
||||||
{isSource && (
|
{isSource && (
|
||||||
<Marker
|
<Marker
|
||||||
position={destPosition || map.getCenter()}
|
position={destPosition || map.getCenter()}
|
||||||
ref={mapPrevDestMarker}
|
ref={mapPrevDestMarker}
|
||||||
eventHandlers={{ click: handleDestMarkerClick }}
|
eventHandlers={{ click: handleDestMarkerClick }}
|
||||||
icon={prevDestIcon}
|
icon={prevDestIcon}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{alternateCoords.map((coords, index) => (
|
{alternateCoords.map((coords, index) => (
|
||||||
<Polyline
|
<Polyline
|
||||||
key={`alternate-${index}-${selectedRoute?.index === index}`}
|
key={`alternate-${index}-${selectedRoute?.index === index}`}
|
||||||
positions={coords}
|
positions={coords}
|
||||||
color={selectedRoute?.index === index ? "#015688" : "#91B2C6"}
|
color={selectedRoute?.index === index ? "#015688" : "#91B2C6"}
|
||||||
weight={selectedRoute?.index === index ? 7 : 6}
|
weight={selectedRoute?.index === index ? 7 : 6}
|
||||||
opacity={selectedRoute?.index === index ? 1 : 0.7}
|
opacity={selectedRoute?.index === index ? 1 : 0.7}
|
||||||
eventHandlers={{ click: () => handleSelectRoute(index, coords) }}
|
eventHandlers={{ click: () => handleSelectRoute(index, coords) }}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{routeCoords.length > 0 && (
|
{routeCoords.length > 0 && (
|
||||||
<Polyline
|
<Polyline
|
||||||
key={`main-${selectedRoute?.index === "main"}`}
|
key={`main-${selectedRoute?.index === "main"}`}
|
||||||
positions={routeCoords}
|
positions={routeCoords}
|
||||||
color={selectedRoute?.index === "main" ? "#015688" : "#91B2C6"}
|
color={selectedRoute?.index === "main" ? "#015688" : "#91B2C6"}
|
||||||
weight={selectedRoute?.index === "main" ? 7 : 6}
|
weight={selectedRoute?.index === "main" ? 7 : 6}
|
||||||
opacity={selectedRoute?.index === "main" ? 1 : 0.7}
|
opacity={selectedRoute?.index === "main" ? 1 : 0.7}
|
||||||
eventHandlers={{ click: () => handleSelectRoute("main", routeCoords) }}
|
eventHandlers={{ click: () => handleSelectRoute("main", routeCoords) }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Routing;
|
export default Routing;
|
||||||
|
|||||||
@@ -1,57 +1,57 @@
|
|||||||
import { Box, Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
import { Box, Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import MapIcon from "@mui/icons-material/Map";
|
import MapIcon from "@mui/icons-material/Map";
|
||||||
import MapLayer from "@/core/components/MapLayer";
|
import MapLayer from "@/core/components/MapLayer";
|
||||||
import ShowRoute from "../../Actions/Create/Form/Area/Routing/ShowRoute";
|
import ShowRoute from "../../Actions/Create/Form/Area/Routing/ShowRoute";
|
||||||
|
|
||||||
const RouteDetail = ({ encoded_route }) => {
|
const RouteDetail = ({ encoded_route }) => {
|
||||||
const [openRouteDetailDialog, setOpenRouteDetailDialog] = useState(false);
|
const [openRouteDetailDialog, setOpenRouteDetailDialog] = useState(false);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tooltip title="مسیر انتخابی">
|
<Tooltip title="مسیر انتخابی">
|
||||||
<IconButton color="primary" onClick={() => setOpenRouteDetailDialog(true)}>
|
<IconButton color="primary" onClick={() => setOpenRouteDetailDialog(true)}>
|
||||||
<MapIcon />
|
<MapIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog
|
<Dialog
|
||||||
fullWidth
|
fullWidth
|
||||||
open={openRouteDetailDialog}
|
open={openRouteDetailDialog}
|
||||||
onClose={() => setOpenRouteDetailDialog(false)}
|
onClose={() => setOpenRouteDetailDialog(false)}
|
||||||
PaperProps={{
|
PaperProps={{
|
||||||
sx: {
|
sx: {
|
||||||
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
dir="rtl"
|
dir="rtl"
|
||||||
maxWidth={"sm"}
|
maxWidth={"sm"}
|
||||||
>
|
>
|
||||||
<DialogTitle sx={{ fontSize: "large" }}>مسیر انتخابی</DialogTitle>
|
<DialogTitle sx={{ fontSize: "large" }}>مسیر انتخابی</DialogTitle>
|
||||||
<Box sx={{ mx: 1, borderRadius: "5px" }}>
|
<Box sx={{ mx: 1, borderRadius: "5px" }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "300px",
|
height: "300px",
|
||||||
border: "1px solid #e1e1e1",
|
border: "1px solid #e1e1e1",
|
||||||
borderRadius: "5px",
|
borderRadius: "5px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MapLayer style={{ borderRadius: "4px" }}>
|
<MapLayer style={{ borderRadius: "4px" }}>
|
||||||
<ShowRoute area={encoded_route} />
|
<ShowRoute area={encoded_route} />
|
||||||
</MapLayer>
|
</MapLayer>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setOpenRouteDetailDialog(false)}
|
onClick={() => setOpenRouteDetailDialog(false)}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
autoFocus
|
autoFocus
|
||||||
>
|
>
|
||||||
بستن
|
بستن
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default RouteDetail;
|
export default RouteDetail;
|
||||||
|
|||||||
@@ -1,77 +1,77 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {
|
import {
|
||||||
EXPORT_MISSIONS_REPORT_TARADOD_COUNTRY_EXCEL_ACTIVITY,
|
EXPORT_MISSIONS_REPORT_TARADOD_COUNTRY_EXCEL_ACTIVITY,
|
||||||
EXPORT_MISSIONS_REPORT_TARADOD_PROVINCE_EXCEL_ACTIVITY,
|
EXPORT_MISSIONS_REPORT_TARADOD_PROVINCE_EXCEL_ACTIVITY,
|
||||||
} from "@/core/utils/routes";
|
} from "@/core/utils/routes";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import DescriptionIcon from "@mui/icons-material/Description";
|
import DescriptionIcon from "@mui/icons-material/Description";
|
||||||
import { Button, CircularProgress, IconButton, useMediaQuery } from "@mui/material";
|
import { Button, CircularProgress, IconButton, useMediaQuery } from "@mui/material";
|
||||||
import FileSaver from "file-saver";
|
import FileSaver from "file-saver";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
const PrintExcel = ({ table, filterData }) => {
|
const PrintExcel = ({ table, filterData }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const activeFilters = Object.entries(filterData).reduce((acc, [key, filter]) => {
|
const activeFilters = Object.entries(filterData).reduce((acc, [key, filter]) => {
|
||||||
if (filter.value) {
|
if (filter.value) {
|
||||||
acc.push({ id: filter.id, value: filter.value });
|
acc.push({ id: filter.id, value: filter.value });
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const filterParams = useMemo(() => {
|
const filterParams = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
activeFilters.length > 0 &&
|
activeFilters.length > 0 &&
|
||||||
activeFilters.map((filter, index) => {
|
activeFilters.map((filter, index) => {
|
||||||
params.set(`${filter.id}`, filter.value);
|
params.set(`${filter.id}`, filter.value);
|
||||||
});
|
});
|
||||||
return params;
|
return params;
|
||||||
}, [activeFilters]);
|
}, [activeFilters]);
|
||||||
|
|
||||||
const clickHandler = () => {
|
const clickHandler = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const CountryOrProvince = activeFilters.find((item) => item.id === "province_id");
|
const CountryOrProvince = activeFilters.find((item) => item.id === "province_id");
|
||||||
const requestUrl =
|
const requestUrl =
|
||||||
CountryOrProvince.value === "-1"
|
CountryOrProvince.value === "-1"
|
||||||
? EXPORT_MISSIONS_REPORT_TARADOD_COUNTRY_EXCEL_ACTIVITY
|
? EXPORT_MISSIONS_REPORT_TARADOD_COUNTRY_EXCEL_ACTIVITY
|
||||||
: EXPORT_MISSIONS_REPORT_TARADOD_PROVINCE_EXCEL_ACTIVITY;
|
: EXPORT_MISSIONS_REPORT_TARADOD_PROVINCE_EXCEL_ACTIVITY;
|
||||||
requestServer(`${requestUrl}?${filterParams}`, "get", {
|
requestServer(`${requestUrl}?${filterParams}`, "get", {
|
||||||
requestOptions: { responseType: "blob" },
|
requestOptions: { responseType: "blob" },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const filename = `خروجی کارتابل گزارشات گشت راهداری تاریخ_${moment().format("jYYYY_jMM_jDD")}.xlsx`;
|
const filename = `خروجی کارتابل گزارشات گشت راهداری تاریخ_${moment().format("jYYYY_jMM_jDD")}.xlsx`;
|
||||||
FileSaver.saveAs(response.data, filename);
|
FileSaver.saveAs(response.data, filename);
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isMobile ? (
|
{isMobile ? (
|
||||||
<IconButton aria-label="خروجی اکسل" color="success" onClick={clickHandler}>
|
<IconButton aria-label="خروجی اکسل" color="success" onClick={clickHandler}>
|
||||||
<DescriptionIcon sx={{ fontSize: "25px" }} />
|
<DescriptionIcon sx={{ fontSize: "25px" }} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
color="success"
|
color="success"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
size="small"
|
size="small"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
sx={{ textTransform: "unset", alignSelf: "center" }}
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <DescriptionIcon />}
|
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <DescriptionIcon />}
|
||||||
onClick={clickHandler}
|
onClick={clickHandler}
|
||||||
>
|
>
|
||||||
خروجی اکسل
|
خروجی اکسل
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default PrintExcel;
|
export default PrintExcel;
|
||||||
|
|||||||
@@ -1,138 +1,138 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
|
|
||||||
const TaradodReportLists = ({ data, specialFilter }) => {
|
const TaradodReportLists = ({ data, specialFilter }) => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "edare_name",
|
accessorKey: "edare_name",
|
||||||
header: "اداره کل",
|
header: "اداره کل",
|
||||||
id: "edare_name",
|
id: "edare_name",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "total",
|
accessorKey: "total",
|
||||||
header: "کل ماموریت ها",
|
header: "کل ماموریت ها",
|
||||||
id: "total",
|
id: "total",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "khareg_mahdode",
|
accessorKey: "khareg_mahdode",
|
||||||
header: "تردد خارج از محدوده",
|
header: "تردد خارج از محدوده",
|
||||||
id: "khareg_mahdode",
|
id: "khareg_mahdode",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "durations",
|
accessorKey: "durations",
|
||||||
header: "جمع ساعات ماموریت",
|
header: "جمع ساعات ماموریت",
|
||||||
id: "duration",
|
id: "duration",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "gps",
|
accessorKey: "gps",
|
||||||
header: "جمع ساعات gps",
|
header: "جمع ساعات gps",
|
||||||
id: "gps",
|
id: "gps",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "far_h",
|
accessorKey: "far_h",
|
||||||
header: "با فرایند ساعتی",
|
header: "با فرایند ساعتی",
|
||||||
id: "far_h",
|
id: "far_h",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "far_d",
|
accessorKey: "far_d",
|
||||||
header: "با فرایند روزانه",
|
header: "با فرایند روزانه",
|
||||||
id: "far_d",
|
id: "far_d",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "un_far_h",
|
accessorKey: "un_far_h",
|
||||||
header: "بدون فرایند ساعتی",
|
header: "بدون فرایند ساعتی",
|
||||||
id: "un_far_h",
|
id: "un_far_h",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "un_far_d",
|
accessorKey: "un_far_d",
|
||||||
header: "بدون فرایند روزانه",
|
header: "بدون فرایند روزانه",
|
||||||
id: "un_far_d",
|
id: "un_far_d",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "item",
|
accessorKey: "item",
|
||||||
header: "فعالیت روزانه",
|
header: "فعالیت روزانه",
|
||||||
id: "item",
|
id: "item",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "patrol",
|
accessorKey: "patrol",
|
||||||
header: "گشت راهداری",
|
header: "گشت راهداری",
|
||||||
id: "patrol",
|
id: "patrol",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
TableToolbar={Toolbar}
|
TableToolbar={Toolbar}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data.data}
|
data={data.data}
|
||||||
page_name={"roadMissionReport"}
|
page_name={"roadMissionReport"}
|
||||||
table_name={"roadMissionReportList"}
|
table_name={"roadMissionReportList"}
|
||||||
enablePagination={false}
|
enablePagination={false}
|
||||||
specialFilter={specialFilter}
|
specialFilter={specialFilter}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TaradodReportLists;
|
export default TaradodReportLists;
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
|
|
||||||
const FromDateController = ({ control }) => {
|
const FromDateController = ({ control }) => {
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="from_date"
|
name="from_date"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<MuiDatePicker
|
<MuiDatePicker
|
||||||
name="from_date"
|
name="from_date"
|
||||||
error={!!error}
|
error={!!error}
|
||||||
value={value}
|
value={value}
|
||||||
label={"تاریخ شروع (از تاریخ)"}
|
label={"تاریخ شروع (از تاریخ)"}
|
||||||
placeholder={"از تاریخ"}
|
placeholder={"از تاریخ"}
|
||||||
setFieldValue={(name, newValue) => {
|
setFieldValue={(name, newValue) => {
|
||||||
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
||||||
onChange(formattedDate); // Update the field value in react-hook-form
|
onChange(formattedDate); // Update the field value in react-hook-form
|
||||||
}}
|
}}
|
||||||
helperText={error ? error.message : null}
|
helperText={error ? error.message : null}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default FromDateController;
|
export default FromDateController;
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import { Button, Grid } from "@mui/material";
|
import { Button, Grid } from "@mui/material";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
import FromDateController from "./FromDateController";
|
import FromDateController from "./FromDateController";
|
||||||
import SelectProvince from "./SelectProvince";
|
import SelectProvince from "./SelectProvince";
|
||||||
import ToDateController from "./ToDateController";
|
import ToDateController from "./ToDateController";
|
||||||
|
|
||||||
const SearchReportField = ({ control, hasProvincesPermission }) => {
|
const SearchReportField = ({ control, hasProvincesPermission }) => {
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={2} sx={{ py: 2 }}>
|
<Grid container spacing={2} sx={{ py: 2 }}>
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<FromDateController control={control} />
|
<FromDateController control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<ToDateController control={control} />
|
<ToDateController control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
{hasProvincesPermission && (
|
{hasProvincesPermission && (
|
||||||
<Grid item xs={12} md={3}>
|
<Grid item xs={12} md={3}>
|
||||||
<SelectProvince control={control} />
|
<SelectProvince control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<Controller
|
<Controller
|
||||||
name="submitButton"
|
name="submitButton"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { value, onChange }, formState: { isSubmitting } }) => (
|
render={({ field: { value, onChange }, formState: { isSubmitting } }) => (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
size="medium"
|
size="medium"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
endIcon={<SearchIcon />}
|
endIcon={<SearchIcon />}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
{isSubmitting ? "درحال دریافت اطلاعات" : "جستجو"}
|
{isSubmitting ? "درحال دریافت اطلاعات" : "جستجو"}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SearchReportField;
|
export default SearchReportField;
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
import useProvinces from "@/lib/hooks/useProvince";
|
import useProvinces from "@/lib/hooks/useProvince";
|
||||||
import { FormControl, FormHelperText, InputLabel, MenuItem, Select } from "@mui/material";
|
import { FormControl, FormHelperText, InputLabel, MenuItem, Select } from "@mui/material";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
|
|
||||||
const SelectProvince = ({ control }) => {
|
const SelectProvince = ({ control }) => {
|
||||||
const { provinces, loadingProvinces, errorProvinces } = useProvinces();
|
const { provinces, loadingProvinces, errorProvinces } = useProvinces();
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="province_id"
|
name="province_id"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl error={!!error} size="small" fullWidth>
|
<FormControl error={!!error} size="small" fullWidth>
|
||||||
<InputLabel id="demo-error-label">استان</InputLabel>
|
<InputLabel id="demo-error-label">استان</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
{...field}
|
{...field}
|
||||||
labelId="demo-error-label"
|
labelId="demo-error-label"
|
||||||
id="province_id"
|
id="province_id"
|
||||||
value={loadingProvinces ? "loading" : field.value || ""}
|
value={loadingProvinces ? "loading" : field.value || ""}
|
||||||
label="استان"
|
label="استان"
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
>
|
>
|
||||||
{loadingProvinces ? (
|
{loadingProvinces ? (
|
||||||
<MenuItem value={"loading"}>در حال بارگذاری...</MenuItem>
|
<MenuItem value={"loading"}>در حال بارگذاری...</MenuItem>
|
||||||
) : errorProvinces ? (
|
) : errorProvinces ? (
|
||||||
<MenuItem value={"error"}>خطا در بارگذاری</MenuItem>
|
<MenuItem value={"error"}>خطا در بارگذاری</MenuItem>
|
||||||
) : (
|
) : (
|
||||||
[
|
[
|
||||||
<MenuItem key="-1" value={"-1"}>
|
<MenuItem key="-1" value={"-1"}>
|
||||||
کل کشور
|
کل کشور
|
||||||
</MenuItem>,
|
</MenuItem>,
|
||||||
...provinces.map((province) => (
|
...provinces.map((province) => (
|
||||||
<MenuItem key={province.id} value={province.id}>
|
<MenuItem key={province.id} value={province.id}>
|
||||||
{province.name_fa}
|
{province.name_fa}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)),
|
)),
|
||||||
]
|
]
|
||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
{error && <FormHelperText>{error.message}</FormHelperText>}
|
{error && <FormHelperText>{error.message}</FormHelperText>}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default SelectProvince;
|
export default SelectProvince;
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { Controller, useWatch } from "react-hook-form";
|
import { Controller, useWatch } from "react-hook-form";
|
||||||
|
|
||||||
const ToDateController = ({ control }) => {
|
const ToDateController = ({ control }) => {
|
||||||
const minDate = useWatch({ control, name: "from_date" });
|
const minDate = useWatch({ control, name: "from_date" });
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="date_to"
|
name="date_to"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<MuiDatePicker
|
<MuiDatePicker
|
||||||
name="date_to"
|
name="date_to"
|
||||||
minDate={minDate}
|
minDate={minDate}
|
||||||
maxDate={new Date()}
|
maxDate={new Date()}
|
||||||
error={!!error}
|
error={!!error}
|
||||||
value={value}
|
value={value}
|
||||||
label={"تاریخ پایان (تا تاریخ)"}
|
label={"تاریخ پایان (تا تاریخ)"}
|
||||||
placeholder={"تا تاریخ"}
|
placeholder={"تا تاریخ"}
|
||||||
setFieldValue={(name, newValue) => {
|
setFieldValue={(name, newValue) => {
|
||||||
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
||||||
onChange(formattedDate); // Update the field value in react-hook-form
|
onChange(formattedDate); // Update the field value in react-hook-form
|
||||||
}}
|
}}
|
||||||
helperText={error ? error.message : null}
|
helperText={error ? error.message : null}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default ToDateController;
|
export default ToDateController;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import SearchReportField from "./SearchReportField";
|
import SearchReportField from "./SearchReportField";
|
||||||
|
|
||||||
const SearchReportList = ({ handleSubmit, onSearchSubmit, control, hasProvincesPermission }) => {
|
const SearchReportList = ({ handleSubmit, onSearchSubmit, control, hasProvincesPermission }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledForm onSubmit={handleSubmit(onSearchSubmit)}>
|
<StyledForm onSubmit={handleSubmit(onSearchSubmit)}>
|
||||||
<SearchReportField control={control} hasProvincesPermission={hasProvincesPermission} />
|
<SearchReportField control={control} hasProvincesPermission={hasProvincesPermission} />
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default SearchReportList;
|
export default SearchReportList;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import PrintExcel from "./ExcelPrint";
|
import PrintExcel from "./ExcelPrint";
|
||||||
|
|
||||||
const Toolbar = ({ table, filterData, mutate }) => {
|
const Toolbar = ({ table, filterData, mutate }) => {
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
<PrintExcel table={table} filterData={filterData} />
|
<PrintExcel table={table} filterData={filterData} />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Toolbar;
|
export default Toolbar;
|
||||||
|
|||||||
@@ -1,142 +1,142 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import {
|
import {
|
||||||
GET_MISSIONS_REPORT_TARADOD_COUNTRY_ACTIVITY,
|
GET_MISSIONS_REPORT_TARADOD_COUNTRY_ACTIVITY,
|
||||||
GET_MISSIONS_REPORT_TARADOD_PROVINCE_ACTIVITY,
|
GET_MISSIONS_REPORT_TARADOD_PROVINCE_ACTIVITY,
|
||||||
} from "@/core/utils/routes";
|
} from "@/core/utils/routes";
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { LinearProgress, Stack } from "@mui/material";
|
import { LinearProgress, Stack } from "@mui/material";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import TaradodReportLists from "./MissionsReportLists";
|
import TaradodReportLists from "./MissionsReportLists";
|
||||||
import SearchReportList from "./Search";
|
import SearchReportList from "./Search";
|
||||||
|
|
||||||
const TaradodReportPage = () => {
|
const TaradodReportPage = () => {
|
||||||
const [data, setData] = useState(null);
|
const [data, setData] = useState(null);
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const requestServer = useRequest();
|
const requestServer = useRequest();
|
||||||
const [provinceId, setProvinceId] = useState(user.province_id || "-1");
|
const [provinceId, setProvinceId] = useState(user.province_id || "-1");
|
||||||
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
from_date: moment(new Date()).format("YYYY-MM-DD"),
|
from_date: moment(new Date()).format("YYYY-MM-DD"),
|
||||||
date_to: moment(new Date()).format("YYYY-MM-DD"),
|
date_to: moment(new Date()).format("YYYY-MM-DD"),
|
||||||
province_id: provinceId,
|
province_id: provinceId,
|
||||||
};
|
};
|
||||||
const defaultFilter = [
|
const defaultFilter = [
|
||||||
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
||||||
{ value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
{ value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
||||||
{ value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
{ value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
||||||
];
|
];
|
||||||
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const onSearchSubmit = async (data) => {
|
const onSearchSubmit = async (data) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set("from_date", `${data.from_date}`);
|
params.set("from_date", `${data.from_date}`);
|
||||||
params.set("date_to", `${data.date_to}`);
|
params.set("date_to", `${data.date_to}`);
|
||||||
setSpecialFilter([
|
setSpecialFilter([
|
||||||
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
||||||
{ value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
{ value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
||||||
{ value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
{ value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
||||||
]);
|
]);
|
||||||
if (data.province_id === "-1") {
|
if (data.province_id === "-1") {
|
||||||
try {
|
try {
|
||||||
// params.set("province_id", `${data.province_id}`);
|
// params.set("province_id", `${data.province_id}`);
|
||||||
const response = await requestServer(`${GET_MISSIONS_REPORT_TARADOD_COUNTRY_ACTIVITY}?${params}`);
|
const response = await requestServer(`${GET_MISSIONS_REPORT_TARADOD_COUNTRY_ACTIVITY}?${params}`);
|
||||||
const result = response.data.data;
|
const result = response.data.data;
|
||||||
const nationalReportForItem = result.activities.find((report) => report.province_id === "-1");
|
const nationalReportForItem = result.activities.find((report) => report.province_id === "-1");
|
||||||
const nationalReport = {
|
const nationalReport = {
|
||||||
edare_name: "کل کشور",
|
edare_name: "کل کشور",
|
||||||
...nationalReportForItem,
|
...nationalReportForItem,
|
||||||
};
|
};
|
||||||
|
|
||||||
setData({
|
setData({
|
||||||
data: [
|
data: [
|
||||||
nationalReport,
|
nationalReport,
|
||||||
...result.provinces.map((province) => {
|
...result.provinces.map((province) => {
|
||||||
const filteredReports = result.activities.find(
|
const filteredReports = result.activities.find(
|
||||||
(report) => report.province_id == province.id
|
(report) => report.province_id == province.id
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...filteredReports,
|
...filteredReports,
|
||||||
edare_name: province.name_fa,
|
edare_name: province.name_fa,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
filters: data,
|
filters: data,
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
params.set("province_id", `${data.province_id}`);
|
params.set("province_id", `${data.province_id}`);
|
||||||
const response = await requestServer(`${GET_MISSIONS_REPORT_TARADOD_PROVINCE_ACTIVITY}?${params}`);
|
const response = await requestServer(`${GET_MISSIONS_REPORT_TARADOD_PROVINCE_ACTIVITY}?${params}`);
|
||||||
const result = response.data.data;
|
const result = response.data.data;
|
||||||
|
|
||||||
const nationalReportForItem = result.activities.find((report) => report.city_id === "-1");
|
const nationalReportForItem = result.activities.find((report) => report.city_id === "-1");
|
||||||
|
|
||||||
const nationalReport = {
|
const nationalReport = {
|
||||||
...nationalReportForItem,
|
...nationalReportForItem,
|
||||||
edare_name: "کل استان",
|
edare_name: "کل استان",
|
||||||
};
|
};
|
||||||
setData({
|
setData({
|
||||||
data: [
|
data: [
|
||||||
nationalReport,
|
nationalReport,
|
||||||
...result.city.map((city) => {
|
...result.city.map((city) => {
|
||||||
const filteredReports = result.activities.find((report) => report.city_id == city.id);
|
const filteredReports = result.activities.find((report) => report.city_id == city.id);
|
||||||
return {
|
return {
|
||||||
edare_name: city.name_fa,
|
edare_name: city.name_fa,
|
||||||
...filteredReports,
|
...filteredReports,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
filters: data,
|
filters: data,
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!userPermissions) return;
|
if (!userPermissions) return;
|
||||||
onSearchSubmit(defaultValues);
|
onSearchSubmit(defaultValues);
|
||||||
}, [userPermissions]);
|
}, [userPermissions]);
|
||||||
|
|
||||||
const validationSchema = yup.object().shape({
|
const validationSchema = yup.object().shape({
|
||||||
from_date: yup
|
from_date: yup
|
||||||
.string()
|
.string()
|
||||||
.required("تاریخ شروع الزامی است!")
|
.required("تاریخ شروع الزامی است!")
|
||||||
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ شروع الزامی است!")
|
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ شروع الزامی است!")
|
||||||
.test("is-valid-date", "تاریخ شروع معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
.test("is-valid-date", "تاریخ شروع معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
||||||
date_to: yup
|
date_to: yup
|
||||||
.string()
|
.string()
|
||||||
.required("تاریخ پایان الزامی است!")
|
.required("تاریخ پایان الزامی است!")
|
||||||
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ پایان الزامی است!")
|
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ پایان الزامی است!")
|
||||||
.test("is-valid-date", "تاریخ پایان معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
.test("is-valid-date", "تاریخ پایان معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
||||||
province_id: yup.string().nullable(),
|
province_id: yup.string().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm({
|
const { control, handleSubmit } = useForm({
|
||||||
defaultValues,
|
defaultValues,
|
||||||
resolver: yupResolver(validationSchema),
|
resolver: yupResolver(validationSchema),
|
||||||
mode: "all",
|
mode: "all",
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
<PageTitle title={"کارتابل گزارش تردد ها"} />
|
<PageTitle title={"کارتابل گزارش تردد ها"} />
|
||||||
<SearchReportList
|
<SearchReportList
|
||||||
control={control}
|
control={control}
|
||||||
hasProvincesPermission={hasProvincesPermission}
|
hasProvincesPermission={hasProvincesPermission}
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
/>
|
/>
|
||||||
{!data ? <LinearProgress /> : <TaradodReportLists specialFilter={specialFilter} data={data} />}
|
{!data ? <LinearProgress /> : <TaradodReportLists specialFilter={specialFilter} data={data} />}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default TaradodReportPage;
|
export default TaradodReportPage;
|
||||||
|
|||||||
@@ -1,77 +1,77 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import {
|
import {
|
||||||
EXPORT_MISSIONS_REPORT_VIOLATION_COUNTRY_EXCEL_ACTIVITY,
|
EXPORT_MISSIONS_REPORT_VIOLATION_COUNTRY_EXCEL_ACTIVITY,
|
||||||
EXPORT_MISSIONS_REPORT_VIOLATION_PROVINCE_EXCEL_ACTIVITY,
|
EXPORT_MISSIONS_REPORT_VIOLATION_PROVINCE_EXCEL_ACTIVITY,
|
||||||
} from "@/core/utils/routes";
|
} from "@/core/utils/routes";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import DescriptionIcon from "@mui/icons-material/Description";
|
import DescriptionIcon from "@mui/icons-material/Description";
|
||||||
import { Button, CircularProgress, IconButton, useMediaQuery } from "@mui/material";
|
import { Button, CircularProgress, IconButton, useMediaQuery } from "@mui/material";
|
||||||
import FileSaver from "file-saver";
|
import FileSaver from "file-saver";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
const PrintExcel = ({ table, filterData }) => {
|
const PrintExcel = ({ table, filterData }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const activeFilters = Object.entries(filterData).reduce((acc, [key, filter]) => {
|
const activeFilters = Object.entries(filterData).reduce((acc, [key, filter]) => {
|
||||||
if (filter.value) {
|
if (filter.value) {
|
||||||
acc.push({ id: filter.id, value: filter.value });
|
acc.push({ id: filter.id, value: filter.value });
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const filterParams = useMemo(() => {
|
const filterParams = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
activeFilters.length > 0 &&
|
activeFilters.length > 0 &&
|
||||||
activeFilters.map((filter, index) => {
|
activeFilters.map((filter, index) => {
|
||||||
params.set(`${filter.id}`, filter.value);
|
params.set(`${filter.id}`, filter.value);
|
||||||
});
|
});
|
||||||
return params;
|
return params;
|
||||||
}, [activeFilters]);
|
}, [activeFilters]);
|
||||||
|
|
||||||
const clickHandler = () => {
|
const clickHandler = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const CountryOrProvince = activeFilters.find((item) => item.id === "province_id");
|
const CountryOrProvince = activeFilters.find((item) => item.id === "province_id");
|
||||||
const requestUrl =
|
const requestUrl =
|
||||||
CountryOrProvince.value === "-1"
|
CountryOrProvince.value === "-1"
|
||||||
? EXPORT_MISSIONS_REPORT_VIOLATION_COUNTRY_EXCEL_ACTIVITY
|
? EXPORT_MISSIONS_REPORT_VIOLATION_COUNTRY_EXCEL_ACTIVITY
|
||||||
: EXPORT_MISSIONS_REPORT_VIOLATION_PROVINCE_EXCEL_ACTIVITY;
|
: EXPORT_MISSIONS_REPORT_VIOLATION_PROVINCE_EXCEL_ACTIVITY;
|
||||||
requestServer(`${requestUrl}?${filterParams}`, "get", {
|
requestServer(`${requestUrl}?${filterParams}`, "get", {
|
||||||
requestOptions: { responseType: "blob" },
|
requestOptions: { responseType: "blob" },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const filename = `خروجی کارتابل گزارشات گشت راهداری تاریخ_${moment().format("jYYYY_jMM_jDD")}.xlsx`;
|
const filename = `خروجی کارتابل گزارشات گشت راهداری تاریخ_${moment().format("jYYYY_jMM_jDD")}.xlsx`;
|
||||||
FileSaver.saveAs(response.data, filename);
|
FileSaver.saveAs(response.data, filename);
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isMobile ? (
|
{isMobile ? (
|
||||||
<IconButton aria-label="خروجی اکسل" color="success" onClick={clickHandler}>
|
<IconButton aria-label="خروجی اکسل" color="success" onClick={clickHandler}>
|
||||||
<DescriptionIcon sx={{ fontSize: "25px" }} />
|
<DescriptionIcon sx={{ fontSize: "25px" }} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
color="success"
|
color="success"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
size="small"
|
size="small"
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
sx={{ textTransform: "unset", alignSelf: "center" }}
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <DescriptionIcon />}
|
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <DescriptionIcon />}
|
||||||
onClick={clickHandler}
|
onClick={clickHandler}
|
||||||
>
|
>
|
||||||
خروجی اکسل
|
خروجی اکسل
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default PrintExcel;
|
export default PrintExcel;
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
|
|
||||||
const FromDateController = ({ control }) => {
|
const FromDateController = ({ control }) => {
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="from_date"
|
name="from_date"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<MuiDatePicker
|
<MuiDatePicker
|
||||||
name="from_date"
|
name="from_date"
|
||||||
error={!!error}
|
error={!!error}
|
||||||
value={value}
|
value={value}
|
||||||
label={"تاریخ شروع (از تاریخ)"}
|
label={"تاریخ شروع (از تاریخ)"}
|
||||||
placeholder={"از تاریخ"}
|
placeholder={"از تاریخ"}
|
||||||
setFieldValue={(name, newValue) => {
|
setFieldValue={(name, newValue) => {
|
||||||
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
||||||
onChange(formattedDate); // Update the field value in react-hook-form
|
onChange(formattedDate); // Update the field value in react-hook-form
|
||||||
}}
|
}}
|
||||||
helperText={error ? error.message : null}
|
helperText={error ? error.message : null}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default FromDateController;
|
export default FromDateController;
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import { Button, Grid } from "@mui/material";
|
import { Button, Grid } from "@mui/material";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
import FromDateController from "./FromDateController";
|
import FromDateController from "./FromDateController";
|
||||||
import SelectProvince from "./SelectProvince";
|
import SelectProvince from "./SelectProvince";
|
||||||
import ToDateController from "./ToDateController";
|
import ToDateController from "./ToDateController";
|
||||||
|
|
||||||
const SearchReportField = ({ control, hasProvincesPermission }) => {
|
const SearchReportField = ({ control, hasProvincesPermission }) => {
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={2} sx={{ py: 2 }}>
|
<Grid container spacing={2} sx={{ py: 2 }}>
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<FromDateController control={control} />
|
<FromDateController control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<ToDateController control={control} />
|
<ToDateController control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
{hasProvincesPermission && (
|
{hasProvincesPermission && (
|
||||||
<Grid item xs={12} md={3}>
|
<Grid item xs={12} md={3}>
|
||||||
<SelectProvince control={control} />
|
<SelectProvince control={control} />
|
||||||
</Grid>
|
</Grid>
|
||||||
)}
|
)}
|
||||||
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
<Grid item xs={12} md={hasProvincesPermission ? 3 : 4}>
|
||||||
<Controller
|
<Controller
|
||||||
name="submitButton"
|
name="submitButton"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { value, onChange }, formState: { isSubmitting } }) => (
|
render={({ field: { value, onChange }, formState: { isSubmitting } }) => (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
size="medium"
|
size="medium"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
endIcon={<SearchIcon />}
|
endIcon={<SearchIcon />}
|
||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
{isSubmitting ? "درحال دریافت اطلاعات" : "جستجو"}
|
{isSubmitting ? "درحال دریافت اطلاعات" : "جستجو"}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SearchReportField;
|
export default SearchReportField;
|
||||||
|
|||||||
@@ -1,45 +1,45 @@
|
|||||||
import useProvinces from "@/lib/hooks/useProvince";
|
import useProvinces from "@/lib/hooks/useProvince";
|
||||||
import { FormControl, FormHelperText, InputLabel, MenuItem, Select } from "@mui/material";
|
import { FormControl, FormHelperText, InputLabel, MenuItem, Select } from "@mui/material";
|
||||||
import { Controller } from "react-hook-form";
|
import { Controller } from "react-hook-form";
|
||||||
|
|
||||||
const SelectProvince = ({ control }) => {
|
const SelectProvince = ({ control }) => {
|
||||||
const { provinces, loadingProvinces, errorProvinces } = useProvinces();
|
const { provinces, loadingProvinces, errorProvinces } = useProvinces();
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="province_id"
|
name="province_id"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl error={!!error} size="small" fullWidth>
|
<FormControl error={!!error} size="small" fullWidth>
|
||||||
<InputLabel id="demo-error-label">استان</InputLabel>
|
<InputLabel id="demo-error-label">استان</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
{...field}
|
{...field}
|
||||||
labelId="demo-error-label"
|
labelId="demo-error-label"
|
||||||
id="province_id"
|
id="province_id"
|
||||||
value={loadingProvinces ? "loading" : field.value || ""}
|
value={loadingProvinces ? "loading" : field.value || ""}
|
||||||
label="استان"
|
label="استان"
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
>
|
>
|
||||||
{loadingProvinces ? (
|
{loadingProvinces ? (
|
||||||
<MenuItem value={"loading"}>در حال بارگذاری...</MenuItem>
|
<MenuItem value={"loading"}>در حال بارگذاری...</MenuItem>
|
||||||
) : errorProvinces ? (
|
) : errorProvinces ? (
|
||||||
<MenuItem value={"error"}>خطا در بارگذاری</MenuItem>
|
<MenuItem value={"error"}>خطا در بارگذاری</MenuItem>
|
||||||
) : (
|
) : (
|
||||||
[
|
[
|
||||||
<MenuItem key="-1" value={"-1"}>
|
<MenuItem key="-1" value={"-1"}>
|
||||||
کل کشور
|
کل کشور
|
||||||
</MenuItem>,
|
</MenuItem>,
|
||||||
...provinces.map((province) => (
|
...provinces.map((province) => (
|
||||||
<MenuItem key={province.id} value={province.id}>
|
<MenuItem key={province.id} value={province.id}>
|
||||||
{province.name_fa}
|
{province.name_fa}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)),
|
)),
|
||||||
]
|
]
|
||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
{error && <FormHelperText>{error.message}</FormHelperText>}
|
{error && <FormHelperText>{error.message}</FormHelperText>}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default SelectProvince;
|
export default SelectProvince;
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { Controller, useWatch } from "react-hook-form";
|
import { Controller, useWatch } from "react-hook-form";
|
||||||
|
|
||||||
const ToDateController = ({ control }) => {
|
const ToDateController = ({ control }) => {
|
||||||
const minDate = useWatch({ control, name: "from_date" });
|
const minDate = useWatch({ control, name: "from_date" });
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name="date_to"
|
name="date_to"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<MuiDatePicker
|
<MuiDatePicker
|
||||||
name="date_to"
|
name="date_to"
|
||||||
minDate={minDate}
|
minDate={minDate}
|
||||||
maxDate={new Date()}
|
maxDate={new Date()}
|
||||||
error={!!error}
|
error={!!error}
|
||||||
value={value}
|
value={value}
|
||||||
label={"تاریخ شروع (تا تاریخ)"}
|
label={"تاریخ شروع (تا تاریخ)"}
|
||||||
placeholder={"تا تاریخ"}
|
placeholder={"تا تاریخ"}
|
||||||
setFieldValue={(name, newValue) => {
|
setFieldValue={(name, newValue) => {
|
||||||
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
const formattedDate = moment(new Date(newValue)).locale("en").format("YYYY-MM-DD");
|
||||||
onChange(formattedDate); // Update the field value in react-hook-form
|
onChange(formattedDate); // Update the field value in react-hook-form
|
||||||
}}
|
}}
|
||||||
helperText={error ? error.message : null}
|
helperText={error ? error.message : null}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default ToDateController;
|
export default ToDateController;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import SearchReportField from "./SearchReportField";
|
import SearchReportField from "./SearchReportField";
|
||||||
|
|
||||||
const SearchReportList = ({ handleSubmit, onSearchSubmit, control, hasProvincesPermission }) => {
|
const SearchReportList = ({ handleSubmit, onSearchSubmit, control, hasProvincesPermission }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledForm onSubmit={handleSubmit(onSearchSubmit)}>
|
<StyledForm onSubmit={handleSubmit(onSearchSubmit)}>
|
||||||
<SearchReportField control={control} hasProvincesPermission={hasProvincesPermission} />
|
<SearchReportField control={control} hasProvincesPermission={hasProvincesPermission} />
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default SearchReportList;
|
export default SearchReportList;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import PrintExcel from "./ExcelPrint";
|
import PrintExcel from "./ExcelPrint";
|
||||||
|
|
||||||
const Toolbar = ({ table, filterData, mutate }) => {
|
const Toolbar = ({ table, filterData, mutate }) => {
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", gap: 1 }}>
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
<PrintExcel table={table} filterData={filterData} />
|
<PrintExcel table={table} filterData={filterData} />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Toolbar;
|
export default Toolbar;
|
||||||
|
|||||||
@@ -1,98 +1,98 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
|
|
||||||
const ViolationsReportsList = ({ data, specialFilter }) => {
|
const ViolationsReportsList = ({ data, specialFilter }) => {
|
||||||
const columns = useMemo(() => {
|
const columns = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
accessorKey: "edare_name",
|
accessorKey: "edare_name",
|
||||||
header: "اداره کل",
|
header: "اداره کل",
|
||||||
id: "edare_name",
|
id: "edare_name",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "text",
|
datatype: "text",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "total",
|
accessorKey: "total",
|
||||||
header: "کل تخلفات",
|
header: "کل تخلفات",
|
||||||
id: "total",
|
id: "total",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "done",
|
accessorKey: "done",
|
||||||
header: "اقدام شده",
|
header: "اقدام شده",
|
||||||
id: "done",
|
id: "done",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "undone",
|
accessorKey: "undone",
|
||||||
header: "اقدام نشده",
|
header: "اقدام نشده",
|
||||||
id: "un_done",
|
id: "un_done",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "gps",
|
accessorKey: "gps",
|
||||||
header: "GPS",
|
header: "GPS",
|
||||||
id: "gps",
|
id: "gps",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "herasat",
|
accessorKey: "herasat",
|
||||||
header: "ثبت حراست",
|
header: "ثبت حراست",
|
||||||
id: "herasat",
|
id: "herasat",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "mil_gps",
|
accessorKey: "mil_gps",
|
||||||
header: "کیلومتر GPS",
|
header: "کیلومتر GPS",
|
||||||
id: "mil_gps",
|
id: "mil_gps",
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
grow: false,
|
grow: false,
|
||||||
size: 50,
|
size: 50,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
||||||
<DataTableWithAuth
|
<DataTableWithAuth
|
||||||
TableToolbar={Toolbar}
|
TableToolbar={Toolbar}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data.data}
|
data={data.data}
|
||||||
page_name={"roadMissionReport"}
|
page_name={"roadMissionReport"}
|
||||||
table_name={"roadMissionReportList"}
|
table_name={"roadMissionReportList"}
|
||||||
enablePagination={false}
|
enablePagination={false}
|
||||||
specialFilter={specialFilter}
|
specialFilter={specialFilter}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ViolationsReportsList;
|
export default ViolationsReportsList;
|
||||||
|
|||||||
@@ -1,141 +1,141 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import PageTitle from "@/core/components/PageTitle";
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
import {
|
import {
|
||||||
GET_MISSIONS_REPORT_VIOLATION_COUNTRY_ACTIVITY,
|
GET_MISSIONS_REPORT_VIOLATION_COUNTRY_ACTIVITY,
|
||||||
GET_MISSIONS_REPORT_VIOLATION_PROVINCE_ACTIVITY,
|
GET_MISSIONS_REPORT_VIOLATION_PROVINCE_ACTIVITY,
|
||||||
} from "@/core/utils/routes";
|
} from "@/core/utils/routes";
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import { usePermissions } from "@/lib/hooks/usePermissions";
|
import { usePermissions } from "@/lib/hooks/usePermissions";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import { LinearProgress, Stack } from "@mui/material";
|
import { LinearProgress, Stack } from "@mui/material";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import ViolationsReportsList from "./ViolationsReportsList";
|
import ViolationsReportsList from "./ViolationsReportsList";
|
||||||
import SearchReportList from "./Search";
|
import SearchReportList from "./Search";
|
||||||
|
|
||||||
const ViolationsReportsPage = () => {
|
const ViolationsReportsPage = () => {
|
||||||
const [data, setData] = useState(null);
|
const [data, setData] = useState(null);
|
||||||
const { data: userPermissions } = usePermissions();
|
const { data: userPermissions } = usePermissions();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const requestServer = useRequest();
|
const requestServer = useRequest();
|
||||||
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
const hasProvincesPermission = userPermissions?.includes("mission-report-country");
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
from_date: moment(new Date()).format("YYYY-MM-DD"),
|
from_date: moment(new Date()).format("YYYY-MM-DD"),
|
||||||
date_to: moment(new Date()).format("YYYY-MM-DD"),
|
date_to: moment(new Date()).format("YYYY-MM-DD"),
|
||||||
province_id: user.province_id || "-1",
|
province_id: user.province_id || "-1",
|
||||||
};
|
};
|
||||||
const defaultFilter = [
|
const defaultFilter = [
|
||||||
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
{ value: `${defaultValues.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
||||||
{ value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
{ value: `${defaultValues.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
||||||
{ value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
{ value: `${defaultValues.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
||||||
];
|
];
|
||||||
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
const [specialFilter, setSpecialFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const onSearchSubmit = async (data) => {
|
const onSearchSubmit = async (data) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set("from_date", `${data.from_date}`);
|
params.set("from_date", `${data.from_date}`);
|
||||||
params.set("date_to", `${data.date_to}`);
|
params.set("date_to", `${data.date_to}`);
|
||||||
setSpecialFilter([
|
setSpecialFilter([
|
||||||
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
{ value: `${data.province_id}`, datatype: "numeric", id: "province_id", fn: "equals" },
|
||||||
{ value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
{ value: `${data.from_date}`, datatype: "date", id: "from_date", fn: "between" },
|
||||||
{ value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
{ value: `${data.date_to}`, datatype: "date", id: "date_to", fn: "between" },
|
||||||
]);
|
]);
|
||||||
if (data.province_id === "-1") {
|
if (data.province_id === "-1") {
|
||||||
try {
|
try {
|
||||||
// params.set("province_id", `${data.province_id}`);
|
// params.set("province_id", `${data.province_id}`);
|
||||||
const response = await requestServer(`${GET_MISSIONS_REPORT_VIOLATION_COUNTRY_ACTIVITY}?${params}`);
|
const response = await requestServer(`${GET_MISSIONS_REPORT_VIOLATION_COUNTRY_ACTIVITY}?${params}`);
|
||||||
const result = response.data.data;
|
const result = response.data.data;
|
||||||
const nationalReportForItem = result.activities.find((report) => report.province_id === "-1");
|
const nationalReportForItem = result.activities.find((report) => report.province_id === "-1");
|
||||||
const nationalReport = {
|
const nationalReport = {
|
||||||
edare_name: "کل کشور",
|
edare_name: "کل کشور",
|
||||||
...nationalReportForItem,
|
...nationalReportForItem,
|
||||||
};
|
};
|
||||||
|
|
||||||
setData({
|
setData({
|
||||||
data: [
|
data: [
|
||||||
nationalReport,
|
nationalReport,
|
||||||
...result.provinces.map((province) => {
|
...result.provinces.map((province) => {
|
||||||
const filteredReports = result.activities.find(
|
const filteredReports = result.activities.find(
|
||||||
(report) => report.province_id == province.id
|
(report) => report.province_id == province.id
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...filteredReports,
|
...filteredReports,
|
||||||
edare_name: province.name_fa,
|
edare_name: province.name_fa,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
filters: data,
|
filters: data,
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
params.set("province_id", `${data.province_id}`);
|
params.set("province_id", `${data.province_id}`);
|
||||||
const response = await requestServer(`${GET_MISSIONS_REPORT_VIOLATION_PROVINCE_ACTIVITY}?${params}`);
|
const response = await requestServer(`${GET_MISSIONS_REPORT_VIOLATION_PROVINCE_ACTIVITY}?${params}`);
|
||||||
const result = response.data.data;
|
const result = response.data.data;
|
||||||
|
|
||||||
const nationalReportForItem = result.activities.find((report) => report.city_id === "-1");
|
const nationalReportForItem = result.activities.find((report) => report.city_id === "-1");
|
||||||
|
|
||||||
const nationalReport = {
|
const nationalReport = {
|
||||||
...nationalReportForItem,
|
...nationalReportForItem,
|
||||||
edare_name: "کل استان",
|
edare_name: "کل استان",
|
||||||
};
|
};
|
||||||
setData({
|
setData({
|
||||||
data: [
|
data: [
|
||||||
nationalReport,
|
nationalReport,
|
||||||
...result.city.map((city) => {
|
...result.city.map((city) => {
|
||||||
const filteredReports = result.activities.find((report) => report.city_id == city.id);
|
const filteredReports = result.activities.find((report) => report.city_id == city.id);
|
||||||
return {
|
return {
|
||||||
edare_name: city.name_fa,
|
edare_name: city.name_fa,
|
||||||
...filteredReports,
|
...filteredReports,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
filters: data,
|
filters: data,
|
||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!userPermissions) return;
|
if (!userPermissions) return;
|
||||||
onSearchSubmit(defaultValues);
|
onSearchSubmit(defaultValues);
|
||||||
}, [userPermissions]);
|
}, [userPermissions]);
|
||||||
|
|
||||||
const validationSchema = yup.object().shape({
|
const validationSchema = yup.object().shape({
|
||||||
from_date: yup
|
from_date: yup
|
||||||
.string()
|
.string()
|
||||||
.required("تاریخ شروع الزامی است!")
|
.required("تاریخ شروع الزامی است!")
|
||||||
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ شروع الزامی است!")
|
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ شروع الزامی است!")
|
||||||
.test("is-valid-date", "تاریخ شروع معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
.test("is-valid-date", "تاریخ شروع معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
||||||
date_to: yup
|
date_to: yup
|
||||||
.string()
|
.string()
|
||||||
.required("تاریخ پایان الزامی است!")
|
.required("تاریخ پایان الزامی است!")
|
||||||
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ پایان الزامی است!")
|
.matches(/^\d{4}-\d{2}-\d{2}$/, "تاریخ پایان الزامی است!")
|
||||||
.test("is-valid-date", "تاریخ پایان معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
.test("is-valid-date", "تاریخ پایان معتبر نیست!", (value) => moment(value, "YYYY-MM-DD", true).isValid()),
|
||||||
province_id: yup.string().nullable(),
|
province_id: yup.string().nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm({
|
const { control, handleSubmit } = useForm({
|
||||||
defaultValues,
|
defaultValues,
|
||||||
resolver: yupResolver(validationSchema),
|
resolver: yupResolver(validationSchema),
|
||||||
mode: "all",
|
mode: "all",
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
<PageTitle title={"کارتابل گزارش ماموریت"} />
|
<PageTitle title={"کارتابل گزارش ماموریت"} />
|
||||||
<SearchReportList
|
<SearchReportList
|
||||||
control={control}
|
control={control}
|
||||||
hasProvincesPermission={hasProvincesPermission}
|
hasProvincesPermission={hasProvincesPermission}
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
onSearchSubmit={onSearchSubmit}
|
onSearchSubmit={onSearchSubmit}
|
||||||
/>
|
/>
|
||||||
{!data ? <LinearProgress /> : <ViolationsReportsList specialFilter={specialFilter} data={data} />}
|
{!data ? <LinearProgress /> : <ViolationsReportsList specialFilter={specialFilter} data={data} />}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default ViolationsReportsPage;
|
export default ViolationsReportsPage;
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Marker, Polyline, useMap } from "react-leaflet";
|
import { Marker, Polyline, useMap } from "react-leaflet";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import polyline from "@mapbox/polyline";
|
import polyline from "@mapbox/polyline";
|
||||||
import SourceIcon from "@/assets/images/source-icon.svg";
|
import SourceIcon from "@/assets/images/source-icon.svg";
|
||||||
import DestIcon from "@/assets/images/destination-icon.svg";
|
import DestIcon from "@/assets/images/destination-icon.svg";
|
||||||
|
|
||||||
const ShowRoute = ({ area }) => {
|
const ShowRoute = ({ area }) => {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const defaultIconSize = [35, 35];
|
const defaultIconSize = [35, 35];
|
||||||
|
|
||||||
const createCustomIcon = (size, iconUrl) => {
|
const createCustomIcon = (size, iconUrl) => {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: iconUrl,
|
iconUrl: iconUrl,
|
||||||
iconSize: size,
|
iconSize: size,
|
||||||
iconAnchor: [size[0] / 2, size[1]],
|
iconAnchor: [size[0] / 2, size[1]],
|
||||||
popupAnchor: [0, -size[1]],
|
popupAnchor: [0, -size[1]],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
useEffect(() => {
|
||||||
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
if (coords.length > 0) {
|
||||||
|
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
||||||
if (!area) return null;
|
}
|
||||||
const coords = polyline.decode(area, 6);
|
}, [area]);
|
||||||
|
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
||||||
if (coords.length === 0) return null;
|
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
||||||
|
|
||||||
const sourcePosition = coords[0];
|
if (!area) return null;
|
||||||
const destPosition = coords[coords.length - 1];
|
const coords = polyline.decode(area, 6);
|
||||||
useEffect(() => {
|
|
||||||
if (coords.length > 0) {
|
if (coords.length === 0) return null;
|
||||||
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
|
||||||
}
|
const sourcePosition = coords[0];
|
||||||
}, [area]);
|
const destPosition = coords[coords.length - 1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
||||||
<Marker position={sourcePosition} icon={sourceIcon} />
|
<Marker position={sourcePosition} icon={sourceIcon} />
|
||||||
<Marker position={destPosition} icon={destIcon} />
|
<Marker position={destPosition} icon={destIcon} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowRoute;
|
export default ShowRoute;
|
||||||
|
|||||||
@@ -1,57 +1,57 @@
|
|||||||
import { Box, Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
import { Box, Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import MapIcon from "@mui/icons-material/Map";
|
import MapIcon from "@mui/icons-material/Map";
|
||||||
import MapLayer from "@/core/components/MapLayer";
|
import MapLayer from "@/core/components/MapLayer";
|
||||||
import ShowRoute from "./ShowRoute";
|
import ShowRoute from "./ShowRoute";
|
||||||
|
|
||||||
const RouteDetail = ({ encoded_route }) => {
|
const RouteDetail = ({ encoded_route }) => {
|
||||||
const [openRouteDetailDialog, setOpenRouteDetailDialog] = useState(false);
|
const [openRouteDetailDialog, setOpenRouteDetailDialog] = useState(false);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tooltip title="مسیر انتخابی">
|
<Tooltip title="مسیر انتخابی">
|
||||||
<IconButton color="primary" onClick={() => setOpenRouteDetailDialog(true)}>
|
<IconButton color="primary" onClick={() => setOpenRouteDetailDialog(true)}>
|
||||||
<MapIcon />
|
<MapIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog
|
<Dialog
|
||||||
fullWidth
|
fullWidth
|
||||||
open={openRouteDetailDialog}
|
open={openRouteDetailDialog}
|
||||||
onClose={() => setOpenRouteDetailDialog(false)}
|
onClose={() => setOpenRouteDetailDialog(false)}
|
||||||
PaperProps={{
|
PaperProps={{
|
||||||
sx: {
|
sx: {
|
||||||
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
dir="rtl"
|
dir="rtl"
|
||||||
maxWidth={"sm"}
|
maxWidth={"sm"}
|
||||||
>
|
>
|
||||||
<DialogTitle sx={{ fontSize: "large" }}>مسیر انتخابی</DialogTitle>
|
<DialogTitle sx={{ fontSize: "large" }}>مسیر انتخابی</DialogTitle>
|
||||||
<Box sx={{ mx: 1, borderRadius: "5px" }}>
|
<Box sx={{ mx: 1, borderRadius: "5px" }}>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "300px",
|
height: "300px",
|
||||||
border: "1px solid #e1e1e1",
|
border: "1px solid #e1e1e1",
|
||||||
borderRadius: "5px",
|
borderRadius: "5px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MapLayer style={{ borderRadius: "4px" }}>
|
<MapLayer style={{ borderRadius: "4px" }}>
|
||||||
<ShowRoute area={encoded_route} />
|
<ShowRoute area={encoded_route} />
|
||||||
</MapLayer>
|
</MapLayer>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setOpenRouteDetailDialog(false)}
|
onClick={() => setOpenRouteDetailDialog(false)}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
autoFocus
|
autoFocus
|
||||||
>
|
>
|
||||||
بستن
|
بستن
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default RouteDetail;
|
export default RouteDetail;
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Typography } from "@mui/material";
|
||||||
|
|
||||||
const AlarmText = ({ isSource }) => {
|
const AlarmText = ({ isSource }) => {
|
||||||
if (isSource) return null;
|
if (isSource) return null;
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
top: 5,
|
top: 5,
|
||||||
left: 5,
|
left: 5,
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
border: "1px solid #ed0f02",
|
border: "1px solid #ed0f02",
|
||||||
backgroundColor: "#f19898",
|
backgroundColor: "#f19898",
|
||||||
py: 0.5,
|
py: 0.5,
|
||||||
px: 1,
|
px: 1,
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
opacity: 0.8,
|
opacity: 0.8,
|
||||||
boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
|
boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="caption" sx={{ fontWeight: "bold" }} color="#ed0f02">
|
<Typography variant="caption" sx={{ fontWeight: "bold" }} color="#ed0f02">
|
||||||
با کلیک بر روی مارکر موقعیت را انتخاب کنید
|
با کلیک بر روی مارکر موقعیت را انتخاب کنید
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AlarmText;
|
export default AlarmText;
|
||||||
|
|||||||
@@ -1,53 +1,53 @@
|
|||||||
import { Box, Button, TextField } from "@mui/material";
|
import { Box, Button, TextField } from "@mui/material";
|
||||||
|
|
||||||
const DataBox = ({ isSource, isDest, sourcePosition, destPosition, editingTarget, onEditSource, onEditDest }) => {
|
const DataBox = ({ isSource, isDest, sourcePosition, destPosition, editingTarget, onEditSource, onEditDest }) => {
|
||||||
if (!isSource) return null;
|
if (!isSource) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
bottom: 5,
|
bottom: 5,
|
||||||
left: 5,
|
left: 5,
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
border: "1px solid #e1e1e1",
|
border: "1px solid #e1e1e1",
|
||||||
padding: 1,
|
padding: 1,
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
opacity: 0.8,
|
opacity: 0.8,
|
||||||
gap: 1,
|
gap: 1,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
||||||
<TextField
|
<TextField
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
size="small"
|
size="small"
|
||||||
readOnly
|
readOnly
|
||||||
value={sourcePosition ? `${sourcePosition.lat.toFixed(6)}, ${sourcePosition.lng.toFixed(6)}` : ""}
|
value={sourcePosition ? `${sourcePosition.lat.toFixed(6)}, ${sourcePosition.lng.toFixed(6)}` : ""}
|
||||||
/>
|
/>
|
||||||
{isSource && isDest && (
|
{isSource && isDest && (
|
||||||
<Button variant="contained" color="success" size="small" onClick={onEditSource}>
|
<Button variant="contained" color="success" size="small" onClick={onEditSource}>
|
||||||
ویرایش مبدا
|
ویرایش مبدا
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{isDest && (
|
{isDest && (
|
||||||
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
<div style={{ display: "flex", alignItems: "end", gap: 4 }}>
|
||||||
<TextField
|
<TextField
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
readOnly
|
readOnly
|
||||||
value={destPosition ? `${destPosition.lat.toFixed(6)}, ${destPosition.lng.toFixed(6)}` : ""}
|
value={destPosition ? `${destPosition.lat.toFixed(6)}, ${destPosition.lng.toFixed(6)}` : ""}
|
||||||
/>
|
/>
|
||||||
<Button variant="contained" color="error" size="small" onClick={onEditDest}>
|
<Button variant="contained" color="error" size="small" onClick={onEditDest}>
|
||||||
ویرایش مقصد
|
ویرایش مقصد
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DataBox;
|
export default DataBox;
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Marker, Polyline, useMap } from "react-leaflet";
|
import { Marker, Polyline, useMap } from "react-leaflet";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import polyline from "@mapbox/polyline";
|
import polyline from "@mapbox/polyline";
|
||||||
import SourceIcon from "@/assets/images/source-icon.svg";
|
import SourceIcon from "@/assets/images/source-icon.svg";
|
||||||
import DestIcon from "@/assets/images/destination-icon.svg";
|
import DestIcon from "@/assets/images/destination-icon.svg";
|
||||||
|
|
||||||
const ShowRoute = ({ area }) => {
|
const ShowRoute = ({ area }) => {
|
||||||
const map = useMap();
|
const map = useMap();
|
||||||
const defaultIconSize = [35, 35];
|
const defaultIconSize = [35, 35];
|
||||||
|
|
||||||
const createCustomIcon = (size, iconUrl) => {
|
const createCustomIcon = (size, iconUrl) => {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: iconUrl,
|
iconUrl: iconUrl,
|
||||||
iconSize: size,
|
iconSize: size,
|
||||||
iconAnchor: [size[0] / 2, size[1]],
|
iconAnchor: [size[0] / 2, size[1]],
|
||||||
popupAnchor: [0, -size[1]],
|
popupAnchor: [0, -size[1]],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
|
||||||
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
|
||||||
|
useEffect(() => {
|
||||||
if (!area) return null;
|
if (coords.length > 0) {
|
||||||
const coords = polyline.decode(area, 6);
|
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
||||||
|
}
|
||||||
if (coords.length === 0) return null;
|
}, [area]);
|
||||||
|
|
||||||
const sourcePosition = coords[0];
|
if (!area) return null;
|
||||||
const destPosition = coords[coords.length - 1];
|
const coords = polyline.decode(area, 6);
|
||||||
useEffect(() => {
|
|
||||||
if (coords.length > 0) {
|
if (coords.length === 0) return null;
|
||||||
map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
|
|
||||||
}
|
const sourcePosition = coords[0];
|
||||||
}, [area]);
|
const destPosition = coords[coords.length - 1];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
<Polyline positions={coords} color="#015688" weight={7} opacity={1} />
|
||||||
<Marker position={sourcePosition} icon={sourceIcon} />
|
<Marker position={sourcePosition} icon={sourceIcon} />
|
||||||
<Marker position={destPosition} icon={destIcon} />
|
<Marker position={destPosition} icon={destIcon} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ShowRoute;
|
export default ShowRoute;
|
||||||
|
|||||||
@@ -1,219 +1,219 @@
|
|||||||
import { Marker, Polyline, useMapEvents } from "react-leaflet";
|
import { Marker, Polyline, useMapEvents } from "react-leaflet";
|
||||||
import L from "leaflet";
|
import L from "leaflet";
|
||||||
import polyline from "@mapbox/polyline";
|
import polyline from "@mapbox/polyline";
|
||||||
import SourceIcon from "@/assets/images/source-icon.svg";
|
import SourceIcon from "@/assets/images/source-icon.svg";
|
||||||
import PrevSourceIcon from "@/assets/images/prev-source-icon.svg";
|
import PrevSourceIcon from "@/assets/images/prev-source-icon.svg";
|
||||||
import PrevDestIcon from "@/assets/images/prev-destination-icon.svg";
|
import PrevDestIcon from "@/assets/images/prev-destination-icon.svg";
|
||||||
import DestIcon from "@/assets/images/destination-icon.svg";
|
import DestIcon from "@/assets/images/destination-icon.svg";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import DataBox from "./DataBox";
|
import DataBox from "./DataBox";
|
||||||
import AlarmText from "./AlarmText";
|
import AlarmText from "./AlarmText";
|
||||||
|
|
||||||
const Routing = ({ setArea, setLocations, locations, area }) => {
|
const Routing = ({ setArea, setLocations, locations, area }) => {
|
||||||
const mapPrevSourceMarker = useRef();
|
const mapPrevSourceMarker = useRef();
|
||||||
const mapPrevDestMarker = useRef();
|
const mapPrevDestMarker = useRef();
|
||||||
const mapRef = useRef(null);
|
const mapRef = useRef(null);
|
||||||
const defaultIconSize = [35, 35];
|
const defaultIconSize = [35, 35];
|
||||||
const [isSource, setIsSource] = useState(false);
|
const [isSource, setIsSource] = useState(false);
|
||||||
const [sourcePosition, setSourcePosition] = useState(null);
|
const [sourcePosition, setSourcePosition] = useState(null);
|
||||||
const [isDest, setIsDest] = useState(false);
|
const [isDest, setIsDest] = useState(false);
|
||||||
const [destPosition, setDestPosition] = useState(null);
|
const [destPosition, setDestPosition] = useState(null);
|
||||||
const [routeCoords, setRouteCoords] = useState([]);
|
const [routeCoords, setRouteCoords] = useState([]);
|
||||||
const [alternateCoords, setAlternateCoords] = useState([]);
|
const [alternateCoords, setAlternateCoords] = useState([]);
|
||||||
const [editingTarget, setEditingTarget] = useState(null);
|
const [editingTarget, setEditingTarget] = useState(null);
|
||||||
const [selectedRoute, setSelectedRoute] = useState(null);
|
const [selectedRoute, setSelectedRoute] = useState(null);
|
||||||
|
|
||||||
const createCustomIcon = (size, iconUrl) => {
|
const createCustomIcon = (size, iconUrl) => {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: iconUrl,
|
iconUrl: iconUrl,
|
||||||
iconSize: size,
|
iconSize: size,
|
||||||
iconAnchor: [size[0] / 2, size[1]],
|
iconAnchor: [size[0] / 2, size[1]],
|
||||||
popupAnchor: [0, -size[1]],
|
popupAnchor: [0, -size[1]],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultIcon = createCustomIcon(
|
const defaultIcon = createCustomIcon(
|
||||||
defaultIconSize,
|
defaultIconSize,
|
||||||
isSource && editingTarget !== "source" ? SourceIcon.src : PrevSourceIcon.src
|
isSource && editingTarget !== "source" ? SourceIcon.src : PrevSourceIcon.src
|
||||||
);
|
);
|
||||||
|
|
||||||
const prevDestIcon = createCustomIcon(
|
const prevDestIcon = createCustomIcon(
|
||||||
defaultIconSize,
|
defaultIconSize,
|
||||||
isDest && editingTarget !== "dest" ? DestIcon.src : PrevDestIcon.src
|
isDest && editingTarget !== "dest" ? DestIcon.src : PrevDestIcon.src
|
||||||
);
|
);
|
||||||
|
|
||||||
const isMovingSource = !isSource || editingTarget === "source";
|
const isMovingSource = !isSource || editingTarget === "source";
|
||||||
const isMovingDest = isSource && (!isDest || editingTarget === "dest");
|
const isMovingDest = isSource && (!isDest || editingTarget === "dest");
|
||||||
|
|
||||||
const map = useMapEvents({
|
const map = useMapEvents({
|
||||||
move(e) {
|
move(e) {
|
||||||
if (isMovingSource) mapPrevSourceMarker.current.setLatLng(e.target.getCenter());
|
if (isMovingSource) mapPrevSourceMarker.current.setLatLng(e.target.getCenter());
|
||||||
if (isMovingDest && mapPrevDestMarker.current) mapPrevDestMarker.current.setLatLng(e.target.getCenter());
|
if (isMovingDest && mapPrevDestMarker.current) mapPrevDestMarker.current.setLatLng(e.target.getCenter());
|
||||||
},
|
},
|
||||||
movestart() {
|
movestart() {
|
||||||
if (isMovingSource) mapPrevSourceMarker.current.setIcon(createCustomIcon([45, 45], PrevSourceIcon.src));
|
if (isMovingSource) mapPrevSourceMarker.current.setIcon(createCustomIcon([45, 45], PrevSourceIcon.src));
|
||||||
if (isMovingDest && mapPrevDestMarker.current)
|
if (isMovingDest && mapPrevDestMarker.current)
|
||||||
mapPrevDestMarker.current.setIcon(createCustomIcon([45, 45], PrevDestIcon.src));
|
mapPrevDestMarker.current.setIcon(createCustomIcon([45, 45], PrevDestIcon.src));
|
||||||
},
|
},
|
||||||
moveend() {
|
moveend() {
|
||||||
if (isMovingSource)
|
if (isMovingSource)
|
||||||
mapPrevSourceMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevSourceIcon.src));
|
mapPrevSourceMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevSourceIcon.src));
|
||||||
if (isMovingDest && mapPrevDestMarker.current)
|
if (isMovingDest && mapPrevDestMarker.current)
|
||||||
mapPrevDestMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevDestIcon.src));
|
mapPrevDestMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevDestIcon.src));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mapRef.current = map;
|
mapRef.current = map;
|
||||||
}, [map]);
|
}, [map]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (locations.length < 2) return;
|
if (locations.length < 2) return;
|
||||||
const restoredSource = { lat: locations[0].lat, lng: locations[0].lon };
|
const restoredSource = { lat: locations[0].lat, lng: locations[0].lon };
|
||||||
const restoredDest = { lat: locations[1].lat, lng: locations[1].lon };
|
const restoredDest = { lat: locations[1].lat, lng: locations[1].lon };
|
||||||
setSourcePosition(restoredSource);
|
setSourcePosition(restoredSource);
|
||||||
setDestPosition(restoredDest);
|
setDestPosition(restoredDest);
|
||||||
setIsSource(true);
|
setIsSource(true);
|
||||||
setIsDest(true);
|
setIsDest(true);
|
||||||
if (area) {
|
if (area) {
|
||||||
const decoded = polyline.decode(area, 6);
|
const decoded = polyline.decode(area, 6);
|
||||||
setRouteCoords(decoded);
|
setRouteCoords(decoded);
|
||||||
setSelectedRoute({ index: "main", coords: decoded });
|
setSelectedRoute({ index: "main", coords: decoded });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
mapRef.current?.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
mapRef.current?.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
fetchRoute(restoredSource, restoredDest);
|
fetchRoute(restoredSource, restoredDest);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchRoute = async (source, dest) => {
|
const fetchRoute = async (source, dest) => {
|
||||||
const locs = [
|
const locs = [
|
||||||
{ lat: source.lat, lon: source.lng },
|
{ lat: source.lat, lon: source.lng },
|
||||||
{ lat: dest.lat, lon: dest.lng },
|
{ lat: dest.lat, lon: dest.lng },
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
const response = await fetch("https://jouya.141.ir/api/router/drive", {
|
const response = await fetch("https://jouya.141.ir/api/router/drive", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ locations: locs }),
|
body: JSON.stringify({ locations: locs }),
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const shape = data.trip.legs[0].shape;
|
const shape = data.trip.legs[0].shape;
|
||||||
setLocations(locs);
|
setLocations(locs);
|
||||||
setArea(shape);
|
setArea(shape);
|
||||||
const decoded = polyline.decode(shape, 6);
|
const decoded = polyline.decode(shape, 6);
|
||||||
setRouteCoords(decoded);
|
setRouteCoords(decoded);
|
||||||
setSelectedRoute({ index: "main", coords: decoded });
|
setSelectedRoute({ index: "main", coords: decoded });
|
||||||
|
|
||||||
if (data.alternates?.length > 0) {
|
if (data.alternates?.length > 0) {
|
||||||
const decodedAlternates = data.alternates.map((alt) => polyline.decode(alt.trip.legs[0].shape, 6));
|
const decodedAlternates = data.alternates.map((alt) => polyline.decode(alt.trip.legs[0].shape, 6));
|
||||||
setAlternateCoords(decodedAlternates);
|
setAlternateCoords(decodedAlternates);
|
||||||
} else {
|
} else {
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
}
|
}
|
||||||
map.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
map.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Routing error:", error);
|
console.error("Routing error:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMarkerClick = async () => {
|
const handleMarkerClick = async () => {
|
||||||
if (!isSource || editingTarget === "source") {
|
if (!isSource || editingTarget === "source") {
|
||||||
const clickedPosition = mapPrevSourceMarker.current.getLatLng();
|
const clickedPosition = mapPrevSourceMarker.current.getLatLng();
|
||||||
setSourcePosition(clickedPosition);
|
setSourcePosition(clickedPosition);
|
||||||
setIsSource(true);
|
setIsSource(true);
|
||||||
setEditingTarget(null);
|
setEditingTarget(null);
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
|
|
||||||
if (editingTarget === "source" && destPosition) {
|
if (editingTarget === "source" && destPosition) {
|
||||||
await fetchRoute(clickedPosition, destPosition);
|
await fetchRoute(clickedPosition, destPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDestMarkerClick = async () => {
|
const handleDestMarkerClick = async () => {
|
||||||
if (!isDest || editingTarget === "dest") {
|
if (!isDest || editingTarget === "dest") {
|
||||||
const clickedPosition = mapPrevDestMarker.current.getLatLng();
|
const clickedPosition = mapPrevDestMarker.current.getLatLng();
|
||||||
setDestPosition(clickedPosition);
|
setDestPosition(clickedPosition);
|
||||||
setIsDest(true);
|
setIsDest(true);
|
||||||
setEditingTarget(null);
|
setEditingTarget(null);
|
||||||
|
|
||||||
await fetchRoute(sourcePosition, clickedPosition);
|
await fetchRoute(sourcePosition, clickedPosition);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditSource = () => {
|
const handleEditSource = () => {
|
||||||
setEditingTarget("source");
|
setEditingTarget("source");
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditDest = () => {
|
const handleEditDest = () => {
|
||||||
setEditingTarget("dest");
|
setEditingTarget("dest");
|
||||||
setRouteCoords([]);
|
setRouteCoords([]);
|
||||||
setAlternateCoords([]);
|
setAlternateCoords([]);
|
||||||
setSelectedRoute(null);
|
setSelectedRoute(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectRoute = (index, coords) => {
|
const handleSelectRoute = (index, coords) => {
|
||||||
setSelectedRoute({ index, coords });
|
setSelectedRoute({ index, coords });
|
||||||
const encoded = polyline.encode(coords, 6);
|
const encoded = polyline.encode(coords, 6);
|
||||||
setArea(encoded);
|
setArea(encoded);
|
||||||
map.flyToBounds(coords, { padding: [50, 50], duration: 0.3 });
|
map.flyToBounds(coords, { padding: [50, 50], duration: 0.3 });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DataBox
|
<DataBox
|
||||||
isSource={isSource}
|
isSource={isSource}
|
||||||
isDest={isDest}
|
isDest={isDest}
|
||||||
sourcePosition={sourcePosition}
|
sourcePosition={sourcePosition}
|
||||||
destPosition={destPosition}
|
destPosition={destPosition}
|
||||||
editingTarget={editingTarget}
|
editingTarget={editingTarget}
|
||||||
onEditSource={handleEditSource}
|
onEditSource={handleEditSource}
|
||||||
onEditDest={handleEditDest}
|
onEditDest={handleEditDest}
|
||||||
/>
|
/>
|
||||||
<AlarmText isSource={isSource} />
|
<AlarmText isSource={isSource} />
|
||||||
<Marker
|
<Marker
|
||||||
position={sourcePosition || map.getCenter()}
|
position={sourcePosition || map.getCenter()}
|
||||||
ref={mapPrevSourceMarker}
|
ref={mapPrevSourceMarker}
|
||||||
eventHandlers={{ click: handleMarkerClick }}
|
eventHandlers={{ click: handleMarkerClick }}
|
||||||
icon={defaultIcon}
|
icon={defaultIcon}
|
||||||
/>
|
/>
|
||||||
{isSource && (
|
{isSource && (
|
||||||
<Marker
|
<Marker
|
||||||
position={destPosition || map.getCenter()}
|
position={destPosition || map.getCenter()}
|
||||||
ref={mapPrevDestMarker}
|
ref={mapPrevDestMarker}
|
||||||
eventHandlers={{ click: handleDestMarkerClick }}
|
eventHandlers={{ click: handleDestMarkerClick }}
|
||||||
icon={prevDestIcon}
|
icon={prevDestIcon}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{alternateCoords.map((coords, index) => (
|
{alternateCoords.map((coords, index) => (
|
||||||
<Polyline
|
<Polyline
|
||||||
key={`alternate-${index}-${selectedRoute?.index === index}`}
|
key={`alternate-${index}-${selectedRoute?.index === index}`}
|
||||||
positions={coords}
|
positions={coords}
|
||||||
color={selectedRoute?.index === index ? "#015688" : "#91B2C6"}
|
color={selectedRoute?.index === index ? "#015688" : "#91B2C6"}
|
||||||
weight={selectedRoute?.index === index ? 7 : 6}
|
weight={selectedRoute?.index === index ? 7 : 6}
|
||||||
opacity={selectedRoute?.index === index ? 1 : 0.7}
|
opacity={selectedRoute?.index === index ? 1 : 0.7}
|
||||||
eventHandlers={{ click: () => handleSelectRoute(index, coords) }}
|
eventHandlers={{ click: () => handleSelectRoute(index, coords) }}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{routeCoords.length > 0 && (
|
{routeCoords.length > 0 && (
|
||||||
<Polyline
|
<Polyline
|
||||||
key={`main-${selectedRoute?.index === "main"}`}
|
key={`main-${selectedRoute?.index === "main"}`}
|
||||||
positions={routeCoords}
|
positions={routeCoords}
|
||||||
color={selectedRoute?.index === "main" ? "#015688" : "#91B2C6"}
|
color={selectedRoute?.index === "main" ? "#015688" : "#91B2C6"}
|
||||||
weight={selectedRoute?.index === "main" ? 7 : 6}
|
weight={selectedRoute?.index === "main" ? 7 : 6}
|
||||||
opacity={selectedRoute?.index === "main" ? 1 : 0.7}
|
opacity={selectedRoute?.index === "main" ? 1 : 0.7}
|
||||||
eventHandlers={{ click: () => handleSelectRoute("main", routeCoords) }}
|
eventHandlers={{ click: () => handleSelectRoute("main", routeCoords) }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Routing;
|
export default Routing;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import SearchReportList from "./Search";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ReportLists from "./ReportLists";
|
import ReportLists from "./ReportLists";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { GET_CITY_ACTIVITY_REPORT, GET_PROVINCE_ACTIVITY_REPORT } from "@/core/utils/routes";
|
import { GET_COUNTRY_ACTIVITY_REPORT, GET_PROVINCE_ACTIVITY_REPORT } from "@/core/utils/routes";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -70,7 +70,7 @@ const ReportPage = () => {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
params.set("province_id", `${data.province_id}`);
|
params.set("province_id", `${data.province_id}`);
|
||||||
const response = await requestServer(`${GET_CITY_ACTIVITY_REPORT}?${params}`);
|
const response = await requestServer(`${GET_COUNTRY_ACTIVITY_REPORT}?${params}`);
|
||||||
const result = response.data.data;
|
const result = response.data.data;
|
||||||
const nationalReportForItem = result.activities.find((report) => report.edare_id === "-1");
|
const nationalReportForItem = result.activities.find((report) => report.edare_id === "-1");
|
||||||
const nationalReport = {
|
const nationalReport = {
|
||||||
|
|||||||
Reference in New Issue
Block a user