Fix MCS150Step null crash — was breaking ALL DOT intake pages

MCS150Step script compiled into hoisted JS for all order pages.
Non-null assertions on photo ID elements crashed on non-MCS150 pages,
preventing DOTIntakeStep's showRelevantSections from running.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-30 15:33:56 -05:00
parent c98ac9ae54
commit 989ccaec93

View file

@ -351,15 +351,15 @@
PW.set({ ...state, intake_data: intake });
});
// Photo ID upload handling
const idBtn = document.getElementById("mcs-id-btn")!;
const idInput = document.getElementById("mcs-photo-id") as HTMLInputElement;
const idPreview = document.getElementById("mcs-id-preview")!;
const idImg = document.getElementById("mcs-id-img") as HTMLImageElement;
const idRemove = document.getElementById("mcs-id-remove")!;
// Photo ID upload handling (elements may not exist on non-MCS150 pages)
const idBtn = document.getElementById("mcs-id-btn");
const idInput = document.getElementById("mcs-photo-id") as HTMLInputElement | null;
const idPreview = document.getElementById("mcs-id-preview");
const idImg = document.getElementById("mcs-id-img") as HTMLImageElement | null;
const idRemove = document.getElementById("mcs-id-remove");
idBtn.addEventListener("click", () => idInput.click());
idInput.addEventListener("change", () => {
idBtn?.addEventListener("click", () => idInput?.click());
idInput?.addEventListener("change", () => {
const file = idInput.files?.[0];
if (!file) return;
// Store file reference for upload on submit
@ -367,19 +367,19 @@
// Show preview
if (file.type.startsWith("image/")) {
const reader = new FileReader();
reader.onload = (e) => { idImg.src = e.target?.result as string; };
if (idImg) { reader.onload = (e) => { idImg.src = e.target?.result as string; }; }
reader.readAsDataURL(file);
} else {
} else if (idImg) {
idImg.src = "";
idImg.alt = file.name;
}
idPreview.hidden = false;
idBtn.style.display = "none";
if (idPreview) idPreview.hidden = false;
if (idBtn) idBtn.style.display = "none";
});
idRemove.addEventListener("click", () => {
idRemove?.addEventListener("click", () => {
(window as any).__mcs150PhotoId = null;
idInput.value = "";
idPreview.hidden = true;
idBtn.style.display = "flex";
if (idInput) idInput.value = "";
if (idPreview) idPreview.hidden = true;
if (idBtn) idBtn.style.display = "flex";
});
</script>