> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Create a workflow-powered Document Action

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

> [!WARNING]
> Early access
> Workflows is in early access, built in public. Read [How early access works](https://www.sanity.io/docs/workflows/prerelease) before you rely on it.



The Studio adapter `@sanity/workflows-ui/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 in-flight `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](https://www.sanity.io/docs/workflows/studio-plugin) for ready-made document form, workflow, badge, and locking interfaces.
- Use `@sanity/workflows-ui/sdk` for an [App SDK](https://www.sanity.io/docs/workflows/app-sdk) application outside Studio.

Before you start, you need:

- The finished [quick start](https://www.sanity.io/docs/workflows/getting-started): `article-review` deployed to the `dev` partition of your dataset.
- 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](https://www.sanity.io/docs/studio/document-actions).

## Install the adapter

Before installing, apply the [SDK dependency override](https://www.sanity.io/docs/workflows/app-sdk) 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.

**npm**

```shell
npm install @sanity/workflows-ui @sanity/workflows @sanity/sdk@^3.1
```

**pnpm**

```shell
pnpm add @sanity/workflows-ui @sanity/workflows @sanity/sdk@^3.1
```

**yarn**

```shell
yarn add @sanity/workflows-ui @sanity/workflows @sanity/sdk@^3.1
```

**bun**

```shell
bun add @sanity/workflows-ui @sanity/workflows @sanity/sdk@^3.1
```

## Build the action component

A [Document Action](https://www.sanity.io/docs/studio/document-actions) 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 returns the descriptor Studio renders as 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.

![A Studio editor opens a custom Submit for review Document Action. The action uses the Studio adapter to find the active review workflow and create a reactive session. The adapter asks the workflow engine to evaluate the submit action; after the editor confirms, the action fires the allowed workflow command and the engine commits the Drafting to Review transition.](https://cdn.sanity.io/images/3do82whm/next/80866ecd9db43c05dba877d41d530f43772a1ad3-2800x1880.png)

**workflow-document-action.tsx**

```tsx
import {gdrUri, type Engine} from '@sanity/workflows'
import {
  useDocumentWorkflows,
  useWorkflowEngine,
  useWorkflowSession,
} from '@sanity/workflows-ui/studio'
import {useMemo, useState} from 'react'
import {useClient, type DocumentActionComponent} from 'sanity'

// The dataset and partition the quick start deployed to.
const workflowResource = {type: 'dataset', id: 'PROJECT_ID.DATASET_NAME'} as const

export const SubmitForReviewAction: DocumentActionComponent = (props) => {
  const [open, setOpen] = useState(false)
  const engine = useWorkflowEngine({workflowResource, partition: 'dev'})
  const client = useClient({apiVersion: '2026-07-01'})
  const {projectId, dataset} = client.config()
  if (!projectId || !dataset) throw new Error('Studio client is missing its project or dataset')

  const document = useMemo(
    () => gdrUri({scheme: 'dataset', projectId, dataset, documentId: props.id}),
    [dataset, projectId, props.id],
  )
  const {instances, loading, unreadable, error} = useDocumentWorkflows({
    engine,
    document,
    filter: 'definition == $definition && !defined(completedAt)',
    params: {definition: 'article-review'},
  })
  const instance = instances?.[0]
  const unavailable = error ?? (unreadable.length > 0 ? unreadable[0] : undefined)

  let reason: string | undefined
  if (!loading && unavailable !== undefined) reason = 'Workflow state could not be read'
  else if (!loading && instance === undefined) reason = 'No active article review workflow'

  return {
    label: 'Submit for review',
    disabled: loading || unavailable !== undefined || instance === undefined,
    title: reason,
    onHandle: () => setOpen(true),
    dialog:
      open && instance
        ? {
            type: 'dialog',
            header: 'Submit for review',
            onClose: () => setOpen(false),
            content: (
              <SubmitDialog
                engine={engine}
                instanceId={instance._id}
                onClose={() => setOpen(false)}
              />
            ),
          }
        : false,
  }
}

function SubmitDialog({
  engine,
  instanceId,
  onClose,
}: {
  engine: Engine
  instanceId: string
  onClose: () => void
}) {
  const [submitting, setSubmitting] = useState(false)
  const [submitError, setSubmitError] = useState<unknown>()
  const {evaluation, evaluationError, ready, invalid, error, fireAction} =
    useWorkflowSession({engine, instanceId})
  const activity = evaluation?.currentStage.activities.find(
    (candidate) => candidate.activity.name === 'write',
  )
  const submit = activity?.actions.find((candidate) => candidate.action.name === 'submit')

  if (invalid) return <p>This workflow instance cannot be read by this version.</p>
  if (error) return <p>Workflow state could not be loaded.</p>
  if (evaluationError) return <p>Workflow evaluation failed.</p>
  if (!ready || !evaluation) return <p>Loading workflow…</p>
  if (!activity || !submit) return <p>Submit is not available in the current stage.</p>

  const handleSubmit = async () => {
    setSubmitting(true)
    setSubmitError(undefined)
    try {
      await fireAction({activity: activity.activity.name, action: submit.action.name})
      onClose()
    } catch (caught) {
      setSubmitError(caught)
    } finally {
      setSubmitting(false)
    }
  }

  return (
    <div>
      <p>{submit.allowed ? 'The article is ready to submit.' : 'The article cannot be submitted yet.'}</p>
      {submitError ? <p>Submission failed. Try again.</p> : null}
      <button disabled={!submit.allowed || submitting} onClick={handleSubmit} type="button">
        {submitting ? 'Submitting…' : 'Submit'}
      </button>
    </div>
  )
}
```

The action handles loading, unreadable workflow data, a missing instance, a disabled verdict, and a failed commit. `useDocumentWorkflows` lists every instance that references the document, finished ones included. The `filter` keeps only in-flight instances of the definition this control targets, so the action never opens a finished instance.

> [!NOTE]
> Verdicts are advisory, not enforcement
> `submit.allowed` tells your interface whether to offer the action. It is not a security boundary. Render the loading, observer-failure, and evaluation-failure states, respect the evaluated verdict, and handle a failed commit. Run effects and other background work in a server runtime rather than in a Studio component: see [Effects and runtimes](https://www.sanity.io/docs/workflows/effects-and-runtimes).

## 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.

**sanity.config.ts**

```typescript
import {defineConfig} from 'sanity'

import {SubmitForReviewAction} from './workflow-document-action'

export default defineConfig({
  projectId: 'PROJECT_ID',
  dataset: 'DATASET_NAME',
  document: {
    actions: (previous, context) =>
      context.schemaType === 'article' ? [SubmitForReviewAction, ...previous] : previous,
  },
})
```

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](https://www.sanity.io/docs/studio/studio-components-reference) instead: the root layout wraps every tool and document surface.

## Verify it in the document editor

The quick start’s instance has already finished, so start a new one for an `article` document. It lands in `drafting`, where `write/submit` is available:

**npm**

```shell
npx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
```

**pnpm**

```shell
pnpm dlx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
```

**yarn**

```shell
yarn dlx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
```

**bun**

```shell
bunx sanity-workflows start article-review \
  --field subject='{"id":"dataset:PROJECT_ID:DATASET_NAME:DOCUMENT_ID","type":"article"}'
```

Open that article in Studio. **Submit for review** appears in the document's action menu. Confirming in the dialog fires the workflow action, and the engine moves the instance from `drafting` to `review`.

If the action is disabled, its tooltip names the reason. `No active article review workflow` means the document has no in-flight instance of that definition, and `Workflow state could not be read` means the adapter could not read the document’s workflow instances. While the adapter is still loading, the action is disabled with no tooltip.

## Next steps

- [The reactive session](https://www.sanity.io/docs/workflows/reactive-session): every state a session can be in, how it stays current, and how to preview and commit field edits.
- [Reusable UI components](https://www.sanity.io/docs/workflows/ui-components): assignment, date, member, and workflow-diagram controls you can drop into a custom surface.
- [Add Workflows to Sanity Studio](https://www.sanity.io/docs/workflows/studio-plugin): install the ready-made Studio interface instead of building your own.
- [Reference](https://www.sanity.io/docs/workflows/reference): the engine and Studio plugin API surface, with types and defaults.

> [!NOTE]
> Visiting agent?
> Workflows has MCP tools that let an agent inspect, operate, author, validate, and deploy workflows. An agent host embeds these tools. Ask the person you work for whether your host [includes the Workflows tools](https://www.sanity.io/docs/workflows/mcp).



