Create toast provider
This commit is contained in:
31
frontend/utils/ToastProvider.tsx
Normal file
31
frontend/utils/ToastProvider.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
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: string) => {},
|
||||
};
|
||||
const ToastContext = createContext<ToastContextType>(defaultContext);
|
||||
|
||||
const ToastProvider = ({ children }: ToastProps) => {
|
||||
const showToast = (text: string, mode: string) => {
|
||||
toast(text, { theme: 'light' });
|
||||
};
|
||||
|
||||
const toastContext = {
|
||||
showToast,
|
||||
};
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={toastContext}>
|
||||
<ToastContainer hideProgressBar={true} />
|
||||
{children}
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { ToastContext };
|
||||
export default ToastProvider;
|
||||
Reference in New Issue
Block a user