2026-09-18 12:55:54 -03:00
|
|
|
import { createContext, useContext } from "react";
|
|
|
|
|
|
|
|
|
|
export type NotificationSession = {
|
|
|
|
|
dismissedIds: ReadonlySet<string>;
|
|
|
|
|
readIds: ReadonlySet<string>;
|
|
|
|
|
dismiss: (ids: string[]) => void;
|
|
|
|
|
markRead: (ids: string[]) => void;
|
2026-09-25 11:36:25 -03:00
|
|
|
/** At-risk work orders hidden from the SLA banner for this session. */
|
|
|
|
|
slaBannerDismissedIds: ReadonlySet<number>;
|
|
|
|
|
dismissSlaBanner: (workOrderIds: number[]) => void;
|
|
|
|
|
/** Returns the ids not toasted yet this session and marks them toasted, so each toast fires once. */
|
|
|
|
|
claimSlaToasts: (workOrderIds: number[]) => number[];
|
2026-09-18 12:55:54 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const NotificationSessionContext = createContext<NotificationSession | null>(null);
|
|
|
|
|
|
|
|
|
|
export function useNotificationSession(): NotificationSession {
|
|
|
|
|
const session = useContext(NotificationSessionContext);
|
|
|
|
|
if (!session) {
|
|
|
|
|
throw new Error("useNotificationSession must be used within a NotificationSessionProvider");
|
|
|
|
|
}
|
|
|
|
|
return session;
|
|
|
|
|
}
|