> **ARCHIVED:** 2025-12-22 | Implementation completed. EditorContext removed, publish workflow simplified.

# Implementation Plan: Publish Workflow Simplification

**Branch:** `feature/publish-workflow-simplification`
**Design Doc:** `docs/plans/2025-12-13-publish-workflow-simplification-design.md`

## Implementation Order

Changes ordered by dependency - each phase can be tested independently.

---

## Phase 1: FloatingPublishButton Simplification

**Goal:** Simplify component, restrict to `/dashboard` only

### Step 1.1: Simplify FloatingPublishButton component

**File:** `/components/FloatingPublishButton.tsx`

- [ ] Remove `useEditorOptional` import and usage
- [ ] Remove pathname detection logic (CMS page regex, editor checks)
- [ ] Remove CMS page slug/type fetching useEffect
- [ ] Remove EditorContext save triggering logic
- [ ] Keep only: visibility logic, publish button, view live site link
- [ ] Target: ~50 lines instead of ~280

### Step 1.2: Restrict to dashboard only

**File:** `/app/dashboard/layout.tsx`

- [ ] Add pathname check to only render FloatingPublishButton on exact `/dashboard` path
- [ ] Remove EditorProvider wrapper (will be deleted in Phase 2)

### Step 1.3: Update tests

**File:** `/components/__tests__/FloatingPublishButton.test.tsx`

- [ ] Remove EditorContext mocks
- [ ] Update test cases for simplified behavior
- [ ] Remove pathname-specific test cases

---

## Phase 2: Remove EditorContext

**Goal:** Delete the coordination layer

### Step 2.1: Delete EditorContext

**File:** `/contexts/EditorContext.tsx`

- [ ] Delete file entirely

### Step 2.2: Remove EditorProvider from layout

**File:** `/app/dashboard/layout.tsx`

- [ ] Remove EditorProvider import
- [ ] Remove EditorProvider wrapper from JSX

### Step 2.3: Update editor test mocks

**File:** `/app/dashboard/editor/__tests__/integration.test.tsx`

- [ ] Remove EditorContext mocks

---

## Phase 3: Update Basic Info Editor

**Goal:** "Save Changes" → "Publish" with site publish

### Step 3.1: Update EditorForm

**File:** `/app/dashboard/editor/EditorForm.tsx`

- [ ] Remove `useEditorOptional` import and usage
- [ ] Remove `registerSaveHandler` / `unregisterSaveHandler` calls
- [ ] Rename button from "Save Changes" to "Publish"
- [ ] Add publish API call after successful save:
  ```typescript
  await fetch(`/api/dealers/${dealerId}/publish`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({}),
  });
  ```
- [ ] Update success message

---

## Phase 4: Update Slider Editor

**Goal:** Add "Publish" button header

### Step 4.1: Add Publish button

**File:** `/app/dashboard/slider-editor/page.tsx`

- [ ] Remove `useEditor` import and usage
- [ ] Remove `registerSaveHandler` / `unregisterSaveHandler` calls
- [ ] Add header with "← Back to Dashboard" and "Publish" button
- [ ] Publish button: save slider + call publish API
- [ ] Match CMS editor header styling

---

## Phase 5: Update CMS Page Editor

**Goal:** Simplify to single "Publish" + add "View Page" link

### Step 5.1: Update header layout

**File:** `/app/dashboard/cms/pages/[id]/edit/page.tsx`

- [ ] Remove status badges from header
- [ ] Remove "Save Draft" button from Puck headerActions
- [ ] Keep "Publish" button, update to also call site publish API
- [ ] Add "View Page →" link (only if dealer.status === 'active')
- [ ] View Page URL: dev = `/dealers/{subdomain}/{slug}`, prod = full URL

### Step 5.2: Update Publish behavior

- [ ] For draft pages: save + set status='published' + publish site
- [ ] For published pages: save + publish site (status stays published)

---

## Phase 6: Update Navigation Editor

**Goal:** "Save & Publish" → "Publish"

### Step 6.1: Rename button

**File:** `/app/dashboard/cms/navigation/page.tsx`

- [ ] Rename "Save & Publish" to "Publish"
- [ ] Ensure it still calls both save API and publish API

---

## Phase 7: Update Quick Links Editor

**Goal:** Save icon → "Publish" button

### Step 7.1: Replace save icon

**File:** `/app/dashboard/cms/links/page.tsx` and `/components/cms/LinkEditorContent.tsx`

- [ ] Replace save icon button with "Publish" text button
- [ ] Add publish API call after save
- [ ] Match styling with other editors

---

## Phase 8: Update Preview Page

**Goal:** Add Publish button to banner

### Step 8.1: Add Publish to banner

**File:** `/app/dashboard/preview/page.tsx`

- [ ] Add "Publish" button to preview banner (left of "Back to Dashboard")
- [ ] Button calls publish API
- [ ] Show loading/success states

---

## Phase 9: Verification

### Step 9.1: Manual testing checklist

- [ ] Basic Info Editor: Publish saves + publishes site
- [ ] Slider Editor: Publish saves + publishes site
- [ ] CMS Page Editor (new page): Publish saves + sets published + publishes site
- [ ] CMS Page Editor (existing): Publish saves + publishes site
- [ ] CMS Page Editor: View Page link works (active dealers only)
- [ ] Navigation Editor: Publish saves + publishes site
- [ ] Quick Links Editor: Publish saves + publishes site
- [ ] Preview Page: Publish button works
- [ ] Dashboard: FloatingPublishButton still works
- [ ] Other dashboard pages: FloatingPublishButton NOT visible

### Step 9.2: Run tests

- [ ] `npm test` passes
- [ ] `npm run build` succeeds

---

## Files Summary

| Phase | Files Modified                                                        |
| ----- | --------------------------------------------------------------------- |
| 1     | FloatingPublishButton.tsx, layout.tsx, FloatingPublishButton.test.tsx |
| 2     | EditorContext.tsx (delete), layout.tsx, integration.test.tsx          |
| 3     | EditorForm.tsx                                                        |
| 4     | slider-editor/page.tsx                                                |
| 5     | cms/pages/[id]/edit/page.tsx                                          |
| 6     | cms/navigation/page.tsx                                               |
| 7     | cms/links/page.tsx, LinkEditorContent.tsx                             |
| 8     | preview/page.tsx                                                      |

## Notes

- Each phase can be committed separately
- Test after each phase before proceeding
- Phase 1-2 must be done together (EditorContext removal)
- Phases 3-8 are independent and can be done in any order
