chore: migrate nextui to heroui (#141)
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
import { createContext } from 'react';
|
||||
import { ToastContextType, ToastProps } from '@/types/toast';
|
||||
|
||||
// TODO Temporary use until NextUI's Toast is released.
|
||||
import { ToastContainer, toast } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
|
||||
const defaultContext = {
|
||||
showToast: (text: string, mode: 'error' | 'dark') => {},
|
||||
};
|
||||
const ToastContext = createContext<ToastContextType>(defaultContext);
|
||||
|
||||
const ToastProvider = ({ children }: ToastProps) => {
|
||||
const showToast = (text: string, mode: string) => {
|
||||
if (mode === 'error') {
|
||||
toast.error(text);
|
||||
} else {
|
||||
toast(text, { theme: 'dark' });
|
||||
}
|
||||
};
|
||||
|
||||
const toastContext = {
|
||||
showToast,
|
||||
};
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={toastContext}>
|
||||
<ToastContainer position="bottom-right" hideProgressBar={true} />
|
||||
{children}
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { ToastContext };
|
||||
export default ToastProvider;
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
checkSignInPage as tokenCheckSignInPage,
|
||||
fetchMyRoles,
|
||||
} from './token';
|
||||
import { ToastContext } from './ToastProvider';
|
||||
import { addToast } from '@heroui/react';
|
||||
const LOCAL_STORAGE_KEY = 'unittcms-auth-token';
|
||||
|
||||
function storeTokenToLocalStorage(token: TokenType) {
|
||||
@@ -53,7 +53,6 @@ const TokenContext = createContext<TokenContextType>(defaultContext);
|
||||
const TokenProvider = ({ toastMessages, locale, children }: TokenProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const toastContext = useContext(ToastContext);
|
||||
|
||||
const [hasRestoreFinished, setHasRestoreFinished] = useState(false);
|
||||
const [token, setToken] = useState<TokenType>({
|
||||
@@ -137,11 +136,19 @@ const TokenProvider = ({ toastMessages, locale, children }: TokenProps) => {
|
||||
if (!ret.ok) {
|
||||
if (ret.reason === 'notoken') {
|
||||
if (toastMessages) {
|
||||
toastContext.showToast(toastMessages.needSignedIn, 'error');
|
||||
addToast({
|
||||
title: 'Info',
|
||||
description: toastMessages.needSignedIn,
|
||||
color: 'danger',
|
||||
});
|
||||
}
|
||||
} else if (ret.reason === 'expired') {
|
||||
if (toastMessages) {
|
||||
toastContext.showToast(toastMessages.sessionExpired, 'error');
|
||||
addToast({
|
||||
title: 'Info',
|
||||
description: toastMessages.sessionExpired,
|
||||
color: 'danger',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user