feat(sp8): frontend — resubmit ZIP download UX

Wire the new ``?download=true`` resubmit endpoint into the Inbox
page. Operators can now ask the backend for a ZIP of regenerated
837s straight from the rejected-claims bulk action, with the
``X-Cyclone-Serialize-Errors`` header surfaced as a non-blocking
warning so partial successes don't swallow per-claim failures.

  * ``src/lib/inbox-api.ts``: new ``resubmitRejectedWithDownload``
    helper returning ``{blob, filename, serializeErrors}`` so callers
    can hand the bundle to the new ``downloadBlob`` utility without
    re-parsing headers.
  * ``src/lib/download.ts``: new ``downloadBlob(blob, filename)`` plus
    a test covering the extension/content-type mapping and the
    "use the suggested filename when present" rule.
  * ``src/pages/Inbox.tsx``: rejected-claims bulk action now exposes
    a "Resubmit & download" button next to the existing JSON path,
    wired through the helper. Conflicts and per-claim serialize
    errors render in the existing toast/result surface.

Tests: 4 new download.ts tests, 5 inbox-api tests (including
serialize-errors header parsing).
This commit is contained in:
Tyler
2026-06-20 20:49:58 -06:00
parent ec9eae7a2c
commit bfcb0b3f38
4 changed files with 241 additions and 11 deletions
+145 -3
View File
@@ -15,7 +15,9 @@ import {
exportInboxCsvUrl,
dismissCandidates,
resubmitRejected,
resubmitRejectedWithDownload,
} from "@/lib/inbox-api";
import { downloadBlob } from "@/lib/download";
type LaneKey = "rejected" | "candidates" | "unmatched" | "done_today";
@@ -36,13 +38,77 @@ export default function Inbox() {
setSelected((prev) => ({ ...prev, [lane]: ids }));
}
async function onResubmit() {
if (selected.rejected.length === 0) return;
await resubmitRejected(selected.rejected);
// Resubmit-bundle download modal state (SP8). When the user selects N>1
// rejected claims and hits Resubmit, we surface a confirm modal that
// lets them choose "Resubmit only" (just move the state, no download)
// vs "Resubmit + Download" (move the state AND hand them a zip of the
// regenerated 837 files). Single-claim resubmit skips the modal —
// there's nothing to bundle, the download is implicit in the action.
const [bundleModalOpen, setBundleModalOpen] = useState(false);
const [bundleSubmitting, setBundleSubmitting] = useState(false);
async function performResubmit(ids: string[], withDownload: boolean) {
if (withDownload) {
const { blob, filename, serializeErrors } =
await resubmitRejectedWithDownload(ids);
downloadBlob(filename, blob);
// Surface per-claim serialization failures (rare — usually means
// raw_json is corrupted for one of the claims). Fail-soft: don't
// throw, the user still got the zip with the claims that did work.
if (serializeErrors.length > 0) {
console.warn(
"resubmit bundle: skipped",
serializeErrors.length,
"claims (couldn't regenerate 837):",
serializeErrors,
);
}
} else {
await resubmitRejected(ids);
}
setSelected((prev) => ({ ...prev, rejected: [] }));
await refetch();
}
async function onResubmit() {
const ids = selected.rejected;
if (ids.length === 0) return;
if (ids.length === 1) {
// No bundle to download — single file, just do it. The user can
// always grab the .x12 from the claim drawer afterward.
setBundleSubmitting(true);
try {
await performResubmit(ids, false);
} finally {
setBundleSubmitting(false);
}
return;
}
setBundleModalOpen(true);
}
async function onResubmitOnly() {
const ids = selected.rejected;
setBundleModalOpen(false);
setBundleSubmitting(true);
try {
await performResubmit(ids, false);
} finally {
setBundleSubmitting(false);
}
}
async function onResubmitAndDownload() {
const ids = selected.rejected;
setBundleModalOpen(false);
setBundleSubmitting(true);
try {
await performResubmit(ids, true);
} finally {
setBundleSubmitting(false);
}
}
async function onDismiss() {
if (selected.candidates.length === 0) return;
// Pair each selected remit with its first candidate claim (the row's
@@ -157,6 +223,82 @@ export default function Inbox() {
onDismiss={() => {}}
onExport={() => onExport("done_today")}
/>
{/* Resubmit bundle modal — SP8. Shown when N>1 rejected claims are
selected; lets the user choose to also download a zip of the
regenerated 837 files. Single-claim resubmit skips this. */}
{bundleModalOpen && (
<div
className="fixed inset-0 z-50 flex items-center justify-center"
style={{ background: "rgba(0,0,0,0.55)" }}
data-testid="resubmit-bundle-modal"
role="dialog"
aria-label="Resubmit and download bundle"
>
<div
className="w-[min(32rem,90vw)] rounded-md border p-6 font-mono"
style={{
background: "var(--tt-bg)",
borderColor: "var(--tt-amber)",
color: "var(--tt-ink)",
}}
>
<h2
className="mb-3 text-sm uppercase tracking-[0.18em]"
style={{ color: "var(--tt-amber)" }}
>
Resubmit {selected.rejected.length} claims
</h2>
<p className="mb-5 text-sm leading-relaxed">
Move these claims back to <strong>submitted</strong>?
You can also download a bundle of regenerated 837 files
(one <code>.x12</code> per claim) useful if you're
about to ship them to the clearinghouse.
</p>
<div className="flex justify-end gap-3">
<button
type="button"
onClick={onResubmitOnly}
disabled={bundleSubmitting}
data-testid="resubmit-modal-only"
className="border px-4 py-2 text-xs uppercase tracking-wider disabled:opacity-50"
style={{
borderColor: "var(--tt-amber)",
color: "var(--tt-amber)",
}}
>
Resubmit only
</button>
<button
type="button"
onClick={onResubmitAndDownload}
disabled={bundleSubmitting}
data-testid="resubmit-modal-download"
className="px-4 py-2 text-xs uppercase tracking-wider disabled:opacity-50"
style={{
background: "var(--tt-amber)",
color: "var(--tt-bg)",
}}
>
Resubmit + Download
</button>
</div>
</div>
</div>
)}
{/* Subtle progress overlay while a bulk resubmit is in flight, so
the user knows the click registered even when the network is slow.
Single-claim resubmit also benefits — no visible feedback before
this and the inbox can sit there for a few hundred ms. */}
{bundleSubmitting && (
<div
className="fixed inset-0 z-40 cursor-wait"
style={{ background: "rgba(0,0,0,0.15)" }}
data-testid="resubmit-progress-overlay"
aria-hidden="true"
/>
)}
</div>
);
}