import { useEffect, useState } from 'react'; import { toast } from 'sonner'; import Layout from '../components/Layout'; import { useAuth } from '../contexts/AuthContext'; import { useNotificationPrefs, useUpdateNotificationPrefs, type NotificationPrefs, } from '../api/queries'; const CHANNELS = [ { key: 'assignment', label: 'Ticket assigned to me' }, { key: 'mention', label: 'I am mentioned in a comment' }, { key: 'resolved', label: 'A ticket I created is resolved' }, ] as const; export default function Settings() { const { user } = useAuth(); const prefsQ = useNotificationPrefs(); const updatePrefs = useUpdateNotificationPrefs(); const [local, setLocal] = useState(null); useEffect(() => { if (prefsQ.data && !local) setLocal(prefsQ.data); }, [prefsQ.data, local]); const handleToggle = (channel: 'email' | 'inApp', key: keyof NotificationPrefs['email']) => { setLocal((l) => l ? { ...l, [channel]: { ...l[channel], [key]: !l[channel][key] }, } : l, ); }; const save = async () => { if (!local) return; try { await updatePrefs.mutateAsync(local); toast.success('Preferences saved'); } catch (e) { toast.error((e as Error).message || 'Failed to save'); } }; return (
{/* Profile */}

Profile

{/* Notifications */}

Notification preferences

{local ? (
Email In app
{CHANNELS.map(({ key, label }) => (
{label}
handleToggle('email', key)} />
handleToggle('inApp', key)} />
))}
) : (

Loading…

)}

Email notifications require the server's SMTP config. If SMTP is unset, only in-app delivery happens regardless of these settings.

); } function Field({ label, value, mono }: { label: string; value: string; mono?: boolean }) { return (

{label}

{value || '—'}

); }