Merge branch 'feature/supervisor_road_observations' into 'develop'

Feature/supervisor road observations

See merge request witel-front-end/rms!75
This commit is contained in:
AmirHossein Mahmoodi
2025-02-26 12:31:24 +00:00
27 changed files with 1409 additions and 4 deletions

View File

@@ -0,0 +1,7 @@
"use client";
import PageLoading from "@/core/components/PageLoading";
const Loading = () => {
return <PageLoading />;
};
export default Loading;

View File

@@ -0,0 +1,13 @@
import WithPermission from "@/core/middlewares/withPermission";
import SupervisorPage from "@/components/dashboard/fastReact/supervisor";
import ActivityCodeLog from "@/core/components/ActivityCodeLog";
const Page = () => {
return (
<WithPermission permission_name={["show-fast-react", "show-fast-react-province"]}>
<SupervisorPage />
<ActivityCodeLog activity_code={1137} />
</WithPermission>
);
};
export default Page;

View File

@@ -0,0 +1,271 @@
import { useEffect, useMemo, useState } from "react";
import { Box, Button, Dialog, DialogActions, Stack, Typography } from "@mui/material";
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
import Toolbar from "./Toolbar";
import RowActions from "./RowActions";
import { GET_FAST_REACT_COMPLAINTS } from "@/core/utils/routes";
import useProvinces from "@/lib/hooks/useProvince";
import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsType/CustomSelectByDependency";
import { usePermissions } from "@/lib/hooks/usePermissions";
import { useAuth } from "@/lib/contexts/auth";
import useEdaratLists from "@/lib/hooks/useEdaratLists";
import DescriptionForm from "./RowActions/DescriptionDialog";
import LocationForm from "./RowActions/LocationDialog";
import moment from "jalali-moment";
const ComplaintListTable = ({ open, setOpen, mutate }) => {
const { data: userPermissions } = usePermissions();
const hasCountryPermission = userPermissions?.includes("show-fast-react");
const { user } = useAuth();
const columns = useMemo(() => {
const dynamicColumns = {
header: "استان",
id: "road_observeds__province_id",
enableColumnFilter: true,
datatype: "numeric",
filterMode: "equals",
grow: false,
size: 130,
ColumnSelectComponent: (props) => {
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
const getColumnSelectOptions = useMemo(() => {
if (loadingProvinces) {
return [{ value: "loading", label: "در حال بارگذاری..." }];
}
if (errorProvinces) {
return [{ value: "error", label: "خطا در بارگذاری" }];
}
return [
{ value: "", label: "کل کشور" },
...provinces.map((province) => ({
value: province.id,
label: province.name_fa,
})),
];
}, [provinces, errorProvinces, loadingProvinces]);
return (
<CustomSelectByDependency
{...props}
value={loadingProvinces ? "loading" : props.filterParameters.value}
columnSelectOption={getColumnSelectOptions}
/>
);
},
Cell: ({ row }) => <>{row.original.province_fa}</>,
};
return [
{
accessorKey: "id",
header: "کد یکتا",
id: "id",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "fk_RegisteredEventMessage",
header: "کد سوانح",
id: "fk_RegisteredEventMessage",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
...(hasCountryPermission ? [dynamicColumns] : []),
{
header: "اداره",
id: "edarat_id",
enableColumnFilter: true,
datatype: "numeric",
filterMode: "equals",
dependencyId: hasCountryPermission ? "road_observeds__province_id" : null,
grow: false,
size: 120,
ColumnSelectComponent: (props) => {
const { edaratList, loadingEdaratList, errorEdaratList } = useEdaratLists(
hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
);
const [prevDependency, setPrevDependency] = useState(
hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
);
const getColumnSelectOptions = useMemo(() => {
if (hasCountryPermission && props.dependencyFieldValue.value === "") {
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
}
if (loadingEdaratList) {
return [{ value: "loading", label: "در حال بارگذاری..." }];
}
if (errorEdaratList) {
return [{ value: "error", label: "خطا در بارگذاری" }];
}
return [
{ value: "", label: "کل ادارات" },
...edaratList.map((edare) => ({
value: edare.id,
label: edare.name_fa,
})),
];
}, [edaratList, loadingEdaratList, errorEdaratList]);
useEffect(() => {
if (hasCountryPermission) return;
if (prevDependency === props.dependencyFieldValue?.value) return;
props.handleChange({ ...props.filterParameters, value: "" });
setPrevDependency(props.dependencyFieldValue?.value);
}, [props.dependencyFieldValue?.value, hasCountryPermission]);
return (
<CustomSelectByDependency
{...props}
value={
props.dependencyFieldValue?.value === ""
? "empty"
: loadingEdaratList
? "loading"
: props.filterParameters.value
}
columnSelectOption={getColumnSelectOptions}
/>
);
},
Cell: ({ row }) => <>{row.original.city_fa}</>,
},
{
accessorKey: "Title",
header: "موضوع گزارش",
id: "Title",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "FeatureTypeTitle",
header: "نوع گزارش",
id: "FeatureTypeTitle",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "Description",
header: "توضیح گزارش",
id: "Description",
enableColumnFilter: false,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ renderedCellValue }) => {
if (renderedCellValue) {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<DescriptionForm description={renderedCellValue} title={"توضیح گزارش"} />
</Stack>
);
}
return <Typography variant="body2">بدون توضیحات</Typography>;
},
},
{
header: "موقعیت",
id: "location",
enableColumnFilter: false,
enableSorting: false,
datatype: "array",
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ row }) => {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<LocationForm start_lat={row.original.lat} start_lng={row.original.lng} />
</Stack>
);
},
},
{
accessorKey: "MobileForSendEventSms",
header: "شماره تماس گیرنده",
id: "MobileForSendEventSms",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
header: "تاریخ ثبت",
id: "created_at",
enableColumnFilter: true,
datatype: "date",
filterMode: "between",
grow: false,
size: 100,
},
];
}, []);
return (
<Dialog onClose={() => setOpen(false)} open={open} fullWidth maxWidth={"md"}>
{open && (
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
<DataTableWithAuth
need_filter={true}
table_title={"لیست شکایات"}
columns={columns}
sorting={[{ id: "fk_RegisteredEventMessage", desc: true }]}
table_url={GET_FAST_REACT_COMPLAINTS}
page_name={"complaintFastReact"}
table_name={"complaintList"}
TableToolbar={Toolbar}
enableRowActions
positionActionsColumn={"last"}
RowActions={RowActions}
/>
</Box>
)}
<DialogActions>
<Button variant={"outlined"} color={"secondary"} onClick={() => setOpen(false)}>
بستن
</Button>
</DialogActions>
</Dialog>
);
};
export default ComplaintListTable;

View File

@@ -0,0 +1,50 @@
import { Dialog, DialogContent, DialogTitle, IconButton, Tooltip, Typography, Card, CardContent } from "@mui/material";
import { useState } from "react";
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
import CloseIcon from "@mui/icons-material/Close";
const DescriptionForm = ({ description, title, icon: IconComponent = RemoveRedEyeIcon }) => {
const [openOfficerDescriptionDialog, setOpenOfficerDescriptionDialog] = useState(false);
return (
<>
<Tooltip title={title}>
<IconButton color="primary" onClick={() => setOpenOfficerDescriptionDialog(true)}>
<IconComponent />
</IconButton>
</Tooltip>
<Dialog
open={openOfficerDescriptionDialog}
onClose={() => setOpenOfficerDescriptionDialog(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" }}>
{title}
</Typography>
<IconButton onClick={() => setOpenOfficerDescriptionDialog(false)} size="small">
<CloseIcon />
</IconButton>
</DialogTitle>
<DialogContent>
<Card elevation={0}>
<CardContent>
<Typography variant="body2">{description || "هیچ توضیحی موجود نیست"} </Typography>
</CardContent>
</Card>
</DialogContent>
</Dialog>
</>
);
};
export default DescriptionForm;

View File

@@ -0,0 +1,30 @@
"use client";
import { Box, Button, DialogActions, DialogContent, Stack } from "@mui/material";
import React from "react";
import dynamic from "next/dynamic";
import MapLoading from "@/core/components/MapLayer/Loading";
import ShowLocationMarker from "@/core/components/ShowLocationMarker";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => <MapLoading />,
ssr: false,
});
const LocationFormContent = ({ setOpenLocationDialog, start_lat, start_lng }) => {
return (
<>
<DialogContent>
<Box sx={{ width: "400px", height: "400px" }}>
<MapLayer>
<ShowLocationMarker start_lat={start_lat} start_lng={start_lng} />
</MapLayer>
</Box>
</DialogContent>
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
<Button onClick={() => setOpenLocationDialog(false)} variant="outlined" color="secondary">
بستن
</Button>
</DialogActions>
</>
);
};
export default LocationFormContent;

View File

@@ -0,0 +1,36 @@
import React, { useState } from "react";
import { Tooltip, IconButton, Dialog, DialogTitle } from "@mui/material";
import ExploreIcon from "@mui/icons-material/Explore";
import LocationFormContent from "./LocationFormContent";
const LocationForm = ({ start_lat, start_lng }) => {
const [openLocationDialog, setOpenLocationDialog] = useState(false);
return (
<>
<Tooltip title="موقعیت">
<IconButton color="primary" onClick={() => setOpenLocationDialog(true)}>
<ExploreIcon />
</IconButton>
</Tooltip>
<Dialog
open={openLocationDialog}
onClose={() => setOpenLocationDialog(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>
<LocationFormContent
start_lat={start_lat}
start_lng={start_lng}
setOpenLocationDialog={setOpenLocationDialog}
/>
</Dialog>
</>
);
};
export default LocationForm;

View File

@@ -0,0 +1,6 @@
import { Box } from "@mui/material";
const RowActions = ({ row, mutate }) => {
return <Box sx={{ display: "flex", gap: 1 }}></Box>;
};
export default RowActions;

View File

@@ -0,0 +1,6 @@
import { Stack } from "@mui/material";
const Toolbar = ({ table, filterData, mutate }) => {
return <Stack direction={"row"} spacing={2}></Stack>;
};
export default Toolbar;

View File

@@ -0,0 +1,36 @@
import { Button, IconButton, useMediaQuery } from "@mui/material";
import ChecklistIcon from "@mui/icons-material/Checklist";
import { useTheme } from "@emotion/react";
import { useState } from "react";
import ComplaintListTable from "./ComplaintListTable";
const ComplaintList = ({ 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}>
<ChecklistIcon sx={{ fontSize: "25px" }} />
</IconButton>
) : (
<Button
size={"small"}
variant="contained"
color="primary"
startIcon={<ChecklistIcon />}
onClick={handleOpen}
>
لیست شکایات
</Button>
)}
<ComplaintListTable open={open} setOpen={setOpen} mutate={mutate} />
</>
);
};
export default ComplaintList;

View File

@@ -0,0 +1,75 @@
import { Button, CircularProgress, IconButton, useMediaQuery } from "@mui/material";
import { useMemo, useState } from "react";
import moment from "jalali-moment";
import FileSaver from "file-saver";
import DescriptionIcon from "@mui/icons-material/Description";
import useRequest from "@/lib/hooks/useRequest";
import { EXPORT_ROAD_ITEMS_SUPERVISOR_LIST } from "@/core/utils/routes";
import { useTheme } from "@emotion/react";
import DataTableFilterDataStructure from "@/core/utils/DataTableFilterDataStructure";
import isArrayEmpty from "@/core/utils/isArrayEmpty";
const PrintExcel = ({ table, filterData }) => {
const [loading, setLoading] = useState(false);
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
const requestServer = useRequest();
const activeFilters = Object.entries(filterData).reduce((acc, [key, filter]) => {
if (filter.value && (!Array.isArray(filter.value) || filter.value.some((item) => item.trim() !== ""))) {
acc.push({ id: key, value: filter.value });
}
return acc;
}, []);
const filterParams = useMemo(() => {
const params = new URLSearchParams();
if (activeFilters.length > 0) {
activeFilters.map((filter, index) => {
const filteredFilterData = DataTableFilterDataStructure(filterData, isArrayEmpty);
params.set("filters", JSON.stringify(filteredFilterData.length === 0 ? [] : filteredFilterData));
});
} else {
params.set("filters", JSON.stringify([]));
}
return params;
}, [activeFilters]);
const clickHandler = () => {
setLoading(true);
requestServer(`${EXPORT_ROAD_ITEMS_SUPERVISOR_LIST}?${filterParams}`, "get", {
requestOptions: { responseType: "blob" },
})
.then((response) => {
const filename = `خروجی کارتابل ارزیابی فعالیت روزانه تاریخ_${moment().format("jYYYY_jMM_jDD")}.xlsx`;
FileSaver.saveAs(response.data, filename);
})
.catch(() => {})
.finally(() => {
setLoading(false);
});
};
return (
<>
{isMobile ? (
<IconButton aria-label="خروجی اکسل" color="primary" onClick={clickHandler}>
<DescriptionIcon sx={{ fontSize: "25px" }} />
</IconButton>
) : (
<Button
color="primary"
variant="contained"
size="small"
disabled={loading}
sx={{ textTransform: "unset", alignSelf: "center" }}
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <DescriptionIcon />}
onClick={clickHandler}
>
خروجی اکسل
</Button>
)}
</>
);
};
export default PrintExcel;

View File

@@ -0,0 +1,69 @@
import { Button, DialogActions, DialogContent, Stack, TextField } from "@mui/material";
import { useForm } from "react-hook-form";
import useRequest from "@/lib/hooks/useRequest";
import { VERIFY_BY_FAST_REACT_SUPERVISOR } from "@/core/utils/routes";
const ConfirmContent = ({ rowId, mutate, setOpenConfirmDialog }) => {
const requestServer = useRequest({ notificationSuccess: true });
const {
register,
handleSubmit,
formState: { isSubmitting },
} = useForm({
defaultValues: {
description: "",
},
});
const onSubmit = async (data) => {
const formData = new FormData();
data.description !== "" && formData.append("description", data.description);
formData.append("verify", 1);
requestServer(`${VERIFY_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
data: formData,
})
.then(() => {
mutate();
setOpenConfirmDialog(false);
})
.catch(() => {});
};
return (
<>
<DialogContent>
<Stack spacing={2}>
<Stack>
<TextField
{...register("description")}
multiline
rows={8}
label="توضیحات و دلایل تأیید (اختیاری)"
placeholder="لطفاً علت تأیید خود را توضیح دهید"
fullWidth
variant="outlined"
sx={{ mt: 1 }}
InputLabelProps={{ shrink: true }}
/>
</Stack>
</Stack>
</DialogContent>
<DialogActions>
<Button
onClick={() => setOpenConfirmDialog(false)}
variant="outlined"
color="secondary"
disabled={isSubmitting}
autoFocus
>
بستن
</Button>
<Button onClick={handleSubmit(onSubmit)} variant="contained" color="primary" disabled={isSubmitting}>
{isSubmitting ? "درحال تایید اقدام..." : "تایید اقدام"}
</Button>
</DialogActions>
</>
);
};
export default ConfirmContent;

View File

@@ -0,0 +1,29 @@
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
import { useState } from "react";
import ConfirmContent from "./ConfirmContent";
import DoneIcon from "@mui/icons-material/Done";
const ConfirmForm = ({ rowId, mutate }) => {
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
return (
<>
<Tooltip title="تایید اقدام">
<IconButton color="primary" onClick={() => setOpenConfirmDialog(true)}>
<DoneIcon />
</IconButton>
</Tooltip>
<Dialog
fullWidth
open={openConfirmDialog}
PaperProps={{
sx: {
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
},
}}
>
<DialogTitle>تایید اقدام</DialogTitle>
<ConfirmContent mutate={mutate} rowId={rowId} setOpenConfirmDialog={setOpenConfirmDialog} />
</Dialog>
</>
);
};
export default ConfirmForm;

View File

@@ -0,0 +1,50 @@
import { Dialog, DialogContent, DialogTitle, IconButton, Tooltip, Typography, Card, CardContent } from "@mui/material";
import { useState } from "react";
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
import CloseIcon from "@mui/icons-material/Close";
const DescriptionForm = ({ description, title, icon: IconComponent = RemoveRedEyeIcon }) => {
const [openOfficerDescriptionDialog, setOpenOfficerDescriptionDialog] = useState(false);
return (
<>
<Tooltip title={title}>
<IconButton color="primary" onClick={() => setOpenOfficerDescriptionDialog(true)}>
<IconComponent />
</IconButton>
</Tooltip>
<Dialog
open={openOfficerDescriptionDialog}
onClose={() => setOpenOfficerDescriptionDialog(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" }}>
{title}
</Typography>
<IconButton onClick={() => setOpenOfficerDescriptionDialog(false)} size="small">
<CloseIcon />
</IconButton>
</DialogTitle>
<DialogContent>
<Card elevation={0}>
<CardContent>
<Typography variant="body2">{description || "هیچ توضیحی موجود نیست"} </Typography>
</CardContent>
</Card>
</DialogContent>
</Dialog>
</>
);
};
export default DescriptionForm;

View File

@@ -0,0 +1,44 @@
import { Box, DialogContent, Paper, Stack, Typography, useTheme } from "@mui/material";
import Image from "next/image";
const ImageFormContent = ({ image, title }) => {
const theme = useTheme();
return (
<Stack
spacing={2}
alignItems="center"
justifyContent="center"
sx={{
my: 2,
padding: 2,
borderRadius: "12px",
border: `1px solid ${theme.palette.primary.main}`,
}}
>
<Typography
variant="h6"
sx={{
color: theme.palette.primary.dark,
fontWeight: "bold",
}}
>
{title}
</Typography>
<Box sx={{ width: "100%", position: "relative", aspectRatio: "16/9" }}>
<Image
src={image}
alt="Image"
fill={true}
loading="lazy"
style={{
objectFit: "contain",
marginBottom: "16px",
borderRadius: "12px",
border: `1px solid ${theme.palette.divider}`,
}}
/>
</Box>
</Stack>
);
};
export default ImageFormContent;

View File

@@ -0,0 +1,46 @@
import PhotoLibraryIcon from "@mui/icons-material/PhotoLibrary";
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Tooltip } from "@mui/material";
import { useState } from "react";
import ImageFormContent from "./ImageFormContent";
const ImageDialog = ({ image_before, image_after }) => {
const [openImageDialog, setOpenImageDialog] = useState(false);
return (
<>
<Tooltip title="تصاویر">
<IconButton color="primary" onClick={() => setOpenImageDialog(true)}>
<PhotoLibraryIcon />
</IconButton>
</Tooltip>
<Dialog
fullWidth
open={openImageDialog}
onClose={() => setOpenImageDialog(false)}
PaperProps={{
sx: {
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
},
}}
maxWidth={"sm"}
scroll="paper"
>
<DialogTitle sx={{ fontSize: "large" }}>تصاویر</DialogTitle>
<DialogContent>
{openImageDialog && (
<>
<ImageFormContent image={image_before} title={"عکس قبل از اقدام"} />
<ImageFormContent image={image_after} title={"عکس بعد از اقدام"} />
</>
)}
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenImageDialog(false)} variant="outlined" color="secondary">
بستن
</Button>
</DialogActions>
</Dialog>
</>
);
};
export default ImageDialog;

View File

@@ -0,0 +1,30 @@
"use client";
import { Box, Button, DialogActions, DialogContent, Stack } from "@mui/material";
import React from "react";
import dynamic from "next/dynamic";
import MapLoading from "@/core/components/MapLayer/Loading";
import ShowLocationMarker from "@/core/components/ShowLocationMarker";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => <MapLoading />,
ssr: false,
});
const LocationFormContent = ({ setOpenLocationDialog, start_lat, start_lng }) => {
return (
<>
<DialogContent>
<Box sx={{ width: "400px", height: "400px" }}>
<MapLayer>
<ShowLocationMarker start_lat={start_lat} start_lng={start_lng} />
</MapLayer>
</Box>
</DialogContent>
<DialogActions sx={{ justifyContent: "center", paddingBottom: 2, width: "100%" }}>
<Button onClick={() => setOpenLocationDialog(false)} variant="outlined" color="secondary">
بستن
</Button>
</DialogActions>
</>
);
};
export default LocationFormContent;

View File

@@ -0,0 +1,36 @@
import React, { useState } from "react";
import { Tooltip, IconButton, Dialog, DialogTitle } from "@mui/material";
import ExploreIcon from "@mui/icons-material/Explore";
import LocationFormContent from "./LocationFormContent";
const LocationForm = ({ start_lat, start_lng }) => {
const [openLocationDialog, setOpenLocationDialog] = useState(false);
return (
<>
<Tooltip title="موقعیت">
<IconButton color="primary" onClick={() => setOpenLocationDialog(true)}>
<ExploreIcon />
</IconButton>
</Tooltip>
<Dialog
open={openLocationDialog}
onClose={() => setOpenLocationDialog(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>
<LocationFormContent
start_lat={start_lat}
start_lng={start_lng}
setOpenLocationDialog={setOpenLocationDialog}
/>
</Dialog>
</>
);
};
export default LocationForm;

View File

@@ -0,0 +1,83 @@
import { Button, DialogActions, DialogContent, Stack, TextField } from "@mui/material";
import { useForm } from "react-hook-form";
import { yupResolver } from "@hookform/resolvers/yup";
import * as Yup from "yup";
import useRequest from "@/lib/hooks/useRequest";
import { REJECT_BY_FAST_REACT_SUPERVISOR } from "@/core/utils/routes";
const RejectContent = ({ rowId, mutate, setOpenRejectDialog }) => {
const requestServer = useRequest({ notificationSuccess: true });
const validationSchema = Yup.object().shape({
description: Yup.string().required("لطفاً توضیحات را وارد کنید."),
});
const {
register,
handleSubmit,
formState: { errors, isSubmitting },
reset,
} = useForm({
defaultValues: {
description: "",
},
resolver: yupResolver(validationSchema),
mode: "onBlur",
});
const onSubmit = async (data) => {
const formData = new FormData();
formData.append("description", data.description);
formData.append("verify", 2);
requestServer(`${REJECT_BY_FAST_REACT_SUPERVISOR}/${rowId}`, "post", {
data: formData,
})
.then(() => {
mutate();
setOpenRejectDialog(false);
})
.catch(() => {})
.finally(() => {
reset();
});
};
return (
<>
<DialogContent>
<Stack spacing={2}>
<Stack>
<TextField
{...register("description")}
multiline
rows={8}
label="توضیحات و دلایل عدم تأیید"
placeholder="لطفاً علت عدم تأیید خود را توضیح دهید"
error={!!errors.description}
helperText={errors.description?.message}
fullWidth
variant="outlined"
sx={{ mt: 1 }}
InputLabelProps={{ shrink: true }}
/>
</Stack>
</Stack>
</DialogContent>
<DialogActions>
<Button
onClick={() => setOpenRejectDialog(false)}
variant="outlined"
color="secondary"
disabled={isSubmitting}
autoFocus
>
بستن
</Button>
<Button onClick={handleSubmit(onSubmit)} variant="contained" color="primary" disabled={isSubmitting}>
{isSubmitting ? "درحال ثبت عدم تایید..." : "ثبت عدم تایید"}
</Button>
</DialogActions>
</>
);
};
export default RejectContent;

View File

@@ -0,0 +1,29 @@
import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material";
import { useState } from "react";
import ClearIcon from "@mui/icons-material/Clear";
import RejectContent from "./RejectFormContent";
const RejectForm = ({ rowId, mutate }) => {
const [openRejectDialog, setOpenRejectDialog] = useState(false);
return (
<>
<Tooltip title="عدم تایید">
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
<ClearIcon />
</IconButton>
</Tooltip>
<Dialog
fullWidth
open={openRejectDialog}
PaperProps={{
sx: {
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
},
}}
>
<DialogTitle>عدم تایید اقدام</DialogTitle>
<RejectContent mutate={mutate} rowId={rowId} setOpenRejectDialog={setOpenRejectDialog} />
</Dialog>
</>
);
};
export default RejectForm;

View File

@@ -0,0 +1,22 @@
import {Box} from "@mui/material";
import ConfirmForm from "./ConfirmDialog";
import RejectForm from "./RejectDialog";
import {usePermissions} from "@/lib/hooks/usePermissions";
const RowActions = ({row, mutate}) => {
const {data: userPermissions} = usePermissions();
const hasSupervisePermission = userPermissions.some((item) =>
["supervise-fast-react", "supervise-fast-react-province"].includes(item)
);
return (
<Box sx={{display: "flex", gap: 1}}>
{hasSupervisePermission && row.original?.status === 0 && (
<ConfirmForm rowId={row.getValue("id")} mutate={mutate}/>
)}
{hasSupervisePermission && row.original?.status === 0 &&(
<RejectForm rowId={row.getValue("id")} mutate={mutate}/>
)}
</Box>
);
};
export default RowActions;

View File

@@ -0,0 +1,405 @@
import { useEffect, useMemo, useState } from "react";
import { Box, Stack, Typography } from "@mui/material";
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
import Toolbar from "./Toolbar";
import moment from "jalali-moment";
import RowActions from "./RowActions";
import { GET_FAST_REACT_SUPERVISOR } from "@/core/utils/routes";
import useProvinces from "@/lib/hooks/useProvince";
import CustomSelectByDependency from "@/core/components/DataTable/filter/fieldsType/CustomSelectByDependency";
import { usePermissions } from "@/lib/hooks/usePermissions";
import { useAuth } from "@/lib/contexts/auth";
import useEdaratLists from "@/lib/hooks/useEdaratLists";
import DescriptionForm from "./RowActions/DescriptionDialog";
import LocationForm from "./RowActions/LocationDialog";
import EngineeringIcon from "@mui/icons-material/Engineering";
import ThreePIcon from "@mui/icons-material/ThreeP";
import ImageDialog from "./RowActions/ImageDialog";
const SupervisorList = () => {
const { data: userPermissions } = usePermissions();
const hasCountryPermission = userPermissions?.includes("show-fast-react");
const { user } = useAuth();
const statusOptions = [
{ value: "", label: "همه وضعیت ها" },
{ value: 0, label: "درحال بررسی" },
{ value: 1, label: "تایید شده" },
{ value: 2, label: "عدم تایید" },
];
const columns = useMemo(() => {
const dynamicColumns = {
header: "استان",
id: "road_observeds__province_id",
enableColumnFilter: true,
datatype: "numeric",
filterMode: "equals",
grow: false,
size: 130,
ColumnSelectComponent: (props) => {
const { provinces, errorProvinces, loadingProvinces } = useProvinces();
const getColumnSelectOptions = useMemo(() => {
if (loadingProvinces) {
return [{ value: "loading", label: "در حال بارگذاری..." }];
}
if (errorProvinces) {
return [{ value: "error", label: "خطا در بارگذاری" }];
}
return [
{ value: "", label: "کل کشور" },
...provinces.map((province) => ({
value: province.id,
label: province.name_fa,
})),
];
}, [provinces, errorProvinces, loadingProvinces]);
return (
<CustomSelectByDependency
{...props}
value={loadingProvinces ? "loading" : props.filterParameters.value}
columnSelectOption={getColumnSelectOptions}
/>
);
},
Cell: ({ row }) => <>{row.original.province_fa}</>,
};
return [
{
accessorKey: "id",
header: "کد یکتا",
id: "id",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "fk_RegisteredEventMessage",
header: "کد سوانح",
id: "fk_RegisteredEventMessage",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
...(hasCountryPermission ? [dynamicColumns] : []),
{
header: "اداره",
id: "edarat_id",
enableColumnFilter: true,
datatype: "numeric",
filterMode: "equals",
dependencyId: hasCountryPermission ? "road_observeds__province_id" : null,
grow: false,
size: 120,
ColumnSelectComponent: (props) => {
const { edaratList, loadingEdaratList, errorEdaratList } = useEdaratLists(
hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
);
const [prevDependency, setPrevDependency] = useState(
hasCountryPermission ? props.dependencyFieldValue.value : user.province_id
);
const getColumnSelectOptions = useMemo(() => {
if (hasCountryPermission && props.dependencyFieldValue.value === "") {
return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }];
}
if (loadingEdaratList) {
return [{ value: "loading", label: "در حال بارگذاری..." }];
}
if (errorEdaratList) {
return [{ value: "error", label: "خطا در بارگذاری" }];
}
return [
{ value: "", label: "کل ادارات" },
...edaratList.map((edare) => ({
value: edare.id,
label: edare.name_fa,
})),
];
}, [edaratList, loadingEdaratList, errorEdaratList]);
useEffect(() => {
if (hasCountryPermission) return;
if (prevDependency === props.dependencyFieldValue?.value) return;
props.handleChange({ ...props.filterParameters, value: "" });
setPrevDependency(props.dependencyFieldValue?.value);
}, [props.dependencyFieldValue?.value, hasCountryPermission]);
return (
<CustomSelectByDependency
{...props}
value={
props.dependencyFieldValue?.value === ""
? "empty"
: loadingEdaratList
? "loading"
: props.filterParameters.value
}
columnSelectOption={getColumnSelectOptions}
/>
);
},
Cell: ({ renderedCellValue, row }) => <>{row.original.city_fa}</>,
},
{
accessorKey: "Title",
header: "موضوع گزارش",
id: "Title",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "FeatureTypeTitle",
header: "نوع گزارش",
id: "FeatureTypeTitle",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorKey: "Description",
header: "توضیح گزارش",
id: "Description",
enableColumnFilter: false,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ renderedCellValue }) => {
if (renderedCellValue) {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<DescriptionForm description={renderedCellValue} title={"توضیحات گزارش"} />
</Stack>
);
}
return <Typography variant="body2">بدون توضیحات</Typography>;
},
},
{
header: "موقعیت",
id: "location",
enableColumnFilter: false,
enableSorting: false,
datatype: "array",
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ row }) => {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<LocationForm start_lat={row.original.lat} start_lng={row.original.lng} />
</Stack>
);
},
},
{
header: "تصاویر",
id: "images",
enableColumnFilter: false,
enableSorting: false,
datatype: "array",
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ row }) => {
if (!row.original?.image_before && !row.original?.image_after) return <>بدون تصویر</>;
return (
<Stack alignItems={"center"} justifyContent={"center"}>
{row.original?.image_before && row.original?.image_after && (
<ImageDialog
image_before={row.original?.image_before}
image_after={row.original?.image_after}
/>
)}
</Stack>
);
},
},
{
accessorKey: "MobileForSendEventSms",
header: "شماره تماس گیرنده",
id: "MobileForSendEventSms",
enableColumnFilter: true,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
},
{
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
header: "تاریخ ثبت",
id: "created_at",
enableColumnFilter: true,
datatype: "date",
filterMode: "between",
grow: false,
size: 100,
},
{
accessorFn: (row) => moment(row.rms_last_activity).locale("fa").format("HH:mm | yyyy/MM/DD"),
header: "تاریخ اقدام",
id: "rms_last_activity",
enableColumnFilter: true,
datatype: "date",
filterMode: "between",
grow: false,
size: 100,
},
{
accessorKey: "rms_description",
header: "توضیح مامور",
id: "rms_description",
enableColumnFilter: false,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ renderedCellValue }) => {
if (renderedCellValue) {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<DescriptionForm
description={renderedCellValue}
title={"توضیحات مامور"}
icon={EngineeringIcon}
/>
</Stack>
);
}
return <Typography variant="body2">بدون توضیحات</Typography>;
},
},
{
accessorKey: "supervisor_description",
header: "توضیح کارشناس",
id: "supervisor_description",
enableColumnFilter: false,
datatype: "text",
filterMode: "equals",
sortDescFirst: false,
columnFilterModeOptions: ["equals", "contains"],
grow: false,
size: 100,
muiTableBodyCellProps: {
sx: {
borderLeft: "1px solid #e1e1e1",
py: 0,
"&:first-of-type": {
borderLeft: "unset",
},
},
},
Cell: ({ renderedCellValue }) => {
if (renderedCellValue) {
return (
<Stack alignItems={"center"} justifyContent={"center"}>
<DescriptionForm
description={renderedCellValue}
title={"توضیحات کارشناس"}
icon={ThreePIcon}
/>
</Stack>
);
}
return <Typography variant="body2">بدون توضیحات</Typography>;
},
},
{
accessorKey: "status",
header: "وضعیت",
id: "status",
enableColumnFilter: true,
datatype: "numeric",
filterMode: "equals",
sortDescFirst: true,
grow: false,
size: 100,
columnSelectOption: () => {
return statusOptions.map((status) => ({
value: status.value,
label: status.label,
}));
},
Cell: ({ row }) => <>{row.original.status_fa}</>,
},
];
}, []);
return (
<>
<Box sx={{ p: 1, border: 1, borderColor: "divider", borderRadius: 1 }}>
<DataTableWithAuth
need_filter={true}
columns={columns}
sorting={[
{ id: "status", desc: false },
{ id: "id", desc: true },
]}
table_url={GET_FAST_REACT_SUPERVISOR}
page_name={"supervisorFastReact"}
table_name={"supervisorList"}
TableToolbar={Toolbar}
enableRowActions
positionActionsColumn={"last"}
RowActions={RowActions}
/>
</Box>
</>
);
};
export default SupervisorList;

View File

@@ -0,0 +1,13 @@
import PrintExcel from "./ExcelPrint";
import ComplaintList from "../complaintList";
import { Stack } from "@mui/material";
const Toolbar = ({ table, filterData, mutate }) => {
return (
<Stack direction={"row"} spacing={2}>
<PrintExcel table={table} filterData={filterData} />
<ComplaintList mutate={mutate} />
</Stack>
);
};
export default Toolbar;

View File

@@ -0,0 +1,14 @@
"use client";
import PageTitle from "@/core/components/PageTitle";
import { Stack } from "@mui/material";
import SupervisorList from "./SupervisorList";
const SupervisorPage = () => {
return (
<Stack spacing={1}>
<PageTitle title={"ارزیابی"} />
<SupervisorList />
</Stack>
);
};
export default SupervisorPage;

View File

@@ -32,5 +32,4 @@ const LocationFormContent = ({ setOpenLocationDialog, start_lat, start_lng, end_
</>
);
};
export default LocationFormContent;

View File

@@ -78,7 +78,7 @@ const SupervisorList = () => {
},
...(hasCountryPermission ? [dynamicColumns] : []),
{
header: "اداره", // Office
header: "اداره",
id: "edarat_id",
enableColumnFilter: true,
datatype: "numeric",

View File

@@ -369,8 +369,8 @@ export const pageMenu = [
id: "roadObservationsManagmentSupervisorCartable",
label: "کارتابل",
type: "page",
route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_observations/supervisor/cartable",
permissions: ["supervise-fast-react", "supervise-fast-react-province"],
route: "/dashboard/fast-react/supervisor",
permissions: ["show-fast-react", "show-fast-react-province"],
},
],
},

View File

@@ -110,3 +110,9 @@ export const EXPORT_PROVINCE_RECEIPT_REPORT = api + "/api/v3/receipt_reports/pro
// activity code log
export const ACTIVITY_LOG = api + "/api/v3/profile/add_activity";
// fast react
export const GET_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/supervisor_index";
export const GET_FAST_REACT_COMPLAINTS = api + "/api/v3/road_observations/complaints_index";
export const VERIFY_BY_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/verify";
export const REJECT_BY_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/verify";