// * Packages import { Link, usePage } from "@inertiajs/react"; import { useEffect, useRef } from "react"; import { ChevronDown, MoreHorizontal, Home, Users, SquareArrowOutUpRight, Telescope, } from "lucide-react"; import { route } from "ziggy-js"; // * Components shadcn import { Sidebar, SidebarHeader, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem, 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 { Views } from "@/lib/utils"; import str from "@/hooks/use-string"; import useTrans from "@/hooks/use-translations"; import { AppEnv, AuthProp } from "@/back/types/global"; export default function AppSidebar() { const appMode = (usePage().props.appEnv as AppEnv).mode; const { state } = useSidebar(); const prevStateRef = useRef(state); const isCollapsed = state === "collapsed"; const auth = usePage().props.auth as AuthProp; const navList = [ { title: useTrans("back.pages"), show: true, links: [ { title: useTrans("back.dashboard"), model: "dashboard", show: true, icon: Home, actions: [], }, { title: useTrans("back.your_website"), link: route("front.homepage"), show: true, icon: SquareArrowOutUpRight, actions: [], }, ], }, { title: useTrans("back.administration"), show: auth.user.role === 1, links: [ { title: str(useTrans("models.classes.user")) .ucFirst() .plural() .value(), model: "users", icon: Users, show: auth.policies.users.viewAny, actions: [Views.CREATION], }, { title: useTrans("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]); const GetTranslation = (label: string) => { return useTrans(`crud.actions.${label}`); }; return ( {navList.map( (navGroup) => navGroup.show && ( {!isCollapsed && ( {navGroup.title} )} {navGroup.links.map( (navLink) => { const sidebarButton = ( {navLink.link ? ( { navLink.title } ) : ( { navLink.title } )} ); return ( navLink.show && ( {isCollapsed ? ( { sidebarButton }

{ navLink.title }

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