import { useEffect, useState } from "react"; import { getNotificationPreferences, updateNotificationPreferences } from "@/client/api"; import type { NotificationPreferencesResponse } from "@/client/model"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; import { Loader2, Smartphone, ShieldCheck, AlertCircle } from "lucide-react"; export function PushSettingsPage() { const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const [pushEnabled, setPushEnabled] = useState(false); const canPush = 'Notification' in window && 'serviceWorker' in navigator; useEffect(() => { (async () => { try { setLoading(true); const res = await getNotificationPreferences(); const data = res.data.data as NotificationPreferencesResponse | undefined; setPushEnabled(data?.push_enabled ?? false); } catch { setError("Failed to load notification settings"); } finally { setLoading(false); } })(); }, []); const handleTogglePush = async (checked: boolean) => { if (checked && 'Notification' in window) { const permission = await Notification.requestPermission(); if (permission !== 'granted') { setError("Notification permission denied by browser"); return; } } try { setSaving(true); setError(null); await updateNotificationPreferences({ push_enabled: checked, } as Partial); setPushEnabled(checked); setSuccess(true); setTimeout(() => setSuccess(false), 3000); } catch { setError("Failed to update push settings"); } finally { setSaving(false); } }; if (loading) { return (
); } return (

Push Notifications

Receive real-time alerts even when the app is closed.

{!canPush && (

Push notifications are not supported

Your browser or environment doesn't support Web Push. Please use a modern desktop browser.

)}

Get notified of mentions, issues, and system alerts.

{pushEnabled && (

Notification Filters

Mentions & Replies
New Issuesss
System Updates

More granular controls coming soon.

)}
{error && (
{error}
)} {success && (
Settings saved successfully
)}
); }