"use client"; import React, { useEffect, useState } from "react"; import { SidebarNav } from "@app/components/SidebarNav"; import { OrgSelector } from "@app/components/OrgSelector"; import { cn } from "@app/lib/cn"; import { ListUserOrgsResponse } from "@server/routers/org"; import SupporterStatus from "@app/components/SupporterStatus"; import { ExternalLink, Server, BookOpenText } from "lucide-react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useUserContext } from "@app/hooks/useUserContext"; import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext"; import { useEnvContext } from "@app/hooks/useEnvContext"; import { useTranslations } from "next-intl"; import type { SidebarNavSection } from "@app/app/navigation"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@app/components/ui/tooltip"; interface LayoutSidebarProps { orgId?: string; orgs?: ListUserOrgsResponse["orgs"]; navItems: SidebarNavSection[]; defaultSidebarCollapsed: boolean; } export function LayoutSidebar({ orgId, orgs, navItems, defaultSidebarCollapsed }: LayoutSidebarProps) { const [isSidebarCollapsed, setIsSidebarCollapsed] = useState( defaultSidebarCollapsed ); const pathname = usePathname(); const isAdminPage = pathname?.startsWith("/admin"); const { user } = useUserContext(); const { isUnlocked } = useLicenseStatusContext(); const { env } = useEnvContext(); const t = useTranslations(); const setSidebarStateCookie = (collapsed: boolean) => { if (typeof window !== "undefined") { const isSecure = window.location.protocol === "https:"; document.cookie = `pangolin-sidebar-state=${collapsed ? "collapsed" : "expanded"}; path=/; max-age=${60 * 60 * 24 * 30}; samesite=lax${isSecure ? "; secure" : ""}`; } }; useEffect(() => { setSidebarStateCookie(isSidebarCollapsed); }, [isSidebarCollapsed]); return (
{isSidebarCollapsed ? t("sidebarExpand") : t("sidebarCollapse")}