Spaces:
Running
Running
| import { useNotification } from "@/context/NotificationContext"; | |
| import { useNavigation } from "@/context/NavigationContext"; | |
| import { useCallback } from "react"; | |
| export interface SystemNotificationOptions { | |
| type: "success" | "error" | "warning" | "info"; | |
| title: string; | |
| message: string; | |
| duration?: number; | |
| persistent?: boolean; // Whether to also add to persistent notifications | |
| } | |
| export function useSystemNotifications() { | |
| const { showNotification } = useNotification(); | |
| const { actions } = useNavigation(); | |
| const notify = useCallback( | |
| ({ persistent = true, ...options }: SystemNotificationOptions) => { | |
| // Always show toast notification | |
| showNotification(options); | |
| // Add to persistent notifications if requested (default: true for system events) | |
| if (persistent) { | |
| actions.addNotification({ | |
| type: options.type, | |
| title: options.title, | |
| message: options.message, | |
| }); | |
| } | |
| }, | |
| [showNotification, actions] | |
| ); | |
| // Convenience methods for different types | |
| const notifySuccess = useCallback( | |
| (title: string, message: string, persistent = true) => { | |
| notify({ type: "success", title, message, persistent }); | |
| }, | |
| [notify] | |
| ); | |
| const notifyError = useCallback( | |
| (title: string, message: string, persistent = true) => { | |
| notify({ type: "error", title, message, persistent }); | |
| }, | |
| [notify] | |
| ); | |
| const notifyWarning = useCallback( | |
| (title: string, message: string, persistent = true) => { | |
| notify({ type: "warning", title, message, persistent }); | |
| }, | |
| [notify] | |
| ); | |
| const notifyInfo = useCallback( | |
| (title: string, message: string, persistent = false) => { | |
| notify({ type: "info", title, message, persistent }); | |
| }, | |
| [notify] | |
| ); | |
| return { | |
| notify, | |
| notifySuccess, | |
| notifyError, | |
| notifyWarning, | |
| notifyInfo, | |
| }; | |
| } | |