// This file is part of Shadcn Admin Kit (https://github.com/marmelab/shadcn-admin-kit) import { createElement } from "react"; import { useCanAccess, useCreatePath, useGetResourceLabel, useHasDashboard, useResourceDefinitions, useTranslate, } from "ra-core"; import { Link, useMatch } from "react-router"; import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar, } from "@/components/ui/sidebar"; import { Skeleton } from "@/components/ui/skeleton"; import { House, List, Shell } from "lucide-react"; export function AppSidebar() { const hasDashboard = useHasDashboard(); const resources = useResourceDefinitions(); const { openMobile, setOpenMobile } = useSidebar(); const handleClick = () => { if (openMobile) { setOpenMobile(false); } }; return ( Acme Inc. {hasDashboard ? ( ) : null} {Object.keys(resources) .filter((name) => resources[name].hasList) .map((name) => ( ))} ); } export const DashboardMenuItem = ({ onClick }: { onClick?: () => void }) => { const translate = useTranslate(); const label = translate("ra.page.dashboard", { _: "Dashboard", }); const match = useMatch({ path: "/", end: true }); return ( {label} ); }; export const ResourceMenuItem = ({ name, onClick, }: { name: string; onClick?: () => void; }) => { const { canAccess, isPending } = useCanAccess({ resource: name, action: "list", }); const resources = useResourceDefinitions(); const getResourceLabel = useGetResourceLabel(); const createPath = useCreatePath(); const to = createPath({ resource: name, type: "list", }); const match = useMatch({ path: to, end: false }); if (isPending) { return ; } if (!resources || !resources[name] || !canAccess) return null; return ( {resources[name].icon ? ( createElement(resources[name].icon) ) : ( )} {getResourceLabel(name, 2)} ); };