/** UsersTab — Authentik user directory for the Authentik service page. */ import { useState } from "react"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import type { ServiceInstance } from "../../types"; import { useAuthentikUsers } from "../../hooks/useAuthentik"; const PAGE_SIZE = 25; export function UsersTab({ instance }: { instance: ServiceInstance }) { const [search, setSearch] = useState(""); const [page, setPage] = useState(1); const [committedSearch, setCommittedSearch] = useState(""); const { data, isLoading } = useAuthentikUsers(instance.id, { search: committedSearch, page, page_size: PAGE_SIZE, }); const error = data?.error; const users = data?.items ?? []; const total = data?.total ?? 0; const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE)); function handleSearch() { setPage(1); setCommittedSearch(search); } return (
{error ? ( {error} ) : null}
setSearch(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") handleSearch(); }} className="max-w-xs" />
Name Username Email Status {isLoading && users.length === 0 ? ( Loading… ) : users.length === 0 ? ( No users found. ) : ( users.map((user) => ( {user.name || "—"} {user.username} {user.email || "—"} {user.is_active ? "Active" : "Inactive"} )) )}
{total > 0 ? (
{total} user{total === 1 ? "" : "s"} · Page {page} of {totalPages}
) : null}
); }