diff --git a/.env.local.example b/.env.local.example index 8f5293b..fe53ba8 100644 --- a/.env.local.example +++ b/.env.local.example @@ -1,3 +1,3 @@ -NEXT_PUBLIC_VERSION="0.11.1" +NEXT_PUBLIC_VERSION="0.12.0" NEXT_PUBLIC_API_URL="https://rms.witel.ir" NEXT_PUBLIC_MAPTILE_ENDPOINT="https://rmsmap.rmto.ir/141map" \ No newline at end of file diff --git a/src/components/dashboard/azmayesh/AzmayeshList.jsx b/src/components/dashboard/azmayesh/AzmayeshList.jsx index 5e6d68c..904c50c 100644 --- a/src/components/dashboard/azmayesh/AzmayeshList.jsx +++ b/src/components/dashboard/azmayesh/AzmayeshList.jsx @@ -8,6 +8,7 @@ import { GET_AZMAYESH_LIST } from "@/core/utils/routes"; import ShowLocation from "./ShowLocation"; import moment from "jalali-moment"; import RowActions from "./RowActions"; +import ShowSampleOfAzmayesh from "./RowActions/ShowSampleOfAzmayesh"; const AzmayeshList = () => { const columns = useMemo( @@ -19,6 +20,16 @@ const AzmayeshList = () => { enableColumnFilter: false, datatype: "text", filterMode: "notEquals", + grow: false, + size: 100, + }, + { + accessorKey: "province_name", + header: "استان", + id: "province_name", + enableColumnFilter: false, + datatype: "text", + filterMode: "notEquals", }, { accessorKey: "azmayesh_type_name", @@ -28,6 +39,14 @@ const AzmayeshList = () => { datatype: "text", filterMode: "notEquals", }, + { + accessorKey: "contract_subitem_id", + header: "کد یکتا پروژه", + id: "contract_subitem_id", + enableColumnFilter: false, + datatype: "text", + filterMode: "equals", + }, { accessorKey: "project_name", header: "پروژه", @@ -37,13 +56,24 @@ const AzmayeshList = () => { filterMode: "equals", }, { - accessorKey: "lat", + accessorKey: "location", header: "نمایش مختصات", - id: "lat", + id: "location", enableColumnFilter: false, datatype: "text", enableSorting: false, filterMode: "equals", + grow: false, + size: 100, + muiTableBodyCellProps: { + sx: { + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, Cell: ({ row }) => , }, { @@ -101,6 +131,8 @@ const AzmayeshList = () => { enableColumnFilter: false, datatype: "date", filterMode: "equals", + grow: false, + size: 100, Cell: ({ renderedCellValue }) => ( {renderedCellValue ? moment(renderedCellValue).locale("fa").format("YYYY/MM/DD") : "-"} @@ -114,6 +146,8 @@ const AzmayeshList = () => { enableColumnFilter: false, datatype: "date", filterMode: "equals", + grow: false, + size: 100, Cell: ({ renderedCellValue }) => ( {renderedCellValue ? moment(renderedCellValue).locale("fa").format("YYYY/MM/DD") : "-"} @@ -127,12 +161,35 @@ const AzmayeshList = () => { enableColumnFilter: false, datatype: "date", filterMode: "equals", + grow: false, + size: 100, Cell: ({ renderedCellValue }) => ( {renderedCellValue ? moment(renderedCellValue).locale("fa").format("HH:mm | YYYY/MM/DD") : "-"} ), }, + { + accessorKey: "samples", + header: "نمونه ها", + id: "samples", + enableColumnFilter: false, + datatype: "text", + enableSorting: false, + filterMode: "equals", + grow: false, + size: 100, + muiTableBodyCellProps: { + sx: { + borderLeft: "1px solid #e1e1e1", + py: 0, + "&:first-of-type": { + borderLeft: "unset", + }, + }, + }, + Cell: ({ row }) => , + }, ], [] ); diff --git a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx index 469b1f5..afd329f 100644 --- a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx +++ b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx @@ -1,11 +1,12 @@ "use client"; import { Marker, useMapEvents } from "react-leaflet"; -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import L from "leaflet"; import AzmayeshIcon from "@/assets/images/examine_marker.png"; import AzmayeshActiveIcon from "@/assets/images/examine_marker_active.png"; import { + Alert, Box, Button, FormControl, @@ -14,6 +15,7 @@ import { OutlinedInput, Stack, Tooltip, + Zoom, useMediaQuery, } from "@mui/material"; import NewReleasesIcon from "@mui/icons-material/NewReleases"; @@ -21,9 +23,12 @@ import VerifiedIcon from "@mui/icons-material/Verified"; import EditIcon from "@mui/icons-material/Edit"; import { useTheme } from "@emotion/react"; +const MAX_ZOOM_FOR_MARKER = 13; + const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); + const [enableSend, setEnableSend] = useState(false); const mapAzmayeshMarker = useRef(); const defaultIconSize = [35, 35]; @@ -38,6 +43,7 @@ const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { const map = useMapEvents({ move(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); if (!mapBoxData) { mapAzmayeshMarker.current.setLatLng(e.target.getCenter()); } @@ -52,22 +58,24 @@ const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { mapAzmayeshMarker.current.setIcon(createCustomIcon(defaultIconSize, AzmayeshIcon.src)); } }, + zoom(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); + }, }); useEffect(() => { - if (mapAzmayeshMarker.current) { - const newIcon = mapBoxData - ? createCustomIcon([45, 45], AzmayeshActiveIcon.src) - : createCustomIcon(defaultIconSize, AzmayeshIcon.src); - mapAzmayeshMarker.current.setIcon(newIcon); - } + if (!mapAzmayeshMarker.current) return; if (mapBoxData) { + mapAzmayeshMarker.current.setIcon(createCustomIcon([45, 45], AzmayeshActiveIcon.src)); mapAzmayeshMarker.current.setLatLng(mapBoxData); - map.flyTo(mapBoxData, 14); + map.setView(mapBoxData, 14); + } else { + mapAzmayeshMarker.current.setIcon(createCustomIcon(defaultIconSize, AzmayeshIcon.src)); } - }, [mapBoxData]); + }, [mapBoxData, mapAzmayeshMarker.current]); const handleMarkerClick = () => { + if (!enableSend) return; if (!mapBoxData) { setMapBoxData({ lat: mapAzmayeshMarker.current.getLatLng().lat, @@ -86,93 +94,118 @@ const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { position={map.getCenter()} ref={mapAzmayeshMarker} eventHandlers={{ click: handleMarkerClick }} - icon={createCustomIcon(defaultIconSize, AzmayeshIcon.src)} + icon={L.divIcon({ className: "" })} /> - - - - - - طول جغرافیایی - - - {mapBoxData ? ( - - ) : ( - - )} - - } - label="طول جغرافیایی" - /> - - - - - - عرض جغرافیایی - - - {mapBoxData ? ( - - ) : ( - - )} - - } - label="عرض جغرافیایی" - /> - - - - - + + + برای ثبت محل آزمایش، لطفاً نقشه را بیشتر زوم کنید. + + + + + + + + + + طول جغرافیایی + + + {mapBoxData ? ( + + ) : ( + + )} + + } + label="طول جغرافیایی" + /> + + + + + + عرض جغرافیایی + + + {mapBoxData ? ( + + ) : ( + + )} + + } + label="عرض جغرافیایی" + /> + + + + + + ); }; diff --git a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUGeneralInfo.jsx b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUGeneralInfo.jsx index 24f4493..359e5b9 100644 --- a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUGeneralInfo.jsx +++ b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUGeneralInfo.jsx @@ -66,6 +66,11 @@ const CandUGeneralInfo = ({ control, register, setValue, errors }) => { label="نوع آزمایش" /> )} + renderOption={(props, option) => ( +
  • + {option.name} +
  • + )} /> )} @@ -122,6 +127,23 @@ const CandUGeneralInfo = ({ control, register, setValue, errors }) => { )} /> + + + کد یکتا پروژه + + + {errors.contract_subitem_id ? errors.contract_subitem_id.message : null} + + + پروژه @@ -252,6 +274,7 @@ const CandUGeneralInfo = ({ control, register, setValue, errors }) => { onChange={(newValue) => { onChange(newValue); }} + closeOnSelect slotProps={{ textField: { size: "small", @@ -305,6 +328,7 @@ const CandUGeneralInfo = ({ control, register, setValue, errors }) => { onChange={(newValue) => { onChange(newValue); }} + closeOnSelect slotProps={{ textField: { size: "small", diff --git a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx index f74dd22..f397229 100644 --- a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx +++ b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx @@ -33,6 +33,7 @@ function TabPanel(props) { const validationSchema = object({ azmayesh_type_id: string().required("نوع آزمایش را مشخص کنید!"), province_id: string().required("استان را وارد کنید!"), + contract_subitem_id: string().required("کد یکتا پروژه را وارد کنید!"), project_name: string().required("عنوان پروژه را وارد کنید!"), employer: string().required("کارفرما را وارد کنید!"), consultant: string().required("مشاور را وارد کنید!"), @@ -46,7 +47,7 @@ const validationSchema = object({ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { const theme = useTheme(); - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const [tabState, setTabState] = useState(0); const [mapBoxData, setMapBoxData] = useState(updateInfo ? { lat: updateInfo.lat, lng: updateInfo.lng } : null); @@ -72,6 +73,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { azmayesh_type_name: updateInfo ? updateInfo.azmayesh_type_name : "", province_id: updateInfo ? updateInfo.province_id : "", province_name: updateInfo ? updateInfo.province_name : "", + contract_subitem_id: updateInfo ? updateInfo.contract_subitem_id : "", project_name: updateInfo ? updateInfo.project_name : "", employer: updateInfo ? updateInfo.employer : "", consultant: updateInfo ? updateInfo.consultant : "", @@ -88,7 +90,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { register, handleSubmit, setValue, - formState: { isSubmitting, errors, touchedFields }, + formState: { isSubmitting, errors }, } = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" }); const onSubmit = async (data) => { @@ -99,6 +101,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { formData.append("azmayesh_type_name", data.azmayesh_type_name); formData.append("province_id", data.province_id); formData.append("province_name", data.province_name); + formData.append("contract_subitem_id", data.contract_subitem_id); formData.append("project_name", data.project_name); formData.append("employer", data.employer); formData.append("consultant", data.consultant); @@ -109,14 +112,13 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { formData.append("request_date", moment(new Date(data.request_date)).format("YYYY-MM-DD")); formData.append("report_date", moment(new Date(data.report_date)).format("YYYY-MM-DD")); - requestServer(updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH, "post", { - data: formData, - }) - .then(() => { - mutate(); - handleClose(); - }) - .catch(() => {}); + try { + await requestServer(updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH, "post", { + data: formData, + }); + mutate(); + handleClose(); + } catch (error) {} }; return ( diff --git a/src/components/dashboard/azmayesh/RowActions/AzmayeshUpdate/index.jsx b/src/components/dashboard/azmayesh/RowActions/AzmayeshUpdate/index.jsx index f36bbae..d1dc7b6 100644 --- a/src/components/dashboard/azmayesh/RowActions/AzmayeshUpdate/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/AzmayeshUpdate/index.jsx @@ -6,7 +6,7 @@ import { GET_AZMAYESH_LIST } from "@/core/utils/routes"; import CandUAzmayesh from "@/components/dashboard/azmayesh/Forms/CandUAzmayesh"; const AzmayeshUpdate = ({ rowId, mutate }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest(); const [openUpdateDialog, setOpenUpdateDialog] = useState(false); const [updateInfo, setUpdateInfo] = useState(null); const [loadingOpen, setLoadingOpen] = useState(false); diff --git a/src/components/dashboard/azmayesh/RowActions/DeleteAzmayesh/index.jsx b/src/components/dashboard/azmayesh/RowActions/DeleteAzmayesh/index.jsx index c424e8e..ed25f23 100644 --- a/src/components/dashboard/azmayesh/RowActions/DeleteAzmayesh/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/DeleteAzmayesh/index.jsx @@ -14,7 +14,7 @@ import DeleteIcon from "@mui/icons-material/Delete"; import { DELETE_AZMAYESH } from "@/core/utils/routes"; const DeleteAzmayesh = ({ rowId, mutate }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Actions/Create/index.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Actions/Create/index.jsx index 3cecfb6..2139d22 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Actions/Create/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Actions/Create/index.jsx @@ -7,7 +7,7 @@ import { useTheme } from "@emotion/react"; import CandUSampleOfAzmayesh from "@/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh"; const AddSampleToAzmayesh = ({ azmayeshTypeId, mutate, rowId }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("sm")); const [sampleInfo, setSampleInfo] = useState(null); diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/FormAndRequest.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/FormAndRequest.jsx index 682c13c..a6c89fa 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/FormAndRequest.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/FormAndRequest.jsx @@ -15,10 +15,10 @@ const CandUSampleOfAzmayesh = ({ isUpdate, azmayesh_id, }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [isSubmitting, setIsSubmitting] = useState(false); - const handleSubmit = () => { + const handleSubmit = async () => { const data = {}; setIsSubmitting(true); const formData = new FormData(); @@ -27,17 +27,20 @@ const CandUSampleOfAzmayesh = ({ data[key] = value; }); formData.append("data", JSON.stringify(data)); - requestServer(isUpdate ? `${UPDATE_SAMPLE_OF_AZMAYESH}/${rowId}` : `${ADD_SAMPLE_TO_AZMAYESH}`, "post", { - data: formData, - }) - .then(() => { - mutate(); - }) - .catch(() => {}) - .finally(() => { - setOpenSampleDialog(false); - setIsSubmitting(false); - }); + try { + await requestServer( + isUpdate ? `${UPDATE_SAMPLE_OF_AZMAYESH}/${rowId}` : `${ADD_SAMPLE_TO_AZMAYESH}`, + "post", + { + data: formData, + } + ); + mutate(); + setOpenSampleDialog(false); + setIsSubmitting(false); + } catch (error) { + setIsSubmitting(false); + } }; return ( diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/index.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/index.jsx index 7709eda..5cabf7c 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/Forms/CandUSampleOfAzmayesh/index.jsx @@ -16,7 +16,7 @@ const CandUSampleOfAzmayesh = ({ isUpdate, azmayesh_id, }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [isSubmitting, setIsSubmitting] = useState(false); const handleSubmit = () => { diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/DeleteSample.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/DeleteSample.jsx index 477afeb..b382fa1 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/DeleteSample.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/DeleteSample.jsx @@ -14,7 +14,7 @@ import DeleteIcon from "@mui/icons-material/Delete"; import { DELETE_SAMPLE_LIST } from "@/core/utils/routes"; const DeleteSample = ({ rowId, mutate }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/UpdateSample.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/UpdateSample.jsx index f16253a..3516f47 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/UpdateSample.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/RowActions/UpdateSample.jsx @@ -6,7 +6,7 @@ import CandUSampleOfAzmayesh from "@/components/dashboard/azmayesh/RowActions/Sh import EditIcon from "@mui/icons-material/Edit"; const UpdateSample = ({ azmayeshTypeId, mutate, rowId, azmayesh_id }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest(); const [sampleInfo, setSampleInfo] = useState(null); const [openUpdateSampleDialog, setOpenUpdateSampleDialog] = useState(false); const [defaultValues, setDefaultValues] = useState({}); diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/ShowSampleList.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/ShowSampleList.jsx index 2c11f67..e55d9ab 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/ShowSampleList.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/ShowSampleList.jsx @@ -24,10 +24,12 @@ const ShowSampleList = ({ sampleInfo, rowData }) => { id: "id", enableColumnFilter: false, datatype: "text", + grow: false, + size: 100, }, ...sampleInfo.map((item) => ({ accessorKey: item.id.toString(), - header: item.name, + header: item.unit ? `${item.name} (${item.unit})` : item.name, id: item.id.toString(), enableColumnFilter: false, datatype: "text", @@ -38,6 +40,8 @@ const ShowSampleList = ({ sampleInfo, rowData }) => { id: "updated_at", enableColumnFilter: false, datatype: "date", + grow: false, + size: 100, Cell: ({ renderedCellValue }) => ( {renderedCellValue ? moment(renderedCellValue).locale("fa").format("HH:mm | YYYY/MM/DD") : "-"} diff --git a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx index 1677d82..a3ba7e9 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx @@ -1,4 +1,4 @@ -import { Button, Dialog, DialogActions, DialogContent, IconButton, Tooltip } from "@mui/material"; +import { Box, Button, Dialog, DialogActions, DialogContent, IconButton, Tooltip } from "@mui/material"; import AssignmentIcon from "@mui/icons-material/Assignment"; import { useState } from "react"; import ShowSampleList from "./ShowSampleList"; @@ -6,7 +6,7 @@ import { GET_AZMAYESH_SAMPLE_FIELDS } from "@/core/utils/routes"; import useRequest from "@/lib/hooks/useRequest"; const ShowSampleOfAzmayesh = ({ rowData }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest(); const [openShowSampleDialog, setOpenShowSampleDialog] = useState(false); const [sampleInfo, setSampleInfo] = useState(null); const handleGetSampleFields = () => { @@ -20,7 +20,7 @@ const ShowSampleOfAzmayesh = ({ rowData }) => { }); }; return ( - <> + { - + @@ -40,7 +40,7 @@ const ShowSampleOfAzmayesh = ({ rowData }) => { - + ); }; export default ShowSampleOfAzmayesh; diff --git a/src/components/dashboard/azmayesh/RowActions/index.jsx b/src/components/dashboard/azmayesh/RowActions/index.jsx index 19447cb..7f6440d 100644 --- a/src/components/dashboard/azmayesh/RowActions/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/index.jsx @@ -7,7 +7,6 @@ const RowActions = ({ row, mutate }) => { return ( - ); diff --git a/src/components/dashboard/azmayeshType/Forms/CandUAzmayeshType/FormAndRequest.jsx b/src/components/dashboard/azmayeshType/Forms/CandUAzmayeshType/FormAndRequest.jsx index 79a8d5b..a794154 100644 --- a/src/components/dashboard/azmayeshType/Forms/CandUAzmayeshType/FormAndRequest.jsx +++ b/src/components/dashboard/azmayeshType/Forms/CandUAzmayeshType/FormAndRequest.jsx @@ -42,9 +42,8 @@ const validationSchema = object({ }); const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [selectedListItem, setSelectedListItem] = useState(null); - const [isSubmitting, setIsSubmitting] = useState(false); const handleClose = () => { setOpen(false); @@ -68,7 +67,7 @@ const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => { handleSubmit, setValue, watch, - formState: { errors }, + formState: { errors, isSubmitting }, } = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" }); const { fields, append, remove } = useFieldArray({ @@ -90,25 +89,22 @@ const FormAndRequest = ({ setOpen, mutate, rowId, updateInfo }) => { }; const onSubmit = async (data) => { - setIsSubmitting(true); const formData = new FormData(); formData.append("name", data.name); data.fields.map((field, index) => { formData.append(`fields[${index}][name]`, field.name); - formData.append(`fields[${index}][unit]`, field.unit); + if (field.unit !== "") formData.append(`fields[${index}][unit]`, field.unit); formData.append(`fields[${index}][type]`, field.type); if (field.options.length !== 0) formData.append(`fields[${index}][option]`, JSON.stringify(field.options)); }); - requestServer(updateInfo ? `${UPDATE_AZMAYESH_TYPE}/${rowId}` : ADD_AZMAYESH_TYPE, "post", { - data: formData, - }) - .then(() => { - mutate(); - handleClose(); - }) - .catch(() => {}) - .finally(() => setIsSubmitting(false)); + try { + await requestServer(updateInfo ? `${UPDATE_AZMAYESH_TYPE}/${rowId}` : ADD_AZMAYESH_TYPE, "post", { + data: formData, + }); + mutate(); + handleClose(); + } catch (error) {} }; return ( diff --git a/src/components/dashboard/azmayeshType/RowActions/DeleteAzmayeshType/index.jsx b/src/components/dashboard/azmayeshType/RowActions/DeleteAzmayeshType/index.jsx index 888ab6d..78d400d 100644 --- a/src/components/dashboard/azmayeshType/RowActions/DeleteAzmayeshType/index.jsx +++ b/src/components/dashboard/azmayeshType/RowActions/DeleteAzmayeshType/index.jsx @@ -14,7 +14,7 @@ import { useState } from "react"; import { DELETE_AZMAYESH_TYPE_LIST } from "@/core/utils/routes"; const DeleteAzmayeshType = ({ rowId, mutate }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest({ notificationSuccess: true }); const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); diff --git a/src/components/dashboard/azmayeshType/RowActions/UpdateAzmayeshType/index.jsx b/src/components/dashboard/azmayeshType/RowActions/UpdateAzmayeshType/index.jsx index b94dcf6..7c7099f 100644 --- a/src/components/dashboard/azmayeshType/RowActions/UpdateAzmayeshType/index.jsx +++ b/src/components/dashboard/azmayeshType/RowActions/UpdateAzmayeshType/index.jsx @@ -6,7 +6,7 @@ import useRequest from "@/lib/hooks/useRequest"; import CandUAzmayeshType from "@/components/dashboard/azmayeshType/Forms/CandUAzmayeshType"; const UpdateAzmayeshType = ({ rowId, mutate }) => { - const requestServer = useRequest({ auth: true }); + const requestServer = useRequest(); const [openUpdateDialog, setOpenUpdateDialog] = useState(false); const [updateInfo, setUpdateInfo] = useState(null); const [loadingOpen, setLoadingOpen] = useState(false); diff --git a/src/components/dashboard/inquiryPrivacy/assistant/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx b/src/components/dashboard/inquiryPrivacy/assistant/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx index a1492fd..d9cd72d 100644 --- a/src/components/dashboard/inquiryPrivacy/assistant/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx +++ b/src/components/dashboard/inquiryPrivacy/assistant/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx @@ -57,7 +57,7 @@ const RoadSafetyFormContext = ({ rowId, mutate, setOpenRoadSafetyForm }) => { setOpenRoadSafetyForm(false); mutate(); }) - .catch(() => { }); + .catch(() => {}); }; return ( diff --git a/src/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext.jsx b/src/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext.jsx index 01127c4..fbc6c47 100644 --- a/src/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext.jsx +++ b/src/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext.jsx @@ -50,7 +50,7 @@ const ReferFormContext = ({ setOpenReferDialog, rowId, mutate }) => { setOpenReferDialog(false); mutate(); }) - .catch(() => { }); + .catch(() => {}); }; return ( diff --git a/src/components/dashboard/inquiryPrivacy/generalManager/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx b/src/components/dashboard/inquiryPrivacy/generalManager/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx index 8acd6f7..c480382 100644 --- a/src/components/dashboard/inquiryPrivacy/generalManager/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx +++ b/src/components/dashboard/inquiryPrivacy/generalManager/zaminGov/RowActions/RoadSafetyForm/RoadSafetyFormContext.jsx @@ -57,7 +57,7 @@ const RoadSafetyFormContext = ({ rowId, mutate, setOpenRoadSafetyForm }) => { setOpenRoadSafetyForm(false); mutate(); }) - .catch(() => { }); + .catch(() => {}); }; return ( diff --git a/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx b/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx index e05531b..a481fb5 100644 --- a/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx +++ b/src/components/dashboard/roadItems/operator/Actions/Create/Forms/CreateFormContent.jsx @@ -1,10 +1,9 @@ -import React, { useState } from "react"; -import { useForm } from "react-hook-form"; -import { yupResolver } from "@hookform/resolvers/yup"; -import { array, mixed, object, string } from "yup"; -import { useTheme } from "@emotion/react"; -import useRequest from "@/lib/hooks/useRequest"; -import { Box, Button, DialogActions, DialogContent, Tab, Tabs, useMediaQuery } from "@mui/material"; +import React, {useState} from "react"; +import {useForm} from "react-hook-form"; +import {yupResolver} from "@hookform/resolvers/yup"; +import {array, mixed, object, string} from "yup"; +import {useTheme} from "@emotion/react"; +import {Box, Button, DialogActions, DialogContent, Tab, Tabs, useMediaQuery} from "@mui/material"; import StyledForm from "@/core/components/StyledForm"; import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile"; import FileCopyIcon from "@mui/icons-material/FileCopy"; @@ -15,10 +14,9 @@ import BeenhereIcon from "@mui/icons-material/Beenhere"; import GetItemsForm from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetItemsForm"; import GetSubItemsForm from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetSubItemsForm"; import GetItemInfo from "@/components/dashboard/roadItems/operator/Actions/Create/Forms/GetItemInfo"; -import { CREATE_ROAD_ITEMS } from "@/core/utils/routes"; function TabPanel(props) { - const { children, value, index } = props; + const {children, value, index} = props; return (