mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-28 19:03:21 +03:00
Correct unavailable date handling in booking page
This commit is contained in:
parent
eedcb3b8d9
commit
6fecbc7cd7
2 changed files with 25 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 +
|
||||
'-' +
|
||||
|
|
Loading…
Reference in a new issue