import { isApiError } from '@impuestos/contracts'; import type { Locale } from '@impuestos/i18n'; import { setRequestLocale } from 'next-intl/server'; import { redirect } from '@/i18n/navigation'; import { serverApi } from '@/lib/api-server'; import { Dashboard } from './dashboard'; /** * Flow C. The profile is fetched server side so an unfinished setup redirects before * anything renders; the position itself loads on the client, where TanStack Query keeps it * fresh as documents are confirmed. */ export default async function InicioPage({ params }: { params: Promise<{ locale: string }> }) { const { locale } = await params; setRequestLocale(locale); const api = await serverApi(); const profile = await api.getProfile().catch((error: unknown) => { if (!isApiError(error)) throw error; if (error.code === 'not_found') return null; if (error.code === 'unauthorized') redirect({ href: '/login', locale }); throw error; }); // No profile means setup was never finished, so send them there rather than showing an // empty shell they cannot act on. if (!profile) redirect({ href: '/configuracion', locale }); return ; }