From 00a81b3fda228ce1457373548b310f12a49a77f7 Mon Sep 17 00:00:00 2001 From: Gitead Date: Wed, 9 Sep 2026 08:56:52 -0400 Subject: [PATCH] fix: correctly suppress PDF popup for last claim in AI-column batch closeClaim() was clearing chatbotAutoSubmitSiteKey synchronously right after the selenium job kicked off, before the job's async completion handler could check it. This was masked for all but the last claim in the batch because closeClaim() also navigated away (unmounting the page) whenever more claims were queued. On the last claim the page stayed mounted, so the completion handler read a stale cleared value and let the PDF preview popup through. Track the site key in a ref that survives closeClaim() and is cleared only after the job's own completion handler consumes it. Co-Authored-By: Claude Sonnet 5 --- apps/Frontend/src/pages/claims-page.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/Frontend/src/pages/claims-page.tsx b/apps/Frontend/src/pages/claims-page.tsx index fca13944..f17b7197 100755 --- a/apps/Frontend/src/pages/claims-page.tsx +++ b/apps/Frontend/src/pages/claims-page.tsx @@ -44,6 +44,10 @@ export default function ClaimsPage() { const [isClaimFormOpen, setIsClaimFormOpen] = useState(false); const [selectedPatientId, setSelectedPatientId] = useState(null); const [chatbotAutoSubmitSiteKey, setChatbotAutoSubmitSiteKey] = useState(undefined); + // Mirrors chatbotAutoSubmitSiteKey but survives closeClaim(), which resets the state + // synchronously right after the selenium job is kicked off — well before the job's async + // completion handlers (which gate the PDF preview popup) actually run. + const chatbotAutoSubmitSiteKeyRef = useRef(undefined); const [chatbotInitialTab, setChatbotInitialTab] = useState(undefined); const [chatbotAutoSubmitPreauthSiteKey, setChatbotAutoSubmitPreauthSiteKey] = useState(undefined); // for redirect from appointment page directly, then passing to claimform @@ -156,11 +160,12 @@ export default function ClaimsPage() { if (jobResult.pdfFileId) { advanceAiClaimQueue(); const advancedToNext = advanceChatbotClaimQueue(); - if (!advancedToNext && !chatbotAutoSubmitSiteKey) { + if (!advancedToNext && !chatbotAutoSubmitSiteKeyRef.current) { setPreviewPdfId(jobResult.pdfFileId); setPreviewFallbackFilename(jobResult.pdfFilename ?? `cca_claim_${jobResult.claimNumber ?? "unknown"}.pdf`); setPreviewOpen(true); } + chatbotAutoSubmitSiteKeyRef.current = undefined; dispatch(setTaskStatus({ key: "claimSubmit", status: "success", @@ -240,6 +245,7 @@ export default function ClaimsPage() { const parsed = JSON.parse(raw); if (parsed?.autoSubmit && parsed?.siteKey) { setChatbotAutoSubmitSiteKey(parsed.siteKey); + chatbotAutoSubmitSiteKeyRef.current = parsed.siteKey; } } } catch {} @@ -308,6 +314,7 @@ export default function ClaimsPage() { const parsed = JSON.parse(raw); if (parsed?.autoSubmit && parsed?.siteKey) { setChatbotAutoSubmitSiteKey(parsed.siteKey); + chatbotAutoSubmitSiteKeyRef.current = parsed.siteKey; } } } catch {} @@ -994,11 +1001,12 @@ export default function ClaimsPage() { // Pop up the final PDF so the user doesn't need to navigate to Documents // (skip if we're about to navigate to the next queued patient's claim, // or if this claim was submitted via the AI chat column) - if (result.pdfFileId && !advancedToNext && !chatbotAutoSubmitSiteKey) { + if (result.pdfFileId && !advancedToNext && !chatbotAutoSubmitSiteKeyRef.current) { setPreviewPdfId(result.pdfFileId); setPreviewFallbackFilename(result.fileName ?? null); setPreviewOpen(true); } + chatbotAutoSubmitSiteKeyRef.current = undefined; return result; } catch (error: any) {