project-nomad/admin/inertia/context/NotificationContext.ts
2025-08-08 15:07:32 -07:00

29 lines
735 B
TypeScript

import { createContext, useContext } from "react";
export interface Notification {
message: string;
type: "error" | "success" | "info";
duration?: number; // in milliseconds
}
export interface NotificationContextType {
notifications: Notification[];
addNotification: (notification: Notification) => void;
removeNotification: (id: string) => void;
removeAllNotifications: () => void;
}
export const NotificationContext = createContext<
NotificationContextType | undefined
>(undefined);
export const useNotifications = () => {
const context = useContext(NotificationContext);
if (!context) {
throw new Error(
"useNotifications must be used within a NotificationProvider"
);
}
return context;
};