2023-10-30 10:00:20 -04:00
|
|
|
import { createContext, useContext } from 'react';
|
2023-10-27 17:10:07 -04:00
|
|
|
import type { TShowToast } from '~/common';
|
|
|
|
|
import { useToast } from '~/hooks';
|
|
|
|
|
|
|
|
|
|
type ToastContextType = {
|
|
|
|
|
showToast: ({ message, severity, showIcon }: TShowToast) => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ToastContext = createContext<ToastContextType>({
|
|
|
|
|
showToast: () => ({}),
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-30 10:00:20 -04:00
|
|
|
export function useToastContext() {
|
|
|
|
|
return useContext(ToastContext);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 17:10:07 -04:00
|
|
|
export default function ToastProvider({ children }) {
|
|
|
|
|
const { showToast } = useToast();
|
|
|
|
|
|
|
|
|
|
return <ToastContext.Provider value={{ showToast }}>{children}</ToastContext.Provider>;
|
|
|
|
|
}
|