Files
HealthLog/src/app/onboarding/page.tsx
T
Marc-André Bombeck 1c2e7c29de Add the setup flow's welcome screen and shell
The front door reads the same ledger every screen reads: a record that
never entered the flow sees the welcome, one mid-way is sent to the step
it owes, a finished one is offered the questions again. The shell prints
the counter and an ordered step list off the step machine, so it shows
exactly the screens this flow has, and every screen moves focus to its
heading on arrival.

"Skip for now" is a real exit — it stamps the account past the first-run
redirect and opens the checklist on the dashboard — and the one-time
medical disclaimer now gates it as well as "Set up", because a skip that
reached the dashboard without it would be a way round the acknowledgment.

The five-step wizard's welcome carousel, goal picker and source grid go
with it; the numbered step route follows in the next commit.
2026-09-10 15:10:50 +02:00

50 lines
1.8 KiB
TypeScript

import { redirect } from "next/navigation";
import { OnboardingShell } from "@/components/onboarding/onboarding-shell";
import { WelcomeScreen } from "@/components/onboarding/welcome-screen";
import { loadOnboardingFlowState } from "@/lib/onboarding/load-flow-state";
import { isOnboardingSettled } from "@/lib/onboarding/needs";
import { resumeScreen } from "@/lib/onboarding/wizard-steps";
/**
* v1.39 (C2) — the setup flow's front door.
*
* The proxy lands every account still pending its first run here, and
* Settings → "Set up again" does too. What is shown depends on where the
* flow stands, read off the same ledger every screen reads:
*
* - never entered → the welcome screen ("Set up" / "Skip for now")
* - a step still owed → redirect to that step
* - finished → the welcome screen's "again" variant, which
* offers the questions once more or the dashboard
*
* No session mirrors the proxy's own gate (`/onboarding` is a public path,
* so the page has to say it too).
*/
export default async function OnboardingRootPage() {
const flow = await loadOnboardingFlowState();
if (!flow) {
redirect("/auth/login");
}
const { state, userLocale } = flow;
const resume = resumeScreen(state);
if (resume !== "welcome") {
const finished = state.completedAt !== null && isOnboardingSettled(state);
if (!finished) {
redirect(`/onboarding/${resume}`);
}
return (
<OnboardingShell screen="welcome" state={state} userLocale={userLocale}>
<WelcomeScreen variant="again" />
</OnboardingShell>
);
}
return (
<OnboardingShell screen="welcome" state={state} userLocale={userLocale}>
<WelcomeScreen variant="fresh" />
</OnboardingShell>
);
}