import { useEffect, useState } from "react"; import { ChevronLeft, ChevronRight, Clock, Filter, Loader2, Search } from "lucide-react"; import { Link } from "react-router-dom"; import { Button, Card, ErrorBanner, PageHeader } from "@/client/components/ui"; import { useAdminSessionGuard } from "@/client/hooks/useAdminSessionGuard"; import { listAdminTempInboxes, type AdminTempInbox } from "@/client/lib/api"; import { fullDate } from "@/client/lib/time"; import { ADMIN_TEMP_INBOX_PAGE_SIZE } from "@/shared/contracts"; interface TempInboxListProps { onSessionError: (message?: string) => void; } export function TempInboxList({ onSessionError }: TempInboxListProps) { const [inboxes, setInboxes] = useState([]); const [page, setPage] = useState(0); const [total, setTotal] = useState(0); const [pageSize, setPageSize] = useState(ADMIN_TEMP_INBOX_PAGE_SIZE); const [hasEmails, setHasEmails] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleAdminError = useAdminSessionGuard(onSessionError); useEffect(() => { let active = true; const load = async () => { setLoading(true); setError(null); try { const results = await listAdminTempInboxes(page, hasEmails); if (!active) return; setInboxes(results.inboxes); setTotal(results.total); setPageSize(results.pageSize); } catch (fetchError) { if (!active) return; handleAdminError(fetchError, setError); } finally { if (active) setLoading(false); } }; void load(); return () => { active = false; }; }, [handleAdminError, hasEmails, page]); const totalPages = Math.max(1, Math.ceil(total / pageSize)); const handlePageChange = (nextPage: number) => { if (nextPage < 0 || nextPage >= totalPages || nextPage === page) return; setPage(nextPage); }; const handleToggleFilter = () => { setHasEmails((prev) => !prev); setPage(0); }; return (
} heading="Currently active mailboxes" description="Browse live temporary inboxes, see how many emails they contain, and inspect them in read-only admin mode." />
{total} active mailbox{total !== 1 ? "es" : ""}
{error ? {error} : null} {loading ? (

Loading active temporary inboxes...

) : null} {!loading && !error && inboxes.length === 0 ? (

{hasEmails ? "No active temporary inboxes with emails right now." : "There are no active temporary inboxes right now."}

) : null}
{inboxes.map((inbox) => (
{inbox.address}

Created {fullDate(inbox.createdAt)} · Expires {inbox.expiresAt ? fullDate(inbox.expiresAt) : "never"}

{inbox.domain} · {inbox.ttlHours ? `${inbox.ttlHours}h lifetime` : "temporary"} ·{" "} {inbox.emailCount} email{inbox.emailCount !== 1 ? "s" : ""}

Inspect mailbox
))}
{total > pageSize ? (
Page {page + 1} of {totalPages}
) : null}
); }