complete notifications
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"register_navy": "ثبت نام اعضای ناوگان",
|
||||
"login_welfare_services": "ورود اعضای خدمات رفاهی",
|
||||
"register_welfare_services": "ثبت نام اعضای خدمات رفاهی",
|
||||
"pending": "درحال اجرا...",
|
||||
"user_navy": "ناوگان",
|
||||
"header": {
|
||||
"open_profile": "پروفایل",
|
||||
@@ -15,6 +16,13 @@
|
||||
"change_password": "تغییر رمز عبور",
|
||||
"logout": "خروج"
|
||||
},
|
||||
"notifications": {
|
||||
"error_static_text": "عملیات با خطا مواجه شد",
|
||||
"success_static_text": "عملیات با موفقیت انجام شد",
|
||||
"code": "کد",
|
||||
"success": "موفق",
|
||||
"error": "خطا"
|
||||
},
|
||||
"Titles": {
|
||||
"title_login_page": "صفحه ورود",
|
||||
"title_login_navy_page": "ورود اعضای ناوگان",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// import Notifications from "@/core/components/notifications";
|
||||
import LinkRouting from "@/core/components/LinkRouting";
|
||||
import Notifications from "@/core/components/notifications";
|
||||
import StyledForm from "@/core/components/StyledForm";
|
||||
import { LOGIN_SEND_OTP_TOKEN } from "@/core/data/apiRoutes";
|
||||
import CenterLayout from "@/layouts/CenterLayout";
|
||||
@@ -8,14 +8,14 @@ import useDirection from "@/lib/app/hooks/useDirection";
|
||||
import FingerprintIcon from "@mui/icons-material/Fingerprint";
|
||||
import PersonAddIcon from "@mui/icons-material/PersonAdd";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Container,
|
||||
Grid,
|
||||
Paper,
|
||||
Stack,
|
||||
TextField,
|
||||
Typography
|
||||
Box,
|
||||
Button,
|
||||
Container,
|
||||
Grid,
|
||||
Paper,
|
||||
Stack,
|
||||
TextField,
|
||||
Typography
|
||||
} from "@mui/material";
|
||||
import axios from "axios";
|
||||
import { Field, Formik } from "formik";
|
||||
@@ -39,16 +39,18 @@ const SendUserData = ({ setOtpToken, setPhoneNumber }) => {
|
||||
});
|
||||
|
||||
const handleSubmit = async (values, props) => {
|
||||
Notifications(directionApp, t, undefined);
|
||||
await axios
|
||||
.post(LOGIN_SEND_OTP_TOKEN, {
|
||||
phone_number: values.phone_number,
|
||||
})
|
||||
.then(function (response) {
|
||||
Notifications(directionApp, t, response);
|
||||
setPhoneNumber(values.phone_number);
|
||||
setOtpToken(true);
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Notifications(directionApp, error.response, t);
|
||||
Notifications(directionApp, t, error.response);
|
||||
props.setSubmitting(false);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { toast } from "react-toastify";
|
||||
import ErrorNotification from "./ErrorNotification";
|
||||
import SuccessNotification from "./successNotification";
|
||||
import WarningNotification from "./warningNotification";
|
||||
|
||||
const Notifications = (directionApp, response) => {
|
||||
toast.dismiss();
|
||||
switch (response.status) {
|
||||
case 200:
|
||||
SuccessNotification(directionApp, response.status);
|
||||
break;
|
||||
case 400:
|
||||
ErrorNotification(directionApp, response.status);
|
||||
break;
|
||||
case 401:
|
||||
ErrorNotification(directionApp, response.status);
|
||||
break;
|
||||
case 403:
|
||||
ErrorNotification(directionApp, response.status);
|
||||
break;
|
||||
case 422:
|
||||
ErrorNotification(directionApp, response.status, response.data.message);
|
||||
break;
|
||||
case 500:
|
||||
WarningNotification(directionApp, response.status);
|
||||
break;
|
||||
case 503:
|
||||
WarningNotification(directionApp, response.status);
|
||||
break;
|
||||
case 504:
|
||||
WarningNotification(directionApp, response.status);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
export default Notifications;
|
||||
@@ -1,10 +1,8 @@
|
||||
import DangerousIcon from "@mui/icons-material/Dangerous";
|
||||
import { Box, Button, Divider, Typography } from "@mui/material";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { toast } from "react-toastify";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
const ErrorNotification = (directionApp, status, message) => {
|
||||
const t = useTranslations();
|
||||
const ErrorNotification = (directionApp, t, status, message) => {
|
||||
toast(
|
||||
({ closeToast }) => (
|
||||
<>
|
||||
@@ -20,27 +18,14 @@ const ErrorNotification = (directionApp, status, message) => {
|
||||
<DangerousIcon color="error" sx={{ mr: 1.6 }} />
|
||||
<Box sx={{ display: "flex", flexDirection: "column" }}>
|
||||
<Typography color="error" variant="button">
|
||||
{t("error")} ({t("code")}: {status})
|
||||
{t("notifications.error")} ({t("notifications.code")}: {status})
|
||||
</Typography>
|
||||
<Typography variant="caption">
|
||||
{message && t("error_static_text")}
|
||||
{message || t("notifications.error_static_text")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Divider sx={{ my: 1 }} />
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
color="error"
|
||||
sx={{ mr: 0.5 }}
|
||||
onClick={closeToast}
|
||||
>
|
||||
{t("button_close")}
|
||||
</Button>
|
||||
<Button variant="contained" size="small" color="info">
|
||||
{t("button_contact_us")}
|
||||
</Button>
|
||||
</>
|
||||
),
|
||||
{
|
||||
@@ -1,10 +1,8 @@
|
||||
import BeenhereIcon from "@mui/icons-material/Beenhere";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
const SuccessNotification = (directionApp, status) => {
|
||||
const t = useTranslations();
|
||||
const SuccessNotification = (directionApp, t, status) => {
|
||||
toast(
|
||||
() => (
|
||||
<>
|
||||
@@ -20,10 +18,11 @@ const SuccessNotification = (directionApp, status) => {
|
||||
<BeenhereIcon color="success" sx={{ mr: 1.6 }} />
|
||||
<Box sx={{ display: "flex", flexDirection: "column" }}>
|
||||
<Typography color="success.main" variant="button">
|
||||
{t("success")} ({t("code")}: {status})
|
||||
{t("notifications.success")} ({t("notifications.code")}:{" "}
|
||||
{status})
|
||||
</Typography>
|
||||
<Typography variant="caption">
|
||||
{t("success_static_text")}
|
||||
{t("notifications.success_static_text")}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -1,10 +1,8 @@
|
||||
import ReportIcon from "@mui/icons-material/Report";
|
||||
import { Box, Button, Divider, Typography } from "@mui/material";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { Box, Divider, Typography } from "@mui/material";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
const WarningNotification = (directionApp, status) => {
|
||||
const t = useTranslations();
|
||||
const WarningNotification = (directionApp, t, status) => {
|
||||
toast(
|
||||
({ closeToast }) => (
|
||||
<>
|
||||
@@ -29,18 +27,6 @@ const WarningNotification = (directionApp, status) => {
|
||||
</Box>
|
||||
</Box>
|
||||
<Divider sx={{ my: 1 }} />
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
color="warning"
|
||||
sx={{ mr: 0.5 }}
|
||||
onClick={closeToast}
|
||||
>
|
||||
{t("button_close")}
|
||||
</Button>
|
||||
<Button variant="contained" size="small" color="info">
|
||||
{t("button_contact_us")}
|
||||
</Button>
|
||||
</>
|
||||
),
|
||||
{
|
||||
46
src/core/components/notifications/index.jsx
Normal file
46
src/core/components/notifications/index.jsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { toast } from "react-toastify";
|
||||
import ErrorNotification from "./ErrorNotification";
|
||||
import SuccessNotification from "./successNotification";
|
||||
import WarningNotification from "./warningNotification";
|
||||
|
||||
const Notifications = async (directionApp, t, response) => {
|
||||
console.log(directionApp, t, response);
|
||||
const { status, data } = response != undefined ? response : ""
|
||||
toast.dismiss();
|
||||
switch (status) {
|
||||
case 200:
|
||||
SuccessNotification(directionApp, t, status);
|
||||
break;
|
||||
case 400:
|
||||
ErrorNotification(directionApp, t,status);
|
||||
break;
|
||||
case 401:
|
||||
ErrorNotification(directionApp, t, status);
|
||||
break;
|
||||
case 403:
|
||||
ErrorNotification(directionApp, t, status);
|
||||
break;
|
||||
case 422:
|
||||
ErrorNotification(directionApp, t, status, data.message);
|
||||
break;
|
||||
case 500:
|
||||
WarningNotification(directionApp, t, status);
|
||||
break;
|
||||
case 503:
|
||||
WarningNotification(directionApp, t, status);
|
||||
break;
|
||||
case 504:
|
||||
WarningNotification(directionApp, t, status);
|
||||
break;
|
||||
default:
|
||||
toast(t("pending"), {
|
||||
position: directionApp === "ltr" ? "top-left" : "top-right",
|
||||
autoClose: false,
|
||||
closeOnClick: false,
|
||||
draggable: false,
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
export default Notifications;
|
||||
Reference in New Issue
Block a user