2026-10-16 07:40:29 -06:00
|
|
|
import { useNavigate } from "react-router";
|
2026-10-16 22:46:56 -06:00
|
|
|
import { rememberScreen, SCREEN_LABELS, type Screen } from "../auth/roles";
|
2026-10-16 07:40:29 -06:00
|
|
|
|
|
|
|
|
interface RoleSwitcherProps {
|
|
|
|
|
screens: readonly Screen[];
|
|
|
|
|
active: Screen | null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-16 22:46:56 -06:00
|
|
|
/** One button per screen the user has. Drawn only when there is more than one. The pick is remembered for the next landing. */
|
2026-10-16 07:40:29 -06:00
|
|
|
export function RoleSwitcher({ screens, active }: RoleSwitcherProps) {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
if (screens.length < 2) return null;
|
|
|
|
|
return (
|
|
|
|
|
<nav className="roles" aria-label="Screens">
|
|
|
|
|
{screens.map((s) => (
|
2026-10-16 22:46:56 -06:00
|
|
|
<button
|
|
|
|
|
key={s}
|
|
|
|
|
type="button"
|
|
|
|
|
aria-pressed={active === s}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
rememberScreen(s);
|
|
|
|
|
navigate(`/${s}`);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-10-16 07:40:29 -06:00
|
|
|
{SCREEN_LABELS[s]}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</nav>
|
|
|
|
|
);
|
|
|
|
|
}
|