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 43340dd..aeb766d 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 @@ -163,9 +163,10 @@ interface FieldPlacerProps { textFillData?: Record; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; } -export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false, onFieldsChanged, selectedFieldId, textFillData, onFieldSelect, onFieldValueChange }: FieldPlacerProps) { +export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = false, onFieldsChanged, selectedFieldId, textFillData, onFieldSelect, onFieldValueChange, aiPlacementKey = 0 }: FieldPlacerProps) { const [fields, setFields] = useState([]); const [isDraggingToken, setIsDraggingToken] = useState(null); const containerRef = useRef(null); @@ -198,7 +199,8 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = useSensor(TouchSensor, { activationConstraint: { delay: 150, tolerance: 5 } }), ); - // Load existing fields from server on mount + // Load existing fields from server on mount and whenever aiPlacementKey changes + // aiPlacementKey increments after AI placement so this re-fetches AI-placed fields from DB useEffect(() => { async function loadFields() { try { @@ -212,7 +214,7 @@ export function FieldPlacer({ docId, pageInfo, currentPage, children, readOnly = } } loadFields(); - }, [docId]); + }, [docId, aiPlacementKey]); // Update containerSize whenever pageInfo changes (page load or zoom change) // Use pageInfo.width/height (from react-pdf canvas) as the authoritative rendered size. diff --git a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx index b1dce2d..c3dceb9 100644 --- a/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx +++ b/teressa-copeland-homes/src/app/portal/(protected)/documents/[docId]/_components/PdfViewer.tsx @@ -27,6 +27,7 @@ export function PdfViewer({ textFillData, onFieldSelect, onFieldValueChange, + aiPlacementKey, }: { docId: string; docStatus?: string; @@ -35,6 +36,7 @@ export function PdfViewer({ textFillData?: Record; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; }) { const [numPages, setNumPages] = useState(0); const [pageNumber, setPageNumber] = useState(1); @@ -95,6 +97,7 @@ export function PdfViewer({ textFillData={textFillData} onFieldSelect={onFieldSelect} onFieldValueChange={onFieldValueChange} + aiPlacementKey={aiPlacementKey} > ; onFieldSelect?: (fieldId: string | null) => void; onFieldValueChange?: (fieldId: string, value: string) => void; + aiPlacementKey?: number; }) { return ( ); }