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 <noreply@anthropic.com>
This commit is contained in:
2026-09-09 08:56:52 -04:00
co-authored by Claude Sonnet 5
parent fd2d1e6aba
commit 00a81b3fda
+10 -2
View File
@@ -44,6 +44,10 @@ export default function ClaimsPage() {
const [isClaimFormOpen, setIsClaimFormOpen] = useState(false);
const [selectedPatientId, setSelectedPatientId] = useState<number | null>(null);
const [chatbotAutoSubmitSiteKey, setChatbotAutoSubmitSiteKey] = useState<string | undefined>(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<string | undefined>(undefined);
const [chatbotInitialTab, setChatbotInitialTab] = useState<string | undefined>(undefined);
const [chatbotAutoSubmitPreauthSiteKey, setChatbotAutoSubmitPreauthSiteKey] = useState<string | undefined>(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) {