Reservation List
| # | Name | Phone | Date | Time Slot | Table Type | Booked On | Action |
|---|
Loading bookings...
Live view of every reservation made through AquaBook
| # | Name | Phone | Date | Time Slot | Table Type | Booked On | Action |
|---|
Loading bookings...
No bookings found for this filter.
'; return; } stateDiv.style.display = 'none'; tbody.innerHTML = bookings.map((b, i) => `Loading bookings...
'; try { const res = await fetch('https://aquabook-u419.onrender.com/api/bookings'); const data = await res.json(); allBookings = data; updateStats(data); const filtered = currentFilter === 'all' ? allBookings : allBookings.filter(b => b.tableType === currentFilter); renderTable(filtered); } catch (err) { stateDiv.style.display = 'block'; stateDiv.innerHTML = `Could not connect to backend. Make sure the server is running on port 5000.
`; } } // ── Cancel / Delete booking ── async function cancelBooking(id) { if (!confirm('Are you sure you want to cancel this booking?')) return; const btn = document.getElementById(`cancel-${id}`); btn.disabled = true; btn.textContent = 'Cancelling...'; try { const res = await fetch(`https://aquabook-u419.onrender.com/api/bookings/${id}`, { method: 'DELETE' }); const data = await res.json(); if (res.ok) { // Remove row with fade const row = document.getElementById(`row-${id}`); row.style.opacity = '0'; row.style.transition = 'opacity 0.3s ease'; setTimeout(() => { allBookings = allBookings.filter(b => b._id !== id); updateStats(allBookings); const filtered = currentFilter === 'all' ? allBookings : allBookings.filter(b => b.tableType === currentFilter); renderTable(filtered); }, 300); showToast('✅ Booking cancelled successfully.', 'success'); } else { showToast(`❌ Error: ${data.error}`, 'error'); btn.disabled = false; btn.textContent = 'Cancel'; } } catch (err) { showToast('❌ Could not connect to server.', 'error'); btn.disabled = false; btn.textContent = 'Cancel'; } } // ── Load stats from /api/stats (Mongoose aggregation) ── async function loadStats() { try { const res = await fetch('https://aquabook-u419.onrender.com/api/stats'); const data = await res.json(); if (!res.ok) return; document.getElementById('stat-total').textContent = data.total; document.getElementById('stat-8ball').textContent = data.byType['8ball'] || 0; document.getElementById('stat-snooker').textContent = data.byType['snooker'] || 0; document.getElementById('stat-vip').textContent = data.byType['vip'] || 0; // Add Most Booked Date card if bookings exist const statsSection = document.getElementById('stats-section'); if (statsSection && !document.getElementById('stat-most-booked') && data.mostBookedDate.date !== 'N/A') { const card = document.createElement('div'); card.className = 'stat-card'; card.innerHTML = `