From 893975c63ba03abf407aa5fc501187f3f5ab7c78 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Sun, 5 Nov 2023 15:42:00 +0330 Subject: [PATCH] LFFE-12 debugs and testing manually --- .../Form/ConfirmForm/ConfirmContent.jsx | 2 +- .../Form/RejectForm/RejectContent.jsx | 6 +- .../Form/ConfirmForm/ConfirmContent.jsx | 2 +- .../Form/RejectForm/RejectContent.jsx | 2 +- .../Form/ConfirmForm/ConfirmContent.jsx | 2 +- .../Form/RejectForm/RejectContent.jsx | 2 +- .../Form/RejectForm/RejectContent.jsx | 2 +- .../Form/ConfirmForm/ConfirmContent.jsx | 4 +- .../Form/RejectForm/RejectContent.jsx | 2 +- .../notifications/ErrorNotification.jsx | 8 ++- .../notifications/PendingNotification.jsx | 8 ++- .../notifications/SuccessNotification.jsx | 8 ++- .../notifications/UploadFileNotification.jsx | 4 +- .../notifications/WarningNotification.jsx | 8 ++- src/core/components/notifications/index.jsx | 63 ++++++------------- .../dashboard/expert-management/index.jsx | 2 +- 16 files changed, 54 insertions(+), 71 deletions(-) diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx index 261c083..da0acda 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx @@ -37,7 +37,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("proposed_amount", values.proposed_amount); - if (values.description != "") formData.append("description", values.description); + if (values.description != "") formData.append("expert_description", values.description); if (values.confirm_img != null) formData.append("attachment", values.confirm_img); requestServer(`${CONFIRM_MACHINARY_OFFICE}/${rowId}`, 'post', { diff --git a/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx index 340a757..479b213 100644 --- a/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/machinary-office/Form/RejectForm/RejectContent.jsx @@ -6,7 +6,7 @@ import {useFormik} from "formik"; import {useTranslations} from "next-intl"; import {useState} from "react"; import * as Yup from "yup"; -import {REJECT_INSPECTOR_EXPERT} from "@/core/data/apiRoutes"; +import {REJECT_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { const [selectedImage, setSelectedImage] = useState(""); @@ -29,10 +29,10 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - formData.append("description", values.description); + formData.append("expert_description", values.description); if (values.reject_img != null) formData.append("attachment", values.reject_img); - requestServer(`${REJECT_INSPECTOR_EXPERT}/${rowId}`, 'post', { + requestServer(`${REJECT_MACHINARY_OFFICE}/${rowId}`, 'post', { data: formData, }).then((response) => { setOpenRejectDialog(false) diff --git a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx index 5de9eb3..af9e93a 100644 --- a/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/navgan-province-manager/Form/ConfirmForm/ConfirmContent.jsx @@ -24,7 +24,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { }, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - if (values.description != "") formData.append("description", values.description); + if (values.description != "") formData.append("expert_description", values.description); if (values.confirm_img != null) formData.append("attachment", values.confirm_img); requestServer(`${CONFIRM_NAVGAN_PROVINCE_MANAGER}/${rowId}`, 'post', { diff --git a/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx index 2502898..0b26c8b 100644 --- a/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/navgan-province-manager/Form/RejectForm/RejectContent.jsx @@ -29,7 +29,7 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - formData.append("description", values.description); + formData.append("expert_description", values.description); if (values.reject_img != null) formData.append("attachment", values.reject_img); requestServer(`${REJECT_NAVGAN_PROVINCE_MANAGER}/${rowId}`, 'post', { diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx index 66ccd27..d189a6b 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx @@ -37,7 +37,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("approved_amount", values.approved_amount); - if (values.description != "") formData.append("description", values.description); + if (values.description != "") formData.append("expert_description", values.description); if (values.confirm_img != null) formData.append("attachment", values.confirm_img); requestServer(`${CONFIRM_PASSENGER_BOSS}/${rowId}`, 'post', { diff --git a/src/components/dashboard/passenger-boss/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/passenger-boss/Form/RejectForm/RejectContent.jsx index 6b6b385..93fe8c3 100644 --- a/src/components/dashboard/passenger-boss/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/passenger-boss/Form/RejectForm/RejectContent.jsx @@ -29,7 +29,7 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - formData.append("description", values.description); + formData.append("expert_description", values.description); if (values.reject_img != null) formData.append("attachment", values.reject_img); requestServer(`${REJECT_PASSENGER_BOSS}/${rowId}`, 'post', { diff --git a/src/components/dashboard/passenger-office/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/passenger-office/Form/RejectForm/RejectContent.jsx index fd7ea2c..2a8a82d 100644 --- a/src/components/dashboard/passenger-office/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/passenger-office/Form/RejectForm/RejectContent.jsx @@ -29,7 +29,7 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - formData.append("description", values.description); + formData.append("expert_description", values.description); if (values.reject_img != null) formData.append("attachment", values.reject_img); requestServer(`${REJECT_PASSENGER_OFFICE}/${rowId}`, 'post', { diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx index dc4d093..52137c2 100644 --- a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx @@ -24,7 +24,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { }, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - if (values.description != "") formData.append("description", values.description); + if (values.description != "") formData.append("expert_description", values.description); if (values.confirm_img != null) formData.append("attachment", values.confirm_img); requestServer(`${CONFIRM_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { @@ -106,7 +106,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => { {t("ConfirmDialog.button-cancel")} diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx index 3641f71..b692df4 100644 --- a/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx +++ b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx @@ -29,7 +29,7 @@ const RejectContent = ({rowId, mutate, setOpenRejectDialog}) => { validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); - formData.append("description", values.description); + formData.append("expert_description", values.description); if (values.reject_img != null) formData.append("attachment", values.reject_img); requestServer(`${REJECT_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { diff --git a/src/core/components/notifications/ErrorNotification.jsx b/src/core/components/notifications/ErrorNotification.jsx index 4ff1ab0..776c904 100644 --- a/src/core/components/notifications/ErrorNotification.jsx +++ b/src/core/components/notifications/ErrorNotification.jsx @@ -2,8 +2,8 @@ import DangerousIcon from "@mui/icons-material/Dangerous"; import {Box, Typography} from "@mui/material"; import {toast} from "react-toastify"; -const ErrorNotification = (t, status, message) => { - toast( +const ErrorNotification = (pushToastList, notificationType, t, status, message) => { + const toastId = toast( () => ( <> { ), { + containerId: 'validation', autoClose: false, closeOnClick: false, draggable: false, } ); + pushToastList(notificationType, toastId); }; -export default ErrorNotification; +export default ErrorNotification; \ No newline at end of file diff --git a/src/core/components/notifications/PendingNotification.jsx b/src/core/components/notifications/PendingNotification.jsx index 846b847..cc28a58 100644 --- a/src/core/components/notifications/PendingNotification.jsx +++ b/src/core/components/notifications/PendingNotification.jsx @@ -1,12 +1,14 @@ import {toast} from "react-toastify"; -const PendingNotification = (t) => { - toast(t("notifications.pending"), { +const PendingNotification = (pushToastList, notificationType, t) => { + const toastId = toast(t("notifications.pending"), { + containerId: 'validation', autoClose: false, closeButton: false, closeOnClick: false, draggable: false, }); + pushToastList(notificationType, toastId); }; -export default PendingNotification; +export default PendingNotification; \ No newline at end of file diff --git a/src/core/components/notifications/SuccessNotification.jsx b/src/core/components/notifications/SuccessNotification.jsx index 998deaa..1207000 100644 --- a/src/core/components/notifications/SuccessNotification.jsx +++ b/src/core/components/notifications/SuccessNotification.jsx @@ -2,8 +2,8 @@ import BeenhereIcon from "@mui/icons-material/Beenhere"; import {Box, Typography} from "@mui/material"; import {toast} from "react-toastify"; -const SuccessNotification = (t, status) => { - toast( +const SuccessNotification = (pushToastList, notificationType, t, status) => { + const toastId = toast( () => ( <> { ), { + containerId: 'validation', autoClose: 3000, hideProgressBar: true, pauseOnHover: true, @@ -37,6 +38,7 @@ const SuccessNotification = (t, status) => { draggable: true, } ); + pushToastList(notificationType, toastId); }; -export default SuccessNotification; +export default SuccessNotification; \ No newline at end of file diff --git a/src/core/components/notifications/UploadFileNotification.jsx b/src/core/components/notifications/UploadFileNotification.jsx index 6556944..1c20ba3 100644 --- a/src/core/components/notifications/UploadFileNotification.jsx +++ b/src/core/components/notifications/UploadFileNotification.jsx @@ -26,6 +26,8 @@ const UploadFileNotification = (t) => { ), { + containerId: 'validation', + toastId: 'upload', autoClose: 3000, hideProgressBar: true, pauseOnHover: true, @@ -35,4 +37,4 @@ const UploadFileNotification = (t) => { ); }; -export default UploadFileNotification; +export default UploadFileNotification; \ No newline at end of file diff --git a/src/core/components/notifications/WarningNotification.jsx b/src/core/components/notifications/WarningNotification.jsx index 8493180..bc2a1fb 100644 --- a/src/core/components/notifications/WarningNotification.jsx +++ b/src/core/components/notifications/WarningNotification.jsx @@ -2,8 +2,8 @@ import ReportIcon from "@mui/icons-material/Report"; import {Box, Typography} from "@mui/material"; import {toast} from "react-toastify"; -const WarningNotification = (t, status) => { - toast( +const WarningNotification = (pushToastList, notificationType, t, status) => { + const toastId = toast( () => ( <> { ), { + containerId: 'validation', autoClose: false, closeOnClick: false, draggable: false, } ); + pushToastList(notificationType, toastId); }; -export default WarningNotification; +export default WarningNotification; \ No newline at end of file diff --git a/src/core/components/notifications/index.jsx b/src/core/components/notifications/index.jsx index bc8eb66..34e44f3 100644 --- a/src/core/components/notifications/index.jsx +++ b/src/core/components/notifications/index.jsx @@ -1,54 +1,27 @@ -import {toast} from "react-toastify"; -import ErrorNotification from "./ErrorNotification"; -import WarningNotification from "./WarningNotification"; -import SuccessNotification from "./SuccessNotification"; +import pendingNotification from "@/core/components/notifications/PendingNotification"; +import WarningNotification from "@/core/components/notifications/WarningNotification"; +import ErrorNotification from "@/core/components/notifications/ErrorNotification"; +import SuccessNotification from "@/core/components/notifications/SuccessNotification"; -const Notifications = async (t, response) => { - const {status, data} = response != undefined ? response : "" - toast.dismiss(); - switch (status) { - case 200: - SuccessNotification(t, status); +const Notifications = (pushToastList, notificationType, t, status, message) => { + switch (notificationType) { + case "pending": + pendingNotification(pushToastList, notificationType, t); break; - case 400: - ErrorNotification(t, status); + case "warning": + WarningNotification(pushToastList, notificationType, t, status); break; - case 401: - ErrorNotification(t, status); + case "error": + if (message) { + ErrorNotification(pushToastList, notificationType, t, status, message) + } else { + ErrorNotification(pushToastList, notificationType, t, status) + } break; - case 403: - ErrorNotification(t, status); - break; - case 422: - ErrorNotification(t, status, data.message); - break; - case 500: - WarningNotification(t, status); - break; - case 503: - WarningNotification(t, status); - break; - case 504: - WarningNotification(t, status); - break; - default: - toast(t("notifications.pending"), { - autoClose: false, - closeOnClick: false, - draggable: false, - }); + case "success": + SuccessNotification(pushToastList, notificationType, t, status); break; } }; export default Notifications; - -/* -usage document - -** for pending use ( Notifications( t, undefined) ) this before your request. -** for success use ( Notifications( t, response) ) this inside .then() of your request. -** for Error and Warning use ( Notifications( t, error.response) ) this inside .catche() of your request. - -end usage document -*/ diff --git a/src/pages/dashboard/expert-management/index.jsx b/src/pages/dashboard/expert-management/index.jsx index 7b2de1e..5f1c29a 100644 --- a/src/pages/dashboard/expert-management/index.jsx +++ b/src/pages/dashboard/expert-management/index.jsx @@ -15,7 +15,7 @@ export async function getServerSideProps({req, locale}) { title: "Dashboard.expert_management", isBot, locale, - layout: {name: 'DashboardLayout', props: {permissions: ["manage_transportation_navgan"]}} + layout: {name: 'DashboardLayout', props: {permissions: ["manage_experts"]}} }, }; }