CFE-6 debugging notifications
This commit is contained in:
@@ -29,6 +29,7 @@ const ErrorNotification = (t, status, message) => {
|
||||
</>
|
||||
),
|
||||
{
|
||||
containerId: 'validation',
|
||||
autoClose: false,
|
||||
closeOnClick: false,
|
||||
draggable: false,
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
let a = {pending: []}
|
||||
const PendingNotification = (t) => {
|
||||
toast(t("notifications.pending"), {
|
||||
containerId: 'validation',
|
||||
autoClose: false,
|
||||
closeButton: false,
|
||||
closeOnClick: false,
|
||||
draggable: false,
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
export default PendingNotification;
|
||||
@@ -30,6 +30,7 @@ const SuccessNotification = (t, status) => {
|
||||
</>
|
||||
),
|
||||
{
|
||||
containerId: 'validation',
|
||||
autoClose: 3000,
|
||||
hideProgressBar: true,
|
||||
pauseOnHover: true,
|
||||
|
||||
@@ -26,6 +26,8 @@ const UploadFileNotification = (t) => {
|
||||
</>
|
||||
),
|
||||
{
|
||||
containerId: 'validation',
|
||||
toastId: 'upload',
|
||||
autoClose: 3000,
|
||||
hideProgressBar: true,
|
||||
pauseOnHover: true,
|
||||
|
||||
@@ -30,6 +30,7 @@ const WarningNotification = (t, status) => {
|
||||
</>
|
||||
),
|
||||
{
|
||||
containerId: 'validation',
|
||||
autoClose: false,
|
||||
closeOnClick: false,
|
||||
draggable: false,
|
||||
|
||||
@@ -1,54 +1,25 @@
|
||||
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);
|
||||
break;
|
||||
case 400:
|
||||
ErrorNotification(t, status);
|
||||
break;
|
||||
case 401:
|
||||
ErrorNotification(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,
|
||||
});
|
||||
break;
|
||||
const Notifications = (notificationType, t, status, message) => {
|
||||
let notification_type_id = {
|
||||
pending: [],
|
||||
error: [],
|
||||
warning: [],
|
||||
success: []
|
||||
}
|
||||
|
||||
if (notificationType === "pending") {
|
||||
pendingNotification(t);
|
||||
} else if (notificationType === "warning") {
|
||||
WarningNotification(t, status);
|
||||
} else if (notificationType === "error") {
|
||||
message ? ErrorNotification(t, status, message) : ErrorNotification(t, status);
|
||||
} else if (notificationType === "success") {
|
||||
SuccessNotification(t, status);
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
import ErrorNotification from "@/core/components/notifications/ErrorNotification";
|
||||
import WarningNotification from "@/core/components/notifications/WarningNotification";
|
||||
import {toast} from "react-toastify";
|
||||
import Notifications from "@/core/components/notifications";
|
||||
|
||||
export const errorSetting = (t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
if (notification) {
|
||||
toast.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
export const errorRequest = (t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
if (notification) {
|
||||
toast.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
export const errorResponse = (response, clearToken, t, notification) => {
|
||||
if (notification) toast.dismiss();
|
||||
if (notification) {
|
||||
toast.dismiss()
|
||||
}
|
||||
if (isServerError(response.status)) {
|
||||
errorServer(response, t, notification)
|
||||
} else if (isClientError(response.status)) {
|
||||
@@ -20,13 +25,13 @@ export const errorResponse = (response, clearToken, t, notification) => {
|
||||
}
|
||||
|
||||
const errorServer = (response, t, notification) => {
|
||||
if (notification) WarningNotification(t, response.status);
|
||||
if (notification) Notifications("warning", t, response.status);
|
||||
}
|
||||
const errorClient = (response, clearToken, t, notification) => {
|
||||
switch (response.status) {
|
||||
case 401:
|
||||
clearToken()
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
if (notification) Notifications("error", t, response.status);
|
||||
break;
|
||||
case 422:
|
||||
if ('type' in response.data) {
|
||||
@@ -36,10 +41,10 @@ const errorClient = (response, clearToken, t, notification) => {
|
||||
errorValidation(response, t, notification)
|
||||
break;
|
||||
case 429:
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
if (notification) Notifications("error", t, response.status);
|
||||
break
|
||||
default:
|
||||
if (notification) ErrorNotification(t, response.status)
|
||||
if (notification) Notifications("error", t, response.status);
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -48,7 +53,7 @@ const isServerError = status => status >= 500 && status <= 599;
|
||||
const isClientError = status => status >= 400 && status <= 499;
|
||||
|
||||
const errorLogic = (response, t, notification) => {
|
||||
if (notification) ErrorNotification(t, response.status, response.data.message)
|
||||
if (notification) Notifications("error", t, response.status, response.data.message);
|
||||
}
|
||||
const errorValidation = (response, t, notification) => {
|
||||
if (notification) {
|
||||
@@ -56,7 +61,7 @@ const errorValidation = (response, t, notification) => {
|
||||
const errorsArray = response.data.errors
|
||||
|
||||
errorsMap.map((item, index) => {
|
||||
ErrorNotification(t, response.status, errorsArray[item][0]);
|
||||
Notifications("error", t, errorsArray[item][0], response.data.message);
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import SuccessNotification from "@/core/components/notifications/SuccessNotification";
|
||||
import {toast} from "react-toastify";
|
||||
import Notifications from "@/core/components/notifications";
|
||||
|
||||
export const successRequest = (response, t, options) => {
|
||||
if (options.notification && options.success.notification.show) {
|
||||
toast.dismiss();
|
||||
SuccessNotification(t, response.status)
|
||||
Notifications("success", t, response.status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user