Automatically select the next available date in the booking page or display a message if this month is unavailable (#1075) (#1204)

This commit is contained in:
Alex Tselegidis 2023-07-11 08:11:19 +02:00
parent 07ff42c1a4
commit ebe087553e
2 changed files with 24 additions and 0 deletions

View file

@ -708,6 +708,15 @@ class Booking extends EA_Controller {
$unavailable_dates[] = $current_date->format('Y-m-d'); $unavailable_dates[] = $current_date->format('Y-m-d');
} }
} }
if (count($unavailable_dates) === $number_of_days_in_month)
{
json_response([
'is_month_unavailable' => TRUE,
]);
return;
}
json_response($unavailable_dates); json_response($unavailable_dates);
} }

View file

@ -28,6 +28,7 @@ App.Http.Booking = (function () {
let unavailableDatesBackup; let unavailableDatesBackup;
let selectedDateStringBackup; let selectedDateStringBackup;
let processingUnavailableDates = false; let processingUnavailableDates = false;
let searchedMonthCounter = 0;
/** /**
* Get Available Hours * Get Available Hours
@ -260,6 +261,20 @@ App.Http.Booking = (function () {
data: data, data: data,
dataType: 'json' dataType: 'json'
}).done((response) => { }).done((response) => {
if (response.is_month_unavailable) {
if (searchedMonthCounter >= 3) {
searchedMonthCounter = 0;
return; // Stop searching
}
searchedMonthCounter++;
const selectedDateMoment = moment(selectedDateString);
selectedDateMoment.add(1, 'month');
const nextSelectedDate = selectedDateMoment.format('YYYY-MM-DD');
getUnavailableDates(providerId, serviceId, nextSelectedDate);
return;
}
unavailableDatesBackup = response; unavailableDatesBackup = response;
selectedDateStringBackup = selectedDateString; selectedDateStringBackup = selectedDateString;
applyUnavailableDates(response, selectedDateString, true); applyUnavailableDates(response, selectedDateString, true);