Create toast provider
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
/* TODO Temporary use until NextUI's Toast is released. */
|
||||||
|
.Toastify__toast-body {
|
||||||
|
font-family: 'systems-ui';
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ const ToastContext = createContext<ToastContextType>(defaultContext);
|
|||||||
|
|
||||||
const ToastProvider = ({ children }: ToastProps) => {
|
const ToastProvider = ({ children }: ToastProps) => {
|
||||||
const showToast = (text: string, mode: string) => {
|
const showToast = (text: string, mode: string) => {
|
||||||
toast(text, { theme: 'light' });
|
if (mode === 'error') {
|
||||||
|
toast.error(text);
|
||||||
|
} else {
|
||||||
|
toast(text, { theme: 'light' });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const toastContext = {
|
const toastContext = {
|
||||||
@@ -21,7 +25,7 @@ const ToastProvider = ({ children }: ToastProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ToastContext.Provider value={toastContext}>
|
<ToastContext.Provider value={toastContext}>
|
||||||
<ToastContainer hideProgressBar={true} />
|
<ToastContainer position="bottom-right" hideProgressBar={true} theme="colored" />
|
||||||
{children}
|
{children}
|
||||||
</ToastContext.Provider>
|
</ToastContext.Provider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -111,12 +111,12 @@ const TokenProvider = ({ toastMessages, locale, children }: TokenProps) => {
|
|||||||
}
|
}
|
||||||
if (isPrivatePath(pathname) && !isSignedIn()) {
|
if (isPrivatePath(pathname) && !isSignedIn()) {
|
||||||
if (tokenExists()) {
|
if (tokenExists()) {
|
||||||
toastContext.showToast(toastMessages.needSignedIn, 'default');
|
toastContext.showToast(toastMessages.needSignedIn, 'error');
|
||||||
router.push(`/account/signin`, { locale: locale });
|
router.push(`/account/signin`, { locale: locale });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isTokenValid()) {
|
if (isTokenValid()) {
|
||||||
toastContext.showToast(toastMessages.sessionExpired, 'default');
|
toastContext.showToast(toastMessages.sessionExpired, 'error');
|
||||||
router.push(`/account/signin`, { locale: locale });
|
router.push(`/account/signin`, { locale: locale });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user