Add logout button
This commit is contained in:
@@ -1,16 +1,26 @@
|
|||||||
import { Home, Package, ShoppingCart, BarChart2, Settings, Box, ClipboardList } from "lucide-react";
|
import {
|
||||||
|
Home,
|
||||||
|
Package,
|
||||||
|
ShoppingCart,
|
||||||
|
BarChart2,
|
||||||
|
Settings,
|
||||||
|
Box,
|
||||||
|
ClipboardList,
|
||||||
|
LogOut,
|
||||||
|
} from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupContent,
|
SidebarGroupContent,
|
||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
|
SidebarFooter,
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
SidebarSeparator,
|
SidebarSeparator,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
@@ -38,18 +48,26 @@ const items = [
|
|||||||
icon: BarChart2,
|
icon: BarChart2,
|
||||||
url: "/analytics",
|
url: "/analytics",
|
||||||
},
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export function AppSidebar() {
|
export function AppSidebar() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const handleLogout = () => {
|
||||||
|
sessionStorage.removeItem('isLoggedIn');
|
||||||
|
sessionStorage.removeItem('token');
|
||||||
|
navigate('/login');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible="icon" variant="sidebar">
|
<Sidebar collapsible="icon" variant="sidebar">
|
||||||
<SidebarHeader>
|
<SidebarHeader>
|
||||||
<div className="p-4 flex items-center gap-2 group-data-[collapsible=icon]:justify-center">
|
<div className="p-4 flex items-center gap-2 group-data-[collapsible=icon]:justify-center">
|
||||||
<Box className="h-6 w-6 shrink-0" />
|
<Box className="h-6 w-6 shrink-0" />
|
||||||
<h2 className="text-lg font-semibold group-data-[collapsible=icon]:hidden">Inventory Manager</h2>
|
<h2 className="text-lg font-semibold group-data-[collapsible=icon]:hidden">
|
||||||
|
Inventory Manager
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarSeparator />
|
<SidebarSeparator />
|
||||||
@@ -58,14 +76,21 @@ export function AppSidebar() {
|
|||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const isActive = location.pathname === item.url ||
|
const isActive =
|
||||||
|
location.pathname === item.url ||
|
||||||
(item.url !== "/" && location.pathname.startsWith(item.url));
|
(item.url !== "/" && location.pathname.startsWith(item.url));
|
||||||
return (
|
return (
|
||||||
<SidebarMenuItem key={item.title}>
|
<SidebarMenuItem key={item.title}>
|
||||||
<SidebarMenuButton asChild tooltip={item.title} isActive={isActive}>
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
tooltip={item.title}
|
||||||
|
isActive={isActive}
|
||||||
|
>
|
||||||
<a href={item.url}>
|
<a href={item.url}>
|
||||||
<item.icon className="h-4 w-4" />
|
<item.icon className="h-4 w-4" />
|
||||||
<span className="group-data-[collapsible=icon]:hidden">{item.title}</span>
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
|
{item.title}
|
||||||
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
@@ -76,25 +101,39 @@ export function AppSidebar() {
|
|||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
<SidebarSeparator />
|
<SidebarSeparator />
|
||||||
|
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
|
<SidebarMenu>
|
||||||
|
<SidebarMenuItem>
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
tooltip="Settings"
|
||||||
|
isActive={location.pathname === "/settings"}
|
||||||
|
>
|
||||||
|
<a href="/settings">
|
||||||
|
<Settings className="h-4 w-4" />
|
||||||
|
<span className="group-data-[collapsible=icon]:hidden">
|
||||||
|
Settings
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
</SidebarMenu>
|
||||||
|
</SidebarGroupContent>
|
||||||
|
</SidebarGroup>
|
||||||
|
</SidebarContent>
|
||||||
|
<SidebarFooter>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
<SidebarMenuItem>
|
<SidebarMenuItem>
|
||||||
<SidebarMenuButton
|
<SidebarMenuButton asChild tooltip="Logout" onClick={handleLogout}>
|
||||||
asChild
|
<button>
|
||||||
tooltip="Settings"
|
<LogOut className="h-4 w-4" />
|
||||||
isActive={location.pathname === "/settings"}
|
<span className="group-data-[collapsible=icon]:hidden">Logout</span>
|
||||||
>
|
</button>
|
||||||
<a href="/settings">
|
|
||||||
<Settings className="h-4 w-4" />
|
|
||||||
<span className="group-data-[collapsible=icon]:hidden">Settings</span>
|
|
||||||
</a>
|
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroupContent>
|
</SidebarFooter>
|
||||||
</SidebarGroup>
|
|
||||||
</SidebarContent>
|
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user