# Publish Workflow Simplification Design

**Date:** 2025-12-13
**Issue:** #171 - Page publishing errors
**Status:** Approved

## Overview

Replace complex save/publish workflow with simple "Publish" button on each editor. Remove EditorContext coordination layer. Keep draft/published page status for visibility control.

## Principles

1. **One action per editor** - "Publish" saves changes AND publishes site
2. **Draft protection** - Pages created as drafts stay hidden until published
3. **Dashboard as hub** - FloatingPublishButton stays on `/dashboard` as convenience
4. **Context-aware links** - CMS editor links to specific page being edited

## Current State

- FloatingPublishButton appears on all dashboard pages
- Complex pathname detection triggers different save behaviors
- EditorContext coordinates saves between editors and FloatingPublishButton
- CMS pages have "Save Draft" + "Publish" buttons
- Draft/published status controls page visibility

## Target State

### Editor Changes

| Editor          | Path                             | Current                                | New                            |
| --------------- | -------------------------------- | -------------------------------------- | ------------------------------ |
| Basic Info      | `/dashboard/editor`              | "Save Changes"                         | "Publish"                      |
| Slider Editor   | `/dashboard/slider-editor`       | No button (uses FloatingPublishButton) | "Publish" button in header     |
| CMS Page Editor | `/dashboard/cms/pages/[id]/edit` | "Save Draft" + "Publish"               | "Publish" + "View Page →" link |
| Navigation      | `/dashboard/cms/navigation`      | "Save & Publish"                       | "Publish"                      |
| Quick Links     | `/dashboard/cms/links`           | Save icon                              | "Publish"                      |

### Publish Button Behavior

All editors: "Publish" button performs:

1. Save current editor's data to API
2. Call `POST /api/dealers/{id}/publish` for ISR revalidation
3. Show success/error feedback

### CMS Page Editor

Header layout:

```
← Back                          [View Page →] [Settings] [Publish]
```

- "View Page →" only shows if dealer is active
- Links to `/dealers/{subdomain}/{slug}` (dev) or live URL (prod)
- Status badges removed from header (draft/published tabs remain in pages list)

Page state behavior:
| Page State | What "Publish" does |
|------------|---------------------|
| New draft (never published) | Save content + set status='published' + publish site |
| Already published | Save content + publish site (status stays 'published') |

### FloatingPublishButton

**Location:** Only on `/dashboard` (removed from all other pages)

**Simplified logic:**

```
IF dealer.status !== 'active' (first-time):
  → Show "Publish Site" button

ELSE IF dealer.updatedAt > dealer.lastPublishedAt:
  → Show "View Live Site" link + "Publish Changes" button

ELSE (no changes):
  → Show "View Live Site" link only
```

### Preview Page

Banner updated:

```
[PREVIEW MODE] This is a preview...  [Publish] [← Back to Dashboard]
```

- "Publish" button added to left of "Back to Dashboard"
- FloatingPublishButton removed from this page

## Files to Modify

### Delete

- `/contexts/EditorContext.tsx`

### Modify

| File                                          | Changes                                                                                    |
| --------------------------------------------- | ------------------------------------------------------------------------------------------ |
| `/components/FloatingPublishButton.tsx`       | Simplify - remove EditorContext, pathname detection, CMS logic (~50 lines instead of ~280) |
| `/app/dashboard/layout.tsx`                   | Remove EditorProvider, conditionally render FloatingPublishButton only on `/dashboard`     |
| `/app/dashboard/editor/EditorForm.tsx`        | Remove EditorContext, "Save Changes" → "Publish", add publish API call                     |
| `/app/dashboard/slider-editor/page.tsx`       | Remove EditorContext, add "Publish" button header                                          |
| `/app/dashboard/cms/pages/[id]/edit/page.tsx` | Remove "Save Draft", keep "Publish", add "View Page →" link                                |
| `/app/dashboard/cms/navigation/page.tsx`      | "Save & Publish" → "Publish"                                                               |
| `/app/dashboard/cms/links/page.tsx`           | Save icon → "Publish" button                                                               |
| `/app/dashboard/preview/page.tsx`             | Add "Publish" button to banner                                                             |

### Tests to Update

| File                                                   | Changes                          |
| ------------------------------------------------------ | -------------------------------- |
| `/components/__tests__/FloatingPublishButton.test.tsx` | Rewrite for simplified component |
| `/app/dashboard/editor/__tests__/integration.test.tsx` | Remove EditorContext mocks       |

## What Stays the Same

- Draft/published page status in database schema
- Page visibility control (drafts hidden from public dealer site)
- Pages list with draft/published filter tabs
- Preview page and preview banner functionality
- Dashboard preview banner for first-time publish

## Migration

No database migrations needed. Draft/published status remains unchanged.

## Risks & Mitigations

| Risk                    | Mitigation                                      |
| ----------------------- | ----------------------------------------------- |
| Users forget to publish | Clear success feedback after publish            |
| Accidental publish      | Publish is explicit action (button click)       |
| Lost draft work         | Pages stay as drafts until explicitly published |
