Spaces:
Paused
Paused
File size: 5,286 Bytes
f3bcb28 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | 'use client';
import { useState } from 'react';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import {
LayoutDashboard,
AppWindow,
Shield,
ShieldCheck,
MessageSquare,
Settings,
Menu,
X,
LogOut,
Cpu,
FileText,
Users,
Wallet,
} from 'lucide-react';
import clsx from 'clsx';
import { useAuth } from '@/lib/auth-context';
const navigation = [
{ name: 'Dashboard', href: '/', icon: LayoutDashboard },
{ name: 'Applications', href: '/applications', icon: AppWindow },
{ name: 'Guardrails', href: '/policies', icon: Shield },
{ name: 'Security Guard', href: '/security', icon: ShieldCheck },
{ name: 'Budgets', href: '/budgets', icon: Wallet },
{ name: 'Requests', href: '/requests', icon: FileText },
{ name: 'Playground', href: '/playground', icon: MessageSquare },
];
// Admin navigation items
const adminNavigation = [
{ name: 'Models', href: '/admin/models', icon: Cpu },
{ name: 'Users', href: '/users', icon: Users },
{ name: 'Settings', href: '/settings', icon: Settings },
];
export default function Sidebar() {
const pathname = usePathname();
const { user, logout } = useAuth();
const [mobileOpen, setMobileOpen] = useState(false);
return (
<>
{/* Mobile menu button */}
<button
className="lg:hidden fixed top-4 left-4 z-50 p-2 bg-gray-800 rounded-md"
onClick={() => setMobileOpen(!mobileOpen)}
>
{mobileOpen ? <X className="w-6 h-6 text-white" /> : <Menu className="w-6 h-6 text-white" />}
</button>
{/* Sidebar */}
<div className={clsx(
'fixed inset-y-0 left-0 z-40 w-64 bg-gray-900 transform transition-transform lg:translate-x-0',
mobileOpen ? 'translate-x-0' : '-translate-x-full'
)}>
<div className="flex flex-col h-full">
{/* Logo */}
<div className="flex items-center h-16 px-6 bg-gray-800">
<h1 className="text-xl font-bold text-white">TensorWall</h1>
</div>
{/* Navigation */}
<nav className="flex-1 px-4 py-6 space-y-2 overflow-y-auto">
{/* Regular navigation items */}
{navigation.map((item) => {
const isActive = pathname === item.href;
return (
<Link
key={item.name}
href={item.href}
onClick={() => setMobileOpen(false)}
className={clsx(
'flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors',
isActive
? 'bg-blue-600 text-white'
: 'text-gray-300 hover:bg-gray-800 hover:text-white'
)}
>
<item.icon className="w-5 h-5 mr-3" />
{item.name}
</Link>
);
})}
{/* Admin section divider */}
<div className="pt-4 mt-4 border-t border-gray-700">
<p className="px-4 text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">
Admin
</p>
{adminNavigation.map((item) => {
const isActive = pathname === item.href;
return (
<Link
key={item.name}
href={item.href}
onClick={() => setMobileOpen(false)}
className={clsx(
'flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors',
isActive
? 'bg-blue-600 text-white'
: 'text-gray-300 hover:bg-gray-800 hover:text-white'
)}
>
<item.icon className="w-5 h-5 mr-3" />
{item.name}
</Link>
);
})}
</div>
</nav>
{/* User Info & Logout */}
{user && (
<div className="px-4 py-4 border-t border-gray-700/50">
<div className="flex items-center gap-3">
<div className="flex-shrink-0 w-9 h-9 bg-gradient-to-br from-blue-500 to-blue-600 rounded-full flex items-center justify-center shadow-lg">
<span className="text-sm font-semibold text-white">
{user.name.charAt(0).toUpperCase()}
</span>
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-white truncate">{user.name}</p>
<p className="text-xs text-gray-500 truncate">{user.email}</p>
</div>
<button
onClick={logout}
className="flex-shrink-0 p-2 text-gray-400 hover:text-white hover:bg-gray-800 rounded-lg transition-colors"
title="Sign Out"
>
<LogOut className="w-4 h-4" />
</button>
</div>
</div>
)}
{/* Footer */}
<div className="px-6 py-4 border-t border-gray-800">
<p className="text-xs text-gray-500">v0.1.0 (Community)</p>
</div>
</div>
</div>
</>
);
}
|