# Approvals

> The approvals page: the inbox with filters (oldest first, escalation warning, A–D on the selected row) next to the selected card with its preview (message, refund, DNS change, command).

Pattern · Pro kit · [Live page](https://ui.twentyfirst.media/pro/patterns/ApprovalsScreen/)

The approvals page: the inbox with filters (oldest first, escalation warning, A–D on the selected row) next to the selected card with its preview (message, refund, DNS change, command). Money and infrastructure ask for a passkey; the answer spins until the app confirms it, then the card collapses to its record and the row moves to "Done". On phones the card follows the list.

## Code

```tsx
import * as React from "react";
import {
  ApprovalCard,
  ApprovalInbox,
  ChangePreview,
  CommandPreview,
  MessagePreview,
  MoneyPreview,
  PageHeader,
} from "@twentyfirstmedia/pro";
import type { ApprovalInboxItem, ApprovalKey } from "@twentyfirstmedia/pro";
import { fakeDecision } from "./_approvals";

const ITEMS: ApprovalInboxItem[] = [
  {
    id: "reply",
    title: "Reply to Erika L. on WhatsApp",
    agent: "Atlas",
    project: "Support",
    family: "comms",
    age: "2 h 10 min",
    ageMin: 130,
    urgent: true,
  },
  {
    id: "refund",
    title: "Refund €10.00 to card ending 4242",
    agent: "Ledger",
    project: "Billing",
    family: "money",
    age: "38 min",
    ageMin: 38,
  },
  {
    id: "dns",
    title: "Update TXT record ops-test",
    agent: "Scout",
    project: "Domains",
    family: "infra",
    age: "3 min",
    ageMin: 3,
  },
  {
    id: "restart",
    title: "Restart nginx on web-1",
    agent: "Ops",
    project: "Platform",
    family: "infra",
    age: "1 min",
    ageMin: 1,
  },
];

const WHY: Record<string, string> = {
  reply: "Atlas answers in the open reply window; replies need your OK.",
  refund: "The customer was charged twice for order 2041.",
  dns: "The verification value changed after the provider renewed the token.",
  restart: "The health check has failed for 4 minutes.",
};

function Payload({ id }: { id: string }) {
  if (id === "reply")
    return (
      <MessagePreview
        channel="WhatsApp"
        recipient="Erika L. (…5678)"
        window={{ state: "closing", until: "2026-04-16T18:20:00" }}
        context={[
          {
            from: "in",
            at: "2026-04-16T09:02:00",
            text: "Any news on order 2041? I need it by Friday.",
          },
        ]}
        text="Good news: order 2041 left the warehouse this morning and arrives Thursday."
      />
    );
  if (id === "refund")
    return (
      <MoneyPreview
        amount={10}
        recipient="Visa …4242"
        reference="Order 2041"
        refund={{ payment: "pay_3PqL8x2k", paidAt: "Apr 14, 18:02" }}
      />
    );
  if (id === "dns")
    return (
      <ChangePreview
        title="Update TXT record · northwind.example"
        fields={[
          { label: "Name", before: "ops-test", after: "ops-test", mono: true },
          { label: "Content", before: "verify=4f1c0e92", after: "verify=b7d2a6f1", mono: true },
          { label: "TTL", before: "3600", after: "300", mono: true },
        ]}
      />
    );
  return (
    <CommandPreview
      command="systemctl restart nginx"
      server="web-1"
      host="deploy@203.0.113.7:22"
      risk="critical"
      timeout={60}
      stateBefore="Active: failed (Result: exit-code) since 09:37:12; 4min ago"
    />
  );
}

export default function Preview() {
  const [items, setItems] = React.useState(ITEMS);
  const [selected, setSelected] = React.useState<string | number>("reply");
  const item = items.find((x) => x.id === selected);
  const record = (id: string | number, key: ApprovalKey, text?: string) =>
    setItems((all) =>
      all.map((x) => (x.id === id ? { ...x, decision: { key, text, by: "You", at: "now" } } : x)),
    );
  return (
    <div className="tf-col" style={{ gap: 16 }}>
      <PageHeader title="Approvals" subtitle="What agents may not do alone, oldest first" />
      <div
        className="tf-grid"
        style={
          {
            "--cols": "minmax(0, 2fr) minmax(0, 3fr)",
            "--cols-sm": "1fr",
            gap: 16,
            alignItems: "start",
          } as React.CSSProperties
        }
      >
        <div className="tf-panel">
          <ApprovalInbox
            items={items}
            selected={selected}
            onSelect={setSelected}
            filters={["project", "family"]}
            onDecide={(id, key) => {
              if (key === "A" || key === "C") record(id, key);
            }}
          />
        </div>
        {item && (
          <ApprovalCard
            key={String(item.id)}
            agent={item.agent}
            project={item.project}
            family={item.family}
            age={item.age}
            title={item.title}
            text={WHY[String(item.id)]}
            escalation={item.urgent ? "Escalates to the owner in 12 min" : undefined}
            stepUp={item.family === "money" || item.family === "infra"}
            decision={item.decision ?? null}
            onDecide={async (key, text) => {
              await fakeDecision(key, 900);
              record(item.id, key, text);
            }}
          >
            <Payload id={String(item.id)} />
          </ApprovalCard>
        )}
      </div>
    </div>
  );
}
```

## Props

### ApprovalInbox

| Prop | Type | Notes |
| --- | --- | --- |
| `items` | `ApprovalInboxItem[]` | Required |
| `selected?` | `ApprovalInboxItem["id"]` |  |
| `defaultSelected?` | `ApprovalInboxItem["id"]` |  |
| `onSelect?` | `(id: ApprovalInboxItem["id"]) => void` |  |
| `onDecide?` | `(id: ApprovalInboxItem["id"], key: ApprovalKey) => void` | A–D while the list has focus answer the selected approval. A and C usually decide at once; B and D open the text field of the card next to the list. |
| `filters?` | `boolean \| ("project" \| "family" \| "agent")[]` | Filter selects above the list: `true` for project, family and agent, or the ones you want. |
| `filter?` | `ApprovalFilter` |  |
| `defaultFilter?` | `ApprovalFilter` |  |
| `onFilterChange?` | `(filter: ApprovalFilter) => void` |  |
| `view?` | `"open" \| "done"` | "open" (default) or "done": the decided approvals. The switch shows when any item is decided or `showDone`. |
| `defaultView?` | `"open" \| "done"` |  |
| `onViewChange?` | `(view: "open" \| "done") => void` |  |
| `showDone?` | `boolean` |  |
| `escalationWarning?` | `boolean` | Warns above the list when approvals are close to escalating (default true). |
| `linkAs?` | `ElementType` |  |
| `emptyTitle?` | `string` |  |
| `emptyText?` | `string` |  |
| `label?` | `string` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### ApprovalCard

| Prop | Type | Notes |
| --- | --- | --- |
| `title` | `ReactNode` | Required |
| `text?` | `ReactNode` |  |
| `children?` | `ReactNode` |  |
| `agent?` | `string` |  |
| `project?` | `string` |  |
| `family?` | `RiskFamily` |  |
| `familyLabel?` | `string` |  |
| `age?` | `string` |  |
| `escalation?` | `ReactNode` |  |
| `trace?` | `ReactNode` |  |
| `note?` | `ReactNode` |  |
| `heading?` | `string` |  |
| `options?` | `ApprovalOption[]` |  |
| `approveLabel?` | `string` |  |
| `onDecide?` | `(key: ApprovalKey, text?: string) => void \| Promise<unknown>` | Called with the answer (and the text of B or D). Return a Promise to keep the card busy until it settles: the answer's button spins and every answer is disabled; a rejection shows an error (a rejected string is shown as is) and keeps the card open. Once it resolves, a card without a `decision` prop collapses to its one-line record; with a plain callback, set `decision` yourself. |
| `decision?` | `ApprovalDecision \| null` | The decision record: shown as one line instead of the card; `null` keeps the card open. |
| `compact?` | `boolean` | Side panels: tighter, the answers in a row, the payload folded behind "Show what runs" (one click, never a summary). |
| `stepUp?` | `boolean` | Money, legal and infrastructure decisions: A and B (the answers that run something) need a fresh passkey. They show "Needs your passkey"; while `onDecide` is pending the pressed answer says "Confirm with passkey". Do the WebAuthn step-up in `onDecide` and reject if it fails. |
| `busy?` | `ApprovalKey \| null` | The answer being sent, when you track it yourself (controlled busy state). |
| `error?` | `ReactNode` | An error to show above the answers (controlled); a rejected `onDecide` shows one by itself. |
| `screen?` | `boolean` | Fills its container, e.g. a deep link on a phone: the content scrolls and A–D stay at the bottom, full width, in thumb reach (with the safe area). |
| `href?` | `string` | Makes the title a link to the full approval (with `linkAs` for a router's link). |
| `linkAs?` | `ElementType` |  |
| `onApprove?` | `() => void` |  |
| `onDeny?` | `() => void` |  |
| `onEdit?` | `(text: string) => void` |  |
| `state?` | `"approved" \| "denied"` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MessagePreview

| Prop | Type | Notes |
| --- | --- | --- |
| `title?` | `ReactNode` | One line: "Reply to Erika M. on WhatsApp". |
| `channel` | `string` | The channel's name ("WhatsApp", "Instagram", "SMS"). |
| `channelIcon?` | `IconName` | The channel's icon (default `send`); register brand icons to show the logo. |
| `recipient?` | `string` | Already masked, or pass it through `maskRecipient`. |
| `sender?` | `string` | The account it is sent from. |
| `window?` | `{ state: "open" \| "closing" \| "closed"; until?: Date \| string \| number }` | Messaging windows (e.g. 24 hours after the customer's last message). |
| `context?` | `MessagePreviewContext[]` | The last messages, oldest first. |
| `text?` | `string` | Exactly what goes out. |
| `template?` | `{ name: string; category?: string; language?: string; params?: string[] }` | A pre-approved template instead of free text. |
| `media?` | `{ kind: "image" \| "video"; src: string; alt?: string; poster?: string }` | The image or video of a post. |
| `warnings?` | `ReactNode[]` |  |
| `facts?` | `KeyValueItem[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### MoneyPreview

| Prop | Type | Notes |
| --- | --- | --- |
| `title?` | `ReactNode` |  |
| `amount` | `number` | In the currency's units (12.5 = €12.50); negative for money going out of a booking. |
| `currency?` | `string` | ISO code (default EUR). |
| `recipient?` | `string` | Already masked ("DE89 …3000", "…4242"). |
| `reference?` | `ReactNode` |  |
| `account?` | `ReactNode` |  |
| `bookings?` | `MoneyBooking[]` | The bookings this writes, with their sum below. |
| `refund?` | `{ payment: ReactNode; paidAt?: ReactNode; original?: number }` | A refund: the payment it goes back to. |
| `stepUp?` | `boolean` | Shows "Needs a fresh passkey" (default true). |
| `facts?` | `KeyValueItem[]` |  |
| `warnings?` | `ReactNode[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### ChangePreview

| Prop | Type | Notes |
| --- | --- | --- |
| `title?` | `ReactNode` | What changes, in one line ("Update TXT record ops-test · example.com"). |
| `facts?` | `KeyValueItem[]` | Context above the table: provider, account, region, target. |
| `fields` | `ChangeField[]` | Required |
| `fieldHeading?` | `string` | Heading of the first column (default "Field"). |
| `onlyChanged?` | `boolean` | Only the changed rows. |
| `diff?` | `{ before: string; after: string; context?: number }` | A line diff below the table (config files, long texts), folded around the changes. |
| `warnings?` | `ReactNode[]` | Worded by you; shown as warnings under the change. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### CommandPreview

| Prop | Type | Notes |
| --- | --- | --- |
| `command` | `string` | The command exactly as it runs. |
| `argv?` | `string[]` | The same command word by word, when it runs without a shell (argv). |
| `server` | `ReactNode` | Required |
| `host?` | `string` | Host, user and port ("deploy@203.0.113.7:22"). |
| `risk?` | `CommandRisk` |  |
| `timeout?` | `number` | Seconds until it is stopped. |
| `stateBefore?` | `string` | What was read before asking (status, a log excerpt), verbatim. |
| `stateAt?` | `ReactNode` | When `stateBefore` was read ("09:41"). |
| `facts?` | `KeyValueItem[]` | More facts: host key, whitelist entry, parameters. |
| `warnings?` | `ReactNode[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### PageHeader

| Prop | Type | Notes |
| --- | --- | --- |
| `crumbs?` | `(string \| Crumb)[]` | A breadcrumb above the title (see `Breadcrumb`): labels, or items with `href`/`onClick`. |
| `crumbLinkAs?` | `ElementType` | The element crumb links render as, e.g. Next.js `Link`. |
| `title` | `string` | Required |
| `subtitle?` | `string` |  |
| `actions?` | `ReactNode[]` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
