Skip to content

Commit

Permalink
Preselect the date with a query parameter (#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextselegidis committed Jul 3, 2023
1 parent 66dfd36 commit 4d58075
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions assets/js/http/booking_http_client.js
Expand Up @@ -22,9 +22,9 @@ App.Http.Booking = (function () {
const $availableHours = $('#available-hours');
const $captchaHint = $('#captcha-hint');
const $captchaTitle = $('.captcha-title');

const moment = window.moment;

let unavailableDatesBackup;
let selectedDateStringBackup;
let processingUnavailableDates = false;
Expand Down Expand Up @@ -283,7 +283,7 @@ App.Http.Booking = (function () {
if (setDate && !vars('manage_mode')) {
for (let i = 1; i <= numberOfDays; i++) {
const currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i);

if (unavailableDates.indexOf(moment(currentDate).format('YYYY-MM-DD')) === -1) {
$('#select-date')[0]._flatpickr.setDate(currentDate);
getAvailableHours(moment(currentDate).format('YYYY-MM-DD'));
Expand All @@ -300,6 +300,16 @@ App.Http.Booking = (function () {
// Grey out unavailable dates.
$('#select-date')[0]._flatpickr.set('disable', unavailableDates.map(unavailableDate => new Date(unavailableDate)));

const dateQueryParam = App.Utils.Url.queryParam('date');

if (dateQueryParam) {
const dateQueryParamMoment = moment(dateQueryParam);

if (dateQueryParamMoment.isValid() && !unavailableDates.includes(dateQueryParam) && dateQueryParamMoment.format('YYYY-MM') === selectedDateMoment.format('YYYY-MM')) {
$('#select-date')[0]._flatpickr.setDate(dateQueryParamMoment.toDate());
}
}

processingUnavailableDates = false;
}

Expand Down

0 comments on commit 4d58075

Please sign in to comment.