diff --git a/src/index.ts b/src/index.ts index 1366e6d..1f7b16a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,11 +13,6 @@ app.get("/test", (req: Request, res: Response) => { app.post('/submit', (req, res) => { const report = req.body; - - // For now, just log it - console.log('📥 New form submission:'); - - // TODO: Validate and write to MongoDB later handleFormData(report); res.status(200).json({ status: 'ok', message: 'Form received' }); }); diff --git a/static/script.js b/static/script.js index 23993b9..09b441e 100644 --- a/static/script.js +++ b/static/script.js @@ -14,11 +14,9 @@ const dataPromise = fetch("units.converted.json") window.location.reload(); }); - window.addEventListener('DOMContentLoaded', () => { const input = document.getElementById('unitNumber'); const resultDiv = document.getElementById('formExpansion'); - input.addEventListener('input', async () => { await dataPromise; @@ -41,9 +39,7 @@ window.addEventListener("load", retryOfflineReports); async function loadForm(values) { const formExpansion = document.getElementById('formExpansion'); const formHidden = document.getElementById('formHidden'); - formExpansion.innerHTML = ''; - const heading = document.createElement('h2'); heading.textContent = "Choose all areas where A/C failed"; formExpansion.appendChild(heading); @@ -52,29 +48,23 @@ async function loadForm(values) { const coachTitle = document.createElement('h3'); coachTitle.textContent = vehicle.id; formExpansion.appendChild(coachTitle); - for (const zone of vehicle.zones) { const checkboxId = `${zone}-${vehicle.id}`; - const wrapper = document.createElement('div'); wrapper.className = 'checkbox-wrapper'; - const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.id = checkboxId; checkbox.name = checkboxId; checkbox.title = zone; - const label = document.createElement('label'); label.htmlFor = checkboxId; label.textContent = zone; - wrapper.appendChild(checkbox); wrapper.appendChild(label); formExpansion.appendChild(wrapper); } } - formHidden.style = 'display:block'; } @@ -85,13 +75,10 @@ function reset() { async function formSubmit(event) { event.preventDefault(); - const form = event.target; const formData = new FormData(form); - const submitButton = form.querySelector('button[type="submit"]'); submitButton.disabled = true; - const data = {}; for (const [key, value] of formData.entries()) { if (data[key]) { @@ -101,16 +88,13 @@ async function formSubmit(event) { data[key] = value; } } - data.utcTimestamp = new Date().toISOString(); - try { const res = await fetch("/submit", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(data), }); - if (!res.ok) throw new Error("Submission failed"); console.log("Form Submitted") showStatus("✅ Form received, thank-you.", type="success"); @@ -134,13 +118,9 @@ function saveReportOffline(report) { async function retryOfflineReports() { const key = "offlineReports"; const stored = JSON.parse(localStorage.getItem(key) || "[]"); - if (stored.length === 0) return; - console.log(`Attempting to resend ${stored.length} stored report(s)...`); - const remaining = []; - for (const report of stored) { try { const res = await fetch("/submit", { @@ -156,7 +136,6 @@ async function retryOfflineReports() { remaining.push(report); } } - if (remaining.length === 0) { localStorage.removeItem(key); } else { @@ -169,7 +148,6 @@ function showStatus(message, type) { statusDiv.textContent = message; statusDiv.className = `status-${type}`; statusDiv.style = 'display:flex'; - setTimeout(() => { statusDiv.style = 'display:none'; }, 5000); diff --git a/static/units.converted.json b/static/units.converted.json index 7abb8de..6bf07cd 100644 --- a/static/units.converted.json +++ b/static/units.converted.json @@ -1416,20 +1416,73 @@ } ], "175002": [ - { "id": "A", "zones": ["saloon", "cab"] }, - { "id": "B", "zones": ["saloon", "cab"] } + { + "id": "A", + "zones": [ + "saloon", + "cab" + ] + }, + { + "id": "B", + "zones": [ + "saloon", + "cab" + ] + } ], "175007": [ - { "id": "A", "zones": ["saloon", "cab"] }, - { "id": "B", "zones": ["saloon", "cab"] } + { + "id": "A", + "zones":[ + "saloon", + "cab" + ] + }, + { + "id": "B", + "zones": [ + "saloon", + "cab" + ] + } ], "175009": [ - { "id": "A", "zones": ["saloon", "cab"] }, - { "id": "B", "zones": ["saloon", "cab"] } + { + "id": "A", + "zones": [ + "saloon", + "cab" + ] + }, + { + "id": "B", + "zones": [ + "saloon", + "cab" + ] + } ], "175114": [ - { "id": "A", "zones": ["saloon", "cab"] }, - { "id": "B", "zones": ["saloon"] }, - { "id": "C", "zones": ["saloon", "cab"] } + { + "id": "A", + "zones": [ + "saloon", + "cab" + ] + }, + { + "id": "B", + "zones": [ + "saloon" + ] + }, + { + "id": "C", + "zones": [ + "saloon", + "cab" + ] + } ] } \ No newline at end of file