diff --git a/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx b/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx
index 17fd595..d6311e9 100644
--- a/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx
+++ b/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx
@@ -137,15 +137,26 @@ const CreateFormContent = ({ setOpen, onSubmit }) => {
const onSubmitBase = (data) => {
let result = { ...data };
- result.before_image === null && delete result.before_image;
- result.after_image === null && delete result.after_image;
+ if (result.before_image === null) {
+ delete result.before_image;
+ delete data.before_image;
+ }
+
+ if (result.after_image === null) {
+ delete result.after_image;
+ delete data.after_image;
+ }
+
if (result.end_point === "") {
delete result.end_point;
+ delete data.end_point;
} else {
result.end_point = `${result.end_point.lat},${result.end_point.lng}`;
}
+
if (result.start_point === "") {
delete result.start_point;
+ delete data.start_point;
} else {
result.start_point = `${result.start_point.lat},${result.start_point.lng}`;
}
diff --git a/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditController.jsx b/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditController.jsx
index 169170b..164fc70 100644
--- a/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditController.jsx
+++ b/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditController.jsx
@@ -33,7 +33,21 @@ const EditController = ({ rowId, mutate, setOpenEditDialog, openEditDialog, row
}}
>
ویرایش اطلاعات
-
+
);
};
diff --git a/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormContent.jsx b/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormContent.jsx
index 7bd5a49..363529d 100644
--- a/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormContent.jsx
+++ b/src/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormContent.jsx
@@ -1,26 +1,26 @@
-import { LinearProgress, Typography } from "@mui/material";
+import {LinearProgress, Typography} from "@mui/material";
import React from "react";
import useRoadItemGetISubtems from "@/lib/hooks/useRoadItemGetISubtems";
import EditFormCreate from "@/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormCreate";
-const EditFormContent = ({ setOpenEditDialog, onSubmit, defaultData }) => {
- const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetISubtems(defaultData?.item);
- const subItem = subItemsList.find((SubItem) => SubItem.sub_item === defaultData?.sub_item);
+const EditFormContent = ({setOpenEditDialog, onSubmit, defaultData}) => {
+ const {subItemsList, loadingSubItemsList, errorSubItemsList} = useRoadItemGetISubtems(defaultData?.item_id);
+ const subItem = subItemsList.find((SubItem) => SubItem.sub_item === defaultData?.sub_item_id);
const defaultValues = {
- before_image: defaultData?.files[0]?.full_path_for_fast_react || null,
- after_image: defaultData?.files[1]?.full_path_for_fast_react || null,
- amount: defaultData?.sub_item_data || null,
- start_point: { lat: defaultData?.start_lat || "", lng: defaultData?.start_lng || "" },
- end_point: { lat: defaultData?.end_lat || "", lng: defaultData?.end_lng || "" },
+ before_image: defaultData?.before_image || null,
+ after_image: defaultData?.after_image || null,
+ amount: defaultData?.amount || null,
+ start_point: defaultData?.start_point || {lat: "", lng: ""},
+ end_point: defaultData?.end_point || {lat: "", lng: ""},
cmms_machines: defaultData?.cmms_machines || null,
rahdaran_id: defaultData?.rahdaran || null,
};
const onSubmitBase = (data) => {
- let result = { ...data };
+ let result = {...data};
(result.before_image === null || result.before_image === defaultValues.before_image) &&
- delete result.before_image;
+ delete result.before_image;
(result.after_image === null || result.after_image === defaultValues.after_image) && delete result.after_image;
if (subItem.needs_end_point !== 1) {
delete result.end_point;
@@ -57,7 +57,7 @@ const EditFormContent = ({ setOpenEditDialog, onSubmit, defaultData }) => {
خطا در دریافت اطلاعات!!!
) : loadingSubItemsList ? (
-
+
) : (
{subItem.needs_image === 1 ? (
{
render={({field, fieldState: {error}}) => {
return (
field.onChange(value || [])}
+ carCode={field.value}
+ setCarCode={(value) => field.onChange(value)}
error={error}
/>
);
diff --git a/src/core/components/CarCode.jsx b/src/core/components/CarCode.jsx
index 20e0a30..a5e5ea7 100644
--- a/src/core/components/CarCode.jsx
+++ b/src/core/components/CarCode.jsx
@@ -1,10 +1,10 @@
-import {Autocomplete, CircularProgress, TextField} from "@mui/material";
-import {useEffect, useState} from "react";
+import { Autocomplete, CircularProgress, TextField } from "@mui/material";
+import { useEffect, useState } from "react";
import useRequest from "@/lib/hooks/useRequest";
-import {debounce} from "@mui/material/utils";
-import {GET_CAR_LIST_SEARCH} from "@/core/utils/routes";
+import { debounce } from "@mui/material/utils";
+import { GET_CAR_LIST_SEARCH } from "@/core/utils/routes";
-const CarCode = ({carCode, setCarCode, inputValueDefault = "", error, multiple = false}) => {
+const CarCode = ({ carCode, setCarCode, inputValueDefault = "", error, multiple = false }) => {
const [inputValue, setInputValue] = useState(inputValueDefault);
const [options, setOptions] = useState([]);
const [loading, setLoading] = useState(false);
@@ -18,10 +18,10 @@ const CarCode = ({carCode, setCarCode, inputValueDefault = "", error, multiple =
}
setLoading(true);
requestServer(`${GET_CAR_LIST_SEARCH}?machine_code=${query}`, "get", {
- requestOptions: {signal: controller.signal},
+ requestOptions: { signal: controller.signal },
})
.then((response) => {
- const combinedArray = [...carCode, ...response.data.data];
+ const combinedArray = carCode ? [...carCode, ...response.data.data] : [...response.data.data];
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
setOptions(uniqueArray || []);
})
@@ -55,7 +55,7 @@ const CarCode = ({carCode, setCarCode, inputValueDefault = "", error, multiple =
options={options}
getOptionLabel={(option) => {
if (typeof option === "string") return option;
- const {machine_code, car_name, plak_number} = option;
+ const { machine_code, car_name, plak_number } = option;
let label = `${machine_code || ""}`;
if (car_name) {
label += ` | ${car_name}`;
@@ -85,7 +85,7 @@ const CarCode = ({carCode, setCarCode, inputValueDefault = "", error, multiple =
...params.InputProps,
endAdornment: (
<>
- {loading ? : null}
+ {loading ? : null}
{params.InputProps.endAdornment}
>
),
diff --git a/src/core/components/RahdarCode.jsx b/src/core/components/RahdarCode.jsx
index f6d0e90..1c374ee 100644
--- a/src/core/components/RahdarCode.jsx
+++ b/src/core/components/RahdarCode.jsx
@@ -22,7 +22,9 @@ const RahdarCode = ({ rahdarsCode, setRahdarsCode, error, multiple = true }) =>
requestOptions: { signal: controller.signal },
})
.then((response) => {
- const combinedArray = [...rahdarsCode, ...response.data.data];
+ const combinedArray = rahdarsCode
+ ? [...rahdarsCode, ...response.data.data]
+ : [...response.data.data];
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
setOptions(uniqueArray || []);
})