# The approval flow

An approval flow moves a record from draft to submitted to approved or rejected, and the same rule is asked twice: by the screen, to show the decision card, and by the api, before it saves. In Meadowstack the decision is an `ApprovalPanel` card at the top of the side column, nobody approves their own record, a rejection always has a written reason and every move writes a history entry.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/patterns/approval-flow/

*The decision card on the starter's purchase request. It asks the same permission the api checks, and the author reads who decides instead of a button. Read from the repository when the site was built.*

From `templates/starter/src/modules/requests/components/request-record.tsx` in the Meadowstack repository:

```tsx
const decision =
  request.status === "submitted" ? (
    <ApprovalPanel
      canDecide={can("request.approve", request)}
      decidedBy={
        mine ? "You can't approve your own request. An approver or admin decides." : "An approver or admin decides."
      }
      onApprove={() => move("approve")}
      onReject={(reason) => move("reject", reason)}
      copy={approvalCopy}
    >
      <p className="text-xl font-semibold text-fg tabular">{formatMoney(request.amount)}</p>
      <p className="text-xs text-fg-muted">
        incl. VAT, needed by <span className="tabular">{formatDate(request.neededBy)}</span>
      </p>
    </ApprovalPanel>
```

Open it in the live demo: https://meadowstack.com/demo/?lang=en#/juniper/lide/volno/lv-114

## The flow, step by step

The starter's purchase requests, with its three sample people: Leah Morgan (member), Marcus Webb (approver) and Hannah Brooks (admin).

1. **Draft.** Leah writes a request. A draft is private to her and the admins: to anyone else the api answers "not found", the way row-level security hides a row.
2. **Submit.** She presses "Submit for approval". The status turns to "Waiting for approval", the history gains "Submitted for approval" with her name, and the toast offers Undo. While it waits she may withdraw it to a draft. She never sees an Approve button on it.
3. **Decide.** Marcus opens the request beside the list. The decision card sits at the top of the side column (first on a phone) with the amount it decides on. Approve asks once more, so a stray click decides nothing. Reject opens a dialog that does not send without a reason.
4. **The answer.** Status, card and history change at once, before the server answers, through the same `applyMove()` and `moveEvent()` the api runs. If the api refuses, a toast says why and the screen swaps back to what is stored. The toast's Undo reopens the request, and only the person who decided may do that.
5. **Rejected, then fixed.** Leah reads "Rejected by Marcus Webb" with his reason, edits the request and submits it again. The history keeps both rounds.
6. **Many at once.** In the list, the selection bar approves only the rows this person may approve and says how many: "Approve 2 of 5". The api moves all of them or none.

## The rules and where each one is enforced

| Rule | Where it is enforced |
| --- | --- |
| Nobody approves their own record, an admin included | one line in `domain/permissions.ts` (`request.status === "submitted" && !mine`), asked by the card through `can()` and by the api before it saves; unit test "keeps four eyes", e2e "nobody approves their own request, an approver included" |
| A rejection has a written reason | the card's reject dialog does not send an empty one, and the api refuses it too ("Write why the request is rejected."); api test "asks for a reason before a rejection, and keeps it in the history" |
| Approving asks once | `ApprovalPanel` confirms before it calls `onApprove` |
| People who cannot decide read who does | with `canDecide` false the card shows the `decidedBy` sentence in place of the buttons, never a disabled button |
| Every move writes a history entry | `moveEvent()` in `domain/workflow.ts`, written by the api with the move; in the Supabase example a trigger writes it in the same transaction |
| Only the decider undoes a decision | `request.reopen` in `domain/permissions.ts` (`decidedById === person.id`); unit test "lets only the decider undo a decision" |
| A bulk approve says how many rows it applies to | the selection bar counts the rows `can("request.approve", row)` allows; api test "moves all or nothing" |
| The detail offers approve and reject | `contract.ts` declares `approval: true`, and `e2e/contract.spec.ts` looks for both actions |

The `kit-approval` skill builds this flow for a new entity with every rule above, and `docs/recipes/approval.md` is the checklist it works through.

## What AI coding tools build instead

- **An Approve button anyone can press.** The page hides it from members, the endpoint accepts it from anyone who sends the request. Here the page and the api ask the same `canFor()`, and the api tests run against the simulated adapter and the HTTP one alike.
- **Four eyes written in a component.** `if (request.requesterId !== user.id)` holds until the bulk bar, the bell or a second screen offers the same action and forgets it. The rule is one line in `domain/permissions.ts`.
- **A disabled Approve button with no reason.** The author stares at grey. The card says who decides instead.
- **Reject without a reason,** or a reason field the api never checks. The person who has to fix the request learns nothing, and neither does the history.
- **A coloured banner across the page** for a routine step, so every waiting request looks like an alarm. The decision is a white card with the half-filled status glyph.
- **A status change without a history entry,** from an update that only sets `status`. Nobody can tell who approved what, or when.
- **Only one person may decide.** With four eyes, that person's own requests then wait for ever. Give the deciding role to two people.

## Where to see it

- [Order record](https://meadowstack.com/screens/order-record/): Reject and Approve on a card at the top of the side column.
- [Proof approval](https://meadowstack.com/screens/proof-approval/): a customer approves or returns a print proof, and the reason is a comment pinned on the artwork (`onRejectInPlace`).
- [Time-off approval](https://meadowstack.com/screens/time-off-approval/): a leave request decided by someone other than the person taking the leave.
- [Quote form](https://meadowstack.com/screens/quote-form/): a quote approved by someone other than its author.
- The kit's [ApprovalPanel](https://meadowstack.com/components/approval-panel/), the [audit trail](https://meadowstack.com/patterns/audit-trail/) every move writes and the [permissions](https://meadowstack.com/patterns/permissions/) the card asks.

## Example apps with a decision card

*Which example apps and modules render the kit's ApprovalPanel, computed from the demo's code when the site was built.*

| Example app | Modules that render it |
| --- | --- |
| [An app for a packaging and print company](https://meadowstack.com/examples/packaging-print-production/) | Jobs, Print file editor, Quotes |
| [An app for a studio or agency](https://meadowstack.com/examples/agency-capacity-planning/) | Capacity |
| [An app for a sports club](https://meadowstack.com/examples/sports-club-court-bookings/) | Coaching |
| [An app for a construction company](https://meadowstack.com/examples/construction-site-management/) | Crews, Drawings |
| [An app for an accounting office](https://meadowstack.com/examples/accounting-office-documents/) | Invoicing |
| [An app for restaurants and venues](https://meadowstack.com/examples/restaurant-staff-rota/) | Shifts, People |

Read from the demo's source when the site was built: 6 of 9 example apps render <ApprovalPanel>, in the modules named here as each app's sidebar names them.

## Five moves in one table

*Each move, the status it leads to, the history entry it writes and the permission it needs. The api applies these functions to the stored request and the screen to what it shows, so an optimistic change looks exactly like the answer that follows.*

From `templates/starter/src/modules/requests/domain/workflow.ts` in the Meadowstack repository:

```ts
export type Move = "submit" | "withdraw" | "approve" | "reject" | "reopen";

const moves: Record<Move, { to: RequestStatus; event: RequestEventType; action: Action }> = {
  submit: { to: "submitted", event: "submitted", action: "request.submit" },
  withdraw: { to: "draft", event: "withdrawn", action: "request.withdraw" },
  approve: { to: "approved", event: "approved", action: "request.approve" },
  reject: { to: "rejected", event: "rejected", action: "request.reject" },
  reopen: { to: "submitted", event: "reopened", action: "request.reopen" },
};
```

## Questions

### Can an admin approve their own request?

No. Four eyes holds for every role: approving and rejecting need a submitted request that someone else wrote. An app where only one person decides gives the deciding role to a second person, or that person's own requests wait for ever.

### Why does a rejection need a reason when an approval does not?

A rejection sends work back to someone who has to fix it, and the reason is the only thing that says what to fix. It stays in the history with the decision. An approval moves the record on, so one confirmation against a stray click is enough.

### What does the author see while the request waits?

The status Waiting for approval, a sentence that says who decides, and the choice to withdraw the request to a draft. There is no Approve button for them to wonder about.

### How is an approval made by mistake undone?

Undo in the toast after the decision reopens the request and writes Decision undone in the history. The permission behind it, request.reopen, lets only the person who decided do it.

### Where does the rule live once the app has a real database?

In the database as well as in the screens. The starter's Supabase example writes the same rules as row-level security policies and a function that moves several requests all or nothing, and the screens keep asking the rules in domain/permissions.ts, so nothing on them changes.

## Related

- [A time-off request waiting for a decision](https://meadowstack.com/screens/time-off-approval/) (Screens)
- [A driver record that says what expires next](https://meadowstack.com/screens/driver-record/) (Screens)
- [A lot record that traces one step back and one step forward](https://meadowstack.com/screens/lot-traceability/) (Screens)
- [A month close that knows what each step waits for](https://meadowstack.com/screens/month-end-close/) (Screens)
- [A site diary day, prefilled and signed by the right person](https://meadowstack.com/screens/site-diary/) (Screens)
- [An order record with its decision](https://meadowstack.com/screens/order-record/) (Screens)
