// * Packages import { Link, usePage } from "@inertiajs/react"; import { useEffect, useRef } from "react"; import { ChevronDown, MoreHorizontal, Home, Users, SquareArrowOutUpRight, Telescope } from "lucide-react"; // * Components shadcn import { Sidebar, SidebarHeader, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarFooter, SidebarMenuAction, useSidebar } from "@/components/ui/sidebar"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "@/components/ui/collapsible"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { Button } from "@/components/ui/button"; // * Other import ApplicationLogo from "@/back/Components/ApplicationLogo"; import { checkConceptor, Views } from "@/lib/utils"; import str from "@/hooks/use-string"; import trans from "@/hooks/use-translations"; import { AuthProp } from "@/back/types/global"; export function AppSidebar() { const appMode = import.meta.env.VITE_MODE const { state } = useSidebar(); const prevStateRef = useRef(state); const isCollapsed = state === "collapsed"; const auth = usePage().props.auth as AuthProp; const navList = [ { title: trans("back.pages"), show: true, links: [ { title: trans("back.dashboard"), model: "dashboard", show: true, icon: Home, actions: [], }, { title: trans("back.your_website"), link: route("front.homepage"), show: true, icon: SquareArrowOutUpRight, actions: [], }, ], }, { title: trans("back.administration"), show: checkConceptor(), links: [ { title: str(trans("models.classes.user")).ucFirst().plural().value(), model: "users", icon: Users, show: auth.policies.users['viewAny'], actions: [Views.CREATION], }, { title: trans("back.telescope"), link: route("telescope"), icon: Telescope, show: appMode === "local", actions: [], }, ], }, ]; useEffect(() => { if (prevStateRef.current !== state) { const elmts = document.querySelectorAll(".sidebar-transition"); elmts.forEach((element) => { element.classList.add("animation-transition"); setTimeout(() => { element.classList.remove("animation-transition"); }, 400); }); prevStateRef.current = state; } }, [state]); return ( {navList.map((navGroup, navGroupIndex) => navGroup.show && ( {!isCollapsed && ( {navGroup.title} )} {navGroup.links.map((navLink, navLinkIndex) => { const sidebarButton = ( {navLink.link ? ( {navLink.title} ) : ( {navLink.title} )} ); return navLink.show && ( {isCollapsed ? ( {sidebarButton}

{navLink.title}

) : (sidebarButton)} {navLink.actions.length > 0 && ( {navLink.actions.map((action, actionIndex) => auth.policies.users[action.policy] && ( ))} )}
); })}
))}
); }