Compare commits
11 Commits
v1.8.8
...
0d6269004e
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d6269004e | |||
| 05dc5505cd | |||
| a975bd1f88 | |||
| 01bb171ebb | |||
| 5f88728d67 | |||
| 63ec584aca | |||
| 16889752a1 | |||
| 5c05af0828 | |||
| 8753f23146 | |||
| 9ee9132ed8 | |||
| a798a36fcd |
@@ -0,0 +1,7 @@
|
|||||||
|
"use client";
|
||||||
|
import PageLoading from "@/core/components/PageLoading";
|
||||||
|
|
||||||
|
const Loading = () => {
|
||||||
|
return <PageLoading />;
|
||||||
|
};
|
||||||
|
export default Loading;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import WithPermission from "@/core/middlewares/withPermission";
|
||||||
|
import MachinesPage from "@/components/dashboard/machines";
|
||||||
|
|
||||||
|
export const metadata = {
|
||||||
|
title: "کارتابل ماشینها",
|
||||||
|
};
|
||||||
|
const Page = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<WithPermission permission_name={["all"]}>
|
||||||
|
<MachinesPage />
|
||||||
|
</WithPermission>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Page;
|
||||||
134
src/components/dashboard/machines/MachinesList.jsx
Normal file
134
src/components/dashboard/machines/MachinesList.jsx
Normal file
@@ -0,0 +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 <Typography variant="body2">{status?.label || ""}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
|
||||||
|
<DataTableWithAuth
|
||||||
|
need_filter={true}
|
||||||
|
columns={columns}
|
||||||
|
table_url={GET_MACHINES_LIST}
|
||||||
|
page_name={"machines"}
|
||||||
|
table_name={"machinesList"}
|
||||||
|
sorting={[{ id: "id", desc: true }]}
|
||||||
|
enableRowActions
|
||||||
|
positionActionsColumn={"first"}
|
||||||
|
RowActions={RowActions}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default MachinesList;
|
||||||
@@ -0,0 +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 (
|
||||||
|
<>
|
||||||
|
<DialogContent>
|
||||||
|
<Stack alignItems="center" spacing={2}>
|
||||||
|
<Typography mt={2}>آیا از حذف راهدارخانه اطمینان دارید؟</Typography>
|
||||||
|
</Stack>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
|
||||||
|
<Button onClick={() => setOpenDeleteDialog(false)} variant="outlined" color="secondary">
|
||||||
|
خیر !
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleClick} variant="contained" color="error" disabled={submitting}>
|
||||||
|
{submitting ? "درحال حذف..." : "بله اطمینان دارم"}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default DeleteContent;
|
||||||
@@ -0,0 +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 (
|
||||||
|
<>
|
||||||
|
<Tooltip title="حذف">
|
||||||
|
<IconButton color="error" onClick={() => setOpenDeleteDialog(true)}>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Dialog
|
||||||
|
open={openDeleteDialog}
|
||||||
|
onClose={() => setOpenDeleteDialog(false)}
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
dir="rtl"
|
||||||
|
maxWidth={"md"}
|
||||||
|
>
|
||||||
|
<DialogTitle>حذف راهدارخانه</DialogTitle>
|
||||||
|
{openDeleteDialog && (
|
||||||
|
<DeleteContent rowId={rowId} mutate={mutate} setOpenDeleteDialog={setOpenDeleteDialog} />
|
||||||
|
)}
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default DeleteDialog;
|
||||||
281
src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
Normal file
281
src/components/dashboard/machines/RowActions/Edit/Form/index.jsx
Normal file
@@ -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 (
|
||||||
|
<>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>ویرایش ماشین</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogContent dividers>
|
||||||
|
<StyledForm id="updateMachineForm" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<Stack spacing={3}>
|
||||||
|
<Controller
|
||||||
|
name="province_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
|
<InputLabel>استان</InputLabel>
|
||||||
|
|
||||||
|
<Select {...field} label="استان" disabled={loadingProvinces}>
|
||||||
|
{provinces.map((province) => (
|
||||||
|
<MenuItem key={province.id} value={province.id}>
|
||||||
|
{province.name_fa}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="city_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
|
<InputLabel>شهر</InputLabel>
|
||||||
|
|
||||||
|
<Select {...field} label="شهر" disabled={!provinceId || loadingCities}>
|
||||||
|
{cities.map((city) => (
|
||||||
|
<MenuItem key={city.id} value={city.id}>
|
||||||
|
{city.name_fa}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="station_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
|
<InputLabel>راهداری</InputLabel>
|
||||||
|
|
||||||
|
<Select {...field} label="راهداری" disabled={!cityId || loadingStations}>
|
||||||
|
{stations.map((station) => (
|
||||||
|
<MenuItem key={station.id} value={station.id}>
|
||||||
|
{station.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl fullWidth size="small" error={!!error}>
|
||||||
|
<InputLabel>وضعیت</InputLabel>
|
||||||
|
|
||||||
|
<Select {...field} label="وضعیت">
|
||||||
|
{statusOptions.map((item) => (
|
||||||
|
<MenuItem key={item.value} value={item.value}>
|
||||||
|
{item.label}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{(loadingCities || loadingStations) && (
|
||||||
|
<Stack direction="row" justifyContent="center">
|
||||||
|
<CircularProgress size={24} />
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</StyledForm>
|
||||||
|
</DialogContent>
|
||||||
|
|
||||||
|
<DialogActions>
|
||||||
|
<Button onClick={() => setOpen(false)} variant="outlined" color="secondary" startIcon={<ExitToApp />}>
|
||||||
|
بستن
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
type="submit"
|
||||||
|
form="updateMachineForm"
|
||||||
|
endIcon={<Beenhere />}
|
||||||
|
>
|
||||||
|
{isSubmitting ? "در حال ویرایش" : "ویرایش ماشین"}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditFormContent;
|
||||||
44
src/components/dashboard/machines/RowActions/Edit/index.jsx
Normal file
44
src/components/dashboard/machines/RowActions/Edit/index.jsx
Normal file
@@ -0,0 +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 (
|
||||||
|
<>
|
||||||
|
<Tooltip title="ویرایش" arrow placement="right">
|
||||||
|
<IconButton
|
||||||
|
color="primary"
|
||||||
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
|
onClick={() => {
|
||||||
|
setOpenEditDialog(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SwapHoriz />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Dialog open={openEditDialog} fullWidth maxWidth="xs">
|
||||||
|
<IconButton
|
||||||
|
aria-label="close"
|
||||||
|
onClick={() => setOpenEditDialog(false)}
|
||||||
|
sx={(theme) => ({
|
||||||
|
position: "absolute",
|
||||||
|
right: 8,
|
||||||
|
top: 8,
|
||||||
|
zIndex: 50,
|
||||||
|
color: theme.palette.grey[500],
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<CloseIcon />
|
||||||
|
</IconButton>
|
||||||
|
{openEditDialog && (
|
||||||
|
<EditFormContent rowId={rowId} row={row} setOpen={setOpenEditDialog} mutate={mutate} />
|
||||||
|
)}
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Edit;
|
||||||
14
src/components/dashboard/machines/RowActions/index.jsx
Normal file
14
src/components/dashboard/machines/RowActions/index.jsx
Normal file
@@ -0,0 +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 (
|
||||||
|
<Box sx={{ display: "flex", gap: 1 }}>
|
||||||
|
{hasEditPermission && <Edit row={row} mutate={mutate} rowId={row.getValue("id")} />}
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default RowActions;
|
||||||
@@ -0,0 +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 <FeatureGroup ref={featureRef} />;
|
||||||
|
};
|
||||||
|
export default ShowBound;
|
||||||
65
src/components/dashboard/machines/ShowProjectArea/index.jsx
Normal file
65
src/components/dashboard/machines/ShowProjectArea/index.jsx
Normal file
@@ -0,0 +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 (
|
||||||
|
<Box>
|
||||||
|
<Tooltip title="نمایش پلیگان" placement="right" arrow>
|
||||||
|
<IconButton size="small" color="primary" onClick={() => setOpenShowAreaDialog(true)}>
|
||||||
|
<LayersIcon />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
<Dialog
|
||||||
|
open={openShowAreaDialog}
|
||||||
|
onClose={() => setOpenShowAreaDialog(false)}
|
||||||
|
PaperProps={{
|
||||||
|
sx: {
|
||||||
|
transition: "all .3s",
|
||||||
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
|
borderRadius: 2,
|
||||||
|
padding: 1,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
maxWidth="sm"
|
||||||
|
fullWidth
|
||||||
|
dir="rtl"
|
||||||
|
>
|
||||||
|
<DialogTitle sx={{ display: "flex", justifyContent: "space-between", padding: "16px 24px" }}>
|
||||||
|
<Typography variant="body1" sx={{ fontWeight: "bold", fontSize: "large" }}>
|
||||||
|
محدوده طرح
|
||||||
|
</Typography>
|
||||||
|
<IconButton onClick={() => setOpenShowAreaDialog(false)} size="small">
|
||||||
|
<CloseIcon />
|
||||||
|
</IconButton>
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<Box sx={{ flex: 1 }}>
|
||||||
|
<Box sx={{ width: "100%", height: "400px" }}>
|
||||||
|
<MapLayer style={{ borderRadius: "4px" }}>
|
||||||
|
<ShowBound bound={bound} />
|
||||||
|
</MapLayer>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShowProjectArea;
|
||||||
14
src/components/dashboard/machines/index.jsx
Normal file
14
src/components/dashboard/machines/index.jsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
"use client";
|
||||||
|
import PageTitle from "@/core/components/PageTitle";
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import MachinesList from "./MachinesList";
|
||||||
|
|
||||||
|
const MachinesPage = () => {
|
||||||
|
return (
|
||||||
|
<Stack spacing={1}>
|
||||||
|
<PageTitle title={"لیست ماشین ها"} />
|
||||||
|
<MachinesList />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default MachinesPage;
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import Create from "./Actions/Create";
|
import Create from "./Actions/Create";
|
||||||
import CreateWithoutProcess from "./Actions/CreateWithoutProcess";
|
// import CreateWithoutProcess from "./Actions/CreateWithoutProcess";
|
||||||
|
|
||||||
const Toolbar = ({ table, filterData, mutate }) => {
|
const Toolbar = ({ table, filterData, mutate }) => {
|
||||||
return (
|
return (
|
||||||
<Stack direction={"row"} spacing={1}>
|
<Stack direction={"row"} spacing={1}>
|
||||||
<Create mutate={mutate} />
|
<Create mutate={mutate} />
|
||||||
<CreateWithoutProcess mutate={mutate} />
|
{/*<CreateWithoutProcess mutate={mutate} />*/}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { yupResolver } from "@hookform/resolvers/yup";
|
|||||||
import { Button, DialogActions, DialogContent, Stack } from "@mui/material";
|
import { Button, DialogActions, DialogContent, Stack } from "@mui/material";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
|
import MissionDates from "@/components/dashboard/roadMissions/violations/Actions/CreateViolation/Form/MissionDates";
|
||||||
const schema = yup.object().shape({
|
const schema = yup.object().shape({
|
||||||
machinesId: yup.object().required("کد خودرو الزامی است."),
|
machinesId: yup.object().required("کد خودرو الزامی است."),
|
||||||
km: yup.string(),
|
km: yup.string(),
|
||||||
@@ -61,6 +62,9 @@ const CreateViolationForm = ({ setOpenMachinesDialog, defaultValues, onSubmitBas
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<Stack spacing={2} sx={{ minWidth: "200px" }}>
|
||||||
|
<MissionDates control={control} />
|
||||||
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions sx={{ alignItems: "center", justifyContent: "end" }}>
|
<DialogActions sx={{ alignItems: "center", justifyContent: "end" }}>
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
|
import MuiTimePicker from "@/core/components/MuiTimePicker";
|
||||||
|
import { Grid } from "@mui/material";
|
||||||
|
import { Controller, useWatch } from "react-hook-form";
|
||||||
|
|
||||||
|
const MissionDates = ({ control }) => {
|
||||||
|
const start_date = useWatch({ control, name: "start_date" });
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Grid item xs={12} sm={6}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={"start_date"}
|
||||||
|
render={({ field, fieldState: { error } }) => {
|
||||||
|
return (
|
||||||
|
<MuiDatePicker
|
||||||
|
name="start_date"
|
||||||
|
error={error}
|
||||||
|
value={field.value}
|
||||||
|
disableFuture={false}
|
||||||
|
minDate={start_date ? start_date : now}
|
||||||
|
placeholder={"تاریخ شروع ماموریت را وارد کنید"}
|
||||||
|
label={"تاریخ شروع ماموریت"}
|
||||||
|
setFieldValue={(name, value) => field.onChange(value || [])}
|
||||||
|
helperText={error ? error.message : null}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12} sm={6}>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={"start_time"}
|
||||||
|
render={({ field, fieldState: { error } }) => {
|
||||||
|
return (
|
||||||
|
<MuiTimePicker
|
||||||
|
name="start_time"
|
||||||
|
error={error}
|
||||||
|
value={field.value}
|
||||||
|
placeholder={"زمان شروع ماموریت را وارد کنید"}
|
||||||
|
label={"زمان شروع ماموریت"}
|
||||||
|
setFieldValue={(name, value) => field.onChange(value || null)}
|
||||||
|
helperText={error ? error.message : null}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default MissionDates;
|
||||||
@@ -3,6 +3,7 @@ import { DialogHeader } from "next/dist/client/components/react-dev-overlay/inte
|
|||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { CREATE_VIOLATION } from "@/core/utils/routes";
|
import { CREATE_VIOLATION } from "@/core/utils/routes";
|
||||||
import CreateViolationForm from "@/components/dashboard/roadMissions/violations/Actions/CreateViolation/Form/CreateForm";
|
import CreateViolationForm from "@/components/dashboard/roadMissions/violations/Actions/CreateViolation/Form/CreateForm";
|
||||||
|
import moment from "jalali-moment";
|
||||||
|
|
||||||
const ViolationForm = ({ setOpenMachinesDialog, mutate, openMachinesDialog }) => {
|
const ViolationForm = ({ setOpenMachinesDialog, mutate, openMachinesDialog }) => {
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
@@ -10,6 +11,8 @@ const ViolationForm = ({ setOpenMachinesDialog, mutate, openMachinesDialog }) =>
|
|||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
machinesId: null,
|
machinesId: null,
|
||||||
km: "",
|
km: "",
|
||||||
|
start_date: null,
|
||||||
|
start_time: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitForm = async (result) => {
|
const submitForm = async (result) => {
|
||||||
@@ -17,6 +20,7 @@ const ViolationForm = ({ setOpenMachinesDialog, mutate, openMachinesDialog }) =>
|
|||||||
data: {
|
data: {
|
||||||
machine_code: result.machinesId.machine_code,
|
machine_code: result.machinesId.machine_code,
|
||||||
km: result.km,
|
km: result.km,
|
||||||
|
exit_station: `${result.start_date} ${moment(result.start_time).format("HH:mm")}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { AccessTime, Engineering, InsertDriveFile, Person, Verified } from "@mui/icons-material";
|
import { Engineering, InsertDriveFile, Person, Verified } from "@mui/icons-material";
|
||||||
import { Box, Tab, Tabs } from "@mui/material";
|
import { Box, Tab, Tabs } from "@mui/material";
|
||||||
import { useReducer, useState } from "react";
|
import { useReducer, useState } from "react";
|
||||||
import GetDateTime from "./GetDateTime";
|
|
||||||
import GetItemInfo from "./GetItemInfo";
|
import GetItemInfo from "./GetItemInfo";
|
||||||
import MachineAndDriver from "./MachineAndDriver";
|
import MachineAndDriver from "./MachineAndDriver";
|
||||||
import Rahdaran from "./Rahdaran";
|
import Rahdaran from "./Rahdaran";
|
||||||
@@ -42,7 +41,6 @@ const CreateForm = ({ defaultValues, submitForm, setOpen, submitting }) => {
|
|||||||
setTabState((t) => t - 1);
|
setTabState((t) => t - 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Tabs
|
<Tabs
|
||||||
@@ -59,10 +57,9 @@ const CreateForm = ({ defaultValues, submitForm, setOpen, submitting }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Tab icon={<InsertDriveFile />} label="مشخصات" />
|
<Tab icon={<InsertDriveFile />} label="مشخصات" />
|
||||||
<Tab disabled={tabState < 1} icon={<AccessTime />} label="زمانبندی" />
|
<Tab disabled={tabState < 1} icon={<Person />} label="راننده" />
|
||||||
<Tab disabled={tabState < 2} icon={<Person />} label="راننده" />
|
<Tab disabled={tabState < 2} icon={<Engineering />} label="همراهان" />
|
||||||
<Tab disabled={tabState < 3} icon={<Engineering />} label="همراهان" />
|
<Tab disabled={tabState < 3} icon={<Verified />} label="بررسی نهایی" />
|
||||||
<Tab disabled={tabState < 4} icon={<Verified />} label="بررسی نهایی" />
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<TabPanel value={tabState} index={0}>
|
<TabPanel value={tabState} index={0}>
|
||||||
<GetItemInfo
|
<GetItemInfo
|
||||||
@@ -75,16 +72,6 @@ const CreateForm = ({ defaultValues, submitForm, setOpen, submitting }) => {
|
|||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={tabState} index={1}>
|
<TabPanel value={tabState} index={1}>
|
||||||
<GetDateTime
|
|
||||||
allData={allData}
|
|
||||||
setAllData={(data) => {
|
|
||||||
dispatch({ type: "changeData", data });
|
|
||||||
}}
|
|
||||||
handlePrev={handlePrev}
|
|
||||||
setTabState={setTabState}
|
|
||||||
/>
|
|
||||||
</TabPanel>
|
|
||||||
<TabPanel value={tabState} index={2}>
|
|
||||||
<MachineAndDriver
|
<MachineAndDriver
|
||||||
allData={allData}
|
allData={allData}
|
||||||
setAllData={(data) => {
|
setAllData={(data) => {
|
||||||
@@ -94,7 +81,7 @@ const CreateForm = ({ defaultValues, submitForm, setOpen, submitting }) => {
|
|||||||
setTabState={setTabState}
|
setTabState={setTabState}
|
||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={tabState} index={3}>
|
<TabPanel value={tabState} index={2}>
|
||||||
<Rahdaran
|
<Rahdaran
|
||||||
allData={allData}
|
allData={allData}
|
||||||
setAllData={(data) => {
|
setAllData={(data) => {
|
||||||
@@ -104,7 +91,7 @@ const CreateForm = ({ defaultValues, submitForm, setOpen, submitting }) => {
|
|||||||
setTabState={setTabState}
|
setTabState={setTabState}
|
||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={tabState} index={4}>
|
<TabPanel value={tabState} index={3}>
|
||||||
<Verify allData={allData} handlePrev={handlePrev} submitForm={submitForm} submitting={submitting} />
|
<Verify allData={allData} handlePrev={handlePrev} submitForm={submitForm} submitting={submitting} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ const CreateWithoutProcess = ({ row, mutate }) => {
|
|||||||
...(result.rahdaran.length != 0 ? { rahdaran: result.rahdaran.map((r) => r.id) } : {}),
|
...(result.rahdaran.length != 0 ? { rahdaran: result.rahdaran.map((r) => r.id) } : {}),
|
||||||
zone: result.region,
|
zone: result.region,
|
||||||
end_point: result.end_point,
|
end_point: result.end_point,
|
||||||
start_date: `${result.start_date} ${moment(result.start_time).format("HH:mm")}`,
|
|
||||||
end_date: `${result.end_date} ${moment(result.end_time).format("HH:mm")}`,
|
|
||||||
driver: result.driver.id,
|
driver: result.driver.id,
|
||||||
},
|
},
|
||||||
hasSidebarUpdate: true,
|
hasSidebarUpdate: true,
|
||||||
@@ -70,10 +68,6 @@ const CreateWithoutProcess = ({ row, mutate }) => {
|
|||||||
category_id: "",
|
category_id: "",
|
||||||
road_observed_id: "",
|
road_observed_id: "",
|
||||||
rahdaran: [],
|
rahdaran: [],
|
||||||
start_date: "",
|
|
||||||
start_time: null,
|
|
||||||
end_date: "",
|
|
||||||
end_time: null,
|
|
||||||
end_point: "",
|
end_point: "",
|
||||||
region: "",
|
region: "",
|
||||||
driver: null,
|
driver: null,
|
||||||
|
|||||||
@@ -5,24 +5,19 @@ import { DialogHeader } from "next/dist/client/components/react-dev-overlay/inte
|
|||||||
import EditViolationForm from "./EditViolationForm";
|
import EditViolationForm from "./EditViolationForm";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
|
|
||||||
const EditController = ({ rowId, mutate, setOpen }) => {
|
const EditController = ({ rowId, mutate, setOpen, row }) => {
|
||||||
const requestServer = useRequest({ notificationSuccess: true });
|
const requestServer = useRequest({ notificationSuccess: true });
|
||||||
|
const [endDate] = row?.original?.enter_station?.split(" ") || [null];
|
||||||
|
|
||||||
const defaultData = {
|
const defaultData = {
|
||||||
start_date: null,
|
end_date: endDate,
|
||||||
start_time: null,
|
end_time: row?.original?.enter_station ? new Date(row.original.enter_station) : null,
|
||||||
end_date: null,
|
|
||||||
end_time: null,
|
|
||||||
};
|
};
|
||||||
const handleSubmit = async (result) => {
|
const handleSubmit = async (result) => {
|
||||||
const payload = {};
|
const payload = {};
|
||||||
|
|
||||||
if (result.start_date && result.start_time) {
|
|
||||||
payload.enter_time = `${result.start_date} ${moment(result.start_time).format("HH:mm")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.end_date && result.end_time) {
|
if (result.end_date && result.end_time) {
|
||||||
payload.exit_time = `${result.end_date} ${moment(result.end_time).format("HH:mm")}`;
|
payload.enter_station = `${result.end_date} ${moment(result.end_time).format("HH:mm")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
await requestServer(`${EDIT_VIOLATION}/${rowId}`, "post", {
|
await requestServer(`${EDIT_VIOLATION}/${rowId}`, "post", {
|
||||||
|
|||||||
@@ -5,53 +5,11 @@ import { Grid } from "@mui/material";
|
|||||||
import { Controller, useWatch } from "react-hook-form";
|
import { Controller, useWatch } from "react-hook-form";
|
||||||
|
|
||||||
const MissionDates = ({ control }) => {
|
const MissionDates = ({ control }) => {
|
||||||
const start_date = useWatch({ control, name: "start_date" });
|
|
||||||
const end_date = useWatch({ control, name: "end_date" });
|
const end_date = useWatch({ control, name: "end_date" });
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid item xs={12} sm={6}>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={"start_date"}
|
|
||||||
render={({ field, fieldState: { error } }) => {
|
|
||||||
return (
|
|
||||||
<MuiDatePicker
|
|
||||||
name="start_date"
|
|
||||||
error={error}
|
|
||||||
value={field.value}
|
|
||||||
disableFuture={false}
|
|
||||||
maxDate={end_date ?? null}
|
|
||||||
placeholder={"تاریخ شروع ماموریت را وارد کنید"}
|
|
||||||
label={"تاریخ شروع ماموریت"}
|
|
||||||
setFieldValue={(name, value) => field.onChange(value || [])}
|
|
||||||
helperText={error ? error.message : null}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={12} sm={6}>
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={"start_time"}
|
|
||||||
render={({ field, fieldState: { error } }) => {
|
|
||||||
return (
|
|
||||||
<MuiTimePicker
|
|
||||||
name="start_time"
|
|
||||||
error={error}
|
|
||||||
value={field.value}
|
|
||||||
views={["hours"]}
|
|
||||||
placeholder={"زمان شروع ماموریت را وارد کنید"}
|
|
||||||
label={"زمان شروع ماموریت"}
|
|
||||||
setFieldValue={(name, value) => field.onChange(value || null)}
|
|
||||||
helperText={error ? error.message : null}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={12} sm={6}>
|
<Grid item xs={12} sm={6}>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
@@ -63,7 +21,7 @@ const MissionDates = ({ control }) => {
|
|||||||
error={error}
|
error={error}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
disableFuture={false}
|
disableFuture={false}
|
||||||
minDate={start_date ? start_date : now}
|
minDate={end_date ? end_date : now}
|
||||||
placeholder={"تاریخ پایان ماموریت را وارد کنید"}
|
placeholder={"تاریخ پایان ماموریت را وارد کنید"}
|
||||||
label={"تاریخ پایان ماموریت"}
|
label={"تاریخ پایان ماموریت"}
|
||||||
setFieldValue={(name, value) => field.onChange(value || [])}
|
setFieldValue={(name, value) => field.onChange(value || [])}
|
||||||
@@ -83,7 +41,6 @@ const MissionDates = ({ control }) => {
|
|||||||
name="end_time"
|
name="end_time"
|
||||||
error={error}
|
error={error}
|
||||||
value={field.value}
|
value={field.value}
|
||||||
views={["hours"]}
|
|
||||||
placeholder={"زمان پایان ماموریت را وارد کنید"}
|
placeholder={"زمان پایان ماموریت را وارد کنید"}
|
||||||
label={"زمان پایان ماموریت"}
|
label={"زمان پایان ماموریت"}
|
||||||
setFieldValue={(name, value) => field.onChange(value || null)}
|
setFieldValue={(name, value) => field.onChange(value || null)}
|
||||||
|
|||||||
@@ -6,69 +6,167 @@ import moment from "jalali-moment";
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import RowActions from "./RowActions";
|
import RowActions from "./RowActions";
|
||||||
import Toolbar from "./Toolbar";
|
import Toolbar from "./Toolbar";
|
||||||
|
import { violationsCategoryStatus } from "@/core/utils/violationsCategoryStatus";
|
||||||
|
import useProvinces from "@/lib/hooks/useProvince";
|
||||||
|
import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsType/CustomSelectByDependency";
|
||||||
|
import useCities from "@/lib/hooks/useCities";
|
||||||
|
|
||||||
const ViolationsList = () => {
|
const ViolationsList = () => {
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => {
|
||||||
{
|
const dynamicColumns = {
|
||||||
accessorKey: "id",
|
header: "استان",
|
||||||
header: "کد یکتا",
|
id: "province_id",
|
||||||
id: "id",
|
|
||||||
enableColumnFilter: true,
|
|
||||||
datatype: "text",
|
|
||||||
filterMode: "equals",
|
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
|
||||||
grow: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "type",
|
|
||||||
header: "نوع تخلف",
|
|
||||||
id: "type",
|
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterMode: "equals",
|
filterMode: "equals",
|
||||||
sortDescFirst: true,
|
|
||||||
grow: false,
|
grow: false,
|
||||||
Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
|
size: 130,
|
||||||
},
|
ColumnSelectComponent: (props) => {
|
||||||
{
|
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
|
||||||
accessorKey: "machine_code",
|
const getColumnSelectOptions = useMemo(() => {
|
||||||
header: "کد خودرو",
|
if (loadingProvinces) {
|
||||||
id: "machine_code",
|
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
||||||
datatype: "text",
|
}
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
if (errorProvinces) {
|
||||||
grow: false,
|
return [{ value: "error", label: "خطا در بارگذاری" }];
|
||||||
},
|
}
|
||||||
{
|
return [
|
||||||
accessorKey: "machine",
|
{ value: "", label: "کل کشور" },
|
||||||
header: "نام خودرو",
|
...provinces.map((province) => ({
|
||||||
id: "machine",
|
value: province.id,
|
||||||
datatype: "text",
|
label: province.name_fa,
|
||||||
columnFilterModeOptions: ["equals", "contains"],
|
})),
|
||||||
grow: false,
|
];
|
||||||
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
}, [provinces, errorProvinces, loadingProvinces]);
|
||||||
},
|
return (
|
||||||
{
|
<CustomSelectByDependency
|
||||||
accessorKey: "mission_id",
|
{...props}
|
||||||
header: "کد ماموریت",
|
value={loadingProvinces ? "loading" : props.filterParameters.value}
|
||||||
id: "mission_id",
|
columnSelectOption={getColumnSelectOptions}
|
||||||
enableColumnFilter: false,
|
/>
|
||||||
datatype: "numeric",
|
);
|
||||||
filterMode: "equals",
|
},
|
||||||
grow: false,
|
Cell: ({ renderedCellValue, row }) => {
|
||||||
Cell: ({ row }) => row.original.mission_id || "-",
|
return <>{row.original.province_name}</>;
|
||||||
},
|
},
|
||||||
{
|
};
|
||||||
accessorKey: "request_date",
|
return [
|
||||||
header: "تاریخ تخلف",
|
{
|
||||||
id: "request_date",
|
accessorKey: "id",
|
||||||
enableColumnFilter: true,
|
header: "کد یکتا",
|
||||||
datatype: "date",
|
id: "id",
|
||||||
filterMode: "between",
|
enableColumnFilter: true,
|
||||||
grow: false,
|
datatype: "text",
|
||||||
Cell: ({ row }) => moment(row.original.request_date).locale("fa").format("YYYY/MM/DD"),
|
filterMode: "equals",
|
||||||
},
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
],
|
grow: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "status",
|
||||||
|
header: "وضعیت",
|
||||||
|
id: "status",
|
||||||
|
enableColumnFilter: true,
|
||||||
|
datatype: "numeric",
|
||||||
|
filterMode: "equals",
|
||||||
|
sortDescFirst: true,
|
||||||
|
grow: false,
|
||||||
|
columnSelectOption: () => {
|
||||||
|
return violationsCategoryStatus.map((category) => ({
|
||||||
|
value: category.id,
|
||||||
|
label: category.name_fa,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
Cell: ({ row }) => (row.original.type === 1 ? "خروج بدون مجوز" : "عدم تحرک"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "machine_code",
|
||||||
|
header: "کد خودرو",
|
||||||
|
id: "machine_code",
|
||||||
|
datatype: "text",
|
||||||
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
grow: false,
|
||||||
|
},
|
||||||
|
...[dynamicColumns],
|
||||||
|
{
|
||||||
|
header: "شهر",
|
||||||
|
id: "city_id",
|
||||||
|
enableColumnFilter: true,
|
||||||
|
datatype: "numeric",
|
||||||
|
filterMode: "equals",
|
||||||
|
dependencyId: "province_id",
|
||||||
|
grow: false,
|
||||||
|
size: 120,
|
||||||
|
ColumnSelectComponent: (props) => {
|
||||||
|
const { cityList, loadingCityList, errorCityList } = useCities(
|
||||||
|
props.dependencyFieldValue.value
|
||||||
|
);
|
||||||
|
|
||||||
|
const getColumnSelectOptions = useMemo(() => {
|
||||||
|
if (props.dependencyFieldValue.value === "") {
|
||||||
|
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
|
||||||
|
}
|
||||||
|
if (loadingCityList) {
|
||||||
|
return [{ value: "loading", label: "در حال بارگذاری..." }];
|
||||||
|
}
|
||||||
|
if (errorCityList) {
|
||||||
|
return [{ value: "error", label: "خطا در بارگذاری" }];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
{ value: "", label: "کل ادارات" },
|
||||||
|
...cityList.map((edare) => ({
|
||||||
|
value: edare.id,
|
||||||
|
label: edare.name_fa,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}, [cityList, loadingCityList, errorCityList]);
|
||||||
|
return (
|
||||||
|
<CustomSelectByDependency
|
||||||
|
{...props}
|
||||||
|
value={
|
||||||
|
props.dependencyFieldValue?.value === ""
|
||||||
|
? "empty"
|
||||||
|
: loadingCityList
|
||||||
|
? "loading"
|
||||||
|
: props.filterParameters.value
|
||||||
|
}
|
||||||
|
columnSelectOption={getColumnSelectOptions}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Cell: ({ row }) => <>{row.original.city_name}</>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "machine",
|
||||||
|
header: "نام خودرو",
|
||||||
|
id: "machine",
|
||||||
|
datatype: "text",
|
||||||
|
columnFilterModeOptions: ["equals", "contains"],
|
||||||
|
grow: false,
|
||||||
|
Cell: ({ row }) => row.original.machine?.car_name || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "mission_id",
|
||||||
|
header: "کد ماموریت",
|
||||||
|
id: "mission_id",
|
||||||
|
enableColumnFilter: false,
|
||||||
|
datatype: "numeric",
|
||||||
|
filterMode: "equals",
|
||||||
|
grow: false,
|
||||||
|
Cell: ({ row }) => row.original.mission_id || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "request_date",
|
||||||
|
header: "تاریخ تخلف",
|
||||||
|
id: "request_date",
|
||||||
|
enableColumnFilter: true,
|
||||||
|
datatype: "date",
|
||||||
|
filterMode: "between",
|
||||||
|
grow: false,
|
||||||
|
Cell: ({ row }) => moment(row.original.request_date).locale("fa").format("YYYY/MM/DD"),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ReportProblem, RvHookup } from "@mui/icons-material";
|
||||||
import AccountTreeIcon from "@mui/icons-material/AccountTree";
|
import AccountTreeIcon from "@mui/icons-material/AccountTree";
|
||||||
import AdminPanelSettingsIcon from "@mui/icons-material/AdminPanelSettings";
|
import AdminPanelSettingsIcon from "@mui/icons-material/AdminPanelSettings";
|
||||||
import AssessmentIcon from "@mui/icons-material/Assessment";
|
import AssessmentIcon from "@mui/icons-material/Assessment";
|
||||||
@@ -5,7 +6,9 @@ import AssignmentLateIcon from "@mui/icons-material/AssignmentLate";
|
|||||||
import AssistantIcon from "@mui/icons-material/Assistant";
|
import AssistantIcon from "@mui/icons-material/Assistant";
|
||||||
import BallotIcon from "@mui/icons-material/Ballot";
|
import BallotIcon from "@mui/icons-material/Ballot";
|
||||||
import BiotechIcon from "@mui/icons-material/Biotech";
|
import BiotechIcon from "@mui/icons-material/Biotech";
|
||||||
|
import ContactPageIcon from "@mui/icons-material/ContactPage";
|
||||||
import CottageIcon from "@mui/icons-material/Cottage";
|
import CottageIcon from "@mui/icons-material/Cottage";
|
||||||
|
import DirectionsBusIcon from "@mui/icons-material/DirectionsBus";
|
||||||
import DoorbellIcon from "@mui/icons-material/Doorbell";
|
import DoorbellIcon from "@mui/icons-material/Doorbell";
|
||||||
import DriveEtaIcon from "@mui/icons-material/DriveEta";
|
import DriveEtaIcon from "@mui/icons-material/DriveEta";
|
||||||
import ElectricBoltIcon from "@mui/icons-material/ElectricBolt";
|
import ElectricBoltIcon from "@mui/icons-material/ElectricBolt";
|
||||||
@@ -23,17 +26,14 @@ import MapIcon from "@mui/icons-material/Map";
|
|||||||
import MapsHomeWorkIcon from "@mui/icons-material/MapsHomeWork";
|
import MapsHomeWorkIcon from "@mui/icons-material/MapsHomeWork";
|
||||||
import Mediation from "@mui/icons-material/Mediation";
|
import Mediation from "@mui/icons-material/Mediation";
|
||||||
import PsychologyAltIcon from "@mui/icons-material/PsychologyAlt";
|
import PsychologyAltIcon from "@mui/icons-material/PsychologyAlt";
|
||||||
|
import RemoveRoadIcon from "@mui/icons-material/RemoveRoad";
|
||||||
import ReportIcon from "@mui/icons-material/Report";
|
import ReportIcon from "@mui/icons-material/Report";
|
||||||
import RouteIcon from "@mui/icons-material/Route";
|
import RouteIcon from "@mui/icons-material/Route";
|
||||||
import ScienceIcon from "@mui/icons-material/Science";
|
import ScienceIcon from "@mui/icons-material/Science";
|
||||||
import SecurityIcon from "@mui/icons-material/Security";
|
import SecurityIcon from "@mui/icons-material/Security";
|
||||||
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
|
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
|
||||||
import SpeedIcon from "@mui/icons-material/Speed";
|
import SpeedIcon from "@mui/icons-material/Speed";
|
||||||
import ContactPageIcon from "@mui/icons-material/ContactPage";
|
|
||||||
import DirectionsBusIcon from "@mui/icons-material/DirectionsBus";
|
|
||||||
import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle";
|
import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle";
|
||||||
import RemoveRoadIcon from "@mui/icons-material/RemoveRoad";
|
|
||||||
import { ReportProblem, RvHookup } from "@mui/icons-material";
|
|
||||||
|
|
||||||
export const pageMenu = [
|
export const pageMenu = [
|
||||||
{
|
{
|
||||||
@@ -685,12 +685,12 @@ export const pageMenu = [
|
|||||||
permissions: ["manage-damage"],
|
permissions: ["manage-damage"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "CarDetails",
|
id: "machines",
|
||||||
label: "اطلاعات خودرو",
|
label: "ماشینها",
|
||||||
type: "page",
|
type: "page",
|
||||||
route: "/dashboard/car-details",
|
route: "/dashboard/machines",
|
||||||
icon: <DriveEtaIcon sx={{ width: "inherit", height: "inherit" }} />,
|
icon: <DriveEtaIcon sx={{ width: "inherit", height: "inherit" }} />,
|
||||||
permissions: [""],
|
permissions: ["update-machine"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -683,12 +683,12 @@ export const pageMenuDev = [
|
|||||||
permissions: ["manage-damage"],
|
permissions: ["manage-damage"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "CarDetails",
|
id: "machines",
|
||||||
label: "اطلاعات خودرو",
|
label: "ماشینها",
|
||||||
type: "page",
|
type: "page",
|
||||||
route: "/dashboard/car-details",
|
route: "/dashboard/machines",
|
||||||
icon: <DriveEtaIcon sx={{ width: "inherit", height: "inherit" }} />,
|
icon: <DriveEtaIcon sx={{ width: "inherit", height: "inherit" }} />,
|
||||||
permissions: ["show-rahdaran"],
|
permissions: ["update-machine"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -277,3 +277,11 @@ export const CONFIRM_VERIFY_LICENSE_FORM = api + "/api/v3/harim/technical_deputy
|
|||||||
// History
|
// History
|
||||||
export const GET_HISTORY_LIST = api + "/api/v3/harim/detail/histories";
|
export const GET_HISTORY_LIST = api + "/api/v3/harim/detail/histories";
|
||||||
export const GET_REQUEST_INQUIRY_PRIVACY = api + "/api/v3/harim/technical_deputy";
|
export const GET_REQUEST_INQUIRY_PRIVACY = api + "/api/v3/harim/technical_deputy";
|
||||||
|
|
||||||
|
// Machines
|
||||||
|
export const GET_MACHINES_LIST = api + "/api/v3/cmms_machines";
|
||||||
|
export const UPDATE_CMMS_MACHINES = api + "/api/v3/cmms_machines";
|
||||||
|
export const GET_PROVINCES_LIST = api + "/api/v3/provinces/list";
|
||||||
|
export const GET_CITIES_LIST = api + "/api/v3/cities/list";
|
||||||
|
export const GET_STATIONS_LIST = api + "/api/v3/road_maintenance_station";
|
||||||
|
export const UPDATE_MACHINE_STATUS_AND_LOCATION = api + "/api/v3/cmms_machines";
|
||||||
|
|||||||
4
src/core/utils/violationsCategoryStatus.js
Normal file
4
src/core/utils/violationsCategoryStatus.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const violationsCategoryStatus = [
|
||||||
|
{ id: 0, name_fa: "بدون اقدام" },
|
||||||
|
{ id: 1, name_fa: "اقدام شده" },
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user