All files / src/components PersonaFromQuery.tsx

0% Statements 0/12
0% Branches 0/8
0% Functions 0/4
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
"use client";
 
/**
 * Applies `?persona=<personaId>` on any page, not just /graph.
 *
 * The static export has no session, so a role-filtered view comes from the
 * persona in sessionStorage, which until now could only be set by clicking a
 * card on /demo. That makes a deep link into the middle of a journey useless:
 * open `/negotiate` cold and you get the signed-out view, so a demo script has
 * to begin every step with "first go to /demo and click Researcher".
 *
 * Mounted in the root layout, so one link per step is enough:
 *
 *     /negotiate?persona=researcher
 *     /compliance?persona=hdab
 *
 * Accepts a personaId ("researcher", "hdab", "hospital", "edc-admin",
 * "patient") or a username ("regulator", "clinicuser"), because the demo
 * script and the credentials table use different ones and a reader copying
 * either should not land on a silently wrong view.
 */
 
import { useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { DEMO_PERSONAS } from "@/lib/auth";
import { setDemoPersona } from "@/lib/use-demo-persona";
import { IS_STATIC } from "@/lib/static-export";
 
export default function PersonaFromQuery() {
  const searchParams = useSearchParams();
  const requested = searchParams.get("persona");
 
  useEffect(() => {
    if (!IS_STATIC || !requested) return;
    const match =
      DEMO_PERSONAS.find((p) => p.personaId === requested) ??
      DEMO_PERSONAS.find((p) => p.username === requested);
    if (match) setDemoPersona(match.username);
  }, [requested]);
 
  return null;
}