Skip to content

Commit

Permalink
Automatically select the next available date in the booking page or d…
Browse files Browse the repository at this point in the history
…isplay a message if this month is unavailable (#1075) (#1204)
  • Loading branch information
alextselegidis committed Jul 11, 2023
1 parent 07ff42c commit ebe0875
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions application/controllers/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,15 @@ public function get_unavailable_dates()
$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);
}
Expand Down
15 changes: 15 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 searchedMonthCounter = 0;

/**
* Get Available Hours
Expand Down Expand Up @@ -260,6 +261,20 @@ App.Http.Booking = (function () {
data: data,
dataType: 'json'
}).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;
selectedDateStringBackup = selectedDateString;
applyUnavailableDates(response, selectedDateString, true);
Expand Down

0 comments on commit ebe0875

Please sign in to comment.