diff --git a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx index 158d879..25ded60 100644 --- a/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx +++ b/src/components/dashboard/fastReact/complaintList/ComplaintListTable.jsx @@ -134,7 +134,7 @@ const ComplaintListTable = ({ open, setOpen, mutate }) => { /> ); }, - Cell: ({ row }) => <>{row.original.city_fa}, + Cell: ({ row }) => <>{row.original.edarate_shahri_name_fa}, }, { accessorKey: "Title", diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/Refer/EdarateShahriField.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/EdarateShahriField.jsx new file mode 100644 index 0000000..f44d8e1 --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/EdarateShahriField.jsx @@ -0,0 +1,70 @@ +"use client"; +import useEdaratLists from "@/lib/hooks/useEdaratLists"; +import { FormControl, FormHelperText, InputLabel, MenuItem, OutlinedInput, Select } from "@mui/material"; +import { useEffect, useMemo, useState } from "react"; +import { useWatch } from "react-hook-form"; + +const EdarateShahriField = ({ control, field, fieldState: { error } }) => { + const dependencyField = useWatch({ control, name: "province_id" }); + return ( + + ); +}; + +const EdarehShahriController = ({ value, onChange, dependencyField, error }) => { + const { edaratList, loadingEdaratList, errorEdaratList } = useEdaratLists(dependencyField); + const [prevDependency, setPrevDependency] = useState(dependencyField); + + const columnSelectOption = useMemo(() => { + if (dependencyField === "") { + return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }]; + } + if (loadingEdaratList) { + return [{ value: "loading", label: "در حال بارگذاری..." }]; + } + if (errorEdaratList) { + return [{ value: "error", label: "خطا در بارگذاری" }]; + } + return edaratList.map((edare) => ({ + value: edare.id, + label: edare.name_fa, + })); + }, [edaratList, loadingEdaratList, errorEdaratList]); + + useEffect(() => { + if (prevDependency === dependencyField) return; + onChange(""); + setPrevDependency(dependencyField); + }, [dependencyField]); + + return ( + + + اداره + + + {error && {error.message}} + + ); +}; +export default EdarateShahriField; diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ProvinceField.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ProvinceField.jsx new file mode 100644 index 0000000..455339e --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ProvinceField.jsx @@ -0,0 +1,33 @@ +import useProvinces from "@/lib/hooks/useProvince"; +import { FormControl, FormHelperText, InputLabel, MenuItem, Select } from "@mui/material"; + +const ProvinceField = ({ field, fieldState: { error } }) => { + const { provinces, loadingProvinces, errorProvinces } = useProvinces(); + return ( + + استان + + {error && {error.message}} + + ); +}; +export default ProvinceField; diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ReferContent.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ReferContent.jsx new file mode 100644 index 0000000..59774e6 --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/ReferContent.jsx @@ -0,0 +1,101 @@ +import { REFER_FAST_REACT } from "@/core/utils/routes"; +import useRequest from "@/lib/hooks/useRequest"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { Button, DialogActions, DialogContent, Stack, TextField } from "@mui/material"; +import { Controller, useForm } from "react-hook-form"; +import * as Yup from "yup"; +import EdarateShahriField from "./EdarateShahriField"; +import ProvinceField from "./ProvinceField"; + +const ReferContent = ({ rowId, mutate, setOpenReferDialog }) => { + const requestServer = useRequest({ notificationSuccess: true }); + + const validationSchema = Yup.object().shape({ + province_id: Yup.string().required("لطفاً استان را وارد کنید."), + edarat_shahri_id: Yup.string().required("لطفاً اداره را وارد کنید."), + description: Yup.string().required("لطفاً توضیحات را وارد کنید."), + }); + + const { + control, + register, + handleSubmit, + formState: { errors, isSubmitting }, + } = useForm({ + defaultValues: { + province_id: "", + edarat_shahri_id: "", + description: "", + }, + resolver: yupResolver(validationSchema), + mode: "onBlur", + }); + + const onSubmit = async (data) => { + const formData = new FormData(); + formData.append("province_id", data.province_id); + formData.append("edarate_shahri_id", data.edarat_shahri_id); + formData.append("refer_description", data.description); + await requestServer(`${REFER_FAST_REACT}/${rowId}`, "post", { + data: formData, + }) + .then(() => { + mutate(); + setOpenReferDialog(false); + }) + .catch(() => {}); + }; + + return ( + <> + + + { + return ; + }} + /> + { + return ; + }} + /> + + + + + + + + + + + ); +}; +export default ReferContent; diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/Refer/index.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/index.jsx new file mode 100644 index 0000000..8dc9875 --- /dev/null +++ b/src/components/dashboard/fastReact/complaintList/RowActions/Refer/index.jsx @@ -0,0 +1,33 @@ +import SettingsBackupRestoreIcon from "@mui/icons-material/SettingsBackupRestore"; +import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material"; +import { useState } from "react"; +import ReferContent from "./ReferContent"; + +const Refer = ({ rowId, mutate }) => { + const [openReferDialog, setOpenReferDialog] = useState(false); + return ( + <> + + setOpenReferDialog(true)}> + + + + + ارجاع + {openReferDialog && ( + + )} + + + ); +}; +export default Refer; diff --git a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx index 29e6e23..4c9093a 100644 --- a/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx +++ b/src/components/dashboard/fastReact/complaintList/RowActions/index.jsx @@ -1,9 +1,11 @@ import { Box } from "@mui/material"; import ReferList from "./ReferList"; +import Refer from "./Refer"; const RowActions = ({ row, mutate }) => { return ( + ); diff --git a/src/components/dashboard/fastReact/operator/index.jsx b/src/components/dashboard/fastReact/operator/index.jsx index 85759c2..a2b328c 100644 --- a/src/components/dashboard/fastReact/operator/index.jsx +++ b/src/components/dashboard/fastReact/operator/index.jsx @@ -1,13 +1,12 @@ "use client"; import PageTitle from "@/core/components/PageTitle"; import { Stack } from "@mui/material"; -import SupervisorList from "./OperatorList"; import OperatorList from "./OperatorList"; const OperatorPage = () => { return ( - + ); diff --git a/src/components/dashboard/roadItems/supervisor/RowActions/RejectForm/RejectContent.jsx b/src/components/dashboard/roadItems/supervisor/RowActions/RejectForm/RejectContent.jsx index b5945e2..3d319fa 100644 --- a/src/components/dashboard/roadItems/supervisor/RowActions/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/roadItems/supervisor/RowActions/RejectForm/RejectContent.jsx @@ -29,7 +29,7 @@ const RejectContent = ({ rowId, mutate, setOpenRejectDialog }) => { const formData = new FormData(); formData.append("description", data.description); formData.append("verify", 2); - requestServer(`${REJECT_BY_SUPERVISOR}/${rowId}`, "post", { + await requestServer(`${REJECT_BY_SUPERVISOR}/${rowId}`, "post", { data: formData, }) .then(() => { diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index ed9e8c1..1bee5c2 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -118,3 +118,4 @@ export const VERIFY_BY_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/ export const REJECT_BY_FAST_REACT_SUPERVISOR = api + "/api/v3/road_observations/verify"; 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";