import { useState } from "react"; import { Button } from "@/components/ui/button"; import { usePushNotifications } from "../hooks/usePushNotifications"; const DISMISS_KEY = "nexus.notifPromptDismissed"; interface NotificationPermissionPromptProps { agentResponseCount: number; } /** * Notification permission prompt banner. * * Shows when: * - Push notifications are supported in this browser * - Permission is still "default" (not granted or denied) * - User has not previously dismissed this prompt * - User has received at least 3 agent responses (engagement gate) */ export function NotificationPermissionPrompt({ agentResponseCount }: NotificationPermissionPromptProps) { const { isSupported, permission, subscribe } = usePushNotifications(); const [dismissed, setDismissed] = useState(() => { try { return localStorage.getItem(DISMISS_KEY) === "true"; } catch { return false; } }); if (!isSupported) return null; if (permission !== "default") return null; if (dismissed) return null; if (agentResponseCount < 3) return null; const handleAllow = async () => { await subscribe(); }; const handleDismiss = () => { try { localStorage.setItem(DISMISS_KEY, "true"); } catch { // localStorage unavailable — dismiss for session only } setDismissed(true); }; return (
Stay in the loop
Get notified when your agents complete tasks or need input.