fix(booking): prevent past time slots from being selectable for today
This commit is contained in:
@@ -147,6 +147,9 @@ function buildSegmentsForCourt(
|
|||||||
const segments: BookingTimelineSegment[] = [];
|
const segments: BookingTimelineSegment[] = [];
|
||||||
const slotDuration = court.slotDurationMinutes;
|
const slotDuration = court.slotDurationMinutes;
|
||||||
|
|
||||||
|
const nowMinutes = timeToMinutes(getNowTime());
|
||||||
|
const isToday = isTodayIso(selectedDate);
|
||||||
|
|
||||||
const availabilityRanges = court.availability
|
const availabilityRanges = court.availability
|
||||||
.filter((range) => range.dayOfWeek === dayOfWeek)
|
.filter((range) => range.dayOfWeek === dayOfWeek)
|
||||||
.map((range) => ({
|
.map((range) => ({
|
||||||
@@ -181,6 +184,9 @@ function buildSegmentsForCourt(
|
|||||||
slotStart += slotDuration
|
slotStart += slotDuration
|
||||||
) {
|
) {
|
||||||
const slotEnd = slotStart + slotDuration;
|
const slotEnd = slotStart + slotDuration;
|
||||||
|
|
||||||
|
if (isToday && slotEnd <= nowMinutes) continue;
|
||||||
|
|
||||||
const isBooked = courtBookings.some((booking) =>
|
const isBooked = courtBookings.some((booking) =>
|
||||||
overlapsBooking(slotStart, slotEnd, booking)
|
overlapsBooking(slotStart, slotEnd, booking)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import { useBooking } from '../booking-provider';
|
|||||||
import {
|
import {
|
||||||
fromIsoDateLocal,
|
fromIsoDateLocal,
|
||||||
getDayOfWeek,
|
getDayOfWeek,
|
||||||
|
getNowTime,
|
||||||
|
isTodayIso,
|
||||||
minutesToTime,
|
minutesToTime,
|
||||||
timeToMinutes,
|
timeToMinutes,
|
||||||
toIsoDateLocal,
|
toIsoDateLocal,
|
||||||
@@ -128,6 +130,9 @@ export function BookingCreateDialog() {
|
|||||||
minute += selectedCourt.slotDurationMinutes
|
minute += selectedCourt.slotDurationMinutes
|
||||||
) {
|
) {
|
||||||
const slotEnd = minute + selectedCourt.slotDurationMinutes;
|
const slotEnd = minute + selectedCourt.slotDurationMinutes;
|
||||||
|
|
||||||
|
if (isTodayIso(date) && minute <= timeToMinutes(getNowTime())) continue;
|
||||||
|
|
||||||
const isBooked = courtBookings.some((booking) => {
|
const isBooked = courtBookings.some((booking) => {
|
||||||
const bookingStart = timeToMinutes(booking.startTime);
|
const bookingStart = timeToMinutes(booking.startTime);
|
||||||
const bookingEnd = timeToMinutes(booking.endTime);
|
const bookingEnd = timeToMinutes(booking.endTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user