feat(13-03): add aiPlacementKey prop to FieldPlacer and thread through PdfViewerWrapper/PdfViewer

- Add aiPlacementKey?: number to FieldPlacerProps interface
- Add aiPlacementKey to loadFields useEffect dependency array for re-fetch on AI placement
- Thread aiPlacementKey through PdfViewer and PdfViewerWrapper prop chains
This commit is contained in:
Chandler Copeland
2026-03-21 17:07:01 -06:00
parent 970bb4f7cf
commit 3e11eef1c4
3 changed files with 11 additions and 3 deletions

View File

@@ -163,9 +163,10 @@ interface FieldPlacerProps {
textFillData?: Record<string, string>;
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<SignatureFieldData[]>([]);
const [isDraggingToken, setIsDraggingToken] = useState<string | null>(null);
const containerRef = useRef<HTMLDivElement | null>(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.

View File

@@ -27,6 +27,7 @@ export function PdfViewer({
textFillData,
onFieldSelect,
onFieldValueChange,
aiPlacementKey,
}: {
docId: string;
docStatus?: string;
@@ -35,6 +36,7 @@ export function PdfViewer({
textFillData?: Record<string, string>;
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}
>
<Document
file={`/api/documents/${docId}/file`}

View File

@@ -11,6 +11,7 @@ export function PdfViewerWrapper({
textFillData,
onFieldSelect,
onFieldValueChange,
aiPlacementKey,
}: {
docId: string;
docStatus?: string;
@@ -19,6 +20,7 @@ export function PdfViewerWrapper({
textFillData?: Record<string, string>;
onFieldSelect?: (fieldId: string | null) => void;
onFieldValueChange?: (fieldId: string, value: string) => void;
aiPlacementKey?: number;
}) {
return (
<PdfViewer
@@ -29,6 +31,7 @@ export function PdfViewerWrapper({
textFillData={textFillData}
onFieldSelect={onFieldSelect}
onFieldValueChange={onFieldValueChange}
aiPlacementKey={aiPlacementKey}
/>
);
}