import { useState } from 'react'; import { usePushStats, useSendPushNotification } from '@/queries/push'; import { Button } from '@/components/ui/button'; import { Bell, Send, Users, AlertCircle, CheckCircle } from 'lucide-react'; export function PushNotificationManager() { const [title, setTitle] = useState(''); const [body, setBody] = useState(''); const [url, setUrl] = useState(''); const [showSuccess, setShowSuccess] = useState(false); const [result, setResult] = useState<{ sent: number; failed: number } | null>( null, ); const { data: stats, isLoading: loadingStats } = usePushStats(); const sendMutation = useSendPushNotification(); const handleSendTest = async () => { if (!title.trim() || !body.trim()) return; try { const result = await sendMutation.mutateAsync({ title: title.trim(), body: body.trim(), url: url.trim() || undefined, }); setResult(result); setShowSuccess(true); setTimeout(() => setShowSuccess(false), 5000); } catch (error) { console.error('Failed to send notification:', error); } }; const isValid = title.trim().length > 0 && body.trim().length > 0; return (

Push Notifications

Subscribers
{loadingStats ? (
...
) : (
{stats?.totalSubscribers ?? 0}
)}

Active push subscribers

Send Notification

setTitle(e.target.value)} placeholder="Enter notification title..." className="w-full border-2 border-foreground bg-background px-3 py-2 font-body text-sm focus:border-accent focus:outline-none" maxLength={50} />