diff --git a/package.json b/package.json
index 6074c06..79b3f30 100644
--- a/package.json
+++ b/package.json
@@ -1,55 +1,56 @@
-{
- "name": "rms",
- "version": "0.1.0",
- "private": true,
- "scripts": {
- "dev": "next dev",
- "build": "next build",
- "start": "next start",
- "lint": "next lint",
- "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"",
- "build:publish": "npm i && npm run build && pm2 restart ecosystem.config.js"
- },
- "dependencies": {
- "@emotion/cache": "^11.11.0",
- "@emotion/react": "^11.11.3",
- "@emotion/styled": "^11.11.0",
- "@hookform/resolvers": "^3.9.0",
- "@mui/icons-material": "^5.16.7",
- "@mui/lab": "^5.0.0-alpha.173",
- "@mui/material": "^5.16.7",
- "@mui/material-nextjs": "^5.16.6",
- "@mui/x-date-pickers": "^6.19.5",
- "@mui/x-tree-view": "^7.11.0",
- "@turf/turf": "^7.2.0",
- "axios": "^1.7.2",
- "date-fns": "^3.3.1",
- "date-fns-jalali": "^2.13.0-0",
- "dayjs": "^1.11.10",
- "file-saver": "^2.0.5",
- "jalali-moment": "^3.3.11",
- "lz-string": "^1.5.0",
- "material-react-table": "^2.11.2",
- "next": "^14.2.3",
- "react": "^18",
- "react-dom": "^18",
- "react-hook-form": "^7.52.1",
- "react-leaflet": "^4.2.1",
- "react-leaflet-draw": "^0.20.4",
- "react-leaflet-markercluster": "^4.2.1",
- "react-qr-code": "^2.0.18",
- "react-toastify": "^10.0.5",
- "sass": "^1.75.0",
- "sharp": "^0.33.4",
- "stylis": "^4.3.1",
- "stylis-plugin-rtl": "^2.1.1",
- "swr": "^2.2.5",
- "yup": "^1.4.0"
- },
- "devDependencies": {
- "eslint": "^8",
- "eslint-config-next": "14.1.0",
- "eslint-config-prettier": "^9.1.0",
- "prettier": "^3.3.2"
- }
-}
+{
+ "name": "rms",
+ "version": "0.1.0",
+ "private": true,
+ "scripts": {
+ "dev": "next dev",
+ "build": "next build",
+ "start": "next start",
+ "lint": "next lint",
+ "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,html,css,scss}\"",
+ "build:publish": "npm i && npm run build && pm2 restart ecosystem.config.js"
+ },
+ "dependencies": {
+ "@emotion/cache": "^11.11.0",
+ "@emotion/react": "^11.11.3",
+ "@emotion/styled": "^11.11.0",
+ "@hookform/resolvers": "^3.9.0",
+ "@mapbox/polyline": "^1.2.1",
+ "@mui/icons-material": "^5.16.7",
+ "@mui/lab": "^5.0.0-alpha.173",
+ "@mui/material": "^5.16.7",
+ "@mui/material-nextjs": "^5.16.6",
+ "@mui/x-date-pickers": "^6.19.5",
+ "@mui/x-tree-view": "^7.11.0",
+ "@turf/turf": "^7.2.0",
+ "axios": "^1.7.2",
+ "date-fns": "^3.3.1",
+ "date-fns-jalali": "^2.13.0-0",
+ "dayjs": "^1.11.10",
+ "file-saver": "^2.0.5",
+ "jalali-moment": "^3.3.11",
+ "lz-string": "^1.5.0",
+ "material-react-table": "^2.11.2",
+ "next": "^14.2.3",
+ "react": "^18",
+ "react-dom": "^18",
+ "react-hook-form": "^7.52.1",
+ "react-leaflet": "^4.2.1",
+ "react-leaflet-draw": "^0.20.4",
+ "react-leaflet-markercluster": "^4.2.1",
+ "react-qr-code": "^2.0.18",
+ "react-toastify": "^10.0.5",
+ "sass": "^1.75.0",
+ "sharp": "^0.33.4",
+ "stylis": "^4.3.1",
+ "stylis-plugin-rtl": "^2.1.1",
+ "swr": "^2.2.5",
+ "yup": "^1.4.0"
+ },
+ "devDependencies": {
+ "eslint": "^8",
+ "eslint-config-next": "14.1.0",
+ "eslint-config-prettier": "^9.1.0",
+ "prettier": "^3.3.2"
+ }
+}
diff --git a/public/icons/destination-icon.svg b/public/icons/destination-icon.svg
new file mode 100644
index 0000000..ad8a633
--- /dev/null
+++ b/public/icons/destination-icon.svg
@@ -0,0 +1,18 @@
+
diff --git a/public/icons/origin-icon.svg b/public/icons/origin-icon.svg
new file mode 100644
index 0000000..295c9da
--- /dev/null
+++ b/public/icons/origin-icon.svg
@@ -0,0 +1,18 @@
+
diff --git a/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/loading.jsx b/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/loading.jsx
index 4535a8d..c3935ed 100644
--- a/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/loading.jsx
+++ b/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/loading.jsx
@@ -1,7 +1,7 @@
-"use client";
-import PageLoading from "@/core/components/PageLoading";
-
-const Loading = () => {
- return ;
-};
-export default Loading;
+"use client";
+import PageLoading from "@/core/components/PageLoading";
+
+const Loading = () => {
+ return ;
+};
+export default Loading;
diff --git a/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/page.jsx b/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/page.jsx
index 35c27ad..ad5b6c2 100644
--- a/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/page.jsx
+++ b/src/app/(withAuth)/(dashboardLayout)/dashboard/machines/page.jsx
@@ -1,17 +1,17 @@
-import WithPermission from "@/core/middlewares/withPermission";
-import MachinesPage from "@/components/dashboard/machines";
-
-export const metadata = {
- title: "کارتابل ماشینها",
-};
-const Page = () => {
- return (
- <>
-
-
-
- >
- );
-};
-
-export default Page;
+import WithPermission from "@/core/middlewares/withPermission";
+import MachinesPage from "@/components/dashboard/machines";
+
+export const metadata = {
+ title: "کارتابل ماشینها",
+};
+const Page = () => {
+ return (
+ <>
+
+
+
+ >
+ );
+};
+
+export default Page;
diff --git a/src/assets/images/destination-icon.svg b/src/assets/images/destination-icon.svg
new file mode 100644
index 0000000..ad8a633
--- /dev/null
+++ b/src/assets/images/destination-icon.svg
@@ -0,0 +1,18 @@
+
diff --git a/src/assets/images/prev-destination-icon.svg b/src/assets/images/prev-destination-icon.svg
new file mode 100644
index 0000000..656eca3
--- /dev/null
+++ b/src/assets/images/prev-destination-icon.svg
@@ -0,0 +1,21 @@
+
diff --git a/src/assets/images/prev-source-icon.svg b/src/assets/images/prev-source-icon.svg
new file mode 100644
index 0000000..621e71a
--- /dev/null
+++ b/src/assets/images/prev-source-icon.svg
@@ -0,0 +1,21 @@
+
diff --git a/src/assets/images/source-icon.svg b/src/assets/images/source-icon.svg
new file mode 100644
index 0000000..295c9da
--- /dev/null
+++ b/src/assets/images/source-icon.svg
@@ -0,0 +1,18 @@
+
diff --git a/src/components/dashboard/machines/MachinesList.jsx b/src/components/dashboard/machines/MachinesList.jsx
index 880f0cb..ce787e0 100644
--- a/src/components/dashboard/machines/MachinesList.jsx
+++ b/src/components/dashboard/machines/MachinesList.jsx
@@ -1,134 +1,134 @@
-"use client";
-import DataTableWithAuth from "@/core/components/DataTableWithAuth";
-import { GET_MACHINES_LIST } from "@/core/utils/routes";
-import { Box, Typography } from "@mui/material";
-import { useMemo } from "react";
-import RowActions from "./RowActions";
-
-const statusOptions = [
- { value: "", label: "همه وضعیت ها" },
- { value: 1, label: "آماده" },
- { value: 2, label: "رزرو" },
- { value: 3, label: "در ماموریت" },
- { value: 4, label: "خارج از رده" },
- { value: 5, label: "در تعمیر" },
- { value: 6, label: "فروخته شده" },
- { value: 7, label: "نیاز به تعمیر" },
-];
-
-const MachinesList = () => {
- const columns = useMemo(() => {
- return [
- {
- accessorKey: "id",
- header: "کد یکتا", // Unique Code
- id: "id",
- enableColumnFilter: true,
- datatype: "text",
- filterMode: "equals",
- sortDescFirst: false,
- columnFilterModeOptions: ["equals", "contains"],
- grow: false,
- size: 50,
- },
-
- {
- header: "اطلاعات ماشینها",
- id: "machines_info",
- enableColumnFilter: false,
- enableSorting: false,
- datatype: "text",
- grow: false,
- columns: [
- {
- accessorKey: "car_name",
- header: "نام ماشین",
- id: "car_name",
- enableColumnFilter: true,
- datatype: "text",
- filterMode: "equals",
- sortDescFirst: false,
- columnFilterModeOptions: ["equals", "contains"],
- grow: false,
- size: 100,
- },
- {
- accessorKey: "car_type",
- header: "نوع ماشین",
- id: "car_type",
- enableColumnFilter: true,
- datatype: "text",
- filterMode: "equals",
- sortDescFirst: false,
- columnFilterModeOptions: ["equals", "contains"],
- grow: false,
- size: 100,
- },
- {
- accessorKey: "machine_code",
- header: "کد ماشین",
- id: "machine_code",
- enableColumnFilter: true,
- datatype: "text",
- filterMode: "equals",
- sortDescFirst: false,
- columnFilterModeOptions: ["equals", "contains"],
- grow: false,
- size: 100,
- },
- {
- accessorKey: "plak_number",
- header: "پلاک",
- id: "plak_number",
- enableColumnFilter: true,
- datatype: "text",
- filterMode: "equals",
- sortDescFirst: false,
- columnFilterModeOptions: ["equals", "contains"],
- grow: false,
- size: 100,
- },
- {
- accessorKey: "status",
- header: "وضعیت",
- id: "status",
- enableColumnFilter: true,
- datatype: "numeric",
- filterMode: "equals",
- grow: false,
- size: 100,
- columnSelectOption: () => {
- return statusOptions.map((status) => ({
- value: status.value,
- label: status.label,
- }));
- },
- Cell: ({ row }) => {
- const status = statusOptions.find((option) => option.value == row.original.status);
- return {status?.label || ""};
- },
- },
- ],
- },
- ];
- }, []);
-
- return (
- <>
-
-
-
- >
- );
-};
-export default MachinesList;
+"use client";
+import DataTableWithAuth from "@/core/components/DataTableWithAuth";
+import { GET_MACHINES_LIST } from "@/core/utils/routes";
+import { Box, Typography } from "@mui/material";
+import { useMemo } from "react";
+import RowActions from "./RowActions";
+
+const statusOptions = [
+ { value: "", label: "همه وضعیت ها" },
+ { value: 1, label: "آماده" },
+ { value: 2, label: "رزرو" },
+ { value: 3, label: "در ماموریت" },
+ { value: 4, label: "خارج از رده" },
+ { value: 5, label: "در تعمیر" },
+ { value: 6, label: "فروخته شده" },
+ { value: 7, label: "نیاز به تعمیر" },
+];
+
+const MachinesList = () => {
+ const columns = useMemo(() => {
+ return [
+ {
+ accessorKey: "id",
+ header: "کد یکتا", // Unique Code
+ id: "id",
+ enableColumnFilter: true,
+ datatype: "text",
+ filterMode: "equals",
+ sortDescFirst: false,
+ columnFilterModeOptions: ["equals", "contains"],
+ grow: false,
+ size: 50,
+ },
+
+ {
+ header: "اطلاعات ماشینها",
+ id: "machines_info",
+ enableColumnFilter: false,
+ enableSorting: false,
+ datatype: "text",
+ grow: false,
+ columns: [
+ {
+ accessorKey: "car_name",
+ header: "نام ماشین",
+ id: "car_name",
+ enableColumnFilter: true,
+ datatype: "text",
+ filterMode: "equals",
+ sortDescFirst: false,
+ columnFilterModeOptions: ["equals", "contains"],
+ grow: false,
+ size: 100,
+ },
+ {
+ accessorKey: "car_type",
+ header: "نوع ماشین",
+ id: "car_type",
+ enableColumnFilter: true,
+ datatype: "text",
+ filterMode: "equals",
+ sortDescFirst: false,
+ columnFilterModeOptions: ["equals", "contains"],
+ grow: false,
+ size: 100,
+ },
+ {
+ accessorKey: "machine_code",
+ header: "کد ماشین",
+ id: "machine_code",
+ enableColumnFilter: true,
+ datatype: "text",
+ filterMode: "equals",
+ sortDescFirst: false,
+ columnFilterModeOptions: ["equals", "contains"],
+ grow: false,
+ size: 100,
+ },
+ {
+ accessorKey: "plak_number",
+ header: "پلاک",
+ id: "plak_number",
+ enableColumnFilter: true,
+ datatype: "text",
+ filterMode: "equals",
+ sortDescFirst: false,
+ columnFilterModeOptions: ["equals", "contains"],
+ grow: false,
+ size: 100,
+ },
+ {
+ accessorKey: "status",
+ header: "وضعیت",
+ id: "status",
+ enableColumnFilter: true,
+ datatype: "numeric",
+ filterMode: "equals",
+ grow: false,
+ size: 100,
+ columnSelectOption: () => {
+ return statusOptions.map((status) => ({
+ value: status.value,
+ label: status.label,
+ }));
+ },
+ Cell: ({ row }) => {
+ const status = statusOptions.find((option) => option.value == row.original.status);
+ return {status?.label || ""};
+ },
+ },
+ ],
+ },
+ ];
+ }, []);
+
+ return (
+ <>
+
+
+
+ >
+ );
+};
+export default MachinesList;
diff --git a/src/components/dashboard/machines/RowActions/DeleteDialog/DeleteContent.jsx b/src/components/dashboard/machines/RowActions/DeleteDialog/DeleteContent.jsx
index 3f3095a..bf0a3c5 100644
--- a/src/components/dashboard/machines/RowActions/DeleteDialog/DeleteContent.jsx
+++ b/src/components/dashboard/machines/RowActions/DeleteDialog/DeleteContent.jsx
@@ -1,39 +1,39 @@
-import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
-import React, { useState } from "react";
-import useRequest from "@/lib/hooks/useRequest";
-import { DELETE_TOLL_HOUSE_ITEM } from "@/core/utils/routes";
-
-const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
- const [submitting, setSubmitting] = useState(false);
- const requestServer = useRequest({ notificationSuccess: true });
- const handleClick = () => {
- setSubmitting(true);
- requestServer(`${DELETE_TOLL_HOUSE_ITEM}/${rowId}`, "delete")
- .then(() => {
- mutate();
- setOpenDeleteDialog(false);
- setSubmitting(false);
- })
- .catch(() => {
- setSubmitting(false);
- });
- };
- return (
- <>
-
-
- آیا از حذف راهدارخانه اطمینان دارید؟
-
-
-
-
-
-
- >
- );
-};
-export default DeleteContent;
+import { Button, DialogActions, DialogContent, Stack, Typography } from "@mui/material";
+import React, { useState } from "react";
+import useRequest from "@/lib/hooks/useRequest";
+import { DELETE_TOLL_HOUSE_ITEM } from "@/core/utils/routes";
+
+const DeleteContent = ({ rowId, mutate, setOpenDeleteDialog }) => {
+ const [submitting, setSubmitting] = useState(false);
+ const requestServer = useRequest({ notificationSuccess: true });
+ const handleClick = () => {
+ setSubmitting(true);
+ requestServer(`${DELETE_TOLL_HOUSE_ITEM}/${rowId}`, "delete")
+ .then(() => {
+ mutate();
+ setOpenDeleteDialog(false);
+ setSubmitting(false);
+ })
+ .catch(() => {
+ setSubmitting(false);
+ });
+ };
+ return (
+ <>
+
+
+ آیا از حذف راهدارخانه اطمینان دارید؟
+
+
+
+
+
+
+ >
+ );
+};
+export default DeleteContent;
diff --git a/src/components/dashboard/machines/RowActions/DeleteDialog/index.jsx b/src/components/dashboard/machines/RowActions/DeleteDialog/index.jsx
index 54278bd..37eefdf 100644
--- a/src/components/dashboard/machines/RowActions/DeleteDialog/index.jsx
+++ b/src/components/dashboard/machines/RowActions/DeleteDialog/index.jsx
@@ -1,34 +1,34 @@
-import DeleteIcon from "@mui/icons-material/Delete";
-import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
-import { useState } from "react";
-import DeleteContent from "./DeleteContent";
-const DeleteDialog = ({ rowId, mutate }) => {
- const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
-
- return (
- <>
-
- setOpenDeleteDialog(true)}>
-
-
-
-
- >
- );
-};
-export default DeleteDialog;
+import DeleteIcon from "@mui/icons-material/Delete";
+import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
+import { useState } from "react";
+import DeleteContent from "./DeleteContent";
+const DeleteDialog = ({ rowId, mutate }) => {
+ const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
+
+ return (
+ <>
+
+ setOpenDeleteDialog(true)}>
+
+
+
+
+ >
+ );
+};
+export default DeleteDialog;
diff --git a/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx b/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
index 6cfcd9d..5608c57 100644
--- a/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
+++ b/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
@@ -1,281 +1,281 @@
-import StyledForm from "@/core/components/StyledForm";
-import {
- GET_CITIES_LIST,
- GET_PROVINCES_LIST,
- GET_STATIONS_LIST,
- UPDATE_MACHINE_STATUS_AND_LOCATION,
-} from "@/core/utils/routes";
-import useRequest from "@/lib/hooks/useRequest";
-import { yupResolver } from "@hookform/resolvers/yup";
-import { Beenhere, ExitToApp } from "@mui/icons-material";
-import {
- Button,
- CircularProgress,
- DialogActions,
- DialogContent,
- DialogTitle,
- FormControl,
- InputLabel,
- MenuItem,
- Select,
- Stack,
-} from "@mui/material";
-import { DialogHeader } from "next/dist/client/components/react-dev-overlay/internal/components/Dialog";
-import { useEffect, useState } from "react";
-import { Controller, useForm, useWatch } from "react-hook-form";
-import { number, object } from "yup";
-
-const statusOptions = [
- { value: 1, label: "آماده" },
- { value: 2, label: "رزرو" },
- { value: 3, label: "در ماموریت" },
- { value: 4, label: "خارج از رده" },
- { value: 5, label: "در تعمیر" },
- { value: 6, label: "فروخته شده" },
- { value: 7, label: "نیاز به تعمیر" },
-];
-
-const validationSchema = object({
- status: number().required("انتخاب وضعیت الزامی است"),
- province_id: number().required("انتخاب استان الزامی است"),
- city_id: number().required("انتخاب شهر الزامی است"),
- station_id: number().required("انتخاب راهداری الزامی است"),
-});
-
-const EditFormContent = ({ row, rowId, mutate, setOpen }) => {
- const requestServer = useRequest();
-
- const [provinces, setProvinces] = useState([]);
- const [cities, setCities] = useState([]);
- const [stations, setStations] = useState([]);
-
- const [loadingProvinces, setLoadingProvinces] = useState(false);
- const [loadingCities, setLoadingCities] = useState(false);
- const [loadingStations, setLoadingStations] = useState(false);
-
- const {
- control,
- handleSubmit,
- setValue,
- formState: { isSubmitting },
- } = useForm({
- defaultValues: {
- status: row.original.status,
- province_id: row.original.province_id,
- city_id: row.original.city_id,
- station_id: row.original.station_id,
- },
- resolver: yupResolver(validationSchema),
- mode: "all",
- });
-
- const provinceId = useWatch({
- control,
- name: "province_id",
- });
-
- const cityId = useWatch({
- control,
- name: "city_id",
- });
-
- const loadProvinces = async () => {
- try {
- setLoadingProvinces(true);
- const response = await requestServer(GET_PROVINCES_LIST, "get");
- setProvinces(response.data?.data || []);
- } finally {
- setLoadingProvinces(false);
- }
- };
-
- const loadCities = async (provinceId) => {
- if (!provinceId) return;
-
- try {
- setLoadingCities(true);
- const response = await requestServer(`${GET_CITIES_LIST}?province_id=${provinceId}`, "get");
- setCities(response.data?.data || []);
- } finally {
- setLoadingCities(false);
- }
- };
-
- const loadStations = async (cityId) => {
- if (!cityId) return;
-
- try {
- setLoadingStations(true);
- const response = await requestServer(`${GET_STATIONS_LIST}/search_by_city?city_id=${cityId}`, "get");
- setStations(response.data?.data || []);
- } finally {
- setLoadingStations(false);
- }
- };
-
- useEffect(() => {
- loadProvinces();
- }, []);
-
- /**
- * Initial edit mode loading
- */
- useEffect(() => {
- if (row.original.province_id) {
- loadCities(row.original.province_id);
- }
-
- if (row.original.city_id) {
- loadStations(row.original.city_id);
- }
- }, []);
-
- useEffect(() => {
- if (!provinceId) return;
-
- loadCities(provinceId);
-
- if (provinceId !== row.original.province_id) {
- setValue("city_id", "");
- setValue("station_id", "");
- setStations([]);
- }
- }, [provinceId]);
-
- useEffect(() => {
- if (!cityId) return;
-
- loadStations(cityId);
-
- if (cityId !== row.original.city_id) {
- setValue("station_id", "");
- }
- }, [cityId]);
-
- const onSubmit = async (data) => {
- const formData = new FormData();
-
- formData.append("status", String(data.status));
- formData.append("province_id", String(data.province_id));
- formData.append("city_id", String(data.city_id));
- formData.append("station_id", String(data.station_id));
-
- try {
- await requestServer(`${UPDATE_MACHINE_STATUS_AND_LOCATION}/${rowId}`, "post", {
- data: formData,
- });
-
- mutate();
- setOpen(false);
- } catch (error) {}
- };
-
- return (
- <>
-
- ویرایش ماشین
-
-
-
-
-
- (
-
- استان
-
-
-
- )}
- />
-
- (
-
- شهر
-
-
-
- )}
- />
-
- (
-
- راهداری
-
-
-
- )}
- />
- (
-
- وضعیت
-
-
-
- )}
- />
-
- {(loadingCities || loadingStations) && (
-
-
-
- )}
-
-
-
-
-
-
-
- }
- >
- {isSubmitting ? "در حال ویرایش" : "ویرایش ماشین"}
-
-
- >
- );
-};
-
-export default EditFormContent;
+import StyledForm from "@/core/components/StyledForm";
+import {
+ GET_CITIES_LIST,
+ GET_PROVINCES_LIST,
+ GET_STATIONS_LIST,
+ UPDATE_MACHINE_STATUS_AND_LOCATION,
+} from "@/core/utils/routes";
+import useRequest from "@/lib/hooks/useRequest";
+import { yupResolver } from "@hookform/resolvers/yup";
+import { Beenhere, ExitToApp } from "@mui/icons-material";
+import {
+ Button,
+ CircularProgress,
+ DialogActions,
+ DialogContent,
+ DialogTitle,
+ FormControl,
+ InputLabel,
+ MenuItem,
+ Select,
+ Stack,
+} from "@mui/material";
+import { DialogHeader } from "next/dist/client/components/react-dev-overlay/internal/components/Dialog";
+import { useEffect, useState } from "react";
+import { Controller, useForm, useWatch } from "react-hook-form";
+import { number, object } from "yup";
+
+const statusOptions = [
+ { value: 1, label: "آماده" },
+ { value: 2, label: "رزرو" },
+ { value: 3, label: "در ماموریت" },
+ { value: 4, label: "خارج از رده" },
+ { value: 5, label: "در تعمیر" },
+ { value: 6, label: "فروخته شده" },
+ { value: 7, label: "نیاز به تعمیر" },
+];
+
+const validationSchema = object({
+ status: number().required("انتخاب وضعیت الزامی است"),
+ province_id: number().required("انتخاب استان الزامی است"),
+ city_id: number().required("انتخاب شهر الزامی است"),
+ station_id: number().required("انتخاب راهداری الزامی است"),
+});
+
+const EditFormContent = ({ row, rowId, mutate, setOpen }) => {
+ const requestServer = useRequest();
+
+ const [provinces, setProvinces] = useState([]);
+ const [cities, setCities] = useState([]);
+ const [stations, setStations] = useState([]);
+
+ const [loadingProvinces, setLoadingProvinces] = useState(false);
+ const [loadingCities, setLoadingCities] = useState(false);
+ const [loadingStations, setLoadingStations] = useState(false);
+
+ const {
+ control,
+ handleSubmit,
+ setValue,
+ formState: { isSubmitting },
+ } = useForm({
+ defaultValues: {
+ status: row.original.status,
+ province_id: row.original.province_id,
+ city_id: row.original.city_id,
+ station_id: row.original.station_id,
+ },
+ resolver: yupResolver(validationSchema),
+ mode: "all",
+ });
+
+ const provinceId = useWatch({
+ control,
+ name: "province_id",
+ });
+
+ const cityId = useWatch({
+ control,
+ name: "city_id",
+ });
+
+ const loadProvinces = async () => {
+ try {
+ setLoadingProvinces(true);
+ const response = await requestServer(GET_PROVINCES_LIST, "get");
+ setProvinces(response.data?.data || []);
+ } finally {
+ setLoadingProvinces(false);
+ }
+ };
+
+ const loadCities = async (provinceId) => {
+ if (!provinceId) return;
+
+ try {
+ setLoadingCities(true);
+ const response = await requestServer(`${GET_CITIES_LIST}?province_id=${provinceId}`, "get");
+ setCities(response.data?.data || []);
+ } finally {
+ setLoadingCities(false);
+ }
+ };
+
+ const loadStations = async (cityId) => {
+ if (!cityId) return;
+
+ try {
+ setLoadingStations(true);
+ const response = await requestServer(`${GET_STATIONS_LIST}/search_by_city?city_id=${cityId}`, "get");
+ setStations(response.data?.data || []);
+ } finally {
+ setLoadingStations(false);
+ }
+ };
+
+ useEffect(() => {
+ loadProvinces();
+ }, []);
+
+ /**
+ * Initial edit mode loading
+ */
+ useEffect(() => {
+ if (row.original.province_id) {
+ loadCities(row.original.province_id);
+ }
+
+ if (row.original.city_id) {
+ loadStations(row.original.city_id);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (!provinceId) return;
+
+ loadCities(provinceId);
+
+ if (provinceId !== row.original.province_id) {
+ setValue("city_id", "");
+ setValue("station_id", "");
+ setStations([]);
+ }
+ }, [provinceId]);
+
+ useEffect(() => {
+ if (!cityId) return;
+
+ loadStations(cityId);
+
+ if (cityId !== row.original.city_id) {
+ setValue("station_id", "");
+ }
+ }, [cityId]);
+
+ const onSubmit = async (data) => {
+ const formData = new FormData();
+
+ formData.append("status", String(data.status));
+ formData.append("province_id", String(data.province_id));
+ formData.append("city_id", String(data.city_id));
+ formData.append("station_id", String(data.station_id));
+
+ try {
+ await requestServer(`${UPDATE_MACHINE_STATUS_AND_LOCATION}/${rowId}`, "post", {
+ data: formData,
+ });
+
+ mutate();
+ setOpen(false);
+ } catch (error) {}
+ };
+
+ return (
+ <>
+
+ ویرایش ماشین
+
+
+
+
+
+ (
+
+ استان
+
+
+
+ )}
+ />
+
+ (
+
+ شهر
+
+
+
+ )}
+ />
+
+ (
+
+ راهداری
+
+
+
+ )}
+ />
+ (
+
+ وضعیت
+
+
+
+ )}
+ />
+
+ {(loadingCities || loadingStations) && (
+
+
+
+ )}
+
+
+
+
+
+
+
+ }
+ >
+ {isSubmitting ? "در حال ویرایش" : "ویرایش ماشین"}
+
+
+ >
+ );
+};
+
+export default EditFormContent;
diff --git a/src/components/dashboard/machines/RowActions/Edit/index.jsx b/src/components/dashboard/machines/RowActions/Edit/index.jsx
index f3cec95..b777d54 100644
--- a/src/components/dashboard/machines/RowActions/Edit/index.jsx
+++ b/src/components/dashboard/machines/RowActions/Edit/index.jsx
@@ -1,44 +1,44 @@
-import { SwapHoriz } from "@mui/icons-material";
-import CloseIcon from "@mui/icons-material/Close";
-import { Dialog, IconButton, Tooltip } from "@mui/material";
-import { useState } from "react";
-import EditFormContent from "./Form";
-
-const Edit = ({ row, mutate, rowId }) => {
- const [openEditDialog, setOpenEditDialog] = useState(false);
-
- return (
- <>
-
- {
- setOpenEditDialog(true);
- }}
- >
-
-
-
-
- >
- );
-};
-export default Edit;
+import { SwapHoriz } from "@mui/icons-material";
+import CloseIcon from "@mui/icons-material/Close";
+import { Dialog, IconButton, Tooltip } from "@mui/material";
+import { useState } from "react";
+import EditFormContent from "./Form";
+
+const Edit = ({ row, mutate, rowId }) => {
+ const [openEditDialog, setOpenEditDialog] = useState(false);
+
+ return (
+ <>
+
+ {
+ setOpenEditDialog(true);
+ }}
+ >
+
+
+
+
+ >
+ );
+};
+export default Edit;
diff --git a/src/components/dashboard/machines/RowActions/index.jsx b/src/components/dashboard/machines/RowActions/index.jsx
index 526fe10..1e1d4eb 100644
--- a/src/components/dashboard/machines/RowActions/index.jsx
+++ b/src/components/dashboard/machines/RowActions/index.jsx
@@ -1,14 +1,14 @@
-import { usePermissions } from "@/lib/hooks/usePermissions";
-import { Box } from "@mui/material";
-import Edit from "./Edit";
-
-const RowActions = ({ row, mutate }) => {
- const { data: userPermissions } = usePermissions();
- const hasEditPermission = userPermissions.some((item) => ["update-machine"].includes(item));
- return (
-
- {hasEditPermission && }
-
- );
-};
-export default RowActions;
+import { usePermissions } from "@/lib/hooks/usePermissions";
+import { Box } from "@mui/material";
+import Edit from "./Edit";
+
+const RowActions = ({ row, mutate }) => {
+ const { data: userPermissions } = usePermissions();
+ const hasEditPermission = userPermissions.some((item) => ["update-machine"].includes(item));
+ return (
+
+ {hasEditPermission && }
+
+ );
+};
+export default RowActions;
diff --git a/src/components/dashboard/machines/ShowProjectArea/ShowBound.jsx b/src/components/dashboard/machines/ShowProjectArea/ShowBound.jsx
index 24db476..43dd0b8 100644
--- a/src/components/dashboard/machines/ShowProjectArea/ShowBound.jsx
+++ b/src/components/dashboard/machines/ShowProjectArea/ShowBound.jsx
@@ -1,29 +1,29 @@
-import { useEffect, useRef } from "react";
-import { FeatureGroup, useMap } from "react-leaflet";
-
-const ShowBound = ({ bound }) => {
- const map = useMap();
- const featureRef = useRef(null);
-
- const safeFitBounds = (layer) => {
- if (!layer || !map) return;
- try {
- const latLngs = layer.getLatLngs();
- map.fitBounds(latLngs, {
- paddingTopLeft: [20, 20],
- paddingBottomRight: [20, 20],
- });
- } catch (e) {
- console.warn("fitBounds failed:", e);
- }
- };
-
- useEffect(() => {
- bound?.editing?.disable();
- featureRef.current.addLayer(bound);
- safeFitBounds(bound);
- }, []);
-
- return ;
-};
-export default ShowBound;
+import { useEffect, useRef } from "react";
+import { FeatureGroup, useMap } from "react-leaflet";
+
+const ShowBound = ({ bound }) => {
+ const map = useMap();
+ const featureRef = useRef(null);
+
+ const safeFitBounds = (layer) => {
+ if (!layer || !map) return;
+ try {
+ const latLngs = layer.getLatLngs();
+ map.fitBounds(latLngs, {
+ paddingTopLeft: [20, 20],
+ paddingBottomRight: [20, 20],
+ });
+ } catch (e) {
+ console.warn("fitBounds failed:", e);
+ }
+ };
+
+ useEffect(() => {
+ bound?.editing?.disable();
+ featureRef.current.addLayer(bound);
+ safeFitBounds(bound);
+ }, []);
+
+ return ;
+};
+export default ShowBound;
diff --git a/src/components/dashboard/machines/ShowProjectArea/index.jsx b/src/components/dashboard/machines/ShowProjectArea/index.jsx
index 250cd52..29f2697 100644
--- a/src/components/dashboard/machines/ShowProjectArea/index.jsx
+++ b/src/components/dashboard/machines/ShowProjectArea/index.jsx
@@ -1,65 +1,65 @@
-const { IconButton, Tooltip, Box, Dialog, DialogTitle, Typography, DialogContent } = require("@mui/material");
-import MapLayer from "@/core/components/MapLayer";
-import CloseIcon from "@mui/icons-material/Close";
-import LayersIcon from "@mui/icons-material/Layers";
-import L from "leaflet";
-import { useMemo, useState } from "react";
-import ShowBound from "./ShowBound";
-
-const ShowProjectArea = ({ primaryArea }) => {
- const [openShowAreaDialog, setOpenShowAreaDialog] = useState(false);
- const bound = useMemo(() => {
- const coordinates = Object.values(primaryArea.coordinates);
-
- const latLngCoords = coordinates.map(([lat, lng]) => [parseFloat(lng), parseFloat(lat)]);
-
- return primaryArea.type === "polygon"
- ? L.polygon(latLngCoords, { color: "#ff5555" })
- : L.polyline(latLngCoords);
- }, [primaryArea]);
-
- return (
-
-
- setOpenShowAreaDialog(true)}>
-
-
-
-
-
- );
-};
-
-export default ShowProjectArea;
+const { IconButton, Tooltip, Box, Dialog, DialogTitle, Typography, DialogContent } = require("@mui/material");
+import MapLayer from "@/core/components/MapLayer";
+import CloseIcon from "@mui/icons-material/Close";
+import LayersIcon from "@mui/icons-material/Layers";
+import L from "leaflet";
+import { useMemo, useState } from "react";
+import ShowBound from "./ShowBound";
+
+const ShowProjectArea = ({ primaryArea }) => {
+ const [openShowAreaDialog, setOpenShowAreaDialog] = useState(false);
+ const bound = useMemo(() => {
+ const coordinates = Object.values(primaryArea.coordinates);
+
+ const latLngCoords = coordinates.map(([lat, lng]) => [parseFloat(lng), parseFloat(lat)]);
+
+ return primaryArea.type === "polygon"
+ ? L.polygon(latLngCoords, { color: "#ff5555" })
+ : L.polyline(latLngCoords);
+ }, [primaryArea]);
+
+ return (
+
+
+ setOpenShowAreaDialog(true)}>
+
+
+
+
+
+ );
+};
+
+export default ShowProjectArea;
diff --git a/src/components/dashboard/machines/index.jsx b/src/components/dashboard/machines/index.jsx
index ed3db7c..6074488 100644
--- a/src/components/dashboard/machines/index.jsx
+++ b/src/components/dashboard/machines/index.jsx
@@ -1,14 +1,14 @@
-"use client";
-import PageTitle from "@/core/components/PageTitle";
-import { Stack } from "@mui/material";
-import MachinesList from "./MachinesList";
-
-const MachinesPage = () => {
- return (
-
-
-
-
- );
-};
-export default MachinesPage;
+"use client";
+import PageTitle from "@/core/components/PageTitle";
+import { Stack } from "@mui/material";
+import MachinesList from "./MachinesList";
+
+const MachinesPage = () => {
+ return (
+
+
+
+
+ );
+};
+export default MachinesPage;
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/MapControlPolyline/index.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/MapControlPolyline/index.jsx
index 8d9b5d0..0a14736 100644
--- a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/MapControlPolyline/index.jsx
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/MapControlPolyline/index.jsx
@@ -1,116 +1,113 @@
-import { Delete, Route } from "@mui/icons-material";
-import { Box, Button, Stack, Typography } from "@mui/material";
-import { useReducer } from "react";
-import DrawBound from "./DrawBound";
+"use client";
-const statusType = [
- {
- id: 0,
- message: "برای آغاز ترسیم مسیر، کلیک کنید!",
- buttons: [
- {
- label: "شروع ترسیم مسیر",
- key: "start",
- color: "primary",
- icon: ,
- onclick: (controlDispach) => {
- controlDispach({ type: "SET_STATUS", status: 1 });
- },
- },
- ],
- },
- {
- id: 1,
- message: "مسیر موردنظر را با کلیک روی نقشه مشخص کنید. برای اتمام، روی نقطهی پایانی کلیک کنید!",
- buttons: [],
- },
- {
- id: 2,
- message: "برای اصلاح مسیر، گوشهها را بکشید. برای ترسیم دوباره، آن را حذف کنید",
- buttons: [
- {
- label: "حذف",
- key: "end",
- color: "error",
- icon: ,
- onclick: (controlDispach) => {
- controlDispach({ type: "SET_STATUS", status: 0 });
- },
- },
- ],
- },
-];
+import { useEffect, useState } from "react";
+import { Marker, Polyline, useMap } from "react-leaflet";
+import L from "leaflet";
-const createInitialState = (bound) => {
- if (bound) {
- return { status: 2 };
- }
- return { status: 0 };
-};
+// ===== Icons =====
+const originIcon = new L.Icon({
+ iconUrl: "/icons/origin-icon.svg",
+ iconSize: [32, 32],
+ iconAnchor: [16, 32],
+});
-const reducer = (state, action) => {
- switch (action.type) {
- case "SET_STATUS":
- return { ...state, status: action.status };
- default:
- return state;
- }
-};
+const destinationIcon = new L.Icon({
+ iconUrl: "/icons/destination-icon.svg",
+ iconSize: [32, 32],
+ iconAnchor: [16, 32],
+});
-const MapControlPolyline = ({ bound, setBound }) => {
- const [control, controlDispach] = useReducer(reducer, bound, createInitialState);
+// ===== Track Center =====
+function MapCenterTracker({ setCenter }) {
+ const map = useMap();
+
+ useEffect(() => {
+ const updateCenter = () => {
+ setCenter(map.getCenter());
+ };
+
+ updateCenter();
+
+ map.on("move", updateCenter);
+
+ return () => {
+ map.off("move", updateCenter);
+ };
+ }, [map, setCenter]);
+
+ return null;
+}
+
+// ===== Fixed Center Marker =====
+function FixedCenterMarker() {
+ return (
+
+

+
+ );
+}
+
+export default function Example() {
+ const [center, setCenter] = useState(null);
+
+ const [origin, setOrigin] = useState(null);
+ const [destination, setDestination] = useState(null);
+
+ const [step, setStep] = useState("origin");
+
+ const handleOk = () => {
+ if (!center) return;
+
+ if (step === "origin") {
+ setOrigin(center);
+ setStep("destination");
+ return;
+ }
+
+ if (step === "destination") {
+ setDestination(center);
+ setStep("done");
+ }
+ };
return (
- <>
-
-
- theme.palette.info.main,
- borderBottomLeftRadius: 8,
- borderBottomRightRadius: 8,
- py: 0.5,
- px: 2,
- }}
- >
-
- {statusType.find((st) => st.id == control.status).message}
-
-
-
-
+
-
- {statusType
- .find((st) => st.id == control.status)
- .buttons.map((button) => (
-
- ))}
-
-
- >
+
+
+ {/* saved markers */}
+ {origin &&
}
+
+ {destination &&
}
+
+ {/* route line */}
+ {origin && destination &&
}
+
+ {/* fixed center pin */}
+ {step !== "done" &&
}
+
+
+
+
+
+
);
-};
-export default MapControlPolyline;
+}
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/AlarmText.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/AlarmText.jsx
new file mode 100644
index 0000000..0ddf8a0
--- /dev/null
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/AlarmText.jsx
@@ -0,0 +1,28 @@
+import { Box, Typography } from "@mui/material";
+
+const AlarmText = ({ isSource }) => {
+ if (isSource) return null;
+ return (
+
+
+ با کلیک بر روی مارکر موقعیت را انتخاب کنید
+
+
+ );
+};
+
+export default AlarmText;
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/DataBox.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/DataBox.jsx
new file mode 100644
index 0000000..5768f75
--- /dev/null
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/DataBox.jsx
@@ -0,0 +1,53 @@
+import { Box, Button, TextField } from "@mui/material";
+
+const DataBox = ({ isSource, isDest, sourcePosition, destPosition, editingTarget, onEditSource, onEditDest }) => {
+ if (!isSource) return null;
+
+ return (
+
+
+
+ {isSource && isDest && (
+
+ )}
+
+ {isDest && (
+
+
+
+
+ )}
+
+ );
+};
+
+export default DataBox;
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/ShowRoute.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/ShowRoute.jsx
new file mode 100644
index 0000000..7d47ba8
--- /dev/null
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/ShowRoute.jsx
@@ -0,0 +1,46 @@
+import { useEffect, useRef } from "react";
+import { Marker, Polyline, useMap } from "react-leaflet";
+import L from "leaflet";
+import polyline from "@mapbox/polyline";
+import SourceIcon from "@/assets/images/source-icon.svg";
+import DestIcon from "@/assets/images/destination-icon.svg";
+
+const ShowRoute = ({ area }) => {
+ const map = useMap();
+ const defaultIconSize = [35, 35];
+
+ const createCustomIcon = (size, iconUrl) => {
+ return L.icon({
+ iconUrl: iconUrl,
+ iconSize: size,
+ iconAnchor: [size[0] / 2, size[1]],
+ popupAnchor: [0, -size[1]],
+ });
+ };
+
+ useEffect(() => {
+ if (coords.length > 0) {
+ map.flyToBounds(coords, { padding: [50, 50], duration: 1.5 });
+ }
+ }, [area]);
+ const sourceIcon = createCustomIcon(defaultIconSize, SourceIcon.src);
+ const destIcon = createCustomIcon(defaultIconSize, DestIcon.src);
+
+ if (!area) return null;
+ const coords = polyline.decode(area, 6);
+
+ if (coords.length === 0) return null;
+
+ const sourcePosition = coords[0];
+ const destPosition = coords[coords.length - 1];
+
+ return (
+ <>
+
+
+
+ >
+ );
+};
+
+export default ShowRoute;
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/index.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/index.jsx
new file mode 100644
index 0000000..49c4651
--- /dev/null
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/Routing/index.jsx
@@ -0,0 +1,219 @@
+import { Marker, Polyline, useMapEvents } from "react-leaflet";
+import L from "leaflet";
+import polyline from "@mapbox/polyline";
+import SourceIcon from "@/assets/images/source-icon.svg";
+import PrevSourceIcon from "@/assets/images/prev-source-icon.svg";
+import PrevDestIcon from "@/assets/images/prev-destination-icon.svg";
+import DestIcon from "@/assets/images/destination-icon.svg";
+import { useEffect, useRef, useState } from "react";
+import DataBox from "./DataBox";
+import AlarmText from "./AlarmText";
+
+const Routing = ({ setArea, setLocations, locations, area }) => {
+ const mapPrevSourceMarker = useRef();
+ const mapPrevDestMarker = useRef();
+ const mapRef = useRef(null);
+ const defaultIconSize = [35, 35];
+ const [isSource, setIsSource] = useState(false);
+ const [sourcePosition, setSourcePosition] = useState(null);
+ const [isDest, setIsDest] = useState(false);
+ const [destPosition, setDestPosition] = useState(null);
+ const [routeCoords, setRouteCoords] = useState([]);
+ const [alternateCoords, setAlternateCoords] = useState([]);
+ const [editingTarget, setEditingTarget] = useState(null);
+ const [selectedRoute, setSelectedRoute] = useState(null);
+
+ const createCustomIcon = (size, iconUrl) => {
+ return L.icon({
+ iconUrl: iconUrl,
+ iconSize: size,
+ iconAnchor: [size[0] / 2, size[1]],
+ popupAnchor: [0, -size[1]],
+ });
+ };
+
+ const defaultIcon = createCustomIcon(
+ defaultIconSize,
+ isSource && editingTarget !== "source" ? SourceIcon.src : PrevSourceIcon.src
+ );
+
+ const prevDestIcon = createCustomIcon(
+ defaultIconSize,
+ isDest && editingTarget !== "dest" ? DestIcon.src : PrevDestIcon.src
+ );
+
+ const isMovingSource = !isSource || editingTarget === "source";
+ const isMovingDest = isSource && (!isDest || editingTarget === "dest");
+
+ const map = useMapEvents({
+ move(e) {
+ if (isMovingSource) mapPrevSourceMarker.current.setLatLng(e.target.getCenter());
+ if (isMovingDest && mapPrevDestMarker.current) mapPrevDestMarker.current.setLatLng(e.target.getCenter());
+ },
+ movestart() {
+ if (isMovingSource) mapPrevSourceMarker.current.setIcon(createCustomIcon([45, 45], PrevSourceIcon.src));
+ if (isMovingDest && mapPrevDestMarker.current)
+ mapPrevDestMarker.current.setIcon(createCustomIcon([45, 45], PrevDestIcon.src));
+ },
+ moveend() {
+ if (isMovingSource)
+ mapPrevSourceMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevSourceIcon.src));
+ if (isMovingDest && mapPrevDestMarker.current)
+ mapPrevDestMarker.current.setIcon(createCustomIcon(defaultIconSize, PrevDestIcon.src));
+ },
+ });
+
+ useEffect(() => {
+ mapRef.current = map;
+ }, [map]);
+
+ useEffect(() => {
+ if (locations.length < 2) return;
+ const restoredSource = { lat: locations[0].lat, lng: locations[0].lon };
+ const restoredDest = { lat: locations[1].lat, lng: locations[1].lon };
+ setSourcePosition(restoredSource);
+ setDestPosition(restoredDest);
+ setIsSource(true);
+ setIsDest(true);
+ if (area) {
+ const decoded = polyline.decode(area, 6);
+ setRouteCoords(decoded);
+ setSelectedRoute({ index: "main", coords: decoded });
+ setTimeout(() => {
+ mapRef.current?.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
+ }, 100);
+ } else {
+ fetchRoute(restoredSource, restoredDest);
+ }
+ }, []);
+
+ const fetchRoute = async (source, dest) => {
+ const locs = [
+ { lat: source.lat, lon: source.lng },
+ { lat: dest.lat, lon: dest.lng },
+ ];
+ try {
+ const response = await fetch("https://jouya.141.ir/api/router/drive", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ locations: locs }),
+ });
+ const data = await response.json();
+ const shape = data.trip.legs[0].shape;
+ setLocations(locs);
+ setArea(shape);
+ const decoded = polyline.decode(shape, 6);
+ setRouteCoords(decoded);
+ setSelectedRoute({ index: "main", coords: decoded });
+
+ if (data.alternates?.length > 0) {
+ const decodedAlternates = data.alternates.map((alt) => polyline.decode(alt.trip.legs[0].shape, 6));
+ setAlternateCoords(decodedAlternates);
+ } else {
+ setAlternateCoords([]);
+ }
+ map.flyToBounds(decoded, { padding: [50, 50], duration: 1.5 });
+ } catch (error) {
+ console.error("Routing error:", error);
+ }
+ };
+
+ const handleMarkerClick = async () => {
+ if (!isSource || editingTarget === "source") {
+ const clickedPosition = mapPrevSourceMarker.current.getLatLng();
+ setSourcePosition(clickedPosition);
+ setIsSource(true);
+ setEditingTarget(null);
+ setRouteCoords([]);
+ setAlternateCoords([]);
+ setSelectedRoute(null);
+
+ if (editingTarget === "source" && destPosition) {
+ await fetchRoute(clickedPosition, destPosition);
+ }
+ }
+ };
+
+ const handleDestMarkerClick = async () => {
+ if (!isDest || editingTarget === "dest") {
+ const clickedPosition = mapPrevDestMarker.current.getLatLng();
+ setDestPosition(clickedPosition);
+ setIsDest(true);
+ setEditingTarget(null);
+
+ await fetchRoute(sourcePosition, clickedPosition);
+ }
+ };
+
+ const handleEditSource = () => {
+ setEditingTarget("source");
+ setRouteCoords([]);
+ setAlternateCoords([]);
+ setSelectedRoute(null);
+ };
+
+ const handleEditDest = () => {
+ setEditingTarget("dest");
+ setRouteCoords([]);
+ setAlternateCoords([]);
+ setSelectedRoute(null);
+ };
+
+ const handleSelectRoute = (index, coords) => {
+ setSelectedRoute({ index, coords });
+ const encoded = polyline.encode(coords, 6);
+ setArea(encoded);
+ map.flyToBounds(coords, { padding: [50, 50], duration: 0.3 });
+ };
+
+ return (
+ <>
+
+
+
+ {isSource && (
+
+ )}
+ {alternateCoords.map((coords, index) => (
+ handleSelectRoute(index, coords) }}
+ />
+ ))}
+ {routeCoords.length > 0 && (
+ handleSelectRoute("main", routeCoords) }}
+ />
+ )}
+ >
+ );
+};
+
+export default Routing;
diff --git a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/index.jsx b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/index.jsx
index a4240b3..200c1e0 100644
--- a/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/index.jsx
+++ b/src/components/dashboard/roadMissions/operator/Actions/Create/Form/Area/index.jsx
@@ -2,19 +2,21 @@ import MapLoading from "@/core/components/MapLayer/Loading";
import { Box, Button, DialogActions, DialogContent, Stack } from "@mui/material";
import dynamic from "next/dynamic";
import { useCallback, useState } from "react";
-import MapControlPolyline from "./MapControlPolyline";
+import Routing from "./Routing";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => ,
ssr: false,
});
const Area = ({ allData, setAllData, handlePrev, setTabState }) => {
- const [bound, setBound] = useState(allData.bound);
+ const [area, setArea] = useState(allData.area);
+ const [locations, setLocations] = useState(allData.locations);
const handleNext = useCallback(() => {
- setAllData({ bound: bound });
+ setAllData({ area: area });
+ setAllData({ locations: locations });
setTabState((s) => s + 1);
- }, [bound]);
+ }, [area]);
return (
<>
@@ -22,7 +24,7 @@ const Area = ({ allData, setAllData, handlePrev, setTabState }) => {
-
+
@@ -31,8 +33,8 @@ const Area = ({ allData, setAllData, handlePrev, setTabState }) => {
-