"use client"; import { useRef, useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { GitBranch, LayoutDashboard, LogOut, Settings, ShieldCheck, Sparkles, UserRound, } from "lucide-react"; import { Popover } from "@/components/ui/Popover"; import type { SessionUser } from "@/lib/auth/session"; import { cn } from "@/lib/utils"; const LINKS = [ { href: "/", label: "Dashboard", icon: LayoutDashboard }, { href: "/connections", label: "Git-Verbindungen", icon: GitBranch }, ]; export function TopNav({ user, appName, tagline, }: { user: SessionUser | null; appName: string; tagline: string; }) { const pathname = usePathname(); return ( {appName} {tagline} {user ? ( <> {LINKS.map(({ href, label, icon: Icon }) => { const active = href === "/" ? pathname === "/" : pathname.startsWith(href); return ( {label} ); })} > ) : null} ); } function UserMenu({ user }: { user: SessionUser }) { const router = useRouter(); const [open, setOpen] = useState(false); const [busy, setBusy] = useState(false); const triggerRef = useRef(null); async function logout() { setBusy(true); await fetch("/api/auth/logout", { method: "POST" }).catch(() => undefined); setOpen(false); router.replace("/login"); router.refresh(); } const label = user.displayName?.trim() || user.username; const initials = label.slice(0, 2).toUpperCase(); return ( <> setOpen((value) => !value)} className="flex items-center gap-2 rounded-xl border border-white/10 bg-white/4 py-1.5 pl-1.5 pr-3 text-sm text-slate-200 transition-colors hover:bg-white/8" aria-haspopup="menu" aria-expanded={open} > {initials} {label} {user.role === "ADMIN" ? ( ) : null} setOpen(false)} width={240}> {label} @{user.username} {user.role === "ADMIN" ? " ยท Administrator" : ""} setOpen(false)} className="mt-1 flex items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-slate-300 transition-colors hover:bg-white/6 hover:text-white" > Mein Konto {user.role === "ADMIN" ? ( setOpen(false)} className="flex items-center gap-2.5 rounded-lg px-3 py-2 text-sm text-slate-300 transition-colors hover:bg-white/6 hover:text-white" > Admin-Einstellungen ) : null} Abmelden > ); }
{label}
@{user.username} {user.role === "ADMIN" ? " ยท Administrator" : ""}