implement of notif
This commit is contained in:
40
src/core/components/notifications/ErrorNotification.jsx
Normal file
40
src/core/components/notifications/ErrorNotification.jsx
Normal file
@@ -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 }) => (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "start",
|
||||
justifyContent: "start",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
<DangerousIcon color="error" sx={{ mr: 1.6 }} />
|
||||
<Box sx={{ display: "flex", flexDirection: "column" }}>
|
||||
<Typography color="error" variant="button">
|
||||
{t("notifications.error")} ({t("notifications.code")}: {status})
|
||||
</Typography>
|
||||
<Typography variant="caption">
|
||||
{message || t("notifications.error_static_text")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
),
|
||||
{
|
||||
position: directionApp === "ltr" ? "top-left" : "top-right",
|
||||
autoClose: false,
|
||||
closeOnClick: false,
|
||||
draggable: false,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorNotification;
|
||||
43
src/core/components/notifications/SuccessNotification.jsx
Normal file
43
src/core/components/notifications/SuccessNotification.jsx
Normal file
@@ -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(
|
||||
() => (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "start",
|
||||
justifyContent: "start",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||
<BeenhereIcon color="success" sx={{ mr: 1.6 }} />
|
||||
<Box sx={{ display: "flex", flexDirection: "column" }}>
|
||||
<Typography color="success.main" variant="button">
|
||||
{t("notifications.success")} ({t("notifications.code")}:{" "}
|
||||
{status})
|
||||
</Typography>
|
||||
<Typography variant="caption">
|
||||
{t("notifications.success_static_text")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
),
|
||||
{
|
||||
position: directionApp === "ltr" ? "top-left" : "top-right",
|
||||
autoClose: 3000,
|
||||
hideProgressBar: true,
|
||||
pauseOnHover: true,
|
||||
closeOnClick: false,
|
||||
draggable: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default SuccessNotification;
|
||||
38
src/core/components/notifications/index.jsx
Normal file
38
src/core/components/notifications/index.jsx
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user