'use client'; import { useState } from 'react'; import { X, Shield, UserPlus, User, Trash2, Tag, Plus, AlertTriangle, LogOut, Layers } from 'lucide-react'; import { inventoryApi } from '@/lib/api'; import { toast } from 'react-hot-toast'; import CreateUserModal from './CreateUserModal'; import ConfirmationModal from './ConfirmationModal'; import CategoryCreationModal from './CategoryCreationModal'; interface AdminOverlayProps { show: boolean; onClose: () => void; users: any[]; categories: any[]; onUpdateUsers: (users: any[]) => void; onUpdateCategories: (categories: any[]) => void; } export default function AdminOverlay({ show, onClose, users, categories, onUpdateUsers, onUpdateCategories }: AdminOverlayProps) { const [showCreateUserModal, setShowCreateUserModal] = useState(false); const [showCreateCategoryModal, setShowCreateCategoryModal] = useState(false); const [confirmState, setConfirmState] = useState<{ show: boolean; type: 'user' | 'category' | null; itemId?: number; itemName?: string; affectedCount?: number; loading?: boolean; }>({ show: false, type: null, loading: false, }); if (!show) return null; const handleUserCreated = () => { inventoryApi.getUsers().then(onUpdateUsers); }; const handleCategoryCreated = () => { inventoryApi.getCategories().then(onUpdateCategories); }; const handleDeleteUser = async () => { if (!confirmState.itemId) return; setConfirmState(prev => ({ ...prev, loading: true })); try { await inventoryApi.deleteUser(confirmState.itemId); toast.success("User removed"); await inventoryApi.getUsers().then(onUpdateUsers); setConfirmState({ show: false, type: null, loading: false }); } catch (error) { toast.error("Delete failed"); setConfirmState(prev => ({ ...prev, loading: false })); } }; const handleDeleteCategory = async () => { if (!confirmState.itemId) return; setConfirmState(prev => ({ ...prev, loading: true })); try { await inventoryApi.deleteCategory(confirmState.itemId); toast.success("Category removed"); await inventoryApi.getCategories().then(onUpdateCategories); setConfirmState({ show: false, type: null, loading: false }); } catch (error: any) { toast.error(error?.response?.data?.detail || "Delete failed"); setConfirmState(prev => ({ ...prev, loading: false })); } }; return ( <> setShowCreateUserModal(false)} onUserCreated={handleUserCreated} /> setShowCreateCategoryModal(false)} onCategoryCreated={handleCategoryCreated} /> setConfirmState({ show: false, type: null, loading: false })} loading={confirmState.loading} dangerLevel="medium" /> setConfirmState({ show: false, type: null, loading: false })} loading={confirmState.loading} dangerLevel={confirmState.affectedCount && confirmState.affectedCount > 10 ? 'high' : 'medium'} />

System Admin

User Management

{users.map(u => (

{u.username}

{u.role}

{u.username !== 'Admin' && ( )}
))}

Category Groups

{categories.map(cat => (

{cat.name}

{cat.description || 'No description'}

))}

Logout

Exit current session and return to identity check.

); }