/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /components/sidebar.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import Link from "next/link"; import Image from "next/image"; import { usePathname, useRouter } from "next/navigation"; import { MessageSquare, Grid3X3, Server, Users, User, Shield, LogOut, ChevronUp, ChevronDown, AlertCircle, FileText, ExternalLink, ChevronsLeft, ChevronsRight, Menu, } from "lucide-react"; import { cn } from "@/lib/utils"; import { useEffect, useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; export default function Sidebar() { const pathname = usePathname(); const router = useRouter(); const [isAdmin, setIsAdmin] = useState(false); const [userMenuOpen, setUserMenuOpen] = useState(false); const [logoutDialogOpen, setLogoutDialogOpen] = useState(false); const [isCollapsed, setIsCollapsed] = useState(false); useEffect(() => { if (typeof window !== "undefined") { const user = localStorage.getItem("user"); if (user) { try { const parsed = JSON.parse(user); setIsAdmin(!!parsed.is_admin); } catch {} } // Get saved sidebar state from localStorage const savedCollapsedState = localStorage.getItem("sidebar-collapsed"); if (savedCollapsedState) { setIsCollapsed(savedCollapsedState === "true"); } } }, []); // Save collapsed state to localStorage when it changes useEffect(() => { if (typeof window !== "undefined") { localStorage.setItem("sidebar-collapsed", String(isCollapsed)); } }, [isCollapsed]); const menuItems = [ ...(!isAdmin ? [ { name: "Agents", href: "/agents", icon: Grid3X3, }, { name: "Chat", href: "/chat", icon: MessageSquare, }, { name: "Documentation", href: "/documentation", icon: FileText, }, ] : []), ...(isAdmin ? [ { name: "MCP Servers", href: "/mcp-servers", icon: Server, }, { name: "Clients", href: "/clients", icon: Users, }, { name: "Documentation", href: "/documentation", icon: FileText, }, ] : []), ]; const userMenuItems = [ { name: "Profile", href: "/profile", icon: User, onClick: () => {} }, { name: "Security", href: "/security", icon: Shield, onClick: () => {} }, { name: "Logout", href: "#", icon: LogOut, onClick: (e: React.MouseEvent) => { e.preventDefault() setLogoutDialogOpen(true) setUserMenuOpen(false) } }, ]; const handleLogout = () => { setLogoutDialogOpen(false) router.push("/logout") } const toggleSidebar = () => { setIsCollapsed(!isCollapsed); }; return (
{isCollapsed ? (
Evolution API
) : ( Evolution API )} {isCollapsed ? "Expand Sidebar" : "Collapse Sidebar"}
{isCollapsed && ( My Account )} {userMenuOpen && !isCollapsed && (
{userMenuItems.map((item) => { const isActive = pathname === item.href; return ( {item.name} ); })}
)}
{!isCollapsed && ( <>
Evo AI
© {new Date().getFullYear()} Evolution API
)}
Confirmation of Logout
Are you sure you want to logout?
); }