fix: prevent booking past times on current day

This commit is contained in:
2026-06-11 10:38:50 +01:00
parent 0c591bccf2
commit ec56e5802a

View File

@@ -65,8 +65,22 @@ export default function Booking() {
})
.filter(Boolean);
const today = new Date();
const todayStr = today.toISOString().split('T')[0];
const isToday = date === todayStr;
const currentHour = today.getHours();
const currentMinute = today.getMinutes();
return slots.map(time => {
const isBooked = bookedSlots.includes(time);
let isPast = false;
if (isToday) {
const [h, m] = time.split(':').map(Number);
if (h < currentHour || (h === currentHour && m <= currentMinute)) {
isPast = true;
}
}
const isBooked = bookedSlots.includes(time) || isPast;
const waitlistedByMe = user ? waitlists.some(w => w.barberId === barberId && w.date === `${date} ${time}` && w.customerId === user.id && w.status === 'pending') : false;
return { time, isBooked, waitlistedByMe };
});