From 6c5e9506bfa2bd87816bb597a9fccb573e336f62 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Wed, 25 Dec 2024 11:37:01 +0000 Subject: [PATCH 1/6] Feature/amiriis azmayesh --- .../dashboard/azmayesh/AzmayeshList.jsx | 61 ++++- .../CandUAzmayesh/CandUChooseLocation.jsx | 209 ++++++++++-------- .../Forms/CandUAzmayesh/CandUGeneralInfo.jsx | 24 ++ .../Forms/CandUAzmayesh/FormAndRequest.jsx | 24 +- .../ShowSampleOfAzmayesh/ShowSampleList.jsx | 6 +- .../RowActions/ShowSampleOfAzmayesh/index.jsx | 10 +- .../dashboard/azmayesh/RowActions/index.jsx | 1 - src/core/components/FormMaker/InputType.jsx | 7 +- src/core/components/FormMaker/SelectType.jsx | 6 +- 9 files changed, 234 insertions(+), 114 deletions(-) diff --git a/src/components/dashboard/azmayesh/AzmayeshList.jsx b/src/components/dashboard/azmayesh/AzmayeshList.jsx index 5e6d68c..a93940c 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..030eac8 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,25 @@ 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 +95,113 @@ const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { position={map.getCenter()} ref={mapAzmayeshMarker} eventHandlers={{ click: handleMarkerClick }} - icon={createCustomIcon(defaultIconSize, AzmayeshIcon.src)} /> - - - - - - طول جغرافیایی - - - {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..358451d 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("مشاور را وارد کنید!"), @@ -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 : "", @@ -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,15 @@ 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 { + const url = updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH; + await requestServer(url, "post", { + data: formData, + }); + mutate(); + handleClose(); + } catch (error) { + } }; return ( @@ -187,8 +191,8 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { ? "در حال ویرایش آزمایش" : "ویرایش آزمایش" : isSubmitting - ? "در حال ثبت آزمایش" - : "ثبت آزمایش"} + ? "در حال ثبت آزمایش" + : "ثبت آزمایش"} )} 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..a369fc9 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"; @@ -14,13 +14,13 @@ const ShowSampleOfAzmayesh = ({ rowData }) => { .then((response) => { setSampleInfo(response.data.data); }) - .catch(() => {}) + .catch(() => { }) .finally(() => { setOpenShowSampleDialog(true); }); }; 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/core/components/FormMaker/InputType.jsx b/src/core/components/FormMaker/InputType.jsx index 0f36eb8..c87dedf 100644 --- a/src/core/components/FormMaker/InputType.jsx +++ b/src/core/components/FormMaker/InputType.jsx @@ -9,13 +9,16 @@ const InputType = ({ itemInfo, defaultValues, setDefaultValues }) => { [itemInfo.id]: value, })); }; + console.log(itemInfo); + + const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name return ( - {itemInfo.name} + {label} { [itemInfo.id]: newValue, })); }; - + const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name return ( - {itemInfo.name} + {label} } + onChange={(e) => handleChange({ ...filterParameters, value: e.target.value })} + > + {columnSelectOption.map((option) => ( + + {option.label} + + ))} + + + + نوع فیلتر: {defaultFilterTranslation} + + + + ); +} + +export default CustomSelectByDependency; diff --git a/src/core/components/DataTable/filter/index.jsx b/src/core/components/DataTable/filter/index.jsx index 32a09a8..8399857 100644 --- a/src/core/components/DataTable/filter/index.jsx +++ b/src/core/components/DataTable/filter/index.jsx @@ -9,14 +9,16 @@ function FilterColumn({ columns, user_id, page_name, table_name }) { return ( <> - + {open && ( + + )} ); } diff --git a/src/core/components/DataTable/reset/ResetStorage.jsx b/src/core/components/DataTable/reset/ResetStorage.jsx index 8e83d3f..7994867 100644 --- a/src/core/components/DataTable/reset/ResetStorage.jsx +++ b/src/core/components/DataTable/reset/ResetStorage.jsx @@ -6,7 +6,7 @@ import useDataTable from "@/lib/hooks/useDataTable"; function ResetStorage({ user_id, page_name, table_name }) { const { resetAction } = useTableSetting(); - const { isDirty } = useDataTable(); + const { isAnyDirty } = useDataTable(); const reset = () => { resetAction(user_id, page_name, table_name); }; @@ -14,7 +14,7 @@ function ResetStorage({ user_id, page_name, table_name }) { return ( - {isDirty ? ( + {isAnyDirty ? ( { }; console.log(itemInfo); - const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name + const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name; return ( diff --git a/src/core/components/FormMaker/SelectType.jsx b/src/core/components/FormMaker/SelectType.jsx index c9f8221..3292b65 100644 --- a/src/core/components/FormMaker/SelectType.jsx +++ b/src/core/components/FormMaker/SelectType.jsx @@ -9,7 +9,7 @@ const SelectType = ({ itemInfo, defaultValues, setDefaultValues }) => { [itemInfo.id]: newValue, })); }; - const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name + const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name; return ( {label} diff --git a/src/core/components/MapInfoOneMarker.jsx b/src/core/components/MapInfoOneMarker.jsx index 7132d5d..95ccc2b 100644 --- a/src/core/components/MapInfoOneMarker.jsx +++ b/src/core/components/MapInfoOneMarker.jsx @@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from "react"; import { Marker, useMapEvents } from "react-leaflet"; import "leaflet/dist/leaflet.css"; import L from "leaflet"; -import { Box, Button, Typography } from "@mui/material"; +import { Alert, Box, Button, Stack, Typography, Zoom } from "@mui/material"; import dynamic from "next/dynamic"; import MapLoading from "@/core/components/MapLayer/Loading"; import HereIcon from "@/assets/images/examine_marker_active.png"; @@ -40,9 +40,11 @@ const createCustomIcon = (size, iconUrl, labelText) => { popupAnchor: [0, -size[1]], }); }; +const MAX_ZOOM_FOR_MARKER = 13; const MapInteraction = ({ setValue, startLat, startLng }) => { const [isMarkerLocked, setIsMarkerLocked] = useState(!!(startLat && startLng)); // وضعیت قفل مارکر + const [enableSend, setEnableSend] = useState(false); const [markerPosition, setMarkerPosition] = useState( startLat && startLng ? { lat: startLat, lng: startLng } : null ); @@ -50,11 +52,13 @@ const MapInteraction = ({ setValue, startLat, startLng }) => { const map = useMapEvents({ move(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); if (!isMarkerLocked && markerRef.current) { markerRef.current.setLatLng(e.target.getCenter()); } }, zoom(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); if (!isMarkerLocked && markerRef.current) { markerRef.current.setLatLng(e.target.getCenter()); } @@ -69,6 +73,7 @@ const MapInteraction = ({ setValue, startLat, startLng }) => { }, [startLat, startLng, map]); const handleMarkerClick = () => { + if (!enableSend) return; if (!isMarkerLocked) { const center = map.getCenter(); setValue("start_point", { lat: center.lat.toString(), lng: center.lng.toString() }); @@ -93,6 +98,23 @@ const MapInteraction = ({ setValue, startLat, startLng }) => { click: handleMarkerClick, }} /> + + + + برای ثبت محل فعالیت، لطفاً نقشه را بیشتر زوم کنید. + + + {isMarkerLocked && ( { popupAnchor: [0, -size[1]], }); }; +const MAX_ZOOM_FOR_MARKER = 13; const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { const [isStartLocked, setIsStartLocked] = useState(!!(startLat && startLng)); // وضعیت قفل نقطه آغاز const [isEndLocked, setIsEndLocked] = useState(!!(endLat && endLng)); // وضعیت قفل نقطه پایان const [startPosition, setStartPosition] = useState(startLat && startLng ? { lat: startLat, lng: startLng } : null); const [endPosition, setEndPosition] = useState(endLat && endLng ? { lat: endLat, lng: endLng } : null); + const [enableSend, setEnableSend] = useState(false); const startRef = useRef(); const endRef = useRef(); const map = useMapEvents({ move(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); if (!isStartLocked && startRef.current) { startRef.current.setLatLng(e.target.getCenter()); } else if (isStartLocked && !isEndLocked && endRef.current) { @@ -58,6 +61,7 @@ const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { } }, zoom(e) { + setEnableSend(e.target.getZoom() > MAX_ZOOM_FOR_MARKER); if (!isStartLocked && startRef.current) { startRef.current.setLatLng(e.target.getCenter()); } else if (isStartLocked && !isEndLocked && endRef.current) { @@ -101,6 +105,7 @@ const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { icon={createCustomIcon([35, 35], StartIcon.src, "نقطه شروع")} eventHandlers={{ click: () => { + if (!enableSend) return; if (!isStartLocked) { const center = map.getCenter(); setValue("start_point", { lat: center.lat.toString(), lng: center.lng.toString() }); @@ -110,6 +115,23 @@ const MapInteraction = ({ setValue, startLat, startLng, endLat, endLng }) => { }, }} /> + + + + برای ثبت محل فعالیت، لطفاً نقشه را بیشتر زوم کنید. + + + {isStartLocked && !isEndLocked && ( { )} {isStartLocked && ( - { - if (!isEndLocked) { - const center = map.getCenter(); - setValue("end_point", { lat: center.lat.toString(), lng: center.lng.toString() }); - setEndPosition({ lat: center.lat, lng: center.lng }); - setIsEndLocked(true); - } - }, - }} - /> + <> + + + + برای ثبت محل فعالیت، لطفاً نقشه را بیشتر زوم کنید. + + + + { + if (!enableSend) return; + if (!isEndLocked) { + const center = map.getCenter(); + setValue("end_point", { lat: center.lat.toString(), lng: center.lng.toString() }); + setEndPosition({ lat: center.lat, lng: center.lng }); + setIsEndLocked(true); + } + }, + }} + /> + )} {isEndLocked && ( { + return ( + + + + {(props.value / 1).toLocaleString()} + + + {props.unit} + + + + ), + }} + /> + ); +}); +NumberField.displayName = "NumberField"; +export default NumberField; diff --git a/src/core/components/RahdarCode.jsx b/src/core/components/RahdarCode.jsx index 9dfeeb7..76592ef 100644 --- a/src/core/components/RahdarCode.jsx +++ b/src/core/components/RahdarCode.jsx @@ -5,7 +5,7 @@ import useRequest from "@/lib/hooks/useRequest"; import { debounce } from "@mui/material/utils"; import { GET_RAHDARANS_LIST_SEARCH } from "@/core/utils/routes"; -const RahdarCode = ({ rahdarsCode, setRahdarsCode, error }) => { +const RahdarCode = ({ rahdarsCode, setRahdarsCode, error, multiple = true }) => { const [inputValue, setInputValue] = useState(""); // مدیریت مقدار تایپ‌شده const [options, setOptions] = useState([]); const [loading, setLoading] = useState(false); @@ -42,11 +42,11 @@ const RahdarCode = ({ rahdarsCode, setRahdarsCode, error }) => { return ( { - setRahdarsCode(newValue || []); // به‌روزرسانی موارد انتخاب‌شده + setRahdarsCode(multiple ? newValue || [] : newValue || null); // مدیریت حالت چندگانه و تک‌گانه }} inputValue={inputValue} // مقدار تایپ‌شده onInputChange={(event, newInputValue) => { @@ -86,5 +86,4 @@ const RahdarCode = ({ rahdarsCode, setRahdarsCode, error }) => { /> ); }; - export default RahdarCode; diff --git a/src/core/components/ShowPlak.jsx b/src/core/components/ShowPlak.jsx new file mode 100644 index 0000000..04548f1 --- /dev/null +++ b/src/core/components/ShowPlak.jsx @@ -0,0 +1,62 @@ +import { Stack } from "@mui/material"; + +const ShowPlak = ({ plak_number }) => { + const processPlak = (plak_number) => { + const parts = plak_number.match(/^([\u0600-\u06FF]+)(\d+)-(\d+)([^\d]*)(\d+)$/); + if (!parts) return {}; + + return { + region: parts[1], // "ايران" + mainNumber: parts[2], // "13" + serial: parts[3], // "189" + letter: parts[4], // "الف" + number: parts[5], // "15" + }; + }; + const plakParts = processPlak(plak_number); + + return ( + + + {plakParts.region} {plakParts.mainNumber} + + + + {plakParts.serial} + + + {plakParts.letter} + + + {plakParts.number} + + + + ); +}; +export default ShowPlak; diff --git a/src/core/utils/pageMenu.js b/src/core/utils/pageMenu.js index 798d28b..f77574f 100644 --- a/src/core/utils/pageMenu.js +++ b/src/core/utils/pageMenu.js @@ -124,13 +124,6 @@ export const pageMenu = [ hasSubitems: true, badges: ["road_items.operation_cnt"], Subitems: [ - { - id: "roadItemManagmentOparationCreate", - label: "ثبت فعالیت", - type: "page", - route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_items/operator/create", - permissions: ["create-road-item"], - }, { id: "roadItemManagmentOparationCartable", label: "کارتابل", @@ -186,7 +179,7 @@ export const pageMenu = [ id: "roadPatrolManagmentSupervisorCartable", label: "کارتابل", type: "page", - route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/supervisor/cartable", + route: "/dashboard/road-patrols/supervisor", permissions: [ "show-road-patrol-supervise-cartable", "show-road-patrol-supervise-cartable-province", @@ -206,14 +199,14 @@ export const pageMenu = [ id: "roadPatrolManagmentOparationCreate", label: "ثبت اقدام", type: "page", - route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/operator/create", + route: "/dashboard/road-patrols/operator", permissions: ["add-road-patrol"], }, { id: "roadPatrolManagmentOparationCartable", label: "کارتابل", type: "page", - route: process.env.NEXT_PUBLIC_API_URL + "/v2/road_patrols/operator/cartable", + route: "/dashboard/road-patrols/operator", permissions: ["add-road-patrol"], }, ], diff --git a/src/core/utils/routes.js b/src/core/utils/routes.js index 9548f91..db6c244 100644 --- a/src/core/utils/routes.js +++ b/src/core/utils/routes.js @@ -29,9 +29,9 @@ export const ADD_AZMAYESH_TYPE = api + "/api/v3/azmayesh_types/store"; export const UPDATE_AZMAYESH_TYPE = api + "/api/v3/azmayesh_types/update"; //road patrol -export const GET_ROAD_PATROL_OPERATOR_LIST = "/v3/api/fake-road-patrol/operator"; +export const GET_ROAD_PATROL_OPERATOR_LIST = api + "/api/v3/road_patrols/operator_index"; export const EXPORT_ROAD_PATROL_OPERATOR_LIST = "https://rms.rmto.ir/v2/road_patrols/operator/cartable/report"; -export const GET_ROAD_PATROL_SUPERVISOR_LIST = "/v3/api/fake-road-patrol/supervisor"; +export const GET_ROAD_PATROL_SUPERVISOR_LIST = api + "/api/v3/road_patrols/supervisor_index"; export const EXPORT_ROAD_PATROL_SUPERVISOR_LIST = "https://rms.rmto.ir/v2/road_patrols/supervisor/cartable/report"; // road items @@ -41,6 +41,7 @@ export const GET_ROAD_ITEMS_OPERATOR_LIST = api + "/api/v3/road_items/operator_i export const EXPORT_ROAD_ITEMS_OPERATOR_LIST = api + "/api/v3/road_items/operator_report"; export const GET_ROAD_ITEMS_ITEM = "https://rms.witel.ir/v2/items"; export const GET_ROAD_ITEMS_SUB_ITEM = "https://rms.witel.ir/v2/sub_items"; +export const GET_EDARAT_LISTS = "https://rms.witel.ir/public/contents/edarate_shahri_by_province"; export const CREATE_ROAD_ITEMS = api + "/api/v3/road_items/store"; export const UPDATE_ROAD_ITEMS = api + "/api/v3/road_items/update"; export const VERIFY_BY_SUPERVISOR = api + "/api/v3/road_items/verify_by_supervisor"; diff --git a/src/lib/contexts/DataTable.js b/src/lib/contexts/DataTable.js index ec22020..f283da7 100644 --- a/src/lib/contexts/DataTable.js +++ b/src/lib/contexts/DataTable.js @@ -18,14 +18,23 @@ const DataTableProvider = ({ children, user_id, page_name, table_name, columns, const [initHide, setInitHide] = useState({}); const [hideData, setHideData] = useState({}); const [isDirty, setIsDirty] = useState(false); + const [isAnyDirty, setIsAnyDirty] = useState(false); useEffect(() => { + let hasAnyConflict = false; const hasConflict = JSON.stringify(hideData) !== JSON.stringify(initHide) || JSON.stringify(sortData) !== JSON.stringify(initSort) || JSON.stringify(filterData) !== JSON.stringify(initFilter); + const CheckFilterValues = Object.values(filterData).every((innerObject) => innerObject.value === ""); + const CheckHideValues = Object.values(hideData).every((value) => value === true); + + hasAnyConflict = + !CheckHideValues || JSON.stringify(sortData) !== JSON.stringify(initialSort) || !CheckFilterValues; + setIsDirty(hasConflict); + setIsAnyDirty(hasAnyConflict); }, [hideData, sortData, filterData, initHide, initSort, initFilter]); useEffect(() => { @@ -136,7 +145,7 @@ const DataTableProvider = ({ children, user_id, page_name, table_name, columns, return ( {children} diff --git a/src/lib/hooks/useDataTable.js b/src/lib/hooks/useDataTable.js index 9026caa..d1254cb 100644 --- a/src/lib/hooks/useDataTable.js +++ b/src/lib/hooks/useDataTable.js @@ -2,9 +2,9 @@ import { useContext } from "react"; import { DataTableContext } from "@/lib/contexts/DataTable"; const useTableSetting = () => { - const { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty } = + const { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty } = useContext(DataTableContext); - return { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty }; + return { filterData, setFilterData, sortData, setSortData, hideData, setHideData, isDirty, isAnyDirty }; }; export default useTableSetting; diff --git a/src/lib/hooks/useEdaratLists.js b/src/lib/hooks/useEdaratLists.js new file mode 100644 index 0000000..ad0bc53 --- /dev/null +++ b/src/lib/hooks/useEdaratLists.js @@ -0,0 +1,62 @@ +import { useEffect, useReducer } from "react"; +import { GET_EDARAT_LISTS } from "@/core/utils/routes"; +import useRequest from "@/lib/hooks/useRequest"; + +const ACTIONS = { + LOADING: "loading", + SUCCESS: "success", + ERROR: "error", + RESET: "reset", +}; + +const initialState = { + data: [], + loading: true, + error: null, +}; + +function reducer(state, action) { + switch (action.type) { + case ACTIONS.LOADING: + return { ...state, loading: true, error: null }; + case ACTIONS.SUCCESS: + return { ...state, loading: false, data: action.payload }; + case ACTIONS.ERROR: + return { ...state, loading: false, error: action.payload }; + case ACTIONS.RESET: + return { ...initialState, loading: false }; + default: + return state; + } +} + +const useEdaratLists = (id) => { + const requestServer = useRequest({ notificationShow: false }); + const [state, dispatch] = useReducer(reducer, initialState); + useEffect(() => { + if (!id) { + dispatch({ type: ACTIONS.RESET }); + return; + } + + const fetchEdaratLists = async () => { + dispatch({ type: ACTIONS.LOADING }); + try { + const response = await requestServer(`${GET_EDARAT_LISTS}/${id}`); + dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data }); + } catch (error) { + dispatch({ type: ACTIONS.ERROR, payload: error }); + } + }; + + fetchEdaratLists(); + }, [id]); + + return { + edaratList: state.data, + loadingEdaratList: state.loading, + errorEdaratList: state.error, + }; +}; + +export default useEdaratLists; diff --git a/src/lib/hooks/useRequest.js b/src/lib/hooks/useRequest.js index ef17e84..f160f53 100644 --- a/src/lib/hooks/useRequest.js +++ b/src/lib/hooks/useRequest.js @@ -10,7 +10,7 @@ const defaultOptions = { }, notificationShow: true, notificationSuccess: false, - notificationFailed: true + notificationFailed: true, }; const useRequest = (initOptions) => { diff --git a/src/lib/hooks/useRoadItemGetISubtems.js b/src/lib/hooks/useRoadItemGetISubtems.js index f315fd3..b0e3264 100644 --- a/src/lib/hooks/useRoadItemGetISubtems.js +++ b/src/lib/hooks/useRoadItemGetISubtems.js @@ -1,29 +1,62 @@ -import { useEffect, useState } from "react"; +import { useEffect, useReducer } from "react"; import { GET_ROAD_ITEMS_SUB_ITEM } from "@/core/utils/routes"; import useRequest from "@/lib/hooks/useRequest"; -const useRoadItemGetItems = (id) => { - const requestServer = useRequest(); - const [subItemsList, setSubItemsList] = useState([]); - const [loadingSubItemsList, setLoadingSubItemsList] = useState(true); - const [errorSubItemsList, setErrorSubItemsList] = useState(null); +const ACTIONS = { + LOADING: "loading", + SUCCESS: "success", + ERROR: "error", + RESET: "reset", +}; +const initialState = { + data: [], + loading: true, + error: null, +}; + +function reducer(state, action) { + switch (action.type) { + case ACTIONS.LOADING: + return { ...state, loading: true, error: null }; + case ACTIONS.SUCCESS: + return { ...state, loading: false, data: action.payload }; + case ACTIONS.ERROR: + return { ...state, loading: false, error: action.payload }; + case ACTIONS.RESET: + return { ...initialState, loading: false }; + default: + return state; + } +} + +const useRoadItemGetItems = (id) => { + const requestServer = useRequest({ notificationShow: false }); + const [state, dispatch] = useReducer(reducer, initialState); useEffect(() => { + if (!id) { + dispatch({ type: ACTIONS.RESET }); + return; + } + const fetchSubItems = async () => { + dispatch({ type: ACTIONS.LOADING }); try { const response = await requestServer(`${GET_ROAD_ITEMS_SUB_ITEM}/${id}`); - setSubItemsList(response.data.data); - setLoadingSubItemsList(false); - } catch (e) { - setErrorSubItemsList(e); - setLoadingSubItemsList(false); + dispatch({ type: ACTIONS.SUCCESS, payload: response.data.data }); + } catch (error) { + dispatch({ type: ACTIONS.ERROR, payload: error }); } }; fetchSubItems(); - }, []); + }, [id]); - return { subItemsList, loadingSubItemsList, errorSubItemsList }; + return { + subItemsList: state.data, + loadingSubItemsList: state.loading, + errorSubItemsList: state.error, + }; }; export default useRoadItemGetItems; diff --git a/src/lib/hooks/useRoadItemGetItems.js b/src/lib/hooks/useRoadItemGetItems.js index 523f7c9..1528735 100644 --- a/src/lib/hooks/useRoadItemGetItems.js +++ b/src/lib/hooks/useRoadItemGetItems.js @@ -14,6 +14,7 @@ const useRoadItemGetItems = () => { const response = await requestServer(`${GET_ROAD_ITEMS_ITEM}`); setItemsList(response.data.data); setLoadingItemsList(false); + setErrorItemsList(false); } catch (e) { setErrorItemsList(e); setLoadingItemsList(false); From d342fa52c28d82e79fd09901ac744d50531b007d Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Sun, 29 Dec 2024 08:11:21 +0000 Subject: [PATCH 4/6] Feature/amiriis azmayesh --- .../Forms/CandUAzmayesh/FormAndRequest.jsx | 7 ++--- .../RowActions/AzmayeshUpdate/index.jsx | 2 +- .../RowActions/DeleteAzmayesh/index.jsx | 2 +- .../Actions/Create/index.jsx | 2 +- .../CandUSampleOfAzmayesh/FormAndRequest.jsx | 29 ++++++++++--------- .../Forms/CandUSampleOfAzmayesh/index.jsx | 2 +- .../RowActions/DeleteSample.jsx | 2 +- .../RowActions/UpdateSample.jsx | 2 +- .../RowActions/ShowSampleOfAzmayesh/index.jsx | 2 +- .../CandUAzmayeshType/FormAndRequest.jsx | 24 +++++++-------- .../RowActions/DeleteAzmayeshType/index.jsx | 2 +- .../RowActions/UpdateAzmayeshType/index.jsx | 2 +- src/core/components/FormMaker/InputType.jsx | 2 -- 13 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx index 8421abf..f397229 100644 --- a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx +++ b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/FormAndRequest.jsx @@ -47,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); @@ -90,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) => { @@ -113,8 +113,7 @@ const CandUAzmayesh = ({ setOpen, mutate, updateInfo, rowId }) => { formData.append("report_date", moment(new Date(data.report_date)).format("YYYY-MM-DD")); try { - const url = updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH; - await requestServer(url, "post", { + await requestServer(updateInfo ? `${UPDATE_AZMAYESH}/${rowId}` : CREATE_AZMAYESH, "post", { data: formData, }); mutate(); 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/index.jsx b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx index cc64ec6..a3ba7e9 100644 --- a/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx +++ b/src/components/dashboard/azmayesh/RowActions/ShowSampleOfAzmayesh/index.jsx @@ -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 = () => { 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/core/components/FormMaker/InputType.jsx b/src/core/components/FormMaker/InputType.jsx index 2b85d31..af90551 100644 --- a/src/core/components/FormMaker/InputType.jsx +++ b/src/core/components/FormMaker/InputType.jsx @@ -9,8 +9,6 @@ const InputType = ({ itemInfo, defaultValues, setDefaultValues }) => { [itemInfo.id]: value, })); }; - console.log(itemInfo); - const label = itemInfo.unit ? `${itemInfo.name} (${itemInfo.unit})` : itemInfo.name; return ( From 3e28bbed92885ba36ef4e8893ff2ac82f2eeb0b0 Mon Sep 17 00:00:00 2001 From: Amirhossein Mahmoodi Date: Sun, 29 Dec 2024 11:51:29 +0330 Subject: [PATCH 5/6] formattting --- .../azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx index 542945b..afd329f 100644 --- a/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx +++ b/src/components/dashboard/azmayesh/Forms/CandUAzmayesh/CandUChooseLocation.jsx @@ -90,7 +90,12 @@ const CandUChooseLocation = ({ mapBoxData, setMapBoxData }) => { return ( <> - + Date: Sun, 29 Dec 2024 11:55:42 +0330 Subject: [PATCH 6/6] change version to 0.12.0 --- .env.local.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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