import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { client } from '@/ui/api/client' import { ScrollArea } from '@/ui/components/ui/scroll-area' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card' import { Switch } from '@/ui/components/ui/switch' import { Loader2, MessageSquare, MessageCircle, AtSign, UploadCloud, Activity, Bell, LayoutDashboard, } from 'lucide-react' import { toast } from 'sonner' import type { NotificationSettings as Settings } from '@shumai/dtos' import { m } from '@/ui/paraglide/messages.js' export function NotificationSettings({ teamId }: { teamId: string }) { const queryClient = useQueryClient() const { data: settings, isLoading } = useQuery({ queryKey: ['teams', teamId, 'notification-settings'], queryFn: async () => { const res = await client.api.teams[':teamId'].notifications.settings.$get({ param: { teamId }, }) if (!res.ok) throw new Error(m.failed_load_settings()) return (await res.json()) as Settings }, }) const { mutate: updateSettings, isPending: isUpdating } = useMutation({ mutationFn: async (updated: Settings) => { const res = await client.api.teams[':teamId'].notifications.settings.$post({ param: { teamId }, json: updated, }) if (!res.ok) throw new Error(m.failed_to_update_notification_settings()) return await res.json() }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'notification-settings'] }) queryClient.invalidateQueries({ queryKey: ['teams', teamId, 'notifications'] }) toast.success(m.notification_settings_updated()) }, onError: (err) => { toast.error(err instanceof Error ? err.message : m.failed_to_update_notification_settings()) }, }) const handleToggle = (key: keyof Settings) => { if (!settings) return const updated = { ...settings, [key]: !settings[key], } updateSettings(updated) } if (isLoading) { return (
{m.when_someone_comments()}
{m.when_someone_replies()}
{m.when_someone_mentions()}
{m.when_you_upload_assets()}
{m.when_other_users_upload_assets()}
{m.when_someone_changes_status()}
{m.when_kanban_task_events()}
{m.when_kanban_task_commented()}