Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/utils/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const getToast = () => {
return _toast;
};

const isSSR = typeof window === "undefined";
const isServer = () => typeof window === "undefined";

export function showAuthToast(message, onAfterClose) {
if (isSSR) return;
if (isServer()) return;
const toast = getToast();
toast.dismiss(AUTH_TOAST_ID);
toast.success(message, {
Expand All @@ -25,7 +25,7 @@ export function showAuthToast(message, onAfterClose) {
}

export function showErrorToast(message, onAfterClose) {
if (isSSR) return;
if (isServer()) return;
const toast = getToast();
toast.dismiss("error-feedback");
toast.error(message, {
Expand All @@ -36,7 +36,7 @@ export function showErrorToast(message, onAfterClose) {
}

export function showInfoToast(message, onAfterClose) {
if (isSSR) return;
if (isServer()) return;
const toast = getToast();
toast.dismiss("info-feedback");
toast.info(message, {
Expand All @@ -47,23 +47,23 @@ export function showInfoToast(message, onAfterClose) {
}

export function showSuccessToast(message, options = {}) {
if (isSSR) return;
if (isServer()) return;
const { autoClose = 2500, toastId, onClose } = options;
const toast = getToast();
if (toastId) toast.dismiss(toastId);
toast.success(message, { toastId, autoClose, onClose });
}

export function showWarningToast(message, options = {}) {
if (isSSR) return;
if (isServer()) return;
const { autoClose = 3000, toastId, onClose } = options;
const toast = getToast();
if (toastId) toast.dismiss(toastId);
toast.warning(message, { toastId, autoClose, onClose });
}

export function dismissToastsByGroup(groupId) {
if (isSSR) return;
if (isServer()) return;
if (typeof window !== "undefined" && window.__EVENTRA_TOASTS__) {
const list = window.__EVENTRA_TOASTS__[groupId] || [];
list.forEach((_id) => {
Expand All @@ -75,4 +75,4 @@ export function dismissToastsByGroup(groupId) {
});
window.__EVENTRA_TOASTS__[groupId] = [];
}
}
}
Loading