}
- />
- );
-};
-export default CityController;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/EditMachineContent.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/EditMachineContent.jsx
deleted file mode 100644
index 7128b06..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/EditMachineContent.jsx
+++ /dev/null
@@ -1,145 +0,0 @@
-import StyledForm from "@/core/components/StyledForm";
-import { yupResolver } from "@hookform/resolvers/yup";
-import BeenhereIcon from "@mui/icons-material/Beenhere";
-import ExitToAppIcon from "@mui/icons-material/ExitToApp";
-import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
-import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight";
-import OtherHousesIcon from "@mui/icons-material/OtherHouses";
-import { Box, Button, DialogActions, DialogContent, Tab, Tabs } from "@mui/material";
-import { useState } from "react";
-import { useForm } from "react-hook-form";
-import { number, object, string } from "yup";
-import MachineInfo from "./MachineInfo";
-
-function TabPanel(props) {
- const { children, value, index } = props;
- return (
-
- {value === index && {children}}
-
- );
-}
-
-const validationSchema = object({
- name: string().required("وارد کردن نام راهدارخانه الزامیست!"),
- status: string().required("وارد کردن وضعیت الزامیست!"),
- type: string().required("وارد کردن نوع الزامیست!"),
- phone: string().required("وارد کردن تلفن راهدارخانه الزامیست!"),
- team_num: string().required("وارد کردن تعداد اکیپ الزامیست!"),
- staff_num: string().required("وارد کردن تعداد پرسنل الزامیست!"),
- responsible_name: string().required("وارد کردن نام مسئول الزامیست!"),
- responsible_mobile: string()
- .required("وارد کردن تلفن مسئول الزامیست!")
- .matches(/^09\d{9}$/, "شماره تلفن مسئول باید با ۰۹ شروع شده و ۱۱ رقم باشد!"),
- successor_name: string().required("وارد کردن نام جانشین الزامیست!"),
- successor_mobile: string()
- .required("وارد کردن تلفن جانشین الزامیست!")
- .matches(/^09\d{9}$/, "شماره تلفن جانشین باید با ۰۹ شروع شده و ۱۱ رقم باشد!"),
- province_id: number().required("وارد کردن استان الزامیست!"),
- city_id: number().required("وارد کردن شهرستان الزامیست!"),
- machines_light: string().required("وارد کردن ماشین آلات سبک الزامیست!"),
- machines_sheavy: string().required("وارد کردن ماشین آلات نیمه سنگین الزامیست!"),
- machines_heavy: string().required("وارد کردن ماشین آلات سنگین الزامیست!"),
-});
-const EditMachineContent = ({ setOpen, SubmitCreateTollHouse, defaultValues }) => {
- const [tabState, setTabState] = useState(0);
- const handleClose = () => {
- setOpen(false);
- };
-
- const handleChangeTab = (event, newValue) => {
- setTabState(newValue);
- };
- const handleNext = async () => {
- const fieldsToValidate = [
- "status",
- "province_id",
- "city_id",
- "station_id",
- ];
- const isValid = await trigger(fieldsToValidate);
- if (isValid) {
- setTabState(tabState + 1);
- }
- };
- const handlePrev = () => {
- if (tabState === 0) {
- handleClose();
- } else {
- setTabState(tabState - 1);
- }
- };
- const {
- control,
- handleSubmit,
- trigger,
- formState: { isSubmitting },
- } = useForm({
- defaultValues,
- resolver: yupResolver(validationSchema),
- mode: "all",
- });
- const onSubmitBase = async (data) => {
- await SubmitCreateTollHouse(data);
- };
- return (
-
-
- } label="اطلاعات راهدارخانه" />
-
-
-
-
-
-
-
-
-
- : }
- >
- {tabState === 0 ? "بستن" : "مرحله قبل"}
-
- {tabState !== 3 && (
- }
- >
- مرحله بعد
-
- )}
- {tabState === 3 && (
- }
- >
- {isSubmitting ? "در حال ثبت راهدارخانه" : "ثبت راهدارخانه"}
-
- )}
-
-
- );
-};
-export default EditMachineContent;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/ImageUpload.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/ImageUpload.jsx
deleted file mode 100644
index 033a6f1..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/ImageUpload.jsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import { FormControl, FormHelperText } from "@mui/material";
-import UploadSystem from "@/core/components/UploadSystem";
-import React, { useEffect, useState } from "react";
-
-const ImageUpload = ({ name, value, onChange, error, title }) => {
- const [beforeImg, setBeforeImg] = useState(value ? value : null);
- const [beforeFileType, setBeforeFileType] = useState(value ? "image/" : null);
- const [beforeFileName, setBeforeFileName] = useState(null);
- const [showBeforeImage, setShowBeforeImage] = useState(!value);
-
- useEffect(() => {
- if (value) {
- setShowBeforeImage(false);
- if (typeof value === "string") {
- setBeforeImg(value);
- setBeforeFileType("image/");
- } else if (value instanceof File) {
- setBeforeImg(URL.createObjectURL(value));
- setBeforeFileType(value.type);
- }
- }
- }, [value]);
-
- const handleFileChange = (event) => {
- const uploadedFile = event.target?.files?.[0];
- if (uploadedFile) {
- const fileType = event.target?.files?.[0].type;
- const fileName = event.target?.files?.[0].name;
- setBeforeImg(URL.createObjectURL(uploadedFile));
- setBeforeFileType(fileType);
- setBeforeFileName(fileName);
- onChange(uploadedFile);
- setShowBeforeImage(false);
- }
- };
-
- return (
-
-
- {title}
-
-
- {error ? error.message : null}
-
- );
-};
-export default ImageUpload;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/LogesticController.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/LogesticController.jsx
deleted file mode 100644
index 513abbf..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/LogesticController.jsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { Controller, useWatch } from "react-hook-form";
-import SelectBox from "@/core/components/SelectBox";
-import useProvinces from "@/lib/hooks/useProvince";
-import { Grid } from "@mui/material";
-import CityController from "./CityController";
-
-const LogesticController = ({ control }) => {
- const { provinces, errorProvinces, loadingProvinces } = useProvinces();
- const isProvince = useWatch({ control, name: "is_province" });
- return (
-
- {!isProvince ? (
-
- {
- return (
-
- );
- }}
- />
-
- ) : null}
-
-
-
-
- );
-};
-export default LogesticController;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/MachineInfo.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/MachineInfo.jsx
deleted file mode 100644
index 6fca8a4..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/MachineInfo.jsx
+++ /dev/null
@@ -1,311 +0,0 @@
-import { Grid, Stack, TextField } from "@mui/material";
-import { Controller } from "react-hook-form";
-import SelectBox from "@/core/components/SelectBox";
-import useProvince from "@/lib/hooks/useProvince";
-import PersianTextField from "@/core/components/PersianTextField";
-import CityController from "./CityController";
-import LogesticController from "./LogesticController";
-
-const MachineInfo = ({ control }) => {
- const { provinces, loadingProvinces, errorProvinces } = useProvince();
- return (
-
-
-
-
- (
-
- )}
- />
-
-
- (
- {
- const inputValue = event.target.value;
- if (isNaN(Number(inputValue))) {
- return;
- }
- onChange(inputValue);
- }}
- />
- )}
- />
-
-
-
-
-
-
-
-
-
- {
- return (
-
- );
- }}
- />
-
-
- {
- return (
-
- );
- }}
- />
-
-
-
-
-
-
- (
- {
- const inputValue = event.target.value;
- if (isNaN(Number(inputValue))) {
- return;
- }
- onChange(inputValue);
- }}
- />
- )}
- />
-
-
- (
- {
- const inputValue = event.target.value;
- if (isNaN(Number(inputValue))) {
- return;
- }
- onChange(inputValue);
- }}
- />
- )}
- />
-
-
-
-
-
-
- (
-
- )}
- />
-
-
- (
- {
- const inputValue = event.target.value;
- if (isNaN(Number(inputValue))) {
- return;
- }
- onChange(inputValue);
- }}
- />
- )}
- />
-
-
-
-
-
-
- (
-
- )}
- />
-
-
- (
- {
- const inputValue = event.target.value;
- if (isNaN(Number(inputValue))) {
- return;
- }
- onChange(inputValue);
- }}
- />
- )}
- />
-
-
-
-
- );
-};
-export default MachineInfo;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/TollHouseLocation.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/TollHouseLocation.jsx
deleted file mode 100644
index 98d36a7..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/TollHouseLocation.jsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import MapInfoOneMarker from "@/core/components/MapInfoOneMarker";
-import { Stack } from "@mui/material";
-import { useWatch } from "react-hook-form";
-
-const TollHouseLocation = ({ setValue, errors, control }) => {
- const StartPoint = useWatch({ control, name: "start_point" });
- return (
- <>
-
-
-
- >
- );
-};
-export default TollHouseLocation;
diff --git a/src/components/dashboard/machines/Form/CreateTollHouse/index.jsx b/src/components/dashboard/machines/Form/CreateTollHouse/index.jsx
deleted file mode 100644
index 3649dcd..0000000
--- a/src/components/dashboard/machines/Form/CreateTollHouse/index.jsx
+++ /dev/null
@@ -1,154 +0,0 @@
-import { Button, Dialog, IconButton, useMediaQuery } from "@mui/material";
-import { useState } from "react";
-import CreateTollHouseContent from "./EditMachineContent";
-import { AddCircle } from "@mui/icons-material";
-import { useTheme } from "@emotion/react";
-import { CREATE_TOLL_HOUSE } from "@/core/utils/routes";
-import useRequest from "@/lib/hooks/useRequest";
-import CloseIcon from "@mui/icons-material/Close";
-import { useAuth } from "@/lib/contexts/auth";
-import { usePermissions } from "@/lib/hooks/usePermissions";
-
-const CreateTollHouse = ({ mutate }) => {
- const requestServer = useRequest({ notificationSuccess: true });
- const theme = useTheme();
- const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
- const [open, setOpen] = useState(false);
- const { user } = useAuth();
- const { data: userPermissions } = usePermissions();
- const hasCreateProvincePermission = userPermissions.some((item) => ["add-tollhouse"].includes(item));
- const handleOpen = () => {
- setOpen(true);
- };
- const SubmitCreateTollHouse = async (result) => {
- const fields = [
- "province_id",
- "city_id",
- "name",
- "status",
- "type",
- "team_num",
- "staff_num",
- "phone",
- "responsible_name",
- "responsible_mobile",
- "successor_name",
- "successor_mobile",
- "machines_light",
- "machines_sheavy",
- "machines_heavy",
- "overview_files_1",
- "overview_files_2",
- "overview_files_3",
- "overview_files_4",
- "overview_files_5",
- ];
- const formData = new FormData();
- fields.forEach((field) => {
- if (result[field] !== undefined && result[field] !== null) {
- formData.append(field, result[field]);
- }
- });
- formData.append("lat", result.start_point.lat);
- formData.append("lng", result.start_point.lng);
- formData.append("area[type]", "polygon");
- result.area.map((point, pointIndex) => {
- formData.append(`area[coordinates][${pointIndex}][0]`, point.lon);
- formData.append(`area[coordinates][${pointIndex}][1]`, point.lat);
- });
- const repeat_first = result.area.length;
- formData.append(`area[coordinates][${repeat_first}][0]`, result.area[0].lon);
- formData.append(`area[coordinates][${repeat_first}][1]`, result.area[0].lat);
- await requestServer(`${CREATE_TOLL_HOUSE}`, "post", {
- data: formData,
- })
- .then(() => {
- mutate();
- setOpen(false);
- })
- .catch(() => {});
- };
- const defaultValues = {
- name: "",
- is_province: !hasCreateProvincePermission,
- province_id: !hasCreateProvincePermission ? user.province_id : null,
- city_id: null,
- status: "",
- type: "",
- phone: "",
- team_num: "",
- staff_num: "",
- responsible_name: "",
- responsible_mobile: "",
- successor_name: "",
- successor_mobile: "",
- machines_light: "",
- machines_sheavy: "",
- machines_heavy: "",
- overview_files_1: null,
- overview_files_2: null,
- overview_files_3: null,
- overview_files_4: null,
- overview_files_5: null,
- start_point: "",
- area: [
- { lat: "", lon: "" },
- { lat: "", lon: "" },
- { lat: "", lon: "" },
- { lat: "", lon: "" },
- ],
- };
- return (
- <>
- {isMobile ? (
-
-
-
- ) : (
- }
- onClick={handleOpen}
- >
- راهدارخانه جدید
-
- )}
-
- >
- );
-};
-export default CreateTollHouse;
diff --git a/src/components/dashboard/machines/Form/Edit/EditController.jsx b/src/components/dashboard/machines/Form/Edit/EditController.jsx
deleted file mode 100644
index a5f9c7f..0000000
--- a/src/components/dashboard/machines/Form/Edit/EditController.jsx
+++ /dev/null
@@ -1,77 +0,0 @@
-import DialogLoading from "@/core/components/DialogLoading";
-import { GET_TOLL_HOUSE_DETAILS, UPDATE_TOLL_HOUSE_ITEM } from "@/core/utils/routes";
-import { usePermissions } from "@/lib/hooks/usePermissions";
-import useRequest from "@/lib/hooks/useRequest";
-import { useEffect, useState } from "react";
-import EditMachineContent from "../CreateTollHouse/EditMachineContent";
-
-const EditController = ({ rowId, mutate, setOpenEditDialog }) => {
- const { data: userPermissions } = usePermissions();
- const hasCreateProvincePermission = userPermissions.some((item) => ["update-machine"].includes(item));
- const requestServer = useRequest();
- const [MachineItemDetails, setMachineItemDetails] = useState(null);
- const [machineItemDetailsLoading, setMachineItemDetailsLoading] = useState(false);
-
- useEffect(() => {
- setMachineItemDetailsLoading(true);
- requestServer(`${GET_TOLL_HOUSE_DETAILS}/${rowId}`, "get")
- .then((response) => {
- setMachineItemDetails(response.data.data);
- setMachineItemDetailsLoading(false);
- })
- .catch((e) => {
- setMachineItemDetailsLoading(false);
- });
- }, [rowId]);
-
- const defaultData = {
- is_province: !hasCreateProvincePermission,
- province_id: MachineItemDetails?.province_id || null,
- city_id: MachineItemDetails?.city_id || null,
- status: MachineItemDetails?.status || "",
- station_id: MachineItemDetails?.station_id || "",
- };
- const HandleSubmit = async (result) => {
- const fields = [
- "status",
- "province_id",
- "city_id",
- "station_id",
- ];
- const formData = new FormData();
- fields.forEach((field) => {
- if (result[field] !== undefined && result[field] !== null) {
- formData.append(field, result[field]);
- }
- });
- for (let i = 1; i <= 5; i++) {
- if (result[`overview_files_${i}`] !== defaultData[`overview_files_${i}`]) {
- formData.append(`overview_files_${i}`, result[`overview_files_${i}`]);
- }
- }
-
- await requestServer(`${UPDATE_TOLL_HOUSE_ITEM}/${rowId}`, "post", {
- data: formData,
- notificationSuccess: true,
- })
- .then(() => {
- mutate();
- setOpenEditDialog(false);
- })
- .catch(() => {});
- };
- return (
- <>
- {machineItemDetailsLoading ? (
-
- ) : (
-
- )}
- >
- );
-};
-export default EditController;
diff --git a/src/components/dashboard/machines/MachinesList.jsx b/src/components/dashboard/machines/MachinesList.jsx
index bcfb104..880f0cb 100644
--- a/src/components/dashboard/machines/MachinesList.jsx
+++ b/src/components/dashboard/machines/MachinesList.jsx
@@ -1,15 +1,9 @@
"use client";
-import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsType/CustomSelectByDependency";
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
import { GET_MACHINES_LIST } from "@/core/utils/routes";
-import { useAuth } from "@/lib/contexts/auth";
-import useEdaratLists from "@/lib/hooks/useEdaratLists";
-import { usePermissions } from "@/lib/hooks/usePermissions";
-import useProvinces from "@/lib/hooks/useProvince";
import { Box, Typography } from "@mui/material";
-import { useEffect, useMemo, useState } from "react";
+import { useMemo } from "react";
import RowActions from "./RowActions";
-import Toolbar from "./Toolbar";
const statusOptions = [
{ value: "", label: "همه وضعیت ها" },
@@ -23,47 +17,7 @@ const statusOptions = [
];
const MachinesList = () => {
- const { data: userPermissions } = usePermissions();
- const hasCountryPermission = userPermissions?.includes("show-tollhouse");
- const { user } = useAuth();
-
const columns = useMemo(() => {
- const provinceColumn = {
- accessorKey: "province_id",
- header: "استان",
- id: "province_id",
- enableColumnFilter: true,
- datatype: "numeric",
- filterMode: "equals",
- grow: false,
- size: 130,
- ColumnSelectComponent: (props) => {
- const { provinces, errorProvinces, loadingProvinces } = useProvinces();
- const getColumnSelectOptions = useMemo(() => {
- if (loadingProvinces) {
- return [{ value: "loading", label: "در حال بارگذاری..." }];
- }
- if (errorProvinces) {
- return [{ value: "error", label: "خطا در بارگذاری" }];
- }
- return [
- { value: "", label: "کل کشور" },
- ...provinces.map((province) => ({
- value: province.id,
- label: province.name_fa,
- })),
- ];
- }, [provinces, errorProvinces, loadingProvinces]);
- return (
-
- );
- },
- Cell: ({ row }) => <>{row.original.province_name}>,
- };
return [
{
accessorKey: "id",
@@ -75,7 +29,7 @@ const MachinesList = () => {
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
- size: 100,
+ size: 50,
},
{
@@ -85,7 +39,6 @@ const MachinesList = () => {
enableSorting: false,
datatype: "text",
grow: false,
- size: 50,
columns: [
{
accessorKey: "car_name",
@@ -135,65 +88,6 @@ const MachinesList = () => {
grow: false,
size: 100,
},
- ...(hasCountryPermission ? [provinceColumn] : []),
- {
- accessorKey: "city_id",
- header: "شهرستان", // Office
- id: "city_id",
- enableColumnFilter: true,
- datatype: "numeric",
- filterMode: "equals",
- dependencyId: hasCountryPermission ? "province_id" : null,
- grow: false,
- size: 120,
- ColumnSelectComponent: (props) => {
- const { edaratList, loadingEdaratList, errorEdaratList } = useEdaratLists(
- hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
- );
- const [prevDependency, setPrevDependency] = useState(
- hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
- );
-
- const getColumnSelectOptions = useMemo(() => {
- if (hasCountryPermission && props.dependencyFieldValue.value === "") {
- return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
- }
- if (loadingEdaratList) {
- return [{ value: "loading", label: "در حال بارگذاری..." }];
- }
- if (errorEdaratList) {
- return [{ value: "error", label: "خطا در بارگذاری" }];
- }
- return [
- { value: "", label: "کل شهر ها" },
- ...edaratList.map((edare) => ({
- value: edare.id,
- label: edare.name_fa,
- })),
- ];
- }, [edaratList, loadingEdaratList, errorEdaratList]);
- useEffect(() => {
- if (hasCountryPermission) return;
- if (prevDependency === props.dependencyFieldValue?.value) return;
- props.handleChange({ ...props.filterParameters, value: "" });
- setPrevDependency(props.dependencyFieldValue?.value);
- }, [props.dependencyFieldValue?.value, hasCountryPermission]);
- return (
-
- );
- },
- Cell: ({ row }) => <>{row.original.city_name}>,
- },
{
accessorKey: "status",
header: "وضعیت",
@@ -214,7 +108,6 @@ const MachinesList = () => {
return {status?.label || ""};
},
},
-
],
},
];
@@ -230,7 +123,6 @@ const MachinesList = () => {
page_name={"machines"}
table_name={"machinesList"}
sorting={[{ id: "id", desc: true }]}
- TableToolbar={Toolbar}
enableRowActions
positionActionsColumn={"first"}
RowActions={RowActions}
diff --git a/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx b/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
new file mode 100644
index 0000000..6cfcd9d
--- /dev/null
+++ b/src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
@@ -0,0 +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;
diff --git a/src/components/dashboard/machines/Form/Edit/index.jsx b/src/components/dashboard/machines/RowActions/Edit/index.jsx
similarity index 54%
rename from src/components/dashboard/machines/Form/Edit/index.jsx
rename to src/components/dashboard/machines/RowActions/Edit/index.jsx
index 53be78c..f3cec95 100644
--- a/src/components/dashboard/machines/Form/Edit/index.jsx
+++ b/src/components/dashboard/machines/RowActions/Edit/index.jsx
@@ -1,15 +1,15 @@
+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 BorderColorIcon from "@mui/icons-material/BorderColor";
-import EditController from "./EditController";
-import CloseIcon from "@mui/icons-material/Close";
+import EditFormContent from "./Form";
-const EditForm = ({ row, mutate, rowId }) => {
+const Edit = ({ row, mutate, rowId }) => {
const [openEditDialog, setOpenEditDialog] = useState(false);
return (
<>
-
+
{
setOpenEditDialog(true);
}}
>
-
+
-