"use client"; import { Building2, Check, ChevronsUpDown, LogOut, Moon, Plus, Search, Settings as SettingsIcon, Sun, } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useTheme } from "next-themes"; import { useState } from "react"; import { useCommandPalette } from "@/components/command-palette"; import { CreateClinicForm } from "@/components/clinic/create-clinic-form"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Dialog, DialogDescription, DialogHeader, DialogPanel, DialogPopup, DialogTitle, } from "@/components/ui/dialog"; import { Kbd, KbdGroup } from "@/components/ui/kbd"; import { Menu, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuSub, MenuSubPopup, MenuSubTrigger, MenuTrigger, } from "@/components/ui/menu"; import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar, } from "@/components/ui/sidebar"; import { authClient } from "@/lib/auth-client"; import { notify } from "@/lib/toast"; // Open-source repo (placeholder). const REPO_URL = "https://github.com/temetro/temetro"; function initialsFromName(name: string): string { const letters = name .split(/\s+/) .map((w) => w[0]) .filter(Boolean) .join("") .slice(0, 2); return (letters || "?").toUpperCase(); } function GitHubIcon({ className }: { className?: string }) { return ( ); } // The sidebar's single footer row. Its menu also hosts the command-palette // shortcut hint (below Theme) and a clinic switcher submenu (below that) whose // popup reveals the active clinic's details on hover. export function NavUser() { const { isMobile, state } = useSidebar(); const isCollapsed = state === "collapsed"; const router = useRouter(); const { resolvedTheme, setTheme } = useTheme(); const isDark = resolvedTheme === "dark"; const { data } = authClient.useSession(); const { open: openCommand } = useCommandPalette(); const { data: orgs } = authClient.useListOrganizations(); const { data: activeOrg } = authClient.useActiveOrganization(); const [createOpen, setCreateOpen] = useState(false); const name = data?.user?.name ?? "Clinician"; const email = data?.user?.email ?? ""; const initials = initialsFromName(name); const activeName = activeOrg?.name ?? "Select clinic"; const setActive = async (organizationId: string) => { if (organizationId === activeOrg?.id) return; await authClient.organization.setActive({ organizationId }); }; const signOut = async () => { const { error } = await authClient.signOut(); if (error) { notify.error("Sign out failed", error.message ?? "Please try again."); return; } notify.success("Signed out"); router.push("/login"); }; return ( } > {initials} {!isCollapsed && ( <> {name} {email} > )} {initials} {name} {email} }> Settings } > Docs & GitHub setTheme(isDark ? "light" : "dark")} > {isDark ? : } Theme {isDark ? "Dark" : "Light"} {/* Command palette: hint + shortcut, sits below Theme. */} Search ⌘ K {/* Clinic switcher: hover reveals the active clinic's details. */} {activeName} {activeOrg?.name ?? "No clinic selected"} {activeOrg?.slug ? `/${activeOrg.slug}` : "—"} ·{" "} {orgs?.length ?? 0}{" "} {orgs?.length === 1 ? "clinic" : "clinics"} Switch clinic {(orgs ?? []).map((org) => ( setActive(org.id)} > {org.name} {org.id === activeOrg?.id && } ))} setCreateOpen(true)}> Create clinic Log out {/* Create a new clinic */} Create clinic Add a new clinic and switch to it. setCreateOpen(false)} /> ); }
{activeOrg?.name ?? "No clinic selected"}
{activeOrg?.slug ? `/${activeOrg.slug}` : "—"} ·{" "} {orgs?.length ?? 0}{" "} {orgs?.length === 1 ? "clinic" : "clinics"}