import { useNotifications } from "@/hooks/useNotifications"; import { Loader2, BellOff, Trash2, Send, Monitor } from "lucide-react"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { showToast } from "@/lib/toast"; import { formatDistanceToNow } from "date-fns"; export function NotificationSettings() { const { isSupported, isAvailable, permission, isEnabled, preferences, subscriptions, isLoadingSubscriptions, enable, disable, updateEventPreference, removeDevice, sendTest, isSubscribing, isTesting, } = useNotifications(); if (!isSupported) { return (

Push Notifications

Push notifications are not supported in this browser.

); } if (!isAvailable) { return (

Push Notifications

Push notifications are not configured on the server. Set VAPID_PUBLIC_KEY and VAPID_PRIVATE_KEY environment variables to enable.

); } if (permission === "denied") { return (

Push Notifications

Notification permission was denied. Please enable notifications in your browser settings for this site.

); } const handleEnable = async () => { try { await enable(); showToast.success("Push notifications enabled"); } catch { showToast.error("Failed to enable push notifications"); } }; const handleDisable = async () => { try { await disable(); showToast.success("Push notifications disabled"); } catch { showToast.error("Failed to disable push notifications"); } }; const handleTest = () => { sendTest(undefined, { onSuccess: (data) => { showToast.success( `Test notification sent to ${data.devicesNotified} device(s)` ); }, onError: () => { showToast.error("Failed to send test notification"); }, }); }; return (

Push Notifications

Receive notifications when the app is in the background

checked ? handleEnable() : handleDisable() } />
{isEnabled && ( <>

Notification Events

When the agent needs approval to proceed

updateEventPreference("permissionAsked", checked) } />

When the agent has a question for you

updateEventPreference("questionAsked", checked) } />

When a session encounters an error

updateEventPreference("sessionError", checked) } />

When a session finishes processing

updateEventPreference("sessionIdle", checked) } />
)}
{isEnabled && (

Registered Devices

{isLoadingSubscriptions ? (
) : subscriptions.length === 0 ? (

No devices registered for push notifications.

) : (
{subscriptions.map((sub) => (

{sub.deviceName ?? (sub.endpoint.length > 60 ? sub.endpoint.slice(0, 60) + "..." : sub.endpoint)}

{sub.lastUsedAt ? `Last used ${formatDistanceToNow(sub.lastUsedAt, { addSuffix: true })}` : `Added ${formatDistanceToNow(sub.createdAt, { addSuffix: true })}`}

))}
)}
)}
); }