"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import { logout } from "@/app/auth-actions"; type Props = { username: string }; export default function Nav({ username }: Props) { const pathname = usePathname() ?? "/"; const isPasskeys = pathname.startsWith("/cm-passkeys"); const isUsers = pathname.startsWith("/users"); const isAccounts = !isUsers && !isPasskeys; const initial = (username[0] ?? "?").toUpperCase(); return (
CM CM Bot V2 Account dashboard
); } function NavLink({ href, active, children, }: { href: string; active: boolean; children: React.ReactNode; }) { return ( {children} ); } function AccountMenu({ username, initial, }: { username: string; initial: string; }) { const [open, setOpen] = useState(false); const wrapperRef = useRef(null); useEffect(() => { if (!open) return; function onPointerDown(e: PointerEvent) { if (!wrapperRef.current) return; if (!wrapperRef.current.contains(e.target as Node)) setOpen(false); } function onKey(e: KeyboardEvent) { if (e.key === "Escape") setOpen(false); } document.addEventListener("pointerdown", onPointerDown); document.addEventListener("keydown", onKey); return () => { document.removeEventListener("pointerdown", onPointerDown); document.removeEventListener("keydown", onKey); }; }, [open]); return (
{open && (
{username}
setOpen(false)} className="block px-3 py-2 text-xs text-zinc-700 transition-colors hover:bg-zinc-50 hover:text-zinc-900" > Passkey settings
)}
); }