Skip to content
tellerline

Component · client

Maker-checker

One person makes a change and someone else approves it. This shows what would change, who has approved so far and how many approvals are left. Each viewer gets only the actions the policy allows, and a plain reason when they get none.

Try it

Payment to Northwind Supplies GmbH

€17,890.40 · Invoice INV-4471 · value date 5 March

Requested by Mina Rahimi ·

Pending approval

0 of 2 approvals

Amount
from €18,250.00to €17,890.40
Reference
from March suppliesto INV-4471

Payments of €10,000.00 or more need two approvers. Approve as Daniel, then switch to Mina or Omid to see why they can't, and to Sara to finish it.

Install

npx shadcn@latest add https://tellerline-ui.vercel.app/r/maker-checker.json

This adds the component, lib/approval.ts with the rules, and the shared change list. Like the other components, it needs nothing beyond React and the shadcn cn helper.

Usage

"use client"

import { MakerChecker } from "@/components/ui/maker-checker"
import { requiredApprovalsFor } from "@/lib/approval"

const policy = {
  requiredApprovals: requiredApprovalsFor(payment.amount, [
    { from: "0", approvals: 1 },
    { from: "10000", approvals: 2 },
  ]),
  approverRoles: ["approver"],
}

export function PaymentApproval({ payment, request, viewer }) {
  return (
    <MakerChecker
      request={request}
      policy={policy}
      viewer={viewer}
      onApprove={(comment) => approvePayment(payment.id, comment)}
      onReject={(reason) => rejectPayment(payment.id, reason)}
      onWithdraw={() => withdrawPayment(payment.id)}
    />
  )
}

Check again on the server

The component only decides what to show. Anyone can call your API without it, so run the same rules before you save a decision. They are plain functions with no React in them, so the import works in a server action or route handler. More on this in Hide the button, enforce on the server.

// app/payments/actions.ts
"use server"

import { canDecide } from "@/lib/approval"

export async function approvePayment(id: string, comment: string) {
  const viewer = await currentUser()
  const request = await loadApprovalRequest(id)
  const policy = await loadPolicy(request)

  const check = canDecide(request, policy, viewer)
  if (!check.ok) throw new Error(`Not allowed: ${check.reason}`)

  await saveDecision(id, { by: viewer, decision: "approve", comment, at: new Date() })
}

Rules

No self-approval
The maker can never approve their own request, whatever roles they have. People are matched by id, not by name.
Distinct approvers
Each person counts once. A second approval from the same person is shown but not counted.
One rejection ends it
A rejection needs a reason, which is shown to the maker, and nothing after it changes the outcome.
Withdrawing
The maker can withdraw while the request is pending. Decisions made after that point don't count.
Exact thresholds
requiredApprovalsFor compares amounts as BigInt minor units, so 9,999.995 never rounds into the next tier.
Order by time
Decisions are read in the order they were made, so the result doesn't depend on how your API sorts them.

Accessibility

Reasons, not disabled buttons
Someone who can't act sees a sentence saying why, instead of a greyed-out button that gives no explanation.
Rejecting without a reason
The comment field is marked invalid, gets the error as its description and receives focus.
Async actions
While a callback is pending the action area is aria-busy. Errors are announced as alerts and successes through a status message.
Progress
The approval count is written out in text. The bars beside it are decoration and hidden from screen readers.

Props

PropTypeDefaultDescription
requestMakerCheckerRequest—id, title, maker, createdAt, decisions, and optionally summary, changes and withdrawnAt.
policyApprovalPolicy—requiredApprovals, and approverRoles to limit who can decide.
viewerPerson—id, name and roles of the person looking at the request.
onApprove(comment) => void | Promise—Return a promise for a pending state; throw to show its message as an error.
onReject(reason) => void | Promise—Only called with a non-empty reason.
onWithdraw() => void | Promise—Offered to the maker while the request is pending.
formatValue(field, value) => ReactNodeStringFormats values in the change list.
localestring"en-US"Locale for dates and lists of names.
timeZonestringruntime zoneIANA zone for times. Pass it explicitly when rendering on the server.
nowDate—Turns on relative times.
headingLevel2 – 63Level of the request title.