Skip to content

Patterns

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.

By Bohuslav PoláčekChecked

templates/starter/src/modules/requests/components/request-record.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>
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.

Open it in the live demo

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

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: Reject and Approve on a card at the top of the side column.
  • Proof approval: a customer approves or returns a print proof, and the reason is a comment pinned on the artwork (onRejectInPlace).
  • Time-off approval: a leave request decided by someone other than the person taking the leave.
  • Quote form: a quote approved by someone other than its author.
  • The kit's ApprovalPanel, the audit trail every move writes and the 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.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

templates/starter/src/modules/requests/domain/workflow.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" },
};
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.

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.

Two ways

Build it yourself, or have it built

  • Build it yourself

    Build your app on the framework

    Get the codebase these apps stand on and build yours with Claude Code, Cursor or Codex.

    One payment, lifetime updates

    Get the framework
  • Have it built

    Have us build your app

    Tell us how your team works. We plan the app with you and build it on the same framework at a fixed price.

    After launch, Care keeps it improving, from €99 a month.

    from €1,990

    Describe your app