DOT intake: use is:inline script to avoid hoisted bundle crash

FCC step scripts crash on DOT pages due to missing elements. By
using is:inline, DOT intake script runs independently, not in the
hoisted bundle. Stripped TypeScript annotations for plain JS compat.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-30 15:38:04 -05:00
parent db96af53bf
commit b8a52303b3

View file

@ -251,14 +251,14 @@
@media (max-width: 640px) { .pw-row-2, .pw-row-3 { grid-template-columns: 1fr; } .pw-cargo-grid { grid-template-columns: 1fr 1fr; } }
</style>
<script>
<script is:inline>
// Guard: only run on pages that have the DOT intake step
if (!document.querySelector('[data-slug="dot-intake"], [data-step="dot-intake"]')) {
// Not a DOT intake page — skip all initialization
} else {
// Determine which sections to show based on services in the batch
const DOT_SECTIONS: Record<string, string[]> = {
const DOT_SECTIONS = {
"mcs150-update": ["dot-sec-operations","dot-sec-fleet","dot-sec-cargo","dot-sec-photo-id"],
"ucr-registration": ["dot-sec-fleet","dot-sec-ucr"],
"dot-drug-alcohol": ["dot-sec-da"],
@ -270,15 +270,15 @@
};
function showRelevantSections() {
const PW = (window as any).PWIntake;
const PW = (window).PWIntake;
const state = PW?.get?.() || {};
// Get service slug from wizard element or state
const wizardEl = document.querySelector(".pw-wizard[data-service]");
const pageSlug = wizardEl?.getAttribute("data-service") || "";
const slugs: string[] = state.batch_slugs || [pageSlug || state.service_slug || ""];
const slugs = state.batch_slugs || [pageSlug || state.service_slug || ""];
// Collect all sections to show
const show = new Set<string>();
const show = new Set();
for (const slug of slugs) {
for (const sec of (DOT_SECTIONS[slug] || [])) {
show.add(sec);
@ -297,8 +297,8 @@
}
// Auto-fill UCR base state from address
const stateEl = document.getElementById("dot-state") as HTMLSelectElement;
const ucrState = document.getElementById("dot-ucr-state") as HTMLInputElement;
const stateEl = document.getElementById("dot-state");
const ucrState = document.getElementById("dot-ucr-state");
if (stateEl && ucrState) {
ucrState.value = stateEl.value;
stateEl.addEventListener("change", () => { ucrState.value = stateEl.value; });
@ -312,14 +312,14 @@
showRelevantSections();
}
initSections();
window.addEventListener("pw:step-shown", (evt: any) => {
window.addEventListener("pw:step-shown", (evt) => {
if (evt.detail.step !== "dot-intake") return;
showRelevantSections();
// Hydrate from existing intake data
const s = (window as any).PWIntake.get();
const s = (window).PWIntake.get();
const d = s.intake_data || {};
const map: Record<string, string> = {
const map = {
"dot-legal-name": d.legal_name || "", "dot-dba": d.dba_name || "",
"dot-dot": d.dot_number || "", "dot-mc": d.mc_number || "", "dot-ein": d.ein || "",
"dot-street": d.address_street || "", "dot-city": d.address_city || "",
@ -334,27 +334,27 @@
"dot-current-da": d.current_da_provider || "", "dot-ucr-bracket": d.fleet_size_bracket || "",
};
for (const [id, val] of Object.entries(map)) {
const el = document.getElementById(id) as HTMLInputElement | HTMLSelectElement;
const el = document.getElementById(id);
if (el && val) el.value = val;
}
});
// Save all data on step-next
window.addEventListener("pw:step-next", (evt: any) => {
const PW = (window as any).PWIntake;
window.addEventListener("pw:step-next", (evt) => {
const PW = (window).PWIntake;
if (PW.steps[PW.get().step_index] !== "dot-intake") return;
const errDiv = document.getElementById("pw-dot-errors") as HTMLDivElement;
const errDiv = document.getElementById("pw-dot-errors");
errDiv.hidden = true;
// Validate required fields (only visible ones)
const required = ["dot-legal-name","dot-dot","dot-street","dot-city","dot-state","dot-zip","dot-phone","dot-email","dot-signer-name","dot-signer-title"];
const missing: string[] = [];
const missing = [];
for (const id of required) {
const el = document.getElementById(id) as HTMLInputElement;
const el = document.getElementById(id);
if (!el || !el.value.trim()) missing.push(el?.parentElement?.querySelector("span")?.textContent || id);
}
// Validate visible-section-specific required fields
const visibleRequired: Record<string, string[]> = {
const visibleRequired = {
"dot-sec-operations": ["dot-entity-type","dot-carrier-op","dot-interstate","dot-hazmat"],
"dot-sec-fleet": ["dot-power-units","dot-drivers"],
};
@ -362,7 +362,7 @@
const sec = document.getElementById(secId);
if (sec && !sec.hidden) {
for (const id of fields) {
const el = document.getElementById(id) as HTMLInputElement;
const el = document.getElementById(id);
if (!el || !el.value.trim()) missing.push(el?.parentElement?.querySelector("span")?.textContent || id);
}
}
@ -370,12 +370,12 @@
if (missing.length) { evt.preventDefault(); errDiv.hidden = false; errDiv.textContent = "Please fill in: " + missing.join(", "); return; }
// Collect cargo types
const cargoTypes: string[] = [];
document.querySelectorAll<HTMLInputElement>("[data-cargo]").forEach(cb => {
if (cb.checked) cargoTypes.push(cb.dataset.cargo!);
const cargoTypes = [];
document.querySelectorAll("[data-cargo]").forEach(function(cb) {
if (cb.checked) cargoTypes.push(cb.dataset.cargo);
});
const val = (id: string) => (document.getElementById(id) as HTMLInputElement)?.value?.trim() || "";
const val = (id) => (document.getElementById(id))?.value?.trim() || "";
const state = PW.get();
PW.set({ ...state, intake_data: { ...state.intake_data,
legal_name: val("dot-legal-name"), dba_name: val("dot-dba"),
@ -392,31 +392,31 @@
cdl_drivers: val("dot-cdl-drivers"), owner_operators: val("dot-owner-ops"),
der_name: val("dot-der-name"), current_da_provider: val("dot-current-da"),
docket_type: val("dot-docket-type"), docket_number: val("dot-docket-num"),
photo_id_uploaded: !!(window as any).__dotPhotoId,
photo_id_uploaded: !!(window).__dotPhotoId,
}});
});
// Photo ID upload (elements may not exist if section is hidden)
const idBtn = document.getElementById("dot-id-btn");
const idInput = document.getElementById("dot-photo-id") as HTMLInputElement | null;
const idInput = document.getElementById("dot-photo-id");
const idPreview = document.getElementById("dot-id-preview");
const idImg = document.getElementById("dot-id-img") as HTMLImageElement | null;
const idImg = document.getElementById("dot-id-img");
const idRemove = document.getElementById("dot-id-remove");
idBtn?.addEventListener("click", () => idInput?.click());
idInput?.addEventListener("change", () => {
const file = idInput.files?.[0];
if (!file) return;
(window as any).__dotPhotoId = file;
(window).__dotPhotoId = file;
if (file.type.startsWith("image/")) {
const reader = new FileReader();
reader.onload = (e) => { idImg.src = e.target?.result as string; };
reader.onload = (e) => { idImg.src = e.target?.result; };
reader.readAsDataURL(file);
}
if (idPreview) idPreview.hidden = false;
if (idBtn) idBtn.style.display = "none";
});
idRemove?.addEventListener("click", () => {
(window as any).__dotPhotoId = null;
(window).__dotPhotoId = null;
if (idInput) idInput.value = "";
if (idPreview) idPreview.hidden = true;
if (idBtn) idBtn.style.display = "flex";