"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, Zap, CreditCard, FileText, TicketCheck } from "lucide-react"; import { FaDiscord, FaGithub } from "react-icons/fa"; 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"; import { build } from "@server/build"; import SidebarLicenseButton from "./SidebarLicenseButton"; import { SidebarSupportButton } from "./SidebarSupportButton"; import ProductUpdates from "./ProductUpdates"; 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]); function loadFooterLinks(): { text: string; href?: string }[] | undefined { if (!isUnlocked()) { return undefined; } if (env.branding.footer) { try { return JSON.parse(env.branding.footer); } catch (e) { console.error("Failed to parse BRANDING_FOOTER", e); } } } return (
{!isAdminPage && user.serverAdmin && (
{!isSidebarCollapsed && ( {t("serverAdmin")} )}
)}
{build === "enterprise" && (
)} {build === "oss" && (
)} {build === "saas" && (
)} {!isSidebarCollapsed && (
{loadFooterLinks() ? ( <> {loadFooterLinks()!.map((link, index) => (
{link.href ? (
{link.text}
) : (
{link.text}
)}
))} ) : ( <>
{build === "oss" ? t("communityEdition") : build === "enterprise" ? t("enterpriseEdition") : "Pangolin Cloud"}
{env?.app?.version && (
v{env.app.version}
)} )}
)}
{/* Collapse button */}

{isSidebarCollapsed ? t("sidebarExpand") : t("sidebarCollapse")}

); } export default LayoutSidebar;