fix: prevent booking past times on current day
This commit is contained in:
@@ -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 };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user