From 720d07fd540db2d652c39233445e47727b8d9dc8 Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Sat, 21 Mar 2026 15:36:56 -0600 Subject: [PATCH] feat(12-02): FieldPlacer onFieldsChanged callback prop after every persistFields call - Add onFieldsChanged?: () => void to FieldPlacerProps interface - Destructure onFieldsChanged in function signature - Call onFieldsChanged?.() after persistFields in handleDragEnd (new field drop) - Call onFieldsChanged?.() after persistFields in handleZonePointerUp move case - Call onFieldsChanged?.() after persistFields in handleZonePointerUp resize case - Call onFieldsChanged?.() after persistFields in delete button onClick - Add onFieldsChanged to useCallback dependency arrays (handleDragEnd, handleZonePointerUp) --- .../documents/[docId]/_components/FieldPlacer.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx index 0999448..7f59134 100644 --- a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx +++ b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/FieldPlacer.tsx @@ -155,9 +155,10 @@ interface FieldPlacerProps { currentPage: number; children: React.ReactNode; readOnly?: boolean; + onFieldsChanged?: () => void; } -export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false }: FieldPlacerProps) { +export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false, onFieldsChanged }: FieldPlacerProps) { const [fields, setFields] = useState([]); const [isDraggingToken, setIsDraggingToken] = useState(null); const containerRef = useRef(null); @@ -294,8 +295,9 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = const next = [...fields, newField]; setFields(next); persistFields(docId, next); + onFieldsChanged?.(); }, - [fields, pageInfo, currentPage, docId, readOnly], + [fields, pageInfo, currentPage, docId, readOnly, onFieldsChanged], ); // --- Move / Resize pointer handlers (event delegation on DroppableZone) --- @@ -477,6 +479,7 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = }); setFields(next); persistFields(docId, next); + onFieldsChanged?.(); } else if (drag.type === 'resize') { const corner = drag.corner ?? 'se'; const startW = drag.startFieldW ?? 144; @@ -543,8 +546,9 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = }); setFields(next); persistFields(docId, next); + onFieldsChanged?.(); } - }, [docId]); + }, [docId, onFieldsChanged]); // Render placed fields for the current page // Uses pageInfo.width/height (not getBoundingClientRect) for consistent coordinate math @@ -653,6 +657,7 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = const next = fields.filter((f) => f.id !== field.id); setFields(next); persistFields(docId, next); + onFieldsChanged?.(); }} onPointerDown={(e) => { // Prevent dnd-kit sensors and move handler from capturing this pointer event