mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import React, { createContext, useState, useContext } from 'react';
|
|
import FlashNotification from '@/components/FlashNotification';
|
|
|
|
const NotificationContext = createContext();
|
|
|
|
export const NotificationProvider = ({ children }) => {
|
|
const [notification, setNotification] = useState({
|
|
message: '',
|
|
type: '',
|
|
title: '',
|
|
errorCode: '',
|
|
});
|
|
|
|
const showNotification = (
|
|
message,
|
|
type = 'info',
|
|
title = '',
|
|
errorCode = ''
|
|
) => {
|
|
setNotification({ message, type, title, errorCode });
|
|
};
|
|
|
|
const clearNotification = () => {
|
|
setNotification({ message: '', type: '', title: '', errorCode: '' });
|
|
};
|
|
|
|
return (
|
|
<NotificationContext.Provider value={{ showNotification }}>
|
|
{notification.message && (
|
|
<FlashNotification
|
|
title={notification.title}
|
|
message={notification.message}
|
|
type={notification.type}
|
|
errorCode={notification.errorCode}
|
|
onClose={clearNotification}
|
|
/>
|
|
)}
|
|
{children}
|
|
</NotificationContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useNotification = () => useContext(NotificationContext);
|