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 (
Active push subscribers
Notification sent!
Delivered: {result.sent} • Failed: {result.failed}
Failed to send notification. Please try again.
Note: Notifications are sent to all subscribers with push enabled. Use sparingly to avoid spam. Articles and live blog updates are automatically pushed when published.