/** * Admin All Users Page * View and manage all users across all accounts */ import { useState, useEffect } from 'react'; import { Search, Filter, Loader2, AlertCircle } from 'lucide-react'; import { Card } from '../../components/ui/card'; import Badge from '../../components/ui/badge/Badge'; import { fetchAPI } from '../../services/api'; interface User { id: number; email: string; first_name: string; last_name: string; account_name: string; role: string; is_active: boolean; last_login: string | null; date_joined: string; } export default function AdminAllUsersPage() { const [users, setUsers] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [searchTerm, setSearchTerm] = useState(''); const [roleFilter, setRoleFilter] = useState('all'); useEffect(() => { loadUsers(); }, []); const loadUsers = async () => { try { setLoading(true); const data = await fetchAPI('/v1/admin/users/'); setUsers(data.results || []); } catch (err: any) { setError(err.message || 'Failed to load users'); } finally { setLoading(false); } }; const filteredUsers = users.filter((user) => { const matchesSearch = user.email.toLowerCase().includes(searchTerm.toLowerCase()) || `${user.first_name} ${user.last_name}`.toLowerCase().includes(searchTerm.toLowerCase()); const matchesRole = roleFilter === 'all' || user.role === roleFilter; return matchesSearch && matchesRole; }); if (loading) { return (
); } return (

All Users

View and manage all users across all accounts

{error && (

{error}

)} {/* Filters */}
setSearchTerm(e.target.value)} className="w-full pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-800" />
{/* Users Table */}
{filteredUsers.length === 0 ? ( ) : ( filteredUsers.map((user) => ( )) )}
User Account Role Status Last Login Joined Actions
No users found
{user.first_name || user.last_name ? `${user.first_name} ${user.last_name}`.trim() : user.email}
{user.email}
{user.account_name} {user.role} {user.is_active ? 'Active' : 'Inactive'} {user.last_login ? new Date(user.last_login).toLocaleDateString() : 'Never'} {new Date(user.date_joined).toLocaleDateString()}
{/* Summary Stats */}
Total Users
{users.length}
Active
{users.filter(u => u.is_active).length}
Owners
{users.filter(u => u.role === 'owner').length}
Admins
{users.filter(u => u.role === 'admin').length}
); }