intake: fix hoisted payment-step null error and success nav cleanup
- Guard PaymentStep DOM bindings so its hoisted script no longer throws on pages without a payment step. - Remove the correct wizard nav element on successful intake submit (pw-wizard-nav, not the nonexistent pw-wizard-footer).
This commit is contained in:
parent
d0d39ebcbc
commit
219507ce74
2 changed files with 37 additions and 33 deletions
|
|
@ -676,7 +676,7 @@ const STEP_LABELS: Record<string, string> = {
|
|||
</div>
|
||||
`;
|
||||
document.querySelector(".pw-wizard-stepbar")?.remove();
|
||||
document.querySelector(".pw-wizard-footer")?.remove();
|
||||
document.querySelector(".pw-wizard-nav")?.remove();
|
||||
} else {
|
||||
const err = await saveResp.json().catch(() => ({}));
|
||||
alert(err.error || "Failed to submit. Please try again.");
|
||||
|
|
|
|||
|
|
@ -48,37 +48,41 @@ const meta = SERVICE_META[service_slug];
|
|||
</style>
|
||||
|
||||
<script>
|
||||
const slug = document.querySelector(".pw-step[data-slug]")!.getAttribute("data-slug")!;
|
||||
const methodSel = document.getElementById("pw-pay-method") as HTMLSelectElement;
|
||||
const goBtn = document.getElementById("pw-pay-go") as HTMLButtonElement;
|
||||
const err = document.getElementById("pw-pay-err") as HTMLDivElement;
|
||||
const slugEl = document.querySelector(".pw-step[data-slug]") as HTMLElement | null;
|
||||
const methodSel = document.getElementById("pw-pay-method") as HTMLSelectElement | null;
|
||||
const goBtn = document.getElementById("pw-pay-go") as HTMLButtonElement | null;
|
||||
const err = document.getElementById("pw-pay-err") as HTMLDivElement | null;
|
||||
|
||||
goBtn.addEventListener("click", async () => {
|
||||
err.hidden = true;
|
||||
goBtn.disabled = true; goBtn.textContent = "Creating checkout session…";
|
||||
try {
|
||||
const state = (window as any).PWIntake.get();
|
||||
if (!state.order_number) throw new Error("Order was not created; go back to Review.");
|
||||
const resp = await fetch("/api/v1/checkout/create-session", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
order_id: state.order_number,
|
||||
order_type: "compliance",
|
||||
payment_method: methodSel.value,
|
||||
}),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const { checkout_url } = await resp.json();
|
||||
if (!checkout_url) throw new Error("No checkout URL returned.");
|
||||
// Clear the wizard state — success page handles the rest
|
||||
sessionStorage.removeItem(`pw-intake-${slug}`);
|
||||
window.location.href = checkout_url;
|
||||
} catch (e: any) {
|
||||
err.hidden = false;
|
||||
err.textContent = "Could not start checkout: " + e.message;
|
||||
goBtn.disabled = false;
|
||||
goBtn.textContent = "Continue to payment →";
|
||||
}
|
||||
});
|
||||
if (slugEl && methodSel && goBtn && err) {
|
||||
const slug = slugEl.getAttribute("data-slug")!;
|
||||
|
||||
goBtn.addEventListener("click", async () => {
|
||||
err.hidden = true;
|
||||
goBtn.disabled = true; goBtn.textContent = "Creating checkout session…";
|
||||
try {
|
||||
const state = (window as any).PWIntake.get();
|
||||
if (!state.order_number) throw new Error("Order was not created; go back to Review.");
|
||||
const resp = await fetch("/api/v1/checkout/create-session", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
order_id: state.order_number,
|
||||
order_type: "compliance",
|
||||
payment_method: methodSel.value,
|
||||
}),
|
||||
});
|
||||
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
|
||||
const { checkout_url } = await resp.json();
|
||||
if (!checkout_url) throw new Error("No checkout URL returned.");
|
||||
// Clear the wizard state, success page handles the rest
|
||||
sessionStorage.removeItem(`pw-intake-${slug}`);
|
||||
window.location.href = checkout_url;
|
||||
} catch (e: any) {
|
||||
err.hidden = false;
|
||||
err.textContent = "Could not start checkout: " + e.message;
|
||||
goBtn.disabled = false;
|
||||
goBtn.textContent = "Continue to payment →";
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue