// Northline Workshops signup logic (repaired working copy) // Pricing per inputs/brief.md: CAD 240/seat, 10% off subtotal for 3+ seats, // 12% tax applied AFTER the discount. Seats must be an integer 1-8. const PRICE_PER_SEAT = 240; const TAX_RATE = 0.12; function calculateTotal(seats) { const subtotal = seats * PRICE_PER_SEAT; const discount = seats >= 3 ? 0.10 : 0; return subtotal * (1 - discount) * (1 + TAX_RATE); } // Strict seat parsing: rejects blank, non-numeric, fractional, <1 and >8. function parseSeats(raw) { const trimmed = String(raw).trim(); if (trimmed === '' || !/^\d+$/.test(trimmed)) return null; const n = Number(trimmed); if (!Number.isInteger(n) || n < 1 || n > 8) return null; return n; } const seatsInput = document.querySelector('#seats'); const totalEl = document.querySelector('#total'); const status = document.querySelector('#status'); function showStatus(message, kind) { status.textContent = message; status.className = kind || ''; } function renderTotal() { const seats = parseSeats(seatsInput.value); if (seats === null) { totalEl.textContent = 'CAD —'; totalEl.title = 'Enter a whole number of seats from 1 to 8.'; return; } totalEl.title = ''; totalEl.textContent = 'CAD ' + calculateTotal(seats).toFixed(2); } seatsInput.addEventListener('input', renderTotal); renderTotal(); // Same email shape the supplied server accepts (site/server.py). const EMAIL_RE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/; document.querySelector('#signup').addEventListener('submit', async event => { event.preventDefault(); const name = document.querySelector('#name').value.trim(); const email = document.querySelector('#email').value.trim(); const seats = parseSeats(seatsInput.value); if (!name) { showStatus('Please enter your name.', 'error'); return; } if (!EMAIL_RE.test(email)) { showStatus('Please enter a valid email address.', 'error'); return; } if (seats === null) { showStatus('Seats must be a whole number from 1 to 8.', 'error'); return; } showStatus('Sending your request…', ''); try { const response = await fetch('/api/leads', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: name, email: email, seats: seats }) }); if (!response.ok) throw new Error('Signup failed. Please check your details and try again.'); showStatus('Thanks! Your workshop request is saved.', 'success'); } catch (error) { showStatus(error.message, 'error'); } });