Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | import { Outlet, Link, useLocation } from 'react-router-dom'
import {
ChevronLeft,
Shield,
Settings,
User,
Users,
Building2,
ExternalLink,
Menu,
X
} from 'lucide-react'
import { useState, useEffect } from 'react'
import { useAuth } from '../../contexts/AuthContext'
function AdminLayout() {
const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
const [mobileOpen, setMobileOpen] = useState(false)
const { user } = useAuth()
const location = useLocation()
useEffect(() => {
setMobileOpen(false)
}, [location.pathname])
const nav = (
<div className="p-2 overflow-y-auto flex-1 space-y-1">
<Link
to="/admin/users"
onClick={() => setMobileOpen(false)}
className={`flex items-center px-4 py-2 rounded-lg transition-all text-sm ${
location.pathname === '/admin/users'
? 'bg-indigo-600 text-white border-l-4 border-indigo-500'
: 'text-slate-300 hover:bg-slate-800 hover:text-white border-l-4 border-transparent'
}`}
>
<Users className="w-5 h-5 flex-shrink-0" />
<span className="ml-3 font-medium">Utilisateurs</span>
</Link>
<Link
to="/admin/organizations"
onClick={() => setMobileOpen(false)}
className={`flex items-center px-4 py-2 rounded-lg transition-all text-sm ${
location.pathname === '/admin/organizations'
? 'bg-indigo-600 text-white border-l-4 border-indigo-500'
: 'text-slate-300 hover:bg-slate-800 hover:text-white border-l-4 border-transparent'
}`}
>
<Building2 className="w-5 h-5 flex-shrink-0" />
<span className="ml-3 font-medium">Organisations</span>
</Link>
</div>
)
const bottom = (
<div className="mt-auto p-4 border-t border-slate-800 space-y-3">
<Link
to="/"
onClick={() => setMobileOpen(false)}
className="flex items-center justify-center w-full px-3 py-2 text-sm text-slate-300 bg-slate-800 hover:bg-slate-700 rounded-lg transition-colors"
>
<ExternalLink className="w-4 h-4 mr-2" />
Retour à l'interface
</Link>
<Link
to="/profile"
className="flex items-center px-3 py-2 text-slate-300 hover:bg-slate-800 rounded-lg transition-colors border border-slate-700 hover:border-slate-600"
>
<div className="w-8 h-8 rounded-full bg-indigo-900 flex items-center justify-center flex-shrink-0 mr-3">
<User className="w-4 h-4 text-indigo-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">{user?.name}</p>
<p className="text-xs text-slate-400 truncate">{user?.email}</p>
</div>
<Settings className="w-4 h-4 text-slate-400" />
</Link>
</div>
)
return (
<div className="min-h-screen bg-gray-100">
{/* Mobile sidebar (burger) */}
<div className={`fixed inset-0 z-50 lg:hidden ${mobileOpen ? 'block' : 'hidden'}`}>
<div className="fixed inset-0 bg-gray-900/50" onClick={() => setMobileOpen(false)} />
<div className="fixed inset-y-0 left-0 w-72 bg-slate-900 text-white overflow-y-auto flex flex-col">
<div className="flex items-center justify-between h-16 px-4 border-b border-slate-800">
<div className="flex items-center space-x-2">
<Shield className="w-6 h-6 text-indigo-400" />
<span className="text-lg font-bold">Admin Nooloom</span>
</div>
<button onClick={() => setMobileOpen(false)} className="p-1 rounded hover:bg-slate-800">
<X className="w-5 h-5" />
</button>
</div>
{nav}
{bottom}
</div>
</div>
{/* Desktop sidebar */}
<aside
className={`hidden lg:flex lg:fixed lg:inset-y-0 lg:left-0 lg:z-50 bg-slate-900 text-white transition-all duration-300 ${
sidebarCollapsed ? 'lg:w-20' : 'lg:w-72'
}`}
>
<div className="flex items-center justify-between h-16 px-4 border-b border-slate-800 flex-shrink-0">
{!sidebarCollapsed && (
<div className="flex items-center space-x-2">
<Shield className="w-6 h-6 text-indigo-400" />
<span className="text-lg font-bold">Admin Nooloom</span>
</div>
)}
{sidebarCollapsed && <Shield className="w-6 h-6 text-indigo-400 mx-auto" />}
<button
onClick={() => setSidebarCollapsed(!sidebarCollapsed)}
className={`p-1 rounded hover:bg-slate-800 ${sidebarCollapsed ? 'mx-auto' : ''}`}
>
<ChevronLeft className={`w-5 h-5 transition-transform ${sidebarCollapsed ? 'rotate-180' : ''}`} />
</button>
</div>
<div className="p-2 overflow-y-auto flex-1 space-y-1">
<Link
to="/admin/users"
className={`flex items-center px-4 py-2 rounded-lg transition-all text-sm ${
location.pathname === '/admin/users'
? 'bg-indigo-600 text-white border-l-4 border-indigo-500'
: 'text-slate-300 hover:bg-slate-800 hover:text-white border-l-4 border-transparent'
}`}
>
<Users className="w-5 h-5 flex-shrink-0" />
{!sidebarCollapsed && <span className="ml-3 font-medium">Utilisateurs</span>}
</Link>
<Link
to="/admin/organizations"
className={`flex items-center px-4 py-2 rounded-lg transition-all text-sm ${
location.pathname === '/admin/organizations'
? 'bg-indigo-600 text-white border-l-4 border-indigo-500'
: 'text-slate-300 hover:bg-slate-800 hover:text-white border-l-4 border-transparent'
}`}
>
<Building2 className="w-5 h-5 flex-shrink-0" />
{!sidebarCollapsed && <span className="ml-3 font-medium">Organisations</span>}
</Link>
</div>
<div className="absolute bottom-0 left-0 right-0 p-4 border-t border-slate-800 space-y-3">
<Link
to="/"
className="flex items-center justify-center w-full px-3 py-2 text-sm text-slate-300 bg-slate-800 hover:bg-slate-700 rounded-lg transition-colors"
>
<ExternalLink className="w-4 h-4 mr-2" />
{!sidebarCollapsed && "Retour à l'interface"}
</Link>
<Link
to="/profile"
className="flex items-center px-3 py-2 text-slate-300 hover:bg-slate-800 rounded-lg transition-colors border border-slate-700 hover:border-slate-600"
>
<div className="w-8 h-8 rounded-full bg-indigo-900 flex items-center justify-center flex-shrink-0 mr-3">
<User className="w-4 h-4 text-indigo-400" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">{user?.name}</p>
<p className="text-xs text-slate-400 truncate">{user?.email}</p>
</div>
<Settings className="w-4 h-4 text-slate-400" />
</Link>
</div>
</aside>
<div
className={`transition-all duration-300 ${
sidebarCollapsed ? 'lg:ml-20' : 'lg:ml-72'
}`}
>
{/* Mobile header */}
<div className="sticky top-0 z-40 flex items-center justify-between h-16 px-4 bg-slate-900 text-white border-b border-slate-800 lg:hidden">
<button onClick={() => setMobileOpen(true)} className="p-2 -ml-2 rounded hover:bg-slate-800">
<Menu className="w-6 h-6" />
</button>
<span className="flex items-center gap-2 text-lg font-bold">
<Shield className="w-5 h-5 text-indigo-400" />
Admin
</span>
<div className="w-8" />
</div>
<main>
<div className="p-3 sm:p-4 lg:p-8">
<Outlet />
</div>
</main>
</div>
</div>
)
}
export default AdminLayout |