StatusTransitionButton

FSM-aware status change button. Reads the record's current status, looks up allowed transitions in a config, optionally filters via guard predicates, and fires useUpdate on selection.

Installation

pnpm dlx shadcn@latest add @shadmin/status-transition-button

Usage

import { StatusTransitionButton } from "@/components/admin";
 
const TRANSITIONS = {
  draft: ["review", "archived"],
  review: ["published", "draft"],
  published: ["archived"],
  archived: [],
};
 
<StatusTransitionButton source="status" transitions={TRANSITIONS} />;
{
  /* With guards */
}
<StatusTransitionButton
  source="status"
  transitions={TRANSITIONS}
  guards={{
    "review->published": (record) => record.requiredFields != null,
  }}
  confirm
/>;

Props

PropRequiredTypeDefaultDescription
transitionsRequiredRecord<string, readonly string[]>-Allowed transitions per state
sourceOptionalstring"status"Record field holding the state
guardsOptionalRecord<string, (record) => boolean>-${from}->${to} predicates
resourceOptionalstringContextOverride resource
confirmOptionalbooleanfalseNative confirm before update
onTransitionOptional(from, to, record) => void-Side-effect callback

Terminal states

When the current state maps to an empty array, the button is rendered disabled.