parsimony/admin/src/pages/ListPage.tsx
tgiachi ee1f837a20 feat(admin): a Sent tab with the posts of a list and their progress
- route /lists/:id/sent and a Sent tab on the list page
- a table of posts (subject, date, sent of recipients with a progress
  bar, recipients, pending, failed, dropped) and an empty state; a post
  with no recipients shows no bar
- refreshes every 5 seconds while any post has pending deliveries, and
  stops when none has
- api.posts.list, the Post type and the fake API route; tests
2026-11-10 12:43:55 +01:00

62 lines
2.3 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { Link, Outlet, useLocation, useNavigate, useParams } from 'react-router'
import { Badge } from '@/components/ui/badge'
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { api } from '@/lib/api'
const tabs = ['settings', 'members', 'held', 'archive', 'sent'] as const
export function ListPage() {
const params = useParams()
const id = /^\d+$/.test(params.id ?? '') ? Number(params.id) : null
const navigate = useNavigate()
const { pathname } = useLocation()
const list = useQuery({ queryKey: ['list', id], queryFn: () => api.lists.get(id!), enabled: id !== null })
const held = useQuery({ queryKey: ['held', id], queryFn: () => api.held.list(id!), enabled: id !== null })
if (id === null || (list.isError && list.error.message === 'not found')) {
return <NotFound />
}
if (list.isPending) return <p className="text-muted-foreground">Loading…</p>
if (list.isError) return <p role="alert" className="text-destructive">{list.error.message}</p>
const current = tabs.find((t) => pathname.endsWith(`/${t}`)) ?? 'settings'
const heldCount = held.data?.length ?? 0
return (
<div className="space-y-6">
<div>
<Link to="/" className="text-sm text-primary underline">
All lists
</Link>
<h1 className="mt-2 text-2xl font-semibold">{list.data.address}</h1>
<p className="text-muted-foreground">{list.data.title}</p>
</div>
<Tabs value={current} onValueChange={(t) => navigate(t === 'settings' ? `/lists/${id}` : `/lists/${id}/${t}`)}>
<TabsList>
<TabsTrigger value="settings">Settings</TabsTrigger>
<TabsTrigger value="members">Members</TabsTrigger>
<TabsTrigger value="held">
Held
{heldCount > 0 && <Badge className="ml-1">{heldCount}</Badge>}
</TabsTrigger>
<TabsTrigger value="archive">Archive</TabsTrigger>
<TabsTrigger value="sent">Sent</TabsTrigger>
</TabsList>
</Tabs>
<Outlet context={list.data} />
</div>
)
}
function NotFound() {
return (
<div className="space-y-2">
<h1 className="text-2xl font-semibold">List not found</h1>
<Link to="/" className="text-primary underline">
Back to lists
</Link>
</div>
)
}