Correct unavailable date handling in booking page

This commit is contained in:
Alex Tselegidis 2024-02-16 17:08:51 +01:00
parent eedcb3b8d9
commit 6fecbc7cd7
2 changed files with 25 additions and 1 deletions

View file

@ -28,6 +28,7 @@ App.Http.Booking = (function () {
let unavailableDatesBackup;
let selectedDateStringBackup;
let processingUnavailableDates = false;
let searchedMonthStart;
let searchedMonthCounter = 0;
/**
@ -262,7 +263,22 @@ App.Http.Booking = (function () {
dataType: 'json',
}).done((response) => {
if (response.is_month_unavailable) {
if (!searchedMonthStart) {
searchedMonthStart = selectedDateString;
}
if (searchedMonthCounter >= 3) {
// Need to mark the current month dates as unavailable
const selectedDateMoment = moment(searchedMonthStart);
const startOfMonthMoment = selectedDateMoment.clone().startOf('month');
const endOfMonthMoment = selectedDateMoment.clone().endOf('month');
const unavailableDates = [];
while (startOfMonthMoment.isSameOrBefore(endOfMonthMoment)) {
unavailableDates.push(startOfMonthMoment.format('YYYY-MM-DD'));
startOfMonthMoment.add(1, 'days'); // Move to the next day
}
applyUnavailableDates(unavailableDates, searchedMonthStart, false);
searchedMonthStart = undefined;
searchedMonthCounter = 0;
return; // Stop searching
}
@ -332,6 +348,8 @@ App.Http.Booking = (function () {
}
}
searchedMonthStart = undefined;
searchedMonthCounter = 0;
processingUnavailableDates = false;
}

View file

@ -87,6 +87,8 @@ App.Pages.Booking = (function () {
// Initialize page's components (tooltips, date pickers etc).
tippy('[data-tippy-content]');
let monthTimeout;
App.Utils.UI.initializeDatePicker($selectDate, {
inline: true,
minDate: moment().subtract(1, 'day').set({hours: 23, minutes: 59, seconds: 59}).toDate(),
@ -97,7 +99,11 @@ App.Pages.Booking = (function () {
},
onMonthChange: (selectedDates, dateStr, instance) => {
setTimeout(() => {
if (monthTimeout) {
clearTimeout(monthTimeout);
}
monthTimeout = setTimeout(() => {
const displayedMonthMoment = moment(
instance.currentYearElement.value +
'-' +