Add groups to sidebar
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
ShoppingBag,
|
ShoppingBag,
|
||||||
Truck,
|
Truck,
|
||||||
MessageCircle,
|
MessageCircle,
|
||||||
|
LayoutDashboard,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { IconCrystalBall } from "@tabler/icons-react";
|
import { IconCrystalBall } from "@tabler/icons-react";
|
||||||
import {
|
import {
|
||||||
@@ -17,6 +18,7 @@ import {
|
|||||||
SidebarContent,
|
SidebarContent,
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupContent,
|
SidebarGroupContent,
|
||||||
|
SidebarGroupLabel,
|
||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
SidebarFooter,
|
SidebarFooter,
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
@@ -28,12 +30,21 @@ import {
|
|||||||
import { useLocation, useNavigate, Link } from "react-router-dom";
|
import { useLocation, useNavigate, Link } from "react-router-dom";
|
||||||
import { Protected } from "@/components/auth/Protected";
|
import { Protected } from "@/components/auth/Protected";
|
||||||
|
|
||||||
const items = [
|
const dashboardItems = [
|
||||||
|
{
|
||||||
|
title: "Dashboard",
|
||||||
|
icon: LayoutDashboard,
|
||||||
|
url: "",
|
||||||
|
permission: "access:dashboard"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const inventoryItems = [
|
||||||
{
|
{
|
||||||
title: "Overview",
|
title: "Overview",
|
||||||
icon: Home,
|
icon: Home,
|
||||||
url: "/",
|
url: "/",
|
||||||
permission: "access:dashboard"
|
permission: "access:overview"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Products",
|
title: "Products",
|
||||||
@@ -76,15 +87,21 @@ const items = [
|
|||||||
icon: IconCrystalBall,
|
icon: IconCrystalBall,
|
||||||
url: "/forecasting",
|
url: "/forecasting",
|
||||||
permission: "access:forecasting"
|
permission: "access:forecasting"
|
||||||
},
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const productSetupItems = [
|
||||||
{
|
{
|
||||||
title: "Create Products",
|
title: "Create Products",
|
||||||
icon: Plus,
|
icon: Plus,
|
||||||
url: "/import",
|
url: "/import",
|
||||||
permission: "access:import"
|
permission: "access:import"
|
||||||
},
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const chatItems = [
|
||||||
{
|
{
|
||||||
title: "Chat",
|
title: "Chat Archive",
|
||||||
icon: MessageCircle,
|
icon: MessageCircle,
|
||||||
url: "/chat",
|
url: "/chat",
|
||||||
permission: "access:chat"
|
permission: "access:chat"
|
||||||
@@ -102,6 +119,46 @@ export function AppSidebar() {
|
|||||||
navigate('/login');
|
navigate('/login');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderMenuItems = (items: typeof inventoryItems) => {
|
||||||
|
return items.map((item) => {
|
||||||
|
const isActive =
|
||||||
|
location.pathname === item.url ||
|
||||||
|
(item.url !== "/" && item.url !== "#" && location.pathname.startsWith(item.url));
|
||||||
|
return (
|
||||||
|
<Protected
|
||||||
|
key={item.title}
|
||||||
|
permission={item.permission}
|
||||||
|
fallback={null}
|
||||||
|
>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild={item.url !== "#"}
|
||||||
|
tooltip={item.title}
|
||||||
|
isActive={isActive}
|
||||||
|
disabled={item.url === "#"}
|
||||||
|
>
|
||||||
|
{item.url === "#" ? (
|
||||||
|
<div>
|
||||||
|
<item.icon className="h-4 w-4" />
|
||||||
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<Link to={item.url}>
|
||||||
|
<item.icon className="h-4 w-4" />
|
||||||
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</Protected>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible="icon" variant="sidebar">
|
<Sidebar collapsible="icon" variant="sidebar">
|
||||||
<SidebarHeader>
|
<SidebarHeader>
|
||||||
@@ -122,42 +179,53 @@ export function AppSidebar() {
|
|||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarSeparator />
|
<SidebarSeparator />
|
||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
|
{/* Dashboard Section */}
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Dashboard</SidebarGroupLabel>
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{items.map((item) => {
|
{renderMenuItems(dashboardItems)}
|
||||||
const isActive =
|
</SidebarMenu>
|
||||||
location.pathname === item.url ||
|
</SidebarGroupContent>
|
||||||
(item.url !== "/" && location.pathname.startsWith(item.url));
|
</SidebarGroup>
|
||||||
return (
|
|
||||||
<Protected
|
|
||||||
key={item.title}
|
{/* Inventory Section */}
|
||||||
permission={item.permission}
|
<SidebarGroup>
|
||||||
fallback={null}
|
<SidebarGroupLabel>Inventory</SidebarGroupLabel>
|
||||||
>
|
<SidebarGroupContent>
|
||||||
<SidebarMenuItem>
|
<SidebarMenu>
|
||||||
<SidebarMenuButton
|
{renderMenuItems(inventoryItems)}
|
||||||
asChild
|
</SidebarMenu>
|
||||||
tooltip={item.title}
|
</SidebarGroupContent>
|
||||||
isActive={isActive}
|
</SidebarGroup>
|
||||||
>
|
|
||||||
<Link to={item.url}>
|
|
||||||
<item.icon className="h-4 w-4" />
|
{/* Product Setup Section */}
|
||||||
<span className="group-data-[collapsible=icon]:hidden">
|
<SidebarGroup>
|
||||||
{item.title}
|
<SidebarGroupLabel>Product Setup</SidebarGroupLabel>
|
||||||
</span>
|
<SidebarGroupContent>
|
||||||
</Link>
|
<SidebarMenu>
|
||||||
</SidebarMenuButton>
|
{renderMenuItems(productSetupItems)}
|
||||||
</SidebarMenuItem>
|
</SidebarMenu>
|
||||||
</Protected>
|
</SidebarGroupContent>
|
||||||
);
|
</SidebarGroup>
|
||||||
})}
|
|
||||||
|
|
||||||
|
{/* Chat Section */}
|
||||||
|
<SidebarGroup>
|
||||||
|
<SidebarGroupLabel>Chat</SidebarGroupLabel>
|
||||||
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
{renderMenuItems(chatItems)}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroupContent>
|
</SidebarGroupContent>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
<SidebarSeparator />
|
<SidebarSeparator />
|
||||||
|
|
||||||
|
{/* Settings Section */}
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
|
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
<Protected
|
<Protected
|
||||||
|
|||||||
Reference in New Issue
Block a user