Auto-save intake data to server after every step

Intake data now persists to DB after each step completion (non-blocking).
If browser crashes, data is recoverable from compliance_orders.intake_data.

Partial saves (_partial: true) only update intake_data without changing
payment_status or marking intake_data_validated. Final submit still
triggers the full validation + worker dispatch flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-30 16:01:20 -05:00
parent beb23d777e
commit c40dfb552e
2 changed files with 43 additions and 10 deletions

View file

@ -484,12 +484,37 @@ const STEP_LABELS: Record<string, string> = {
if (cancelEvt.defaultPrevented) return;
if (s.step_index < steps.length - 1) {
renderStep(s.step_index + 1);
// Auto-save intake data to server after every step (non-blocking)
autoSaveIntake(loadState());
} else {
// Last step — submit the intake data
submitIntake(s);
}
});
// Auto-save intake data to server after each step (non-blocking, fire-and-forget)
function autoSaveIntake(state: IntakeState) {
const params = new URLSearchParams(window.location.search);
const token = params.get("token");
const orderNumber = state.intake_data?.order_number || params.get("order") || "";
const API = (window as any).__PW_API || "";
if (!orderNumber || !API) return;
fetch(`${API}/api/v1/compliance-orders/${orderNumber}/intake`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
...(token ? { "Authorization": `Bearer ${token}` } : {}),
},
body: JSON.stringify({
intake_data: state.intake_data,
entity: state.entity,
officers: state.officers,
_partial: true, // flag that this is an intermediate save, not final
}),
}).catch(() => {}); // silent — don't block the user
}
async function submitIntake(state: IntakeState) {
const nextBtn = document.getElementById("pw-next") as HTMLButtonElement;
nextBtn.disabled = true;