import { NavLink } from "react-router-dom"; import { Icons, type IconName } from "./icons"; import { LogoWordmark } from "./Logo"; import { Avatar } from "./primitives"; import type { Session } from "../lib/types"; import { useSites, useUserKeys, useAdminApiKeys } from "../lib/queries"; import { useT } from "../lib/i18n"; import { useUiStore } from "../lib/store"; import { fmtInt } from "../lib/format"; type NavItem = { id: string; label: string; icon: IconName; to: string; count?: number; adminOnly?: boolean }; const SUPPORT_URL = "https://nowpayments.io/donation/airano"; export function Sidebar({ session }: { session: Session | undefined }) { const t = useT(); const collapsed = useUiStore((s) => s.sidebarCollapsed); const lang = useUiStore((s) => s.lang); const isAdmin = session?.is_admin ?? false; const isAdminKeySession = isAdmin && session?.type !== "oauth_user"; const sites = useSites(); const userKeys = useUserKeys(); const adminKeys = useAdminApiKeys(); // NavLink `to` props are relative to the BrowserRouter basename // (`/dashboard`) — do NOT prefix them or you'll get // `/dashboard/dashboard/...`. const groups: { label: string; items: NavItem[] }[] = [ { label: t("nav.manage", "Manage"), items: [ { id: "overview", label: t("nav.overview", "Overview"), icon: "home", to: "/overview" }, { id: "sites", label: t("nav.sites", "Sites"), icon: "sites", to: "/sites", count: sites.data?.length, }, { id: "connect", label: t("nav.connect", "Connect"), icon: "plug", to: "/connect" }, ], }, { label: t("nav.access", "Access"), items: [ { id: "apikeys", label: t("nav.api_keys", "API Keys"), icon: "key", to: "/api-keys", count: isAdminKeySession ? adminKeys.data?.length : userKeys.data?.length, }, ], }, ...(isAdmin ? [ { label: t("nav.observability", "Observability"), items: [ { id: "health", label: t("nav.health", "Health"), icon: "activity" as IconName, to: "/health", adminOnly: true, }, { id: "audit", label: t("nav.audit", "Audit Logs"), icon: "logs" as IconName, to: "/audit-logs", adminOnly: true, }, ], }, ] : []), { label: t("nav.account", "Account"), items: [ { id: "settings", label: t("nav.settings", "Settings"), icon: "settings", to: "/settings" }, ], }, ]; return ( ); }