diff --git a/src/components/dashboard/damages/operator/Actions/create/Forms/CreateFormContent.jsx b/src/components/dashboard/damages/operator/Actions/create/Forms/CreateFormContent.jsx index 026f16a..11ec3b4 100644 --- a/src/components/dashboard/damages/operator/Actions/create/Forms/CreateFormContent.jsx +++ b/src/components/dashboard/damages/operator/Actions/create/Forms/CreateFormContent.jsx @@ -4,7 +4,6 @@ import { yupResolver } from "@hookform/resolvers/yup"; import { array, mixed, number, object, string } from "yup"; import { Box, Button, DialogActions, DialogContent, Tab, Tabs } from "@mui/material"; import StyledForm from "@/core/components/StyledForm"; -import FileCopyIcon from "@mui/icons-material/FileCopy"; import InfoIcon from "@mui/icons-material/Info"; import ExitToAppIcon from "@mui/icons-material/ExitToApp"; import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight"; diff --git a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx index 25ded60..82083b5 100644 --- a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx +++ b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx @@ -242,7 +242,7 @@ const ComplaintListTable = ({ open, setOpen, mutate }) => { }, []); return ( - setOpen(false)} open={open} fullWidth maxWidth={"md"}> + setOpen(false)} open={open} fullWidth maxWidth={"xl"}> {open && ( { + const [beforeImg, setBeforeImg] = useState(value ? value : null); + const [beforeFileType, setBeforeFileType] = useState(value ? "image/" : null); + const [beforeFileName, setBeforeFileName] = useState(null); + const [showBeforeImage, setShowBeforeImage] = useState(!value); + + useEffect(() => { + if (value) { + setShowBeforeImage(false); + if (typeof value === "string") { + setBeforeImg(value); + setBeforeFileType("image/"); + } else if (value instanceof File) { + setBeforeImg(URL.createObjectURL(value)); + setBeforeFileType(value.type); + } + } + }, [value]); + + const handleFileChange = (event) => { + const uploadedFile = event.target?.files?.[0]; + if (uploadedFile) { + const fileType = event.target?.files?.[0].type; + const fileName = event.target?.files?.[0].name; + setBeforeImg(URL.createObjectURL(uploadedFile)); + setBeforeFileType(fileType); + setBeforeFileName(fileName); + onChange(uploadedFile); + setShowBeforeImage(false); + } + }; + + return ( + + + {title} + + + {error ? error.message : null} + + ); +}; +export default ImageUpload; diff --git a/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionContent.jsx b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionContent.jsx new file mode 100644 index 0000000..5e57e5a --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionContent.jsx @@ -0,0 +1,108 @@ +import { Button, DialogActions, DialogContent, FormControlLabel, RadioGroup, Stack } from "@mui/material"; +import { Controller, useForm } from "react-hook-form"; +import Radio from "@mui/material/Radio"; +import StyledForm from "@/core/components/StyledForm"; +import { useState } from "react"; +import RegisterActionDone from "./RegisterActionDone"; +import RegisterActionUndone from "./RegisterActionUndone"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { mixed, object, string } from "yup"; +import BeenhereIcon from "@mui/icons-material/Beenhere"; + +const RegisterActionContent = ({ setOpen, defaultValues, onBaseSubmit }) => { + const [selectedOption, setSelectedOption] = useState("1"); + + const handleOptionChange = (e) => { + setSelectedOption(e.target.value); + }; + const validationSchema = object({ + description: string().required("توضیحات الزامی است"), + start_point: mixed().when("rms_status", { + is: "1", + then: (schema) => schema.required("مکان اقدام الزامی است"), + otherwise: (schema) => schema.notRequired(), + }), + image_before_1: mixed().when("rms_status", { + is: "1", + then: (schema) => schema.required("تصویر قبل از اقدام الزامی است"), + otherwise: (schema) => schema.notRequired(), + }), + image_after_1: mixed().when("rms_status", { + is: "1", + then: (schema) => schema.required("تصویر بعد از اقدام الزامی است"), + otherwise: (schema) => schema.notRequired(), + }), + }); + + const { + control, + handleSubmit, + setValue, + formState: { isSubmitting, errors }, + } = useForm({ + defaultValues, + resolver: yupResolver(validationSchema), + mode: "onChange", + }); + + const onSubmit = async (data) => { + console.log(data); + await onBaseSubmit(data); + }; + + return ( + + + + + } + /> + } + label="اقدام انجام شد" + /> + } + /> + } + label="اقدام انجام نشد" + /> + + + {selectedOption === "1" ? ( + + ) : ( + + )} + + + + + + + ); +}; +export default RegisterActionContent; diff --git a/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionDone.jsx b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionDone.jsx new file mode 100644 index 0000000..8ba2616 --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionDone.jsx @@ -0,0 +1,86 @@ +import { Controller, useWatch } from "react-hook-form"; +import { Grid, Stack, TextField } from "@mui/material"; +import ImageUpload from "./ImageUpload"; +import MapInfoOneMarker from "@/core/components/MapInfoOneMarker"; + +const RegisterActionDone = ({ control, setValue, errors }) => { + const StartPoint = useWatch({ control, name: "rms_start_latlng" }); + return ( + + + + + { + return ( + + ); + }} + /> + + + + + + + ( + + )} + /> + + + ( + + )} + /> + + + + + + + + + + + + ); +}; +export default RegisterActionDone; diff --git a/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionUndone.jsx b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionUndone.jsx new file mode 100644 index 0000000..dd2b43b --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/Form/registerAction/RegisterActionUndone.jsx @@ -0,0 +1,37 @@ +import { Grid, Stack, TextField } from "@mui/material"; +import { Controller } from "react-hook-form"; + +const RegisterActionUndone = ({ control }) => { + return ( + + + + + { + return ( + + ); + }} + /> + + + + + ); +}; +export default RegisterActionUndone; diff --git a/src/components/dashboard/fastReact/complaintList/Form/registerAction/index.jsx b/src/components/dashboard/fastReact/complaintList/Form/registerAction/index.jsx new file mode 100644 index 0000000..7362f4b --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/Form/registerAction/index.jsx @@ -0,0 +1,66 @@ +import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material"; +import { useState } from "react"; +import RegisterActionContent from "./RegisterActionContent"; +import AppRegistrationIcon from "@mui/icons-material/AppRegistration"; +import useRequest from "@/lib/hooks/useRequest"; +import { REGISTER_COMPLAINTS_LIST } from "@/core/utils/routes"; +const RegisterAction = ({ rowId, mutate }) => { + const requestServer = useRequest({ notificationSuccess: true }); + const [openRegisterActionDialog, setOpenRegisterActionDialog] = useState(false); + const defaultValues = { + rms_status: "1", + description: "", + start_point: "", + image_before_1: null, + image_after_1: null, + }; + const onBaseSubmit = async (result) => { + console.log(result); + const formData = new FormData(); + const rmsLatLng = `${result.start_point.lat},${result.start_point.lng}`; + if (result.rms_status === "1") { + formData.append("rms_description", result.description); + formData.append("rms_status", 1); + formData.append("start_point", rmsLatLng); + formData.append("image_before", result.image_before_1); + formData.append("image_after", result.image_after_1); + } else { + formData.append("rms_description", result.description); + formData.append("rms_status", 2); + } + await requestServer(`${REGISTER_COMPLAINTS_LIST}/${rowId}`, "post", { + data: formData, + }) + .then((res) => { + mutate(); + setOpenRegisterActionDialog(false); + }) + .catch(() => {}); + }; + return ( + <> + + setOpenRegisterActionDialog(true)}> + + + + + ثبت اقدام + + + + ); +}; +export default RegisterAction; diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx index 4c9093a..71874db 100644 --- a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx +++ b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx @@ -1,10 +1,12 @@ import { Box } from "@mui/material"; +import RegisterAction from "../Form/registerAction"; import ReferList from "./ReferList"; import Refer from "./Refer"; const RowActions = ({ row, mutate }) => { return ( + diff --git a/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx b/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx index b889295..6125a74 100644 --- a/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx +++ b/src/components/dashboard/fastReact/supervisor/RowActions/index.jsx @@ -13,12 +13,12 @@ const RowActions = ({ row, mutate }) => { return ( {hasSupervisePermission && row.original?.status === 0 && ( - + )} {hasSupervisePermission && row.original?.status === 0 && ( - + )} - {hasRestorePermission && } + {hasRestorePermission && } ); }; diff --git a/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx b/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx index cb13855..3a607c2 100644 --- a/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx +++ b/src/components/dashboard/fastReact/supervisor/SupervisorList.jsx @@ -67,7 +67,7 @@ const SupervisorList = () => { { accessorKey: "id", header: "کد یکتا", - id: "id", + id: "road_observeds__id", enableColumnFilter: true, datatype: "text", filterMode: "equals", @@ -91,7 +91,7 @@ const SupervisorList = () => { ...(hasCountryPermission ? [dynamicColumns] : []), { header: "اداره", - id: "edarat_id", + id: "city_id", enableColumnFilter: true, datatype: "numeric", filterMode: "equals", @@ -272,7 +272,7 @@ const SupervisorList = () => { { accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), header: "تاریخ ثبت", - id: "created_at", + id: "road_observeds__created_at", enableColumnFilter: true, datatype: "date", filterMode: "between", @@ -280,7 +280,11 @@ const SupervisorList = () => { size: 100, }, { - accessorFn: (row) => moment(row.rms_last_activity).locale("fa").format("HH:mm | yyyy/MM/DD"), + accessorFn: (row) => { + return row.rms_last_activity + ? moment(row?.rms_last_activity).locale("fa").format("HH:mm | yyyy/MM/DD") + : "بدون تاریخ"; + }, header: "تاریخ اقدام", id: "rms_last_activity", enableColumnFilter: true, diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index 7fa077c..ebcf2ce 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -116,6 +116,7 @@ export const GET_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/superv 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"; +export const REGISTER_COMPLAINTS_LIST = api + "/api/v3/road_observations/register"; export const GET_FAST_REACT_OPERATOR = api + "/api/v3/road_observations/operator_index"; export const GET_FAST_REACT_REFER_LIST = api + "/api/v3/road_observations/refer_list"; export const REFER_FAST_REACT = api + "/api/v3/road_observations/refer";