Files
gatehouse-ui/src/components/navigation/AppSidebar.tsx
T

222 lines
8.0 KiB
TypeScript
Raw Normal View History

2026-01-06 14:46:23 +00:00
import { useLocation } from "react-router-dom";
import {
User,
Shield,
Link2,
Activity,
Building2,
Users,
Settings,
FileText,
Layers,
GitBranch,
ScrollText,
Terminal,
ShieldCheck,
2026-03-04 18:43:12 +05:45
Key,
Network,
Monitor,
ShieldAlert,
2026-01-06 14:46:23 +00:00
} from "lucide-react";
2026-03-06 00:22:57 +05:45
import { SecuirdLogo } from "@/components/branding/SecuirdLogo";
2026-01-06 14:46:23 +00:00
import { NavLink } from "@/components/NavLink";
2026-03-01 16:50:19 +05:45
import { useAuth } from "@/contexts/AuthContext";
2026-01-06 14:46:23 +00:00
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarHeader,
SidebarFooter,
useSidebar,
} from "@/components/ui/sidebar";
import { cn } from "@/lib/utils";
const userNavItems = [
{ title: "Profile", url: "/profile", icon: User },
{ title: "Security", url: "/security", icon: Shield },
{ title: "SSH Keys", url: "/ssh-keys", icon: Terminal },
2026-01-06 14:46:23 +00:00
{ title: "Linked Accounts", url: "/linked-accounts", icon: Link2 },
{ title: "Activity", url: "/activity", icon: Activity },
];
2026-03-01 16:50:19 +05:45
// Visible to ALL org members
const orgMemberNavItems = [
{ title: "Overview", url: "/org", icon: Building2 },
{ title: "My Memberships", url: "/org/my-memberships", icon: Layers },
{ title: "ZeroTier Devices", url: "/org/zerotier/devices", icon: Monitor },
2026-03-01 16:50:19 +05:45
];
// Visible to org admins/owners only (management)
const orgAdminNavItems = [
2026-01-06 14:46:23 +00:00
{ title: "Overview", url: "/org", icon: Building2 },
{ title: "Members", url: "/org/members", icon: Users },
{ title: "Departments", url: "/org/departments", icon: Layers },
{ title: "Principals", url: "/org/principals", icon: GitBranch },
2026-03-08 18:08:42 +05:45
{ title: "API Keys", url: "/org/api-keys", icon: Key },
2026-01-06 14:46:23 +00:00
{ title: "Policies", url: "/org/policies", icon: Settings },
{ title: "ZeroTier Networks", url: "/org/zerotier/networks", icon: Network },
{ title: "ZeroTier Access", url: "/org/zerotier/access", icon: ShieldAlert },
2026-01-06 14:46:23 +00:00
];
const adminNavItems = [
{ title: "Certificate Auth.", url: "/org/cas", icon: ShieldCheck },
2026-03-04 18:43:12 +05:45
{ title: "OIDC Clients", url: "/org/clients", icon: Key },
{ title: "Org Audit Log", url: "/org/audit", icon: FileText },
2026-01-06 14:46:23 +00:00
];
2026-03-06 14:19:54 +05:45
const systemLogNavItem = { title: "System Logs", url: "/admin/audit", icon: ScrollText };
2026-01-06 14:46:23 +00:00
export function AppSidebar() {
const { state } = useSidebar();
const collapsed = state === "collapsed";
const location = useLocation();
2026-03-06 14:19:54 +05:45
const { isOrgAdmin, isOrgMember, canViewSystemLogs } = useAuth();
2026-01-06 14:46:23 +00:00
const isActive = (path: string) => location.pathname === path;
2026-03-01 16:50:19 +05:45
const isOrgActive = orgAdminNavItems.some((item) => isActive(item.url)) || adminNavItems.some((item) => isActive(item.url));
void isOrgActive; // used for future active state tracking
2026-01-06 14:46:23 +00:00
return (
<Sidebar
className={cn(
"border-r border-sidebar-border bg-sidebar transition-all duration-300",
collapsed ? "w-16" : "w-64"
)}
collapsible="icon"
>
{/* Logo */}
<SidebarHeader className="p-4 border-b border-sidebar-border">
<div className="flex items-center gap-3">
2026-03-06 00:22:57 +05:45
<SecuirdLogo size="sm" variant="light" />
2026-01-06 14:46:23 +00:00
{!collapsed && (
<span className="text-lg font-semibold text-sidebar-foreground tracking-tight">
2026-03-06 00:22:57 +05:45
Secuird
2026-01-06 14:46:23 +00:00
</span>
)}
</div>
</SidebarHeader>
<SidebarContent className="py-4">
{/* User Section */}
<SidebarGroup>
2026-03-01 16:50:19 +05:45
{!collapsed && (
<SidebarGroupLabel className="px-4 text-xs font-medium text-sidebar-muted uppercase tracking-wider">
Account
</SidebarGroupLabel>
)}
2026-01-06 14:46:23 +00:00
<SidebarGroupContent>
<SidebarMenu>
{userNavItems.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<NavLink
to={item.url}
end
className={cn(
2026-03-01 16:50:19 +05:45
"flex items-center text-sm text-sidebar-foreground rounded-lg transition-colors",
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
collapsed
? "justify-center w-10 h-10 mx-auto p-0"
: "gap-3 px-4 py-2.5 mx-2"
2026-01-06 14:46:23 +00:00
)}
activeClassName="bg-sidebar-accent text-sidebar-primary font-medium"
>
<item.icon className="w-4 h-4 flex-shrink-0" />
{!collapsed && <span>{item.title}</span>}
</NavLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
2026-03-01 16:50:19 +05:45
{/* Organization Section — content differs by role */}
{isOrgMember && (
2026-01-06 14:46:23 +00:00
<SidebarGroup className="mt-4">
2026-03-01 16:50:19 +05:45
{!collapsed && (
<SidebarGroupLabel className="px-4 text-xs font-medium text-sidebar-muted uppercase tracking-wider">
Organization
</SidebarGroupLabel>
)}
2026-01-06 14:46:23 +00:00
<SidebarGroupContent>
<SidebarMenu>
2026-03-01 16:50:19 +05:45
{(isOrgAdmin ? orgAdminNavItems : orgMemberNavItems).map((item) => (
2026-01-06 14:46:23 +00:00
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<NavLink
to={item.url}
end
className={cn(
2026-03-01 16:50:19 +05:45
"flex items-center text-sm text-sidebar-foreground rounded-lg transition-colors",
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
collapsed
? "justify-center w-10 h-10 mx-auto p-0"
: "gap-3 px-4 py-2.5 mx-2"
2026-01-06 14:46:23 +00:00
)}
activeClassName="bg-sidebar-accent text-sidebar-primary font-medium"
>
<item.icon className="w-4 h-4 flex-shrink-0" />
{!collapsed && <span>{item.title}</span>}
</NavLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
2026-03-01 16:50:19 +05:45
)}
2026-01-06 14:46:23 +00:00
2026-03-01 16:50:19 +05:45
{/* Admin Section — only visible to org admins/owners */}
{isOrgAdmin && (
2026-01-06 14:46:23 +00:00
<SidebarGroup className="mt-4">
2026-03-01 16:50:19 +05:45
{!collapsed && (
<SidebarGroupLabel className="px-4 text-xs font-medium text-sidebar-muted uppercase tracking-wider">
Admin
</SidebarGroupLabel>
)}
2026-01-06 14:46:23 +00:00
<SidebarGroupContent>
<SidebarMenu>
2026-03-06 14:19:54 +05:45
{[...adminNavItems, ...(canViewSystemLogs ? [systemLogNavItem] : [])].map((item) => (
2026-01-06 14:46:23 +00:00
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<NavLink
to={item.url}
end
className={cn(
2026-03-01 16:50:19 +05:45
"flex items-center text-sm text-sidebar-foreground rounded-lg transition-colors",
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
collapsed
? "justify-center w-10 h-10 mx-auto p-0"
: "gap-3 px-4 py-2.5 mx-2"
2026-01-06 14:46:23 +00:00
)}
activeClassName="bg-sidebar-accent text-sidebar-primary font-medium"
>
<item.icon className="w-4 h-4 flex-shrink-0" />
{!collapsed && <span>{item.title}</span>}
</NavLink>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
2026-03-01 16:50:19 +05:45
)}
2026-01-06 14:46:23 +00:00
</SidebarContent>
<SidebarFooter className="p-4 border-t border-sidebar-border">
{!collapsed && (
<div className="text-xs text-sidebar-muted">
v1.0.0 Self-hosted
</div>
)}
</SidebarFooter>
</Sidebar>
);
}