Files
HealthLog/src/hooks/use-nav-modules.ts
T
Marc-André Bombeck 61d912627d feat(coach): follow the coach capability at every entry point
The floating button, the drawer, the launch pills, the nav entry and the
Coach pages read the coach capability from /api/auth/me instead of
combining the operator switch with Hide Coach on their own. A missing
provider or consent now hides the Coach too, instead of opening one that
can only answer with an error.

Stored conversations stay reachable: while the Coach is unavailable the
conversation list turns read-only, opens a transcript in place and keeps
delete. Refusals before the stream opens are read by meta.errorCode and
each code has its own copy.
2026-09-24 11:05:38 +02:00

33 lines
1.1 KiB
TypeScript

"use client";
import { useMemo } from "react";
import { useAiCapability } from "@/hooks/use-ai-capability";
import { useAuth } from "@/hooks/use-auth";
import type { SurfaceModuleMap } from "@/lib/modules/surface";
/**
* The module map the navigation filters by, with the Coach entry following
* the `coach` AI capability.
*
* `modules.coach` answers the operator's switch and the person's Hide Coach,
* but not a missing provider or missing consent, so on its own it would keep
* a Coach entry in the nav that opens a Coach unable to answer. The
* capability answers all of them, and every other Coach entry point (the
* floating button, the launch buttons, the Coach pages) already reads it.
* The sidebar and the bottom bar both take their map from here so the two
* cannot disagree.
*/
export function useNavModules(): SurfaceModuleMap | undefined {
const { user } = useAuth();
const coach = useAiCapability("coach");
const modules = user?.modules;
return useMemo(
() =>
modules === undefined
? undefined
: { ...modules, coach: modules.coach !== false && coach.available },
[modules, coach.available],
);
}