diff --git a/components/wizard/calendar.tsx b/components/wizard/calendar.tsx index e216fa9..ff7cfd0 100644 --- a/components/wizard/calendar.tsx +++ b/components/wizard/calendar.tsx @@ -23,6 +23,22 @@ export default function MyCalendar() { const prevBooked = inSelection && getNextSmaller(daysBooked, start) const nextBooked = inSelection && getNextBigger(daysBooked, start) + function isSelected(date: Date) { + if (!startDate) { + return false + } + + // if end is before start, it is not within + if (endDate && !isAfter(endDate, startDate)) { + return false + } + + return isWithinInterval(date, { + start: startDate, + end: endDate || startDate, + }) + } + function tileClassName({ date, view }) { const isMonthView = view === 'month' const isDaysBookedLoaded = !!daysBooked @@ -37,12 +53,7 @@ export default function MyCalendar() { 'react-calendar__tile--selected-start': isSameDay(date, startDate), 'react-calendar__tile--selected-end': isSameDay(date, endDate), 'react-calendar__tile--selected': - (startDate && - isWithinInterval(date, { - start: startDate, - end: endDate || startDate, - })) || - isSameDay(date, startDate), + isSelected(date) || isSameDay(date, startDate), 'react-calendar__tile--unselectable': inSelection && ((prevBooked && date < new Date(prevBooked)) ||