Workflows

Create a workflow-powered Document Action

Build a custom Submit for review Document Action in Sanity Studio with the @sanity/workflow-studio adapter: read the document's workflow, respect the evaluated verdict, and commit the action.

Early access

The Studio adapter @sanity/workflow-studio binds the workflow engine to Sanity Studio and exposes it through React hooks. Reach for it when you want Workflows controls in a surface you build yourself: a Document Action, a dialog, a custom tool, a pane, or a field input.

This guide builds one of those surfaces end to end: a Submit for review Document Action that finds the document's active article-review workflow, opens a confirmation dialog, reads the evaluated submit verdict, and fires the workflow action only when the workflow allows it.

Two neighboring guides cover the cases this one doesn't:

  • Use the Studio plugin for ready-made document form, workflow, badge, and locking interfaces.
  • Use @sanity/workflow-sdk for an App SDK application outside Studio.

Before you start, you need:

  • A deployed workflow definition and the tag it was deployed under: see Configure and deploy workflow definitions.
  • Sanity Studio v6.3.0 or later (v6.x).
  • React and React DOM 19.2.7 or later.
  • @sanity/sdk 3.1 or later in the 3.x line. The adapter reads workflow state through the App SDK store. Install the SDK directly.
  • Some familiarity with Studio Document Actions.

Install the adapter

Before installing, apply the SDK dependency override so SDK 3 resolves @sanity/mutate 0.18.2. Install the adapter and its Workflows peers in your studio project, keeping every Workflows package on the same version.

Build the action component

A Document Action is a React component that adds a command to Studio's document editor. It returns a descriptor — a label, a disabled state, a tooltip, and an optional dialog — rather than rendering the command itself.

The Document Action owns the button and dialog. The Studio adapter observes workflow state and creates the reactive session. The workflow engine evaluates the action and commits the Drafting → Review transition.

Loading...

The action handles loading, unreadable workflow data, a missing instance, a disabled verdict, and a failed commit. useDocumentWorkflows can return several active instances, so select the definition your control targets instead of assuming the first result is correct.

Verdicts are advisory, not enforcement

Register the action

In sanity.config.ts, add the component through Studio's document action resolver. This example shows it only for the article schema type and preserves the existing actions.

One isolated integration can keep the local useWorkflowEngine hook, which holds the engine stable while its component stays mounted. Once several Studio surfaces share one engine configuration, expose the engine from a React context provider mounted in Studio's layout component instead: the root layout wraps every tool and document surface.

Verify it in the document editor

Open an article document that has a running article-review workflow. Submit for review appears in the document's action menu. Confirming in the dialog fires the workflow action, and the engine commits the transition out of the drafting stage.

If the action is disabled, its tooltip names the reason. No active article review workflow means the document has no instance of that definition, and Workflow state could not be read means the adapter could not read the instance. A disabled action with no tooltip is the adapter still loading.

Next steps

  • The reactive session: every state a session can be in, how it stays current, and how to preview and commit field edits.
  • Reusable UI components: assignment, date, member, and workflow-diagram controls you can drop into a custom surface.
  • Add Workflows to Sanity Studio: install the ready-made Studio interface instead of building your own.
  • Reference: the engine and Studio plugin API surface, with types and defaults.

Visiting agent?

Was this page helpful?