import { useState } from "react" import { Navigate } from "react-router-dom" import { useMutation } from "@tanstack/react-query" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Bell, Mail, MessageSquare, Send } from "lucide-react" import { notificationService } from "@/services" import { useAdminRole } from "@/hooks/use-admin-role" import { toast } from "sonner" import { cn } from "@/lib/utils" export default function NotificationBroadcastPage() { const { canSendBroadcast } = useAdminRole() const [title, setTitle] = useState("") const [message, setMessage] = useState("") const [audience, setAudience] = useState< "all_end_users" | "system_users_only" | "everyone_with_access" >("all_end_users") const [channels, setChannels] = useState({ push: true, sms: false, email: true, }) const mutation = useMutation({ mutationFn: () => notificationService.sendBroadcast({ title, message, audience, channels: ( [ channels.push && "push", channels.sms && "sms", channels.email && "email", ].filter(Boolean) as ("push" | "sms" | "email")[] ), }), onSuccess: () => { toast.success("Broadcast queued for delivery") setTitle("") setMessage("") }, onError: () => toast.error( "Could not send. Ensure POST /admin/notifications/broadcast exists.", ), }) if (!canSendBroadcast) { return } const toggleChannel = (key: keyof typeof channels) => { setChannels((c) => ({ ...c, [key]: !c[key] })) } const channelActive = channels.push || channels.sms || channels.email return (

Send notification

Super Admins and Admins can broadcast via push, SMS, and email. Delivery depends on user preferences and channel configuration.

Channels
Audience Message
setTitle(e.target.value)} className="rounded-none" />