"use client"; import { useQuery } from "@tanstack/react-query"; import { RefreshCw } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card"; import { Table, TableHead, TableBody, TableRow, Th, Td, EmptyState } from "@/components/ui/Table"; import { Badge } from "@/components/ui/Badge"; import { Button } from "@/components/ui/Button"; import { formatDate } from "@/lib/utils"; import api from "@/lib/api"; import type { User, UsersResponse } from "@/types"; export default function UsersPage() { const { data: users, isLoading, refetch } = useQuery({ queryKey: ["users"], queryFn: async () => { const res = await api.get("/api/v1/users?page=1&limit=20"); // Handle both array and paginated response const d = res.data; if (Array.isArray(d)) return d; // eslint-disable-next-line @typescript-eslint/no-explicit-any const anyD = d as any; if (anyD.data) return anyD.data as UsersResponse; return []; }, }); const userList: User[] = users ?? []; return (

Users

{userList.length} total users

All Users {isLoading ? ( Array.from({ length: 3 }).map((_, i) => ( {Array.from({ length: 6 }).map((_, j) => ( ))} )) ) : userList.length === 0 ? ( ) : ( userList.map((user) => { const roles = user.roleAssignments?.map((r) => r.role) ?? []; return ( ); }) )}
Name Email Role Status Last Login Joined
{user.firstName} {user.lastName} {user.email}
{roles.length === 0 ? ( No role ) : ( roles.map((role) => ( {role} )) )}
{user.isActive ? "Active" : "Inactive"} {user.lastLoginAt ? formatDate(user.lastLoginAt) : "Never"} {formatDate(user.createdAt)}
); }