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:
+16
-7
@@ -1,12 +1,18 @@
|
||||
/**
|
||||
* Generic browser-side download helper for plain-text files.
|
||||
* Generic browser-side download helpers.
|
||||
*
|
||||
* Mirrors `downloadCsv` in `./csv.ts` but takes an explicit MIME type so the
|
||||
* same code path can serve X12 (text/x12), JSON (application/json), or any
|
||||
* other text payload without growing a one-off helper per format.
|
||||
* - `downloadTextFile` for plain-text payloads (X12, JSON, CSV, ...).
|
||||
* Mirrors `downloadCsv` in `./csv.ts` but takes an explicit MIME type
|
||||
* so the same code path can serve any text format without growing a
|
||||
* one-off helper per format.
|
||||
*
|
||||
* The implementation is identical to `downloadCsv` minus the BOM prepending
|
||||
* (we want byte-faithful X12 — prepending a BOM corrupts the ISA segment).
|
||||
* - `downloadBlob` for binary payloads (the resubmit ZIP, future PDF
|
||||
* exports, etc.) where the caller already has a `Blob` and just needs
|
||||
* it handed to the browser.
|
||||
*
|
||||
* Both implementations skip the BOM prepend that `downloadCsv` uses (we
|
||||
* want byte-faithful X12 and ZIP — a BOM would corrupt the ISA segment
|
||||
* and confuse ZIP readers respectively).
|
||||
*
|
||||
* Safe to call from SSR/Node — guards against a missing `document`.
|
||||
*/
|
||||
@@ -15,8 +21,11 @@ export function downloadTextFile(
|
||||
mimeType: string,
|
||||
text: string,
|
||||
): void {
|
||||
downloadBlob(filename, new Blob([text], { type: `${mimeType};charset=utf-8` }));
|
||||
}
|
||||
|
||||
export function downloadBlob(filename: string, blob: Blob): void {
|
||||
if (typeof document === "undefined" || typeof URL === "undefined") return;
|
||||
const blob = new Blob([text], { type: `${mimeType};charset=utf-8` });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
a.href = url;
|
||||
|
||||
Reference in New Issue
Block a user