File size: 1,897 Bytes
c2ea5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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,
  };
}