// src/NotificationContext.tsx import React, { createContext, useContext, useState } from 'react'; export type NotificationType = 'success' | 'error'; interface NotificationContextType { notify: (message: string, type: NotificationType) => void; } const NotificationContext = createContext(undefined); export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [notification, setNotification] = useState(null); const [notificationType, setNotificationType] = useState(null); const notify = (message: string, type: NotificationType) => { setNotification(message); setNotificationType(type); // Automatically dismiss notification after 3 seconds setTimeout(() => { setNotification(null); setNotificationType(null); }, 3000); }; return ( {children} {notification && ( setNotification(null)} type={notificationType!} /> )} ); }; export const useNotification = () => { const context = useContext(NotificationContext); if (!context) { throw new Error('useNotification must be used within a NotificationProvider'); } return context.notify; }; interface NotificationProps { message: string; onClose: () => void; type: 'success' | 'error'; // Define notification types } // Notification Component const Notification: React.FC = ({ message, onClose, type }) => { return (

{message}

); }; // Notification styles remain the same... const styles: { [key: string]: React.CSSProperties } = { notification: { position: 'fixed', top: '20px', right: '20px', color: 'white', padding: '15px', borderRadius: '5px', zIndex: 1000, }, closeButton: { background: 'transparent', border: 'none', color: 'white', cursor: 'pointer', marginLeft: '10px', }, };