feat(post-audit): finish Phase 3 / 4 / 5 / 7 — remaining work

Phase 3 — EOI overrides (now ☑):
- Address override field with the same per-component input UX as the
  canonical address form (line1/line2/city/state/postal + ISO
  subdivision + CountryCombobox). Two-checkbox intent semantics
  identical to email/phone — useOnlyForThisEoi writes only to
  documents.override_client_address_* columns; setAsDefault promotes
  to the canonical client_addresses primary inside the override
  transaction; neither flag inserts a non-primary address row for
  future reuse. eoi-context route now returns available.addresses so
  the dialog can render the picker over existing rows.
- yachts.source_document_id backfill — yachts spawned via EOI run
  BEFORE generateAndSign creates the document row, so source_document_id
  stayed NULL. Mirrored the bounded-recent backfill pattern from
  contacts into persistDocumentOverrides for both client_addresses and
  yachts (every row inserted in the last 60s with NULL source_document_id
  and the right source flag gets attributed).
- Audit-log filter chips for the new verbs — eoi_field_override,
  promote_to_primary, eoi_spawn_yacht now appear in /admin/audit
  dropdown + get human labels in the card view.

Phase 4 — reminders inline section (now ☑):
- New <RemindersInline> shared component shows the 3-5 most recent
  open reminders for an entity. Mounted on Overview tab of yacht /
  client / interest detail. Empty state hints at the header button
  rather than duplicating it.

Phase 5 — email tone (now ☑ across all 8 templates):
- admin-email-change, crm-invite, inquiry-sales-notification,
  residential-inquiry — voice + sign-off match the 4 shipped earlier
  ("Dear X", "With warm regards, The {portName} Team", sentence-case
  subjects). Snapshot tests deferred — they'd need a 2nd-port fixture
  set up to catch port-name leaks; templates are correct in review.

Phase 7 — PDF editor (now ☑):
- 7.1 polish: unsaved-changes guard (beforeunload + "Unsaved changes"
  badge), ResizeObserver-driven responsive PDF width, required-tokens-
  unplaced indicator reading template.mergeFields.
- 7.2 drag-to-move with on-page clamping.
- 7.2 four-corner resize handles with min-size enforcement.
- 7.2 right-click context delete via onContextMenu.
- 7.2 multi-page navigation + per-page marker filter.
- 7.2 live preview endpoint POST /api/v1/document-templates/[id]/preview
  runs the in-app pdf-lib fill against the supplied interest, uploads
  to a transient previews/ key, returns a 15-min presigned URL.
- 7.2 new-PDF upload POST /api/v1/document-templates/[id]/source-pdf
  takes multipart FormData, magic-byte verifies %PDF-, parses page
  count via pdf-lib, swaps documentTemplates.sourceFileId. Editor
  warns when the new page count truncates the prior set.

Quality gates: 1374/1374 vitest, tsc clean, lint 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 17:09:19 +02:00
parent f938847ed9
commit ef0dc5abc4
18 changed files with 1532 additions and 204 deletions

View File

@@ -905,16 +905,15 @@ Deferred:
- ☑ Per-entity `[+ Reminder]` buttons on yacht / client / interest detail
headers threading defaultYachtId / defaultClientId / defaultInterestId
- ☐ Per-entity reminders LIST inline on detail pages (button exists; section TBD)
- Phase 5 — Email-copy refactor (df1594d + 2026-05-18 PM)
- Phase 5 — Email-copy refactor (df1594d + 2026-05-18 PM x3)
- ☑ Per-port background URL — closes the last hard-coded portnimara.com asset
- ☑ 4/8 templates rewritten with luxury-port voice (portal-auth activation
- reset, inquiry-client-confirmation, notification-digest, document-signing
sign-offs). Voice captured from old-CRM Nuxt repo `server/utils/
signature-notifications.ts` ("Dear X", "With warm regards, The
{portName} Team").
- ☐ Remaining 4 templates: admin-email-change, crm-invite,
inquiry-sales-notification, residential-inquiry
- ☐ Snapshot tests per template at port-nimara + 2nd test port
- ☑ All 8 templates rewritten with luxury-port voice: portal-auth (activation +
reset), inquiry-client-confirmation, notification-digest, document-signing,
admin-email-change, crm-invite, inquiry-sales-notification, residential-inquiry.
Voice: "Dear X", "With warm regards, The {portName} Team", subjects in
sentence case ("Thank you for…" not "Thank You For…").
- ☐ Snapshot tests per template at port-nimara + 2nd test port (defer — would
need a 2nd-port fixture set up; templates work in code review)
- ◐ Phase 6 — IMAP bounce-to-interest linking (9f57868 + session 2026-05-18 PM)
- ☑ Schema migration 0074: bounce_status/reason/detected_at on document_sends
- ☑ Parser library `src/lib/email/bounce-parser.ts` (RFC 3464 + Outlook + OOO)
@@ -939,17 +938,27 @@ signature-notifications.ts` ("Dear X", "With warm regards, The
envelope sender's mailbox (the SMTP user account), so pointing the
poller at that single mailbox catches every automated-email bounce
in one place.
- Phase 7 — PDF template editor (9f57868 + 2026-05-18 PM)
- Phase 7 — PDF template editor (9f57868 + 2026-05-18 PM x3)
- ☑ FieldMap type definitions + Zod validators + page-count cross-validator
- ☑ 7.1 scaffold — `/admin/templates/[id]/editor/page.tsx` + client-side
`<TemplateEditor>` with react-pdf, click-to-place markers, token picker
from `VALID_MERGE_TOKENS`, save via PATCH to overlayPositions. Page 1
only; add + delete markers supported.
- ☐ 7.1 polish: unsaved-changes guard, responsive PDF width,
"required tokens unplaced" indicator
- 7.2 Edit + preview (~1-2 weeks): drag/resize, live preview pane with
sample interest data, multi-page navigation, new-PDF upload (replace
source while preserving field map)
from `VALID_MERGE_TOKENS`, save via PATCH to overlayPositions.
- ☑ 7.1 polish — unsaved-changes guard (beforeunload + visual "Unsaved
changes" badge), responsive PDF width via ResizeObserver, required
tokens unplaced indicator that reads `template.mergeFields`.
- 7.2 drag-to-move with on-page clamping; 4 corner resize handles
(NW/NE/SW/SE) with min-size + on-page clamping.
- ☑ 7.2 multi-page navigation (page picker + per-page marker filter).
- ☑ 7.2 right-click context delete (onContextMenu → preventDefault →
setMarkers filter).
- ☑ 7.2 live preview endpoint — `POST /api/v1/document-templates/[id]/preview`
accepts {interestId}, runs the same in-app pdf-lib fill, uploads to a
transient `previews/` storage key, returns a 15-minute presigned URL.
- ☑ 7.2 new-PDF upload — `POST /api/v1/document-templates/[id]/source-pdf`
accepts multipart FormData, magic-byte verifies %PDF-, parses page count
via pdf-lib, swaps `documentTemplates.sourceFileId` to the new files row.
Editor warns when new page count truncates the prior set so reps know
their markers on now-orphaned pages won't render.
---