Feature/user log entrance
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import AzmayeshPage from "@/components/dashboard/azmayesh";
|
import AzmayeshPage from "@/components/dashboard/azmayesh";
|
||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission permission_name={["azmayesh-management"]}>
|
<WithPermission permission_name={["azmayesh-management"]}>
|
||||||
<AzmayeshPage />
|
<AzmayeshPage />
|
||||||
|
<ActivityCodeLog activity_code={1157} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import AzmayeshTypePage from "@/components/dashboard/azmayeshType";
|
import AzmayeshTypePage from "@/components/dashboard/azmayeshType";
|
||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission permission_name={["azmayesh-type-management"]}>
|
<WithPermission permission_name={["azmayesh-type-management"]}>
|
||||||
<AzmayeshTypePage />
|
<AzmayeshTypePage />
|
||||||
|
<ActivityCodeLog activity_code={1161} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import OperatorPage from "@/components/dashboard/roadItems/operator";
|
import OperatorPage from "@/components/dashboard/roadItems/operator";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission permission_name={["create-road-item"]}>
|
<WithPermission permission_name={["create-road-item"]}>
|
||||||
<OperatorPage />
|
<OperatorPage />
|
||||||
|
<ActivityCodeLog activity_code={1152} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import SupervisorPage from "@/components/dashboard/roadItems/supervisor";
|
import SupervisorPage from "@/components/dashboard/roadItems/supervisor";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission
|
<WithPermission
|
||||||
permission_name={["show-road-item-supervise-cartable", "show-road-item-supervise-cartable-province"]}
|
permission_name={["show-road-item-supervise-cartable", "show-road-item-supervise-cartable-province"]}
|
||||||
>
|
>
|
||||||
<SupervisorPage />
|
<SupervisorPage />
|
||||||
|
<ActivityCodeLog activity_code={1148} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import OperatorPage from "@/components/dashboard/roadPatrols/operator";
|
import OperatorPage from "@/components/dashboard/roadPatrols/operator";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
|
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission permission_name={["add-road-patrol"]}>
|
<WithPermission permission_name={["add-road-patrol"]}>
|
||||||
<OperatorPage />
|
<OperatorPage />
|
||||||
|
<ActivityCodeLog activity_code={1145} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import WithPermission from "@/core/middlewares/withPermission";
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
import SupervisorPage from "@/components/dashboard/roadPatrols/supervisor";
|
import SupervisorPage from "@/components/dashboard/roadPatrols/supervisor";
|
||||||
|
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
return (
|
return (
|
||||||
<WithPermission permission_name={["show-road-patrol-supervise-cartable"]}>
|
<WithPermission permission_name={["show-road-patrol-supervise-cartable"]}>
|
||||||
<SupervisorPage />
|
<SupervisorPage />
|
||||||
|
<ActivityCodeLog activity_code={1143} />
|
||||||
</WithPermission>
|
</WithPermission>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ function TabPanel(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
itemId: null,
|
item_id: null,
|
||||||
itemSubId: null,
|
sub_item_id: null,
|
||||||
amount: "",
|
amount: "",
|
||||||
action_date: "",
|
activity_time: "",
|
||||||
start_date: "",
|
activity_date: "",
|
||||||
before_image: null,
|
before_image: null,
|
||||||
after_image: null,
|
after_image: null,
|
||||||
cmms_machines: null,
|
cmms_machines: null,
|
||||||
@@ -40,13 +40,13 @@ const defaultValues = {
|
|||||||
end_point: "",
|
end_point: "",
|
||||||
};
|
};
|
||||||
const validationSchema = object({
|
const validationSchema = object({
|
||||||
itemId: string().required("نوع آیتم را مشخص کنید!"),
|
item_id: string().required("نوع آیتم را مشخص کنید!"),
|
||||||
itemSubId: string().required("موضوع مشاهده شده را مشخص کنید!"),
|
sub_item_id: string().required("موضوع مشاهده شده را مشخص کنید!"),
|
||||||
amount: string().required("وارد کردن مقدار الزامیست!"),
|
amount: string().required("وارد کردن مقدار الزامیست!"),
|
||||||
cmms_machines: array().required("وارد کردن کد خودرو الزامیست!"),
|
cmms_machines: array().required("وارد کردن کد خودرو الزامیست!"),
|
||||||
rahdaran_id: array().required("وارد کردن کد راهداران الزامیست!").min(1, "حداقل یک کد راهدار باید وارد شود!"), // بررسی حداقل یک آیتم,
|
rahdaran_id: array().required("وارد کردن کد راهداران الزامیست!").min(1, "حداقل یک کد راهدار باید وارد شود!"), // بررسی حداقل یک آیتم,
|
||||||
action_date: string().required("لطفا زمان فعالیت را انتخاب کنید!"),
|
activity_time: string().required("لطفا زمان فعالیت را انتخاب کنید!"),
|
||||||
start_date: string().required("لطفاً تاریخ شروع فعالیت را انتخاب کنید!"),
|
activity_date: string().required("لطفاً تاریخ شروع فعالیت را انتخاب کنید!"),
|
||||||
before_image: mixed()
|
before_image: mixed()
|
||||||
.nullable()
|
.nullable()
|
||||||
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
||||||
@@ -82,12 +82,13 @@ const validationSchema = object({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const CreateFormContent = ({ setOpen, mutate, onSubmit }) => {
|
const CreateFormContent = ({ setOpen, onSubmit }) => {
|
||||||
const [tabState, setTabState] = useState(0);
|
const [tabState, setTabState] = useState(0);
|
||||||
const [itemsList, setItemsList] = useState();
|
const [itemsList, setItemsList] = useState();
|
||||||
const [subItemsList, setSubItemsList] = useState([]);
|
const [subItemsList, setSubItemsList] = useState([]);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
@@ -100,8 +101,8 @@ const CreateFormContent = ({ setOpen, mutate, onSubmit }) => {
|
|||||||
if (tabState === 2) {
|
if (tabState === 2) {
|
||||||
const fieldsToReset = [
|
const fieldsToReset = [
|
||||||
"amount",
|
"amount",
|
||||||
"action_date",
|
"activity_time",
|
||||||
"start_date",
|
"activity_date",
|
||||||
"before_image",
|
"before_image",
|
||||||
"after_image",
|
"after_image",
|
||||||
"cmms_machines",
|
"cmms_machines",
|
||||||
@@ -133,8 +134,44 @@ const CreateFormContent = ({ setOpen, mutate, onSubmit }) => {
|
|||||||
context: { subItemsList },
|
context: { subItemsList },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onSubmitBase = (data) => {
|
||||||
|
let result = { ...data };
|
||||||
|
|
||||||
|
result.before_image === null && delete result.before_image;
|
||||||
|
result.after_image === null && delete result.after_image;
|
||||||
|
if (result.end_point === "") {
|
||||||
|
delete result.end_point;
|
||||||
|
} else {
|
||||||
|
result.end_point = `${result.end_point.lat},${result.end_point.lng}`;
|
||||||
|
}
|
||||||
|
if (result.start_point === "") {
|
||||||
|
delete result.start_point;
|
||||||
|
} else {
|
||||||
|
result.start_point = `${result.start_point.lat},${result.start_point.lng}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.rahdaran_id.forEach((rahdar, index) => {
|
||||||
|
result[`rahdaran_id[${index}]`] = rahdar.id;
|
||||||
|
});
|
||||||
|
delete result.rahdaran_id;
|
||||||
|
|
||||||
|
result.cmms_machines.forEach((cmms_machine, index) => {
|
||||||
|
result[`machines_id[${index}]`] = cmms_machine.id;
|
||||||
|
});
|
||||||
|
delete result.cmms_machines;
|
||||||
|
|
||||||
|
onSubmit({
|
||||||
|
result,
|
||||||
|
data: {
|
||||||
|
...data,
|
||||||
|
item_name: itemsList.name,
|
||||||
|
sub_item_name: subItemsList.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
<StyledForm onSubmit={handleSubmit(onSubmitBase)}>
|
||||||
<Tabs
|
<Tabs
|
||||||
allowScrollButtonsMobile
|
allowScrollButtonsMobile
|
||||||
value={tabState}
|
value={tabState}
|
||||||
|
|||||||
@@ -82,22 +82,22 @@ const GetItemInfo = ({ register, itemsList, subItemsList, control, setValue, err
|
|||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<Grid item xs={12} md={6}>
|
<Grid item xs={12} md={6}>
|
||||||
<MuiDatePicker
|
<MuiDatePicker
|
||||||
name="start_date"
|
name="activity_date"
|
||||||
error={errors.start_date ? errors.start_date.message : null}
|
error={errors.activity_date ? errors.activity_date.message : null}
|
||||||
value={watch("start_date")}
|
value={watch("activity_date")}
|
||||||
placeholder={"تاریخ شروع فعالیت"}
|
placeholder={"تاریخ شروع فعالیت"}
|
||||||
setFieldValue={setValue}
|
setFieldValue={setValue}
|
||||||
helperText={errors.start_date ? errors.start_date.message : null}
|
helperText={errors.activity_date ? errors.activity_date.message : null}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} md={6}>
|
<Grid item xs={12} md={6}>
|
||||||
<MuiTimePicker
|
<MuiTimePicker
|
||||||
value={watch("action_date")}
|
value={watch("activity_time")}
|
||||||
name="action_date"
|
name="activity_time"
|
||||||
error={errors.action_date ? errors.action_date.message : null}
|
error={errors.activity_time ? errors.activity_time.message : null}
|
||||||
placeholder={"زمان فعالیت"}
|
placeholder={"زمان فعالیت"}
|
||||||
setFieldValue={setValue}
|
setFieldValue={setValue}
|
||||||
helperText={errors.action_date ? errors.action_date.message : null}
|
helperText={errors.activity_time ? errors.activity_time.message : null}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ const GetItemsForm = ({ setValue, setItemsList, tabState, setTabState }) => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setValue("itemId", item.id);
|
setValue("item_id", item.id);
|
||||||
setItemsList(item.name);
|
setItemsList(item);
|
||||||
setTabState(tabState + 1);
|
setTabState(tabState + 1);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Card, CardActionArea, Grid, LinearProgress, Typography } from "@mui/mat
|
|||||||
import useRoadItemGetSubItems from "@/lib/hooks/useRoadItemGetISubtems";
|
import useRoadItemGetSubItems from "@/lib/hooks/useRoadItemGetISubtems";
|
||||||
|
|
||||||
const GetSubItemsForm = ({ setValue, watch, setSubItemsList, tabState, setTabState }) => {
|
const GetSubItemsForm = ({ setValue, watch, setSubItemsList, tabState, setTabState }) => {
|
||||||
const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetSubItems(watch("itemId"));
|
const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetSubItems(watch("item_id"));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -27,7 +27,7 @@ const GetSubItemsForm = ({ setValue, watch, setSubItemsList, tabState, setTabSta
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setValue("itemSubId", item.sub_item);
|
setValue("sub_item_id", item.sub_item);
|
||||||
setSubItemsList(item);
|
setSubItemsList(item);
|
||||||
setTabState(tabState + 1);
|
setTabState(tabState + 1);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const PreviousStatesInfo = ({ itemsList, subItemsList }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
<Divider sx={{ flex: 1, mx: 2 }} />
|
<Divider sx={{ flex: 1, mx: 2 }} />
|
||||||
<Typography variant="body2" sx={{ fontWeight: 600, color: "grey.800" }}>
|
<Typography variant="body2" sx={{ fontWeight: 600, color: "grey.800" }}>
|
||||||
{itemsList || "هیچ آیتمی انتخاب نشده است"}
|
{itemsList.name || "هیچ آیتمی انتخاب نشده است"}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} sm={12} sx={{ display: "flex", alignItems: "center" }}>
|
<Grid item xs={12} sm={12} sx={{ display: "flex", alignItems: "center" }}>
|
||||||
|
|||||||
@@ -6,22 +6,11 @@ import useRequest from "@/lib/hooks/useRequest";
|
|||||||
|
|
||||||
const OperatorCreateForm = ({ open, setOpen, mutate, rowId }) => {
|
const OperatorCreateForm = ({ open, setOpen, mutate, rowId }) => {
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const HandleSubmit = async (data) => {
|
const HandleSubmit = async ({ result }) => {
|
||||||
let endPoint;
|
|
||||||
let startPoint = `${data.start_point.lat},${data.start_point.lng}`;
|
|
||||||
data.end_point !== "" && (endPoint = `${data.end_point.lat},${data.end_point.lng}`);
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
data.rahdaran_id.map((rahdar, index) => formData.append(`rahdaran_id[${index}]`, rahdar.id));
|
for (const [key, value] of Object.entries(result)) {
|
||||||
formData.append("item_id", data.itemId);
|
formData.append(key, value);
|
||||||
formData.append("sub_item_id", data.itemSubId);
|
}
|
||||||
formData.append("amount", data.amount);
|
|
||||||
formData.append("activity_time", data.action_date);
|
|
||||||
formData.append("activity_date", data.start_date);
|
|
||||||
data.cmms_machines.map((machine, index) => formData.append(`machines_id[${index}]`, machine.id));
|
|
||||||
data.before_image !== null && formData.append("before_image", data.before_image);
|
|
||||||
data.after_image !== null && formData.append("after_image", data.after_image);
|
|
||||||
data.start_point !== "" && formData.append("start_point", startPoint);
|
|
||||||
data.end_point !== "" && formData.append("end_point", endPoint);
|
|
||||||
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
await requestServer(CREATE_ROAD_ITEMS, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { Button, Dialog, DialogActions, DialogTitle } from "@mui/material";
|
||||||
|
import GashtCreateContent from "./GashtCreateContent";
|
||||||
|
|
||||||
|
const GashtCreate = ({ open, setOpen, mutate, rowId }) => {
|
||||||
|
return (
|
||||||
|
<Dialog open={open} fullWidth maxWidth="md">
|
||||||
|
<DialogTitle>جستجوی مورد مشاهده شده در گشت راهداری و ترابری</DialogTitle>
|
||||||
|
<GashtCreateContent mutate={mutate} setOpen={setOpen} />
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={() => setOpen(false)} variant="outlined" color="primary" autoFocus>
|
||||||
|
بستن
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default GashtCreate;
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { Box, Button, DialogActions, DialogContent, Grid, Stack, Tab, Tabs } from "@mui/material";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
|
import * as yup from "yup";
|
||||||
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
|
import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile";
|
||||||
|
import FileCopyIcon from "@mui/icons-material/FileCopy";
|
||||||
|
import InfoIcon from "@mui/icons-material/Info";
|
||||||
|
import GetItemsForm from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetItemsForm";
|
||||||
|
import GetSubItemsForm from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetSubItemsForm";
|
||||||
|
import GetItemInfo from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetItemInfo";
|
||||||
|
import ExitToAppIcon from "@mui/icons-material/ExitToApp";
|
||||||
|
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight";
|
||||||
|
import BeenhereIcon from "@mui/icons-material/Beenhere";
|
||||||
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
|
import React from "react";
|
||||||
|
import { TabPanel } from "@mui/lab";
|
||||||
|
|
||||||
|
const GashtCreateContent = ({ mutate, setOpen }) => {
|
||||||
|
const defaultValues = {
|
||||||
|
start_date: null,
|
||||||
|
end_date: null,
|
||||||
|
item_id: null,
|
||||||
|
road_patrol_id: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const validationSchema = yup
|
||||||
|
.object()
|
||||||
|
.shape({
|
||||||
|
start_date: yup.string().nullable(),
|
||||||
|
end_date: yup.string().nullable(),
|
||||||
|
item_id: yup.string().nullable(),
|
||||||
|
road_patrol_id: yup.string().nullable(),
|
||||||
|
})
|
||||||
|
.test("at-least-one", "وارد کردن مقدار ضروریست!!!", (values) => {
|
||||||
|
return (!!values.start_date && !!values.end_date) || !!values.item_id || !!values.road_patrol_id;
|
||||||
|
});
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
getValues,
|
||||||
|
watch,
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
formState: { errors, isSubmitting },
|
||||||
|
} = useForm({
|
||||||
|
defaultValues,
|
||||||
|
resolver: yupResolver(validationSchema),
|
||||||
|
mode: "onBlur",
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<Tabs
|
||||||
|
allowScrollButtonsMobile
|
||||||
|
value={tabState}
|
||||||
|
onChange={handleChangeTab}
|
||||||
|
variant={`${isMobile ? "scrollable" : "fullWidth"}`}
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "space-around",
|
||||||
|
width: "100%",
|
||||||
|
backgroundColor: "#efefef",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Tab icon={<InsertDriveFileIcon />} label="انتخاب آیتم" />
|
||||||
|
<Tab disabled={tabState === 0} icon={<FileCopyIcon />} label="انتخاب موضوع مشاهده شده" />
|
||||||
|
</Tabs>
|
||||||
|
<DialogContent dividers sx={{ overflowY: "auto", maxHeight: "70vh" }}>
|
||||||
|
<Box sx={{ flex: 1 }}>
|
||||||
|
<TabPanel value={tabState} index={0}>
|
||||||
|
<GetItemsForm
|
||||||
|
setItemsList={setItemsList}
|
||||||
|
setValue={setValue}
|
||||||
|
watch={watch}
|
||||||
|
tabState={tabState}
|
||||||
|
setTabState={setTabState}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={tabState} index={1}>
|
||||||
|
<GetSubItemsForm
|
||||||
|
setSubItemsList={setSubItemsList}
|
||||||
|
setValue={setValue}
|
||||||
|
watch={watch}
|
||||||
|
tabState={tabState}
|
||||||
|
setTabState={setTabState}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
</Box>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions sx={{ alignItems: "center", justifyContent: "center" }}>
|
||||||
|
<Button
|
||||||
|
onClick={handlePrev}
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
size="large"
|
||||||
|
startIcon={tabState === 0 ? <ExitToAppIcon /> : <KeyboardDoubleArrowRightIcon />}
|
||||||
|
>
|
||||||
|
{tabState === 0 ? "بستن" : "مرحله قبل"}
|
||||||
|
</Button>
|
||||||
|
{tabState === 2 && (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
size="large"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
type={"submit"}
|
||||||
|
endIcon={<BeenhereIcon />}
|
||||||
|
>
|
||||||
|
{isSubmitting ? "در حال ثبت فعالیت" : "ثبت فعالیت"}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</DialogActions>
|
||||||
|
</StyledForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default GashtCreateContent;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
"use client";
|
||||||
|
import { Button, IconButton, useMediaQuery } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import AddRoadIcon from "@mui/icons-material/AddRoad";
|
||||||
|
import GashtCreate from "./GashtCreate";
|
||||||
|
|
||||||
|
const ObservedGashtCreate = ({ mutate }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleOpen = () => {
|
||||||
|
setOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isMobile ? (
|
||||||
|
<IconButton aria-label="ثبت فعالیت" color="primary" onClick={handleOpen}>
|
||||||
|
<AddRoadIcon sx={{ fontSize: "25px" }} />
|
||||||
|
</IconButton>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
size={"small"}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
startIcon={<AddRoadIcon />}
|
||||||
|
onClick={handleOpen}
|
||||||
|
>
|
||||||
|
ثبت فعالیت برای موارد مشاهده شده در گشت راهداری
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{open && <GashtCreate open={open} setOpen={setOpen} mutate={mutate} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default ObservedGashtCreate;
|
||||||
@@ -1,29 +1,40 @@
|
|||||||
import { LinearProgress, Typography } from "@mui/material";
|
import { Dialog, DialogTitle } from "@mui/material";
|
||||||
import EditFormContent from "./EditFormContent";
|
import EditFormContent from "./EditFormContent";
|
||||||
import useRoadItemGetISubtems from "@/lib/hooks/useRoadItemGetISubtems";
|
import { UPDATE_ROAD_ITEMS } from "@/core/utils/routes";
|
||||||
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
|
|
||||||
const EditController = ({ rowId, mutate, setOpenEditDialog, row }) => {
|
const EditController = ({ rowId, mutate, setOpenEditDialog, openEditDialog, row }) => {
|
||||||
const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetISubtems(row.original?.item);
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
const subItem = subItemsList.find((SubItem) => SubItem.sub_item === row.original?.sub_item);
|
|
||||||
|
const HandleSubmit = async ({ result }) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
for (const [key, value] of Object.entries(result)) {
|
||||||
|
formData.append(key, value);
|
||||||
|
}
|
||||||
|
await requestServer(`${UPDATE_ROAD_ITEMS}/${rowId}`, "post", {
|
||||||
|
data: formData,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
mutate();
|
||||||
|
setOpenEditDialog(false);
|
||||||
|
})
|
||||||
|
.catch((error) => {});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Dialog
|
||||||
{errorSubItemsList ? (
|
maxWidth="sm"
|
||||||
<Typography color={"error"} textAlign={"center"}>
|
fullWidth
|
||||||
خطا در دریافت اطلاعات!!!
|
open={openEditDialog}
|
||||||
</Typography>
|
PaperProps={{
|
||||||
) : loadingSubItemsList ? (
|
sx: {
|
||||||
<LinearProgress />
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
) : (
|
},
|
||||||
<EditFormContent
|
}}
|
||||||
subItem={subItem}
|
>
|
||||||
rowId={rowId}
|
<DialogTitle>ویرایش اطلاعات</DialogTitle>
|
||||||
row={row}
|
<EditFormContent setOpenEditDialog={setOpenEditDialog} onSubmit={HandleSubmit} defaultData={row.original} />
|
||||||
mutate={mutate}
|
</Dialog>
|
||||||
setOpenEditDialog={setOpenEditDialog}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default EditController;
|
export default EditController;
|
||||||
|
|||||||
@@ -1,215 +1,72 @@
|
|||||||
import { Button, DialogActions, DialogContent, Stack, TextField } from "@mui/material";
|
import { LinearProgress, Typography } from "@mui/material";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
|
||||||
import { Controller, useForm } from "react-hook-form";
|
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
|
||||||
import { array, mixed, object, string } from "yup";
|
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ImageUpload from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/ImageUpload";
|
|
||||||
import MapInfoTwoMarker from "@/core/components/MapInfoTwoMarker";
|
|
||||||
import MapInfoOneMarker from "@/core/components/MapInfoOneMarker";
|
|
||||||
import { UPDATE_ROAD_ITEMS } from "@/core/utils/routes";
|
|
||||||
import CarCode from "@/core/components/CarCode";
|
|
||||||
import RahdarCode from "@/core/components/RahdarCode";
|
|
||||||
import useRoadItemGetISubtems from "@/lib/hooks/useRoadItemGetISubtems";
|
import useRoadItemGetISubtems from "@/lib/hooks/useRoadItemGetISubtems";
|
||||||
import NumberField from "@/core/components/NumberField";
|
import EditFormCreate from "@/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormCreate";
|
||||||
|
|
||||||
const validationSchema = object({
|
const EditFormContent = ({ setOpenEditDialog, onSubmit, defaultData }) => {
|
||||||
amount: string().required("وارد کردن مقدار الزامیست!"),
|
const { subItemsList, loadingSubItemsList, errorSubItemsList } = useRoadItemGetISubtems(defaultData?.item);
|
||||||
cmms_machines: array().required("وارد کردن کد خودرو الزامیست!"),
|
const subItem = subItemsList.find((SubItem) => SubItem.sub_item === defaultData?.sub_item);
|
||||||
rahdaran_id: array().required("وارد کردن کد راهداران الزامیست!").min(1, "حداقل یک کد راهدار باید وارد شود!"),
|
|
||||||
before_image: mixed()
|
|
||||||
.nullable()
|
|
||||||
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
|
||||||
const { subItem } = this.options.context;
|
|
||||||
const needsImage = subItem?.needs_image === 1;
|
|
||||||
if (needsImage) {
|
|
||||||
return !!value;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}),
|
|
||||||
after_image: mixed()
|
|
||||||
.nullable()
|
|
||||||
.test("after-image-required", "لطفا عکس بعد از اقدام را بارگذاری کنید!", function (value) {
|
|
||||||
const { subItem } = this.options.context;
|
|
||||||
const needsImage = subItem?.needs_image === 1;
|
|
||||||
if (needsImage) {
|
|
||||||
return !!value;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}),
|
|
||||||
start_point: mixed()
|
|
||||||
.test("start-point-required", "لطفاً نقطه شروع را مشخص کنید!", function (value) {
|
|
||||||
return !!value; // چک میکند که مقدار موجود است
|
|
||||||
})
|
|
||||||
.required("لطفاً نقطه شروع را مشخص کنید!"),
|
|
||||||
end_point: mixed().test("end-point-required", "لطفاً نقطه پایان را مشخص کنید!", function (value) {
|
|
||||||
const { subItem } = this.options.context;
|
|
||||||
const needsEndPoint = subItem?.needs_end_point === 1;
|
|
||||||
if (needsEndPoint) {
|
|
||||||
return !!value; // چک میکند که مقدار موجود است
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const EditFormContent = ({ row, mutate, setOpenEditDialog, rowId, subItem }) => {
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
before_image: row.original?.files[0]?.full_path_for_fast_react || null,
|
before_image: defaultData?.files[0]?.full_path_for_fast_react || null,
|
||||||
after_image: row.original?.files[1]?.full_path_for_fast_react || null,
|
after_image: defaultData?.files[1]?.full_path_for_fast_react || null,
|
||||||
amount: row.original.sub_item_data || null,
|
amount: defaultData?.sub_item_data || null,
|
||||||
start_point: { lat: row.original.start_lat || "", lng: row.original.start_lng || "" },
|
start_point: { lat: defaultData?.start_lat || "", lng: defaultData?.start_lng || "" },
|
||||||
end_point: { lat: row.original.end_lat || "", lng: row.original.end_lng || "" },
|
end_point: { lat: defaultData?.end_lat || "", lng: defaultData?.end_lng || "" },
|
||||||
cmms_machines: row.original.cmms_machines || null,
|
cmms_machines: defaultData?.cmms_machines || null,
|
||||||
rahdaran_id: row.original.rahdaran || null,
|
rahdaran_id: defaultData?.rahdaran || null,
|
||||||
};
|
};
|
||||||
const requestServer = useRequest();
|
|
||||||
|
|
||||||
const {
|
const onSubmitBase = (data) => {
|
||||||
control,
|
let result = { ...data };
|
||||||
getValues,
|
(result.before_image === null || result.before_image === defaultValues.before_image) &&
|
||||||
watch,
|
delete result.before_image;
|
||||||
register,
|
(result.after_image === null || result.after_image === defaultValues.after_image) && delete result.after_image;
|
||||||
handleSubmit,
|
if (subItem.needs_end_point !== 1) {
|
||||||
setValue,
|
delete result.end_point;
|
||||||
formState: { errors, isSubmitting },
|
} else {
|
||||||
} = useForm({
|
result.end_point = `${result.end_point.lat},${result.end_point.lng}`;
|
||||||
defaultValues,
|
}
|
||||||
resolver: yupResolver(validationSchema),
|
|
||||||
mode: "onBlur",
|
|
||||||
context: { subItem },
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
result.start_point = `${result.start_point.lat},${result.start_point.lng}`;
|
||||||
let endPoint;
|
|
||||||
let startPoint = `${data.start_point.lat},${data.start_point.lng}`;
|
|
||||||
subItem.needs_end_point === 1 && (endPoint = `${data.end_point.lat},${data.end_point.lng}`);
|
|
||||||
const formData = new FormData();
|
|
||||||
subItem.needs_image === 1 &&
|
|
||||||
data.before_image !== defaultValues.before_image &&
|
|
||||||
formData.append("before_image", data.before_image);
|
|
||||||
subItem.needs_image === 1 &&
|
|
||||||
data.after_image !== defaultValues.after_image &&
|
|
||||||
formData.append("after_image", data.after_image);
|
|
||||||
formData.append("amount", data.amount);
|
|
||||||
data.cmms_machines.map((machine, index) => formData.append(`machines_id[${index}]`, machine.id));
|
|
||||||
data.rahdaran_id.map((rahdar, index) => formData.append(`rahdaran_id[${index}]`, rahdar.id));
|
|
||||||
formData.append("start_point", startPoint);
|
|
||||||
subItem.needs_end_point === 1 && formData.append("end_point", endPoint);
|
|
||||||
|
|
||||||
await requestServer(`${UPDATE_ROAD_ITEMS}/${rowId}`, "post", {
|
result.rahdaran_id.forEach((rahdar, index) => {
|
||||||
notificationSuccess: true,
|
result[`rahdaran_id[${index}]`] = rahdar.id;
|
||||||
data: formData,
|
});
|
||||||
})
|
delete result.rahdaran_id;
|
||||||
.then((res) => {
|
|
||||||
mutate();
|
result.cmms_machines.forEach((cmms_machine, index) => {
|
||||||
setOpenEditDialog(false);
|
result[`machines_id[${index}]`] = cmms_machine.id;
|
||||||
})
|
});
|
||||||
.catch((err) => {});
|
delete result.cmms_machines;
|
||||||
|
|
||||||
|
onSubmit({
|
||||||
|
result,
|
||||||
|
data: {
|
||||||
|
...data,
|
||||||
|
item_name: subItem.item_str,
|
||||||
|
sub_item_name: subItemsList.name,
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
{errorSubItemsList ? (
|
||||||
<DialogContent sx={{ overflowY: "auto", maxHeight: "70vh" }}>
|
<Typography color={"error"} textAlign={"center"}>
|
||||||
<Stack spacing={2}>
|
خطا در دریافت اطلاعات!!!
|
||||||
<Stack>
|
</Typography>
|
||||||
{subItem.needs_image === 1 ? (
|
) : loadingSubItemsList ? (
|
||||||
<ImageUpload
|
<LinearProgress />
|
||||||
afterImage={row.original?.files[0]?.full_path_for_fast_react}
|
) : (
|
||||||
beforeImage={row.original?.files[1]?.full_path_for_fast_react}
|
<EditFormCreate
|
||||||
getValues={getValues}
|
onSubmitBase={onSubmitBase}
|
||||||
setValue={setValue}
|
subItem={subItem}
|
||||||
control={control}
|
defaultData={defaultData}
|
||||||
errors={errors}
|
defaultValues={defaultValues}
|
||||||
/>
|
setOpenEditDialog={setOpenEditDialog}
|
||||||
) : null}
|
/>
|
||||||
</Stack>
|
)}
|
||||||
<Stack>
|
|
||||||
<NumberField
|
|
||||||
{...register("amount")}
|
|
||||||
label={`مقدار (${subItem.unit})`}
|
|
||||||
error={!!errors.amount}
|
|
||||||
value={watch("amount")}
|
|
||||||
type="text"
|
|
||||||
size={"small"}
|
|
||||||
unit={subItem.unit}
|
|
||||||
inputProps={{
|
|
||||||
inputMode: "number",
|
|
||||||
min: 0,
|
|
||||||
pattern: "[0-9]*",
|
|
||||||
}}
|
|
||||||
onChange={(event) => {
|
|
||||||
if (!isNaN(event.target.value)) {
|
|
||||||
setValue("amount", event.target.value);
|
|
||||||
} else {
|
|
||||||
setValue("amount", watch("amount"));
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
helperText={errors.amount ? errors.amount.message : null}
|
|
||||||
variant="outlined"
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState: { error } }) => {
|
|
||||||
return (
|
|
||||||
<CarCode
|
|
||||||
carCode={field.value || []}
|
|
||||||
setCarCode={(value) => field.onChange(value || [])}
|
|
||||||
inputValueDefault={row.original.cmms_machines}
|
|
||||||
multiple={true}
|
|
||||||
error={error} // اگر خطا وجود داشته باشد
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
name={"cmms_machines"}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState: { error } }) => {
|
|
||||||
return (
|
|
||||||
<RahdarCode
|
|
||||||
rahdarsCode={field.value || []}
|
|
||||||
setRahdarsCode={(value) => field.onChange(value || [])}
|
|
||||||
error={error}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
name={"rahdaran_id"}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Stack>
|
|
||||||
{subItem.needs_end_point === 1 ? (
|
|
||||||
<MapInfoTwoMarker
|
|
||||||
StartPoint={getValues("start_point")}
|
|
||||||
EndPoint={getValues("end_point")}
|
|
||||||
setValue={setValue}
|
|
||||||
errors={errors}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<MapInfoOneMarker
|
|
||||||
StartPoint={getValues("start_point")}
|
|
||||||
setValue={setValue}
|
|
||||||
errors={errors}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</DialogContent>
|
|
||||||
<DialogActions>
|
|
||||||
<Button onClick={() => setOpenEditDialog(false)} variant="outlined" color="primary" autoFocus>
|
|
||||||
بستن
|
|
||||||
</Button>
|
|
||||||
<Button disabled={isSubmitting} type={"submit"} variant="contained" color="primary">
|
|
||||||
{isSubmitting ? "در حال ویرایش" : "ویرایش"}
|
|
||||||
</Button>
|
|
||||||
</DialogActions>
|
|
||||||
</StyledForm>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
import { Button, DialogActions, DialogContent, Stack } from "@mui/material";
|
||||||
|
import ImageUpload from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/ImageUpload";
|
||||||
|
import NumberField from "@/core/components/NumberField";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import CarCode from "@/core/components/CarCode";
|
||||||
|
import RahdarCode from "@/core/components/RahdarCode";
|
||||||
|
import MapInfoTwoMarker from "@/core/components/MapInfoTwoMarker";
|
||||||
|
import MapInfoOneMarker from "@/core/components/MapInfoOneMarker";
|
||||||
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
|
import React from "react";
|
||||||
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
|
import { array, mixed, object, string } from "yup";
|
||||||
|
|
||||||
|
const validationSchema = object({
|
||||||
|
amount: string().required("وارد کردن مقدار الزامیست!"),
|
||||||
|
cmms_machines: array().required("وارد کردن کد خودرو الزامیست!"),
|
||||||
|
rahdaran_id: array().required("وارد کردن کد راهداران الزامیست!").min(1, "حداقل یک کد راهدار باید وارد شود!"),
|
||||||
|
before_image: mixed()
|
||||||
|
.nullable()
|
||||||
|
.test("before-image-required", "لطفا عکس قبل از اقدام را بارگذاری کنید!", function (value) {
|
||||||
|
const { subItem } = this.options.context;
|
||||||
|
const needsImage = subItem?.needs_image === 1;
|
||||||
|
if (needsImage) {
|
||||||
|
return !!value;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
after_image: mixed()
|
||||||
|
.nullable()
|
||||||
|
.test("after-image-required", "لطفا عکس بعد از اقدام را بارگذاری کنید!", function (value) {
|
||||||
|
const { subItem } = this.options.context;
|
||||||
|
const needsImage = subItem?.needs_image === 1;
|
||||||
|
if (needsImage) {
|
||||||
|
return !!value;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
start_point: mixed()
|
||||||
|
.test("start-point-required", "لطفاً نقطه شروع را مشخص کنید!", function (value) {
|
||||||
|
return !!value; // چک میکند که مقدار موجود است
|
||||||
|
})
|
||||||
|
.required("لطفاً نقطه شروع را مشخص کنید!"),
|
||||||
|
end_point: mixed().test("end-point-required", "لطفاً نقطه پایان را مشخص کنید!", function (value) {
|
||||||
|
const { subItem } = this.options.context;
|
||||||
|
const needsEndPoint = subItem?.needs_end_point === 1;
|
||||||
|
if (needsEndPoint) {
|
||||||
|
return !!value;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const EditFormCreate = ({ defaultData, subItem, onSubmitBase, defaultValues, setOpenEditDialog }) => {
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
getValues,
|
||||||
|
watch,
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
formState: { errors, isSubmitting },
|
||||||
|
} = useForm({
|
||||||
|
defaultValues,
|
||||||
|
resolver: yupResolver(validationSchema),
|
||||||
|
mode: "onBlur",
|
||||||
|
context: { subItem },
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<StyledForm onSubmit={handleSubmit(onSubmitBase)}>
|
||||||
|
<DialogContent sx={{ overflowY: "auto", maxHeight: "70vh" }}>
|
||||||
|
<Stack spacing={2}>
|
||||||
|
<Stack>
|
||||||
|
{subItem.needs_image === 1 ? (
|
||||||
|
<ImageUpload
|
||||||
|
afterImage={defaultData?.files[0]?.full_path_for_fast_react}
|
||||||
|
beforeImage={defaultData?.files[1]?.full_path_for_fast_react}
|
||||||
|
getValues={getValues}
|
||||||
|
setValue={setValue}
|
||||||
|
control={control}
|
||||||
|
errors={errors}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</Stack>
|
||||||
|
<Stack>
|
||||||
|
<NumberField
|
||||||
|
{...register("amount")}
|
||||||
|
label={`مقدار (${subItem.unit})`}
|
||||||
|
error={!!errors.amount}
|
||||||
|
value={watch("amount")}
|
||||||
|
type="text"
|
||||||
|
size={"small"}
|
||||||
|
unit={subItem.unit}
|
||||||
|
inputProps={{
|
||||||
|
inputMode: "number",
|
||||||
|
min: 0,
|
||||||
|
pattern: "[0-9]*",
|
||||||
|
}}
|
||||||
|
onChange={(event) => {
|
||||||
|
if (!isNaN(event.target.value)) {
|
||||||
|
setValue("amount", event.target.value);
|
||||||
|
} else {
|
||||||
|
setValue("amount", watch("amount"));
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
helperText={errors.amount ? errors.amount.message : null}
|
||||||
|
variant="outlined"
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => {
|
||||||
|
return (
|
||||||
|
<CarCode
|
||||||
|
carCode={field.value || []}
|
||||||
|
setCarCode={(value) => field.onChange(value || [])}
|
||||||
|
inputValueDefault={defaultData?.cmms_machines}
|
||||||
|
multiple={true}
|
||||||
|
error={error} // اگر خطا وجود داشته باشد
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
name={"cmms_machines"}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => {
|
||||||
|
return (
|
||||||
|
<RahdarCode
|
||||||
|
rahdarsCode={field.value || []}
|
||||||
|
setRahdarsCode={(value) => field.onChange(value || [])}
|
||||||
|
error={error}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
name={"rahdaran_id"}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack>
|
||||||
|
{subItem.needs_end_point === 1 ? (
|
||||||
|
<MapInfoTwoMarker
|
||||||
|
StartPoint={getValues("start_point")}
|
||||||
|
EndPoint={getValues("end_point")}
|
||||||
|
setValue={setValue}
|
||||||
|
errors={errors}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<MapInfoOneMarker
|
||||||
|
StartPoint={getValues("start_point")}
|
||||||
|
setValue={setValue}
|
||||||
|
errors={errors}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={() => setOpenEditDialog(false)} variant="outlined" color="primary" autoFocus>
|
||||||
|
بستن
|
||||||
|
</Button>
|
||||||
|
<Button disabled={isSubmitting} type={"submit"} variant="contained" color="primary">
|
||||||
|
{isSubmitting ? "در حال ویرایش" : "ویرایش"}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</StyledForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default EditFormCreate;
|
||||||
@@ -19,19 +19,13 @@ const EditForm = ({ row, mutate, rowId }) => {
|
|||||||
<BorderColorIcon />
|
<BorderColorIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog
|
<EditController
|
||||||
maxWidth="sm"
|
openEditDialog={openEditDialog}
|
||||||
fullWidth
|
setOpenEditDialog={setOpenEditDialog}
|
||||||
open={openEditDialog}
|
rowId={rowId}
|
||||||
PaperProps={{
|
row={row}
|
||||||
sx: {
|
mutate={mutate}
|
||||||
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
/>
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DialogTitle>ویرایش اطلاعات</DialogTitle>
|
|
||||||
<EditController setOpenEditDialog={setOpenEditDialog} rowId={rowId} row={row} mutate={mutate} />
|
|
||||||
</Dialog>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import PrintExcel from "./ExcelPrint";
|
import PrintExcel from "./ExcelPrint";
|
||||||
import OperatorCreate from "./Actions/Create";
|
import OperatorCreate from "./Actions/Create";
|
||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
|
import ObservedGashtCreate from "./Actions/ObservedGashtCreate";
|
||||||
|
|
||||||
const Toolbar = ({ table, filterData, mutate }) => {
|
const Toolbar = ({ table, filterData, mutate }) => {
|
||||||
return (
|
return (
|
||||||
<Stack direction={"row"} spacing={2}>
|
<Stack direction={"row"} spacing={2}>
|
||||||
<PrintExcel table={table} filterData={filterData} />
|
<PrintExcel table={table} filterData={filterData} />
|
||||||
<OperatorCreate mutate={mutate} />
|
<OperatorCreate mutate={mutate} />
|
||||||
|
{/*<ObservedGashtCreate mutate={mutate} />*/}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
30
src/core/components/ActivityCodeLog.jsx
Normal file
30
src/core/components/ActivityCodeLog.jsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
"use client";
|
||||||
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { ACTIVITY_LOG } from "@/core/utils/routes";
|
||||||
|
|
||||||
|
const ActivityCodeLog = ({ activity_code }) => {
|
||||||
|
const requestServer = useRequest({ notificationShow: false });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!activity_code) return;
|
||||||
|
|
||||||
|
const fetchSubItems = async () => {
|
||||||
|
try {
|
||||||
|
await requestServer(ACTIVITY_LOG, "post", {
|
||||||
|
data: {
|
||||||
|
activityCode: activity_code,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error); // Always helpful to log the error for debugging.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchSubItems();
|
||||||
|
}, [activity_code, requestServer]);
|
||||||
|
|
||||||
|
return null; // Ensure the component still renders something.
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ActivityCodeLog;
|
||||||
@@ -21,7 +21,10 @@ const CarCode = ({ carCode, setCarCode, inputValueDefault = "", error, multiple
|
|||||||
requestOptions: { signal: controller.signal },
|
requestOptions: { signal: controller.signal },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setOptions(response.data.data || []);
|
const combinedArray = [...carCode, ...response.data.data];
|
||||||
|
|
||||||
|
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
|
||||||
|
setOptions(uniqueArray || []);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setOptions([]);
|
setOptions([]);
|
||||||
@@ -38,7 +41,6 @@ const CarCode = ({ carCode, setCarCode, inputValueDefault = "", error, multiple
|
|||||||
fetchCarCodes(inputValue, controller);
|
fetchCarCodes(inputValue, controller);
|
||||||
return () => controller.abort();
|
return () => controller.abort();
|
||||||
}, [inputValue]);
|
}, [inputValue]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
multiple={multiple}
|
multiple={multiple}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ const RahdarCode = ({ rahdarsCode, setRahdarsCode, error, multiple = true }) =>
|
|||||||
requestOptions: { signal: controller.signal },
|
requestOptions: { signal: controller.signal },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setOptions(response.data.data || []);
|
const combinedArray = [...rahdarsCode, ...response.data.data];
|
||||||
|
const uniqueArray = Array.from(new Map(combinedArray.map((item) => [item.id, item])).values());
|
||||||
|
setOptions(uniqueArray || []);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setOptions([]);
|
setOptions([]);
|
||||||
|
|||||||
@@ -51,3 +51,6 @@ export const DELETE_BY_SUPERVISOR = api + "/api/v3/road_items/delete";
|
|||||||
export const RESTORE_BY_SUPERVISOR = api + "/api/v3/road_items/restore";
|
export const RESTORE_BY_SUPERVISOR = api + "/api/v3/road_items/restore";
|
||||||
export const GET_CAR_LIST_SEARCH = api + "/api/v3/cmms_machines/search";
|
export const GET_CAR_LIST_SEARCH = api + "/api/v3/cmms_machines/search";
|
||||||
export const GET_RAHDARANS_LIST_SEARCH = api + "/api/v3/rahdaran/search";
|
export const GET_RAHDARANS_LIST_SEARCH = api + "/api/v3/rahdaran/search";
|
||||||
|
|
||||||
|
// activity code log
|
||||||
|
export const ACTIVITY_LOG = api + "/api/v3/profile/add_activity";
|
||||||
|
|||||||
Reference in New Issue
Block a user