Flows A1 to A6 and E3 end to end. A visitor types a RUC on the landing page, sees their real filing dates, registers, verifies a six digit code, grants consent, completes a three step setup and lands on the first run screen, with the profile, consent and audit rows to show for it. API: public RUC lookup behind a token bucket (10/min/IP), the full /me surface (profile, dependents, consents, notification prefs, data export, account deletion), an append-only audit module that exports an insert and nothing else, and a PII module that is the only thing allowed near those tables. Deletion and consent revocation both freeze the account and drop every session, reusing better-auth's ban flag rather than adding a second notion of disabled. Nothing is destroyed yet: the purge is a job for phase 4. deadlineDigit is always derived server side, never accepted from the client. Web: landing with the RUC hook, registration, OTP verification, consent, the setup wizard, the profile screen with "Tus datos", and legal pages that ship as marked placeholders per COPY.md section 13. Money, Skeleton, Switch and EmptyState components added. The seed is now complete for identity: Maria at 4123456-1, filing digit 6 and day 19, with a dependant, consents and prefs; Carlos as an IVA-only company. Two real defects found by building the screens and fixed with tests: the OTP boxes dropped a digit because the handler fired effects inside a setState updater that React 19 invokes twice, and the switch knob rendered outside its track because translate-x-5.5 does not resolve. 232 vitest tests, 26 Playwright tests across mobile and desktop, coverage still 100% on the rules, typecheck and lint clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
110 lines
3.9 KiB
TypeScript
110 lines
3.9 KiB
TypeScript
'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 { 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 (
|
|
<Card className="space-y-5">
|
|
<h2 className="font-semibold tracking-tight">{t('profile.notifications')}</h2>
|
|
|
|
{prefs.isPending ? <Skeleton name="doc-list-item" count={2} /> : null}
|
|
|
|
{prefs.isError ? (
|
|
<p role="alert" className="text-sm text-overdue">
|
|
{t('common.error.generic')}
|
|
</p>
|
|
) : null}
|
|
|
|
{prefs.data ? (
|
|
<div className="space-y-4">
|
|
<label className="flex items-center justify-between gap-4">
|
|
<span className="text-sm">{t('notif.email')}</span>
|
|
<Switch
|
|
checked={prefs.data.emailEnabled}
|
|
onCheckedChange={(emailEnabled) => update.mutate({ emailEnabled })}
|
|
label={t('notif.email')}
|
|
/>
|
|
</label>
|
|
|
|
<label className="flex items-center justify-between gap-4">
|
|
<span className="text-sm">{t('notif.digestHour')}</span>
|
|
<select
|
|
aria-label={t('notif.digestHour')}
|
|
value={prefs.data.digestHour}
|
|
onChange={(event) => update.mutate({ digestHour: Number(event.target.value) })}
|
|
className="tnum h-11 rounded-2xl border bg-[var(--surface-raised)] px-3"
|
|
>
|
|
{Array.from({ length: 24 }).map((_, hour) => {
|
|
// A clock time, not copy: the same in every locale.
|
|
const label = `${String(hour).padStart(2, '0')}:00`;
|
|
return (
|
|
<option key={hour} value={hour}>
|
|
{label}
|
|
</option>
|
|
);
|
|
})}
|
|
</select>
|
|
</label>
|
|
|
|
{/* Push and Telegram are hidden until they are configured (FLOWS.md section 9).
|
|
They are wired with the notification channels in phase 4. */}
|
|
</div>
|
|
) : null}
|
|
|
|
<div className="flex items-center justify-between gap-4 border-t pt-4">
|
|
<span className="text-sm">{t('common.language')}</span>
|
|
<select
|
|
aria-label={t('common.language')}
|
|
value={profile.locale}
|
|
disabled={setLocale.isPending}
|
|
onChange={(event) => setLocale.mutate(event.target.value as Locale)}
|
|
className="h-11 rounded-2xl border bg-[var(--surface-raised)] px-3"
|
|
>
|
|
{SUPPORTED_LOCALES.map((code) => (
|
|
<option key={code} value={code}>
|
|
{t(LABEL_KEY[code])}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</Card>
|
|
);
|
|
}
|