From 4de9e6d2e5e75647e52898958d1fe9cb1a432031 Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Tue, 11 Jul 2023 10:41:38 +0330 Subject: [PATCH] implement of notif --- .../notifications/ErrorNotification.jsx | 40 +++++++++++++++++ .../notifications/SuccessNotification.jsx | 43 +++++++++++++++++++ src/core/components/notifications/index.jsx | 38 ++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 src/core/components/notifications/ErrorNotification.jsx create mode 100644 src/core/components/notifications/SuccessNotification.jsx create mode 100644 src/core/components/notifications/index.jsx diff --git a/src/core/components/notifications/ErrorNotification.jsx b/src/core/components/notifications/ErrorNotification.jsx new file mode 100644 index 0000000..6fb64d8 --- /dev/null +++ b/src/core/components/notifications/ErrorNotification.jsx @@ -0,0 +1,40 @@ +import DangerousIcon from "@mui/icons-material/Dangerous"; +import { Box, Typography } from "@mui/material"; +import { toast } from "react-toastify"; + +const ErrorNotification = (directionApp, status, t, message) => { + toast( + ({ closeToast }) => ( + <> + + + + + + {t("notifications.error")} ({t("notifications.code")}: {status}) + + + {message || t("notifications.error_static_text")} + + + + + + ), + { + position: directionApp === "ltr" ? "top-left" : "top-right", + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); +}; + +export default ErrorNotification; diff --git a/src/core/components/notifications/SuccessNotification.jsx b/src/core/components/notifications/SuccessNotification.jsx new file mode 100644 index 0000000..ea484d6 --- /dev/null +++ b/src/core/components/notifications/SuccessNotification.jsx @@ -0,0 +1,43 @@ +import BeenhereIcon from "@mui/icons-material/Beenhere"; +import { Box, Typography } from "@mui/material"; +import { toast } from "react-toastify"; + +const SuccessNotification = (directionApp, status, t) => { + toast( + () => ( + <> + + + + + + {t("notifications.success")} ({t("notifications.code")}:{" "} + {status}) + + + {t("notifications.success_static_text")} + + + + + + ), + { + position: directionApp === "ltr" ? "top-left" : "top-right", + autoClose: 3000, + hideProgressBar: true, + pauseOnHover: true, + closeOnClick: false, + draggable: true, + } + ); +}; + +export default SuccessNotification; diff --git a/src/core/components/notifications/index.jsx b/src/core/components/notifications/index.jsx new file mode 100644 index 0000000..f9eb82c --- /dev/null +++ b/src/core/components/notifications/index.jsx @@ -0,0 +1,38 @@ +import ErrorNotification from "./ErrorNotification"; +import SuccessNotification from "./successNotification"; + +const Notifications = async (directionApp, response, t) => { + const { status, data } = response; + + switch (status) { + case 200: + SuccessNotification(directionApp, status, t); + break; + case 400: + ErrorNotification(directionApp, status, t); + break; + case 401: + ErrorNotification(directionApp, status, t); + break; + case 403: + ErrorNotification(directionApp, status, t); + break; + case 422: + ErrorNotification(directionApp, status, t, data.message); + break; + case 500: + WarningNotification(directionApp, status, t); + break; + case 503: + WarningNotification(directionApp, status, t); + break; + case 504: + WarningNotification(directionApp, status, t); + break; + default: + // Handle other cases if needed + break; + } +}; + +export default Notifications;