diff --git a/site/src/components/intake/Wizard.astro b/site/src/components/intake/Wizard.astro index 15bedb6..930e1a6 100644 --- a/site/src/components/intake/Wizard.astro +++ b/site/src/components/intake/Wizard.astro @@ -318,6 +318,47 @@ const STEP_LABELS: Record = { set steps(s: string[]) { steps = s; }, }; + // ── Pre-fill from order data when accessed via token (paid batch order) ── + (async () => { + const params = new URLSearchParams(window.location.search); + const token = params.get("token"); + const frn = params.get("frn"); + if (!token) return; + + const API = (window as any).__PW_API || ""; + try { + // Decode the token to get order_id + email — no server call needed for basic info + // The token is a JWT with {order_id, order_type, email} + const payload = JSON.parse(atob(token.split(".")[1])); + const state = loadState(); + if (payload.email && !state.email) { + state.email = payload.email; + } + if (payload.order_id) { + state.intake_data = { ...state.intake_data, order_number: payload.order_id }; + } + + // Fetch customer info from the compliance order + if (payload.order_id) { + try { + const r = await fetch(`${API}/api/v1/compliance-orders/${payload.order_id}`, { + headers: { "Authorization": `Bearer ${token}` }, + }); + if (r.ok) { + const order = await r.json(); + if (order.customer_name && !state.name) state.name = order.customer_name; + if (order.customer_email && !state.email) state.email = order.customer_email; + if (order.intake_data) { + state.intake_data = { ...state.intake_data, ...order.intake_data }; + } + } + } catch {} + } + + saveState(state); + } catch {} + })(); + function renderStep(idx: number) { const state = loadState(); state.step_index = idx; diff --git a/site/src/components/intake/steps/EntityStep.astro b/site/src/components/intake/steps/EntityStep.astro index 4d02b2b..e8443ce 100644 --- a/site/src/components/intake/steps/EntityStep.astro +++ b/site/src/components/intake/steps/EntityStep.astro @@ -313,7 +313,7 @@ async function autoFillFromFRN(frn: string) { try { const API = (window as any).__PW_API || ""; - const r = await fetch(`${API}/api/v1/fcc/lookup?frn=${frn}`); + const r = await fetch(`${API}/api/v1/fcc/lookup?frn=${frn}&quick=1`); if (!r.ok) return; const d = await r.json(); const entity: any = {};