'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { toast } from 'sonner' import { Trophy } from 'lucide-react' import { Switch } from '@/components/ui/switch' import { Label } from '@/components/ui/label' import { EmailPreviewDialog } from './email-preview-dialog' interface NotifyAdvancedButtonProps { roundId: string targetRoundId?: string } export function NotifyAdvancedButton({ roundId, targetRoundId }: NotifyAdvancedButtonProps) { const [open, setOpen] = useState(false) const [customMessage, setCustomMessage] = useState() const [fullCustomBody, setFullCustomBody] = useState(false) const preview = trpc.round.previewAdvancementEmail.useQuery( { roundId, targetRoundId, customMessage, fullCustomBody }, { enabled: open } ) const sendMutation = trpc.round.sendAdvancementNotifications.useMutation({ onSuccess: (data) => { toast.success( `Sent ${data.sent} notification${data.sent !== 1 ? 's' : ''}${data.failed ? ` (${data.failed} failed)` : ''}` ) setOpen(false) }, onError: (err) => toast.error(err.message), }) return ( <>
sendMutation.mutate({ roundId, targetRoundId, customMessage: msg, fullCustomBody })} isSending={sendMutation.isPending} onRefreshPreview={(msg) => setCustomMessage(msg)} /> ) }