Workflow Manager plugin for Sanity Studio v4 providing workflow management with drag & drop.
npm install @multidots/sanity-plugin-workflow-managerA comprehensive Sanity Studio v4 plugin for managing content workflows with advanced features including drag-and-drop functionality, user assignments, publishing calendar, and state management.
- Document Cards
Rich document cards with metadata and user assignments
``bash`
npm install @multidots/sanity-plugin-workflow-manager
The plugin requires these peer dependencies (install if not already present):
`bash`
npm install @sanity/ui @sanity/icons @hello-pangea/dnd framer-motion styled-components groq lexorank @tanstack/react-virtual
`typescript
// sanity.config.ts
import {defineConfig} from 'sanity'
import {workflowManager} from '@multidots/sanity-plugin-workflow-manager'
export default defineConfig({
name: 'default',
title: 'Your Studio',
projectId: 'your-project-id',
dataset: 'production',
plugins: [
workflowManager({
// Required: List of document types to include in workflow
schemaTypes: ['post', 'article', 'product'],
// Optional: Custom workflow states
states: [
{
id: 'draft',
title: 'Draft',
color: 'primary',
transitions: ['review']
},
{
id: 'review',
title: 'In Review',
color: 'warning',
transitions: ['approved', 'changes-requested'],
requireAssignment: true
},
{
id: 'approved',
title: 'Approved',
color: 'success',
requireAssignment: true,
requireValidation: true
}
]
})
],
schema: {
types: [
// Your existing schemas
],
},
})
`
The plugin automatically creates a workflow.metadata schema type that tracks:
- Document state and transitions
- User assignments
- Order ranking for drag-and-drop
- Publishing schedule information
- Publishing dependencies
The plugin provides several document actions and badges:
- Begin Workflow: Start a document in the workflow
- Assign Workflow: Assign users to a document
- Update Workflow: Move document between states
- Complete Workflow: Remove document from workflow
- Schedule Workflow: Schedule document for publishing
- Schedule Badge: Visual indicator of publishing status
1. Open your Sanity Studio
2. Navigate to the Workflow tool from the navigation menu on top
3. View all documents organized by workflow states
4. Drag and drop documents between states
5. Assign users to documents for review
6. Use filters to view specific users or document types
1. Navigate to the Publishing Calendar tool from the navigation menu on top
2. View scheduled content in calendar format
3. Drag documents to specific dates for scheduling
4. Click on calendar events to open Quick Edit Modal
5. Manage publishing dependencies
6. Filter by workflow states
Document cards display:
- Document type with appropriate icons
- Workflow state with color-coded badges
- Last modified timestamp
- Assigned users with avatars
- Action buttons for editing and state changes
- Visual indicators for validation status
Access the Quick Edit Modal by:
1. Clicking on any calendar event
2. Right-clicking on a calendar event and selecting "Edit"
3. Using the context menu on document cards
Features:
- Edit document title and basic information
- Change workflow state with permission checking
- Assign or reassign users
- Manage publishing dependencies
- Navigate to full document editor
Right-click on calendar events to access:
- Edit document details
- Navigate to document editor
- Change workflow state
- Unschedule document
- View dependency information
Set up dependencies by:
1. Opening the Quick Edit Modal
2. Using the Dependency Manager
3. Searching for documents to depend on
4. Adding or removing dependencies
The plugin stores schedule information in workflow.metadata documents. To enable automatic publishing at scheduled times, you need to set up a cron job that calls a publish endpoint.
1. Copy the API endpoint from examples/serverless/ to your project:publish-scheduled.ts
- TypeScript: → api/publish-scheduled.ts (Vercel) or netlify/functions/publish-scheduled.ts (Netlify)publish-scheduled.js
- JavaScript: → appropriate location for your platform
2. Set environment variables:
`env`
SANITY_PROJECT_ID=your-project-id
SANITY_DATASET=production
SANITY_API_TOKEN=your-write-token
CRON_SECRET=optional-secret-for-auth
3. Set up a cron job (choose one method):
Option A: Platform Cron Jobs (if available)
- Vercel: Copy examples/serverless/vercel.json to project rootexamples/serverless/netlify.toml
- Netlify: Copy and install @netlify/plugin-scheduled-functions
Option B: External Cron Service (works everywhere, including free tiers)
- Use cron-job.org (free)
- Point it to: https://your-app.vercel.app/api/publish-scheduled *
- Schedule: Every minute ()Authorization: Bearer YOUR_CRON_SECRET
- Optional: Add header
Option C: GitHub Actions (free)
- Create .github/workflows/publish-scheduled.ymlexamples/serverless/README.md
- See for template
1. Go to sanity.io/manage
2. Select your project → API → Tokens
3. Click Add API token
4. Set permissions to Editor (needs write access)
5. Copy token to environment variables
1. When you schedule a document, the plugin stores the schedule in workflow.metadata"published"
2. The cron job calls the publish endpoint every minute
3. The endpoint finds documents scheduled to publish (past or current time)
4. It checks dependencies (if any) are published
5. It publishes the draft document automatically
6. Updates the schedule status to
Test the endpoint manually:
`bash`
curl https://your-app.vercel.app/api/publish-scheduled \
-H "Authorization: Bearer YOUR_CRON_SECRET"
See examples/serverless/README.md for:
- Detailed platform-specific setup
- Troubleshooting guide
- Security best practices
- Alternative cron service options
Each workflow state supports:
`typescript`
{
id: 'state-id', // Unique identifier
title: 'State Title', // Display name
color: 'primary', // Visual indicator (primary, success, warning, danger)
roles: ['editor', 'admin'], // User roles that can access this state
transitions: ['next-state'], // Allowed next states
requireAssignment: true, // Requires user assignment
requireValidation: true // Requires document validation
}
If no custom states are provided:
`typescript`
[
{
id: 'inReview',
title: 'In review',
color: 'primary',
roles: ['editor', 'administrator'],
transitions: ['changesRequested', 'approved'],
},
{
id: 'changesRequested',
title: 'Changes requested',
color: 'warning',
roles: ['editor', 'administrator'],
transitions: ['approved'],
},
{
id: 'approved',
title: 'Approved',
color: 'success',
roles: ['administrator'],
transitions: ['changesRequested'],
requireAssignment: true,
},
]
Specify which document types should be included in the workflow:
`typescript`
workflowManager({
schemaTypes: ['post', 'article', 'product', 'page']
})
- WorkflowTool: Main workflow board interface
- CalendarView: Publishing calendar interface
- DocumentCard: Enhanced document display with rich metadata
- DocumentList: List of documents in a workflow state
- QuickEditModal: Inline editing modal for calendar events
- ContextMenu: Right-click context menu for calendar events
- DependencyManager: Publishing dependency management
- UserDisplay: User assignment interface with avatars
- Filters: Filter by user and schema type
- useWorkflowDocuments: Fetch and manage workflow documents
- useWorkflowMetadata: Access workflow metadata
- useWorkflowContext: Workflow context provider
- useProjectUsers: Fetch project users for assignment
- useListeningQuery: Real-time data subscription
- filterItemsAndSort: Document filtering and sorting
- State: Workflow state definition
- UserExtended: Extended user information
- SanityDocumentWithMetadata: Document with workflow metadata
- CalendarEvent: Calendar event with workflow information
- WorkflowConfig: Plugin configuration type
1. Documents not appearing in workflow
- Ensure documents are added to workflow using "Begin Workflow" action
- Check that document types are included in plugin configuration
2. Drag and drop not working
- Verify @hello-pangea/dnd is installed
- Check browser console for JavaScript errors
3. User assignment issues
- Ensure users have proper roles and permissions
- Check that user data is loading correctly
4. Calendar not showing documents
- Verify documents have been scheduled
- Check GROQ query for data fetching issues
5. Theme-related errors
- Plugin uses optional chaining for theme access
- Fallback colors are provided for missing theme properties
1. Check browser console for error messages
2. Verify all required dependencies are installed
3. Ensure Sanity Studio v4 compatibility
4. Check plugin configuration in sanity.config.ts
5. Verify document types are properly configured
`bash`
npm run build
`bash``
npm run dev
The plugin is built with TypeScript and includes comprehensive type definitions for all components and utilities.
This plugin is designed to be extensible. Key areas for customization:
- Workflow state definitions and transitions
- User assignment logic and permissions
- Validation requirements and rules
- UI components and styling
- Calendar view customization
- Dependency management logic
MIT
For issues and questions:
1. Check the configuration examples above
2. Verify your Sanity v4 setup and dependencies
3. Ensure all required peer dependencies are installed
4. Check browser console for error messages
5. Review the troubleshooting section above