76 lines · 3.3 KBRaw
| 1 | import { Banner, Button, Empty, LayerCard, Table } from "@refs/design-system"; |
| 2 | import { Form, useNavigation } from "react-router"; |
| 3 | import type { Route } from "./+types/admin-waitlist"; |
| 4 | import { Avatar, formatDate } from "@refs/design-system"; |
| 5 | import { AppShell, PageHeader } from "../components/shell"; |
| 6 | import { failed, formText, found, signedIn } from "../lib/session"; |
| 7 | |
| 8 | export const meta: Route.MetaFunction = () => [{ title: "Waitlist · refs" }]; |
| 9 | |
| 10 | export async function loader({ context }: Route.LoaderArgs) { |
| 11 | const waitlist = await found(signedIn(context).waitlist()); |
| 12 | return { people: await waitlist.list() }; |
| 13 | } |
| 14 | |
| 15 | export async function action({ request, context }: Route.ActionArgs) { |
| 16 | const waitlist = await found(signedIn(context).waitlist()); |
| 17 | const outcome = await waitlist.approve(formText(await request.formData(), "id")); |
| 18 | return outcome.ok ? { error: null } : failed(outcome.problem, {}); |
| 19 | } |
| 20 | |
| 21 | export default function AdminWaitlist({ loaderData, actionData }: Route.ComponentProps) { |
| 22 | const navigation = useNavigation(); |
| 23 | const approving = navigation.state === "submitting" ? navigation.formData?.get("id") : null; |
| 24 | const { people } = loaderData; |
| 25 | return ( |
| 26 | <AppShell crumbs={[{ label: "Waitlist", href: "/admin/waitlist" }]}> |
| 27 | <PageHeader title="Waitlist" /> |
| 28 | <div className="flex max-w-4xl flex-col gap-6"> |
| 29 | {actionData?.error && <Banner variant="error" description={actionData.error} />} |
| 30 | {people.length === 0 ? ( |
| 31 | <LayerCard> |
| 32 | <Empty size="sm" title="Nobody is waiting" description="New sign-ups appear here for approval." /> |
| 33 | </LayerCard> |
| 34 | ) : ( |
| 35 | <LayerCard> |
| 36 | <Table> |
| 37 | <Table.Header> |
| 38 | <Table.Row> |
| 39 | <Table.Head>Person</Table.Head> |
| 40 | <Table.Head>Handle</Table.Head> |
| 41 | <Table.Head>Joined</Table.Head> |
| 42 | <Table.Head /> |
| 43 | </Table.Row> |
| 44 | </Table.Header> |
| 45 | <Table.Body> |
| 46 | {people.map((person) => ( |
| 47 | <Table.Row key={person.id}> |
| 48 | <Table.Cell> |
| 49 | <span className="flex items-center gap-3"> |
| 50 | <Avatar name={person.name} size="base" /> |
| 51 | <span className="flex flex-col"> |
| 52 | <span className="font-medium">{person.name}</span> |
| 53 | <span className="text-xs text-muted">{person.email}</span> |
| 54 | </span> |
| 55 | </span> |
| 56 | </Table.Cell> |
| 57 | <Table.Cell className="font-mono text-xs">{person.handle}</Table.Cell> |
| 58 | <Table.Cell className="text-muted">{formatDate(person.joinedAt)}</Table.Cell> |
| 59 | <Table.Cell className="text-right"> |
| 60 | <Form method="post" className="inline-flex"> |
| 61 | <input type="hidden" name="id" value={person.id} /> |
| 62 | <Button type="submit" variant="primary" size="sm" loading={approving === person.id}> |
| 63 | Approve |
| 64 | </Button> |
| 65 | </Form> |
| 66 | </Table.Cell> |
| 67 | </Table.Row> |
| 68 | ))} |
| 69 | </Table.Body> |
| 70 | </Table> |
| 71 | </LayerCard> |
| 72 | )} |
| 73 | </div> |
| 74 | </AppShell> |
| 75 | ); |
| 76 | } |