'use client' import { useState } from 'react' import { trpc } from '@/lib/trpc/client' import { Switch } from '@/components/ui/switch' import { Label } from '@/components/ui/label' import { Button } from '@/components/ui/button' import { Skeleton } from '@/components/ui/skeleton' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { toast } from 'sonner' import { Users, Scale, GraduationCap, Eye, Shield } from 'lucide-react' // Category icons and labels const CATEGORIES = { team: { label: 'Team / Applicant', icon: Users }, jury: { label: 'Jury Members', icon: Scale }, mentor: { label: 'Mentors', icon: GraduationCap }, observer: { label: 'Observers', icon: Eye }, admin: { label: 'Administrators', icon: Shield }, } type NotificationSetting = { id: string notificationType: string category: string label: string description: string | null sendEmail: boolean } export function NotificationSettingsForm() { const { data: settings, isLoading, refetch } = trpc.notification.getEmailSettings.useQuery() const updateMutation = trpc.notification.updateEmailSetting.useMutation({ onSuccess: () => { toast.success('Notification setting updated') refetch() }, onError: (error) => { toast.error(`Failed to update: ${error.message}`) }, }) const handleToggle = (notificationType: string, sendEmail: boolean) => { updateMutation.mutate({ notificationType, sendEmail }) } if (isLoading) { return (
No notification types configured yet. Notification settings will appear here once the system is seeded.
Toggle which notifications should also send email notifications to users. Users can still disable email notifications in their personal preferences.
{Object.entries(CATEGORIES).map(([categoryKey, { label, icon: Icon }]) => { const categorySettings = groupedSettings[categoryKey] if (!categorySettings || categorySettings.length === 0) return null return ({setting.description}
)}