'use client'; import type { ProfileDto } from '@impuestos/contracts'; import { SUPPORTED_LOCALES, type Locale } from '@impuestos/i18n'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { PushOptIn } from '@/components/push-optin'; import { ThemeToggle } from '@/components/theme-toggle'; import { Card } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { Switch } from '@/components/ui/switch'; import { usePathname, useRouter } from '@/i18n/navigation'; import { useT } from '@/i18n/t'; import { api } from '@/lib/api'; const LABEL_KEY = { es: 'common.languageEs', en: 'common.languageEn' } as const; export function NotificationsSection({ profile }: { profile: ProfileDto }) { const t = useT(); const queryClient = useQueryClient(); const router = useRouter(); const pathname = usePathname(); const prefs = useQuery({ queryKey: ['me', 'notification-prefs'], queryFn: ({ signal }) => api.getNotificationPrefs(signal), }); const update = useMutation({ mutationFn: api.patchNotificationPrefs, onSuccess: () => queryClient.invalidateQueries({ queryKey: ['me', 'notification-prefs'] }), }); /** * Changing the language here persists it to the profile, because the API sends * notifications, emails and error messages in the locale stored there. */ const setLocale = useMutation({ mutationFn: (locale: Locale) => api.putProfile({ ...profile, locale }), onSuccess: async (_data, locale) => { await queryClient.invalidateQueries({ queryKey: ['me'] }); router.replace(pathname, { locale }); }, }); return (

{t('profile.notifications')}

{prefs.isPending ? : null} {prefs.isError ? (

{t('common.error.generic')}

) : null} {prefs.data ? (
{/* Push shows itself only where it can work; Telegram is linked from the bot rather than here (FLOWS.md section 9: unconfigured channels stay hidden). */}
) : null}
{t('common.language')}
); }