2026-01-06 14:46:23 +00:00
|
|
|
import { useLocation } from "react-router-dom";
|
|
|
|
|
import {
|
|
|
|
|
User,
|
|
|
|
|
Shield,
|
|
|
|
|
Link2,
|
|
|
|
|
Activity,
|
|
|
|
|
Building2,
|
|
|
|
|
Users,
|
|
|
|
|
Settings,
|
|
|
|
|
FileText,
|
2026-02-27 21:08:16 +05:45
|
|
|
Layers,
|
|
|
|
|
GitBranch,
|
|
|
|
|
ScrollText,
|
2026-02-28 23:35:32 +05:45
|
|
|
Terminal,
|
|
|
|
|
ShieldCheck,
|
2026-03-04 18:43:12 +05:45
|
|
|
Key,
|
2026-03-20 21:52:52 +10:30
|
|
|
Network,
|
|
|
|
|
Monitor,
|
|
|
|
|
ShieldAlert,
|
2026-03-22 15:36:17 +05:45
|
|
|
BookOpen,
|
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 },
|
2026-02-28 23:35:32 +05:45
|
|
|
{ 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-22 15:36:17 +05:45
|
|
|
{ title: "CLI Guide", url: "/cli-guide", icon: BookOpen },
|
2026-01-06 14:46:23 +00:00
|
|
|
];
|
|
|
|
|
|
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 },
|
2026-03-20 21:52:52 +10:30
|
|
|
{ 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 },
|
2026-02-27 21:08:16 +05:45
|
|
|
{ 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 },
|
2026-03-20 21:52:52 +10:30
|
|
|
{ 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 = [
|
2026-02-28 23:35:32 +05:45
|
|
|
{ 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">
|
2026-03-22 15:36:17 +05:45
|
|
|
{import.meta.env.VITE_APP_VERSION ?? 'Secuird'}
|
2026-01-06 14:46:23 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</SidebarFooter>
|
|
|
|
|
</Sidebar>
|
|
|
|
|
);
|
|
|
|
|
}
|