import { Avatar, Button, DropdownMenu, directional, Text, Tooltip } from "@cloudhal/ui"; import { SignOut, SquaresFour, Translate, UserGear, UsersThree } from "@phosphor-icons/react"; import { useNavigate } from "@tanstack/react-router"; import { LOCALE_LIST, LOCALES, type Locale, useI18n } from "../i18n/index.tsx"; import { authClient } from "../lib/auth.ts"; import { initials } from "../lib/initials.ts"; import { useThemePreference } from "../lib/theme.ts"; import { RoleBadge } from "./Roles.tsx"; import { ThemeRadioItems, themeIcon } from "./ThemeSwitch.tsx"; import { useMe } from "./useMe.ts"; import { usePlayground } from "./usePlayground.ts"; /** * The signed-in person's menu, at the right end of the top bar (DESIGN.md §1): an avatar button * like Kumo's account demos, so it is there whether the sidebar is expanded, collapsed or a * sheet. It names who is signed in and their staff role (RFC-0005 §10.3), leads to Account, Team * and All sites, carries Theme and Language (the top bar hides those on phones) and signs out. */ export function UserMenu() { const { t, locale, setLocale } = useI18n(); const navigate = useNavigate(); const [theme] = useThemePreference(); const me = useMe(); // RFC-0036 §5: a playground has no account, team or sign-out. const people = !usePlayground(); const name = me.data?.actor.name ?? t("nav.account"); const role = me.data?.role ?? undefined; const signOut = async () => { await authClient.signOut(); await navigate({ to: "/login" }); }; return ( } /> } />
{name} {role && }
{people && ( navigate({ to: "/account" })}> {t("nav.account")} )} {people && ( navigate({ to: "/team" })}> {t("nav.team")} )} navigate({ to: "/sites" })}> {t("nav.allSites")} {t("theme.label")} {t("common.language")} setLocale(v)}> {LOCALE_LIST.map((l) => ( {LOCALES[l]} ))} {people && } {people && ( {t("common.signOut")} )}
); }