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 (