4.5 KiB
4.5 KiB
phase: 19-template-editor-ui
plan: "01"
subsystem: template-editor
tags: [template, field-placer, api-routes, portal-nav]
dependency_graph:
requires: [18-02]
provides: [template-mode props on FieldPlacer/PdfViewer/PdfViewerWrapper, three template API routes, Templates nav link]
affects: [FieldPlacer, PdfViewer, PdfViewerWrapper, PortalNav, /api/templates/[id]/]
tech_stack:
added: []
patterns: [optional-prop-threading, seeds-forms-streaming, soft-delete-filter]
key_files:
created:
- teressa-copeland-homes/src/app/api/templates/[id]/file/route.ts
- teressa-copeland-homes/src/app/api/templates/[id]/fields/route.ts
- teressa-copeland-homes/src/app/api/templates/[id]/ai-prepare/route.ts
modified:
- teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx
- teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx
- teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewerWrapper.tsx
- teressa-copeland-homes/src/app/portal/_components/PortalNav.tsx
decisions:
- "onPersist callback threads through FieldPlacer/PdfViewer/PdfViewerWrapper as optional prop — existing document callers pass no prop and behavior is unchanged"
- "fieldsUrl and fileUrl override default document API endpoints — enables template editor to redirect both field load and PDF source without forking components"
- "ai-prepare for templates passes null client context to classifyFieldsWithAI — templates have no pre-fill data by design (D-15)"
- "All three template routes use isNull(archivedAt) soft-delete filter consistent with Phase 18 pattern"
metrics:
duration_minutes: 8
completed_date: "2026-04-06"
tasks_completed: 2
files_changed: 7
Phase 19 Plan 01: Template Editor Infrastructure Summary
Infrastructure additions that wire the FieldPlacer/PdfViewer component chain for template-mode operation: optional onPersist, fieldsUrl, and fileUrl props added non-breakingly, three new template API routes created, and Templates nav link added.
Tasks Completed
Task 1: Add onPersist + fieldsUrl props to FieldPlacer, fileUrl to PdfViewer/PdfViewerWrapper, and Templates to PortalNav
- Added
onPersist?: (fields: SignatureFieldData[]) => Promise<void> | voidandfieldsUrl?: stringtoFieldPlacerPropsinterface - All 4
persistFieldscall sites (drag-drop, move, resize, delete) conditionally useonPersistwhen provided, falling back topersistFields(docId, next)otherwise loadFieldsuseEffect usesfieldsUrl ?? /api/documents/${docId}/fields;fieldsUrladded to dependency arrayPdfViewerandPdfViewerWrapperaccept and pass through all three new props; bothfilesrc and downloadhrefusefileUrl ?? /api/documents/${docId}/filePortalNavnavLinks array updated with{ href: "/portal/templates", label: "Templates" }between Clients and Profile- Commit:
57efd91
Task 2: Create three template API routes — file, fields, ai-prepare
GET /api/templates/[id]/file— loadsdocumentTemplateswithformTemplaterelation, resolves path inseeds/forms/, path traversal guard, streams PDF withContent-Type: application/pdfGET /api/templates/[id]/fields— returnstemplate.signatureFields ?? []POST /api/templates/[id]/ai-prepare— runsextractBlanks+classifyFieldsWithAI(blanks, null), writessignatureFields+ explicitupdatedAt: new Date()to DB, returns{ fields }- All three routes: auth guard +
isNull(documentTemplates.archivedAt)soft-delete filter - Commit:
275565c
Verification
npx tsc --noEmit— 0 errors after each tasknpm run build— succeeds; all three new route paths appear in build output- All 7 grep checks passed (onPersist x4 sites, fieldsUrl, fileUrl x2, /portal/templates)
Deviations from Plan
None — plan executed exactly as written.
Known Stubs
None — all new routes are fully functional. Field loading and persisting have real implementations.
Self-Check: PASSED
Files created:
- /Users/ccopeland/temp/red/teressa-copeland-homes/src/app/api/templates/[id]/file/route.ts — FOUND
- /Users/ccopeland/temp/red/teressa-copeland-homes/src/app/api/templates/[id]/fields/route.ts — FOUND
- /Users/ccopeland/temp/red/teressa-copeland-homes/src/app/api/templates/[id]/ai-prepare/route.ts — FOUND
Commits: