A returned parcel and a refunded payment are different facts. A support agent can approve a request while the item is still with the customer. A warehouse can receive the parcel before the payment provider confirms the refund. If both appear under one generic “Complete” badge, the admin cannot tell what they should do next.

A small TypeScript model can make that difference visible in a React or Next.js admin dashboard, even when the screen is still using fixture data.

Start with one return, not the whole commerce system

For this example, the shop accepts one return request, waits for the item to arrive, and issues at most one refund for that request. Refunds after inspection, exchanges, partial refunds, disputes, and other shop policies all need their own rules. The receive-before-refund rule below is a sample business decision, not a universal requirement.

Keep the original order’s fulfilment status separate from two pieces of return state.

Record What it answers Example
Order fulfilment What happened to the original shipment? Delivered
Return progress What happened to the return request? Approved, awaiting receipt
Refund progress What happened to the money? Pending at provider

That lets an order still say Delivered while its return says Received and its refund says Pending. Those badges are more useful than one status that has to summarize three workflows.

Derive the available action from the state

Here is a small pure function you can test without a browser, a gateway, or a database. Save it as return-actions.ts.

type Refund = | { state: "not_started" } | { state: "pending"; reference: string } | { state: "succeeded"; reference: string } | { state: "failed"; reference: string }; type ReturnRecord = | { stage: "requested"; refund: { state: "not_started" } } | { stage: "approved"; refund: { state: "not_started" } } | { stage: "received"; refund: Refund }; type ReturnAction = | "approve_return" | "record_receipt" | "request_refund" | "review_refund_failure"; function actionsFor(record: ReturnRecord): ReturnAction[] { switch (record.stage) { case "requested": return ["approve_return"]; case "approved": return ["record_receipt"]; case "received": switch (record.refund.state) { case "not_started": return ["request_refund"]; case "failed": return ["review_refund_failure"]; case "pending": case "succeeded": return []; } } } const approved: ReturnRecord = { stage: "approved", refund: { state: "not_started" }, }; const pending: ReturnRecord = { stage: "received", refund: { state: "pending", reference: "refund-test-001" }, }; console.log(actionsFor(approved)); // ["record_receipt"] console.log(actionsFor(pending)); // [] 

The tagged union encodes a constraint. A requested or approved return cannot carry a successful refund in this simplified model. The TypeScript compiler narrows the available fields after the stage check. See the TypeScript guide to discriminated unions for the underlying pattern.

What the admin should show

Display each badge in text. When an operator opens a received return with a pending refund, show the provider reference and the last update time. Do not render a second Refund button. When the provider reports failure, present Review refund failure with enough context to investigate. A failed or timed-out request is not, by itself, evidence that no money moved.

Put those same rules on the server. The client can hide a button, but it cannot prevent two authenticated operators from trying to refund the same return. Have the server re-read or lock the record, verify the operator's authority and the current state, and record the refund attempt durably. Use a stable idempotency key if your payment provider supports it. Reconcile the result from the provider before marking it succeeded. Handle restocking against its own inventory rule rather than assuming payment confirmation means an item arrived.

Before adding real payments, run these cases against fixtures.

  • An approved return offers Record receipt and no refund action.
  • A received return with no refund offers Request refund.
  • A pending or successful refund never offers a second request.
  • A failed refund offers a review action rather than a blind retry.
  • A stale page cannot force a transition the server no longer allows.

If all five are clear in the interface, the backend integration has a much better starting point. You can keep the demo actions behind a service interface and swap the fixture implementation for the real API without changing what each status means.

AI disclosure: This article was generated with AI. The TypeScript example was checked separately.