import { createFileRoute } from '@tanstack/react-router' import React, { useState } from 'react' import { AppContainer, MyButton, p as MyText, pInput as PInput } from 'web-components' import { Send } from 'lucide-react' import { alert } from '@/components/ui/dialog-host' import { trpc } from '../lib/trpc-client' import { ProtectedRoute } from '../components/ProtectedRoute' import { AppShell } from '../components/AppShell' export const Route = createFileRoute('/send-notifications')({ component: () => ( ), }) function SendAdminNotifications() { const [title, setTitle] = useState('') const [text, setText] = useState('') const [imageUrl, setImageUrl] = useState('') const { mutate, isPending } = trpc.superadmin.staff.sendAdminNotification.useMutation({ onSuccess: (response) => { void alert(`Success\n\n${response.message}`) setTitle('') setText('') setImageUrl('') }, onError: (error) => { void alert(`Error\n\n${error.message || 'Failed to send notification'}`) }, }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!title.trim() || !text.trim()) { void alert('Title and message are required') return } mutate({ title: title.trim(), text: text.trim(), ...(imageUrl.trim() ? { imageUrl: imageUrl.trim() } : {}), }) } return ( Admin Notifs This push notification is delivered to every admin device. setTitle(e.target.value)} /> Message setText(e.target.value)} placeholder="Write the notification body..." rows={4} className="w-full rounded-lg border border-gray-300 bg-white p-3 text-gray-900 outline-none focus:border-blue-500" /> setImageUrl(e.target.value)} /> {isPending ? 'Sending...' : 'Send to all admins'} ) }