'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { getUsers, type AdminUser } from '@/lib/api'; const PAGE_SIZE = 50; export function UsersTable() { const [users, setUsers] = useState([]); const [total, setTotal] = useState(0); const [offset, setOffset] = useState(0); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { setLoading(true); getUsers(PAGE_SIZE, offset) .then(({ users, total }) => { setUsers(users); setTotal(total); }) .catch((e) => setError(String(e.message))) .finally(() => setLoading(false)); }, [offset]); if (error) return

Error: {error}

; return (

Users

{total} total
{['ID', 'Email', 'Name', 'Role', 'Consent', 'Joined', 'Status'].map((h) => ( ))} {loading ? ( ) : users.length === 0 ? ( ) : ( users.map((u) => ( )) )}
{h}
Loading…
No users yet.
{u.id.slice(0, 8)} {u.email} {u.name ?? '—'} {u.role} {u.consentGiven ? ( yes ) : ( no )} {u.createdAt.slice(0, 10)} {u.deletedAt ? ( deleted ) : ( active )}
{/* Pagination */} {total > PAGE_SIZE && (
{offset + 1}–{Math.min(offset + PAGE_SIZE, total)} of {total}
)}
); }