From 11b6119482d25ddddf4ba7731b8f8fcbb205494f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 5 Oct 2026 17:51:32 +0200 Subject: [PATCH] refactor(shell): return the switched-off module instead of a flag The flag helper sat between the module gate's doc comment and the component, so the comment read as its own. It is now switchedOffModule(), which returns the owning module when it is off and has a doc comment of its own above the gate's; the gate narrows on its result directly instead of looking the module up twice. --- src/components/layout/auth-shell.tsx | 4 +-- src/components/layout/module-page-gate.tsx | 30 ++++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/components/layout/auth-shell.tsx b/src/components/layout/auth-shell.tsx index f03f531e4..f6159f081 100644 --- a/src/components/layout/auth-shell.tsx +++ b/src/components/layout/auth-shell.tsx @@ -28,8 +28,8 @@ import { OfflineBanner } from "./offline-banner"; import { SharedRecordBanner } from "./shared-record-banner"; import { SharedRecordUnavailable } from "./shared-record-unavailable"; import { - isModulePageOff, ModulePageGate, + switchedOffModule, } from "@/components/layout/module-page-gate"; import { cn } from "@/lib/utils"; import { isOnboardingPathname } from "@/lib/onboarding/wizard-steps"; @@ -158,7 +158,7 @@ export function AuthShell({ const fullBleed = pathname === COACH_FULL_BLEED_PATH && !outsideSharedRecord && - !isModulePageOff(pathname, user?.modules); + switchedOffModule(pathname, user?.modules) === undefined; // The whole setup flow, not only its front door: every screen lives under // `/onboarding/` (v1.39 C2), and an exact match here put the // questions inside the full app chrome, sidebar and all. diff --git a/src/components/layout/module-page-gate.tsx b/src/components/layout/module-page-gate.tsx index 6d75d4efd..db0a8d35e 100644 --- a/src/components/layout/module-page-gate.tsx +++ b/src/components/layout/module-page-gate.tsx @@ -56,6 +56,21 @@ export function moduleOwningPath(pathname: string): ModuleKey | undefined { return destination ? navDestinationModule(destination) : undefined; } +/** + * The module that owns `pathname` when it is switched off, otherwise + * undefined. The shell reads it too: a switched-off page renders the + * notice in the ordinary padded frame. + */ +export function switchedOffModule( + pathname: string, + modules: Partial> | null | undefined, +): ModuleKey | undefined { + const moduleKey = moduleOwningPath(pathname); + return moduleKey !== undefined && modules?.[moduleKey] === false + ? moduleKey + : undefined; +} + /** * A page of a module that is switched off answers with an inline notice that * names the reason, in one place for every module page: top-level pages @@ -74,24 +89,13 @@ export function moduleOwningPath(pathname: string): ModuleKey | undefined { * only after the account payload resolved, so the map is never read on a * hydration render. */ -/** True when the module that owns `pathname` is switched off. */ -export function isModulePageOff( - pathname: string, - modules: Partial> | null | undefined, -): boolean { - const moduleKey = moduleOwningPath(pathname); - return moduleKey !== undefined && modules?.[moduleKey] === false; -} - export function ModulePageGate({ children }: { children: ReactNode }) { const pathname = usePathname(); const { user } = useAuth(); const { t } = useTranslations(); - const moduleKey = moduleOwningPath(pathname); - if (moduleKey === undefined || !isModulePageOff(pathname, user?.modules)) { - return <>{children}; - } + const moduleKey = switchedOffModule(pathname, user?.modules); + if (moduleKey === undefined) return <>{children}; const destination = NAV_DESTINATIONS.find((d) => isNavDestinationActive(d.href, pathname),