Skip to content

Commit

Permalink
Correct unavailable date handling in booking page
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Feb 16, 2024
1 parent eedcb3b commit 6fecbc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions assets/js/http/booking_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ App.Http.Booking = (function () {
let unavailableDatesBackup;
let selectedDateStringBackup;
let processingUnavailableDates = false;
let searchedMonthStart;
let searchedMonthCounter = 0;

/**
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -332,6 +348,8 @@ App.Http.Booking = (function () {
}
}

searchedMonthStart = undefined;
searchedMonthCounter = 0;
processingUnavailableDates = false;
}

Expand Down
8 changes: 7 additions & 1 deletion assets/js/pages/booking.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 +
'-' +
Expand Down

0 comments on commit 6fecbc7

Please sign in to comment.