Add additional handling for the next days filter

This commit is contained in:
Alex Tselegidis 2024-04-26 16:15:58 +02:00
parent fe7b406cb3
commit ebb682f518
2 changed files with 22 additions and 17 deletions

View file

@ -233,9 +233,9 @@ App.Http.Booking = (function () {
* @param {Number} providerId The selected provider ID. * @param {Number} providerId The selected provider ID.
* @param {Number} serviceId The selected service ID. * @param {Number} serviceId The selected service ID.
* @param {String} selectedDateString Y-m-d value of the selected date. * @param {String} selectedDateString Y-m-d value of the selected date.
* @param {Number} monthChangeStep Whether to add or subtract months. * @param {Number} [monthChangeStep] Whether to add or subtract months.
*/ */
function getUnavailableDates(providerId, serviceId, selectedDateString, monthChangeStep) { function getUnavailableDates(providerId, serviceId, selectedDateString, monthChangeStep = 1) {
if (processingUnavailableDates) { if (processingUnavailableDates) {
return; return;
} }
@ -268,7 +268,7 @@ App.Http.Booking = (function () {
searchedMonthStart = selectedDateString; searchedMonthStart = selectedDateString;
} }
if (searchedMonthCounter >= 3) { if (searchedMonthCounter >= 2) {
// Need to mark the current month dates as unavailable // Need to mark the current month dates as unavailable
const selectedDateMoment = moment(searchedMonthStart); const selectedDateMoment = moment(searchedMonthStart);
const startOfMonthMoment = selectedDateMoment.clone().startOf('month'); const startOfMonthMoment = selectedDateMoment.clone().startOf('month');
@ -278,7 +278,7 @@ App.Http.Booking = (function () {
unavailableDates.push(startOfMonthMoment.format('YYYY-MM-DD')); unavailableDates.push(startOfMonthMoment.format('YYYY-MM-DD'));
startOfMonthMoment.add(monthChangeStep, 'days'); // Move to the next day startOfMonthMoment.add(monthChangeStep, 'days'); // Move to the next day
} }
applyUnavailableDates(unavailableDates, searchedMonthStart, false); applyUnavailableDates(unavailableDates, searchedMonthStart, true);
searchedMonthStart = undefined; searchedMonthStart = undefined;
searchedMonthCounter = 0; searchedMonthCounter = 0;
return; // Stop searching return; // Stop searching
@ -312,6 +312,17 @@ App.Http.Booking = (function () {
const selectedDate = selectedDateMoment.toDate(); const selectedDate = selectedDateMoment.toDate();
const numberOfDays = selectedDateMoment.daysInMonth(); const numberOfDays = selectedDateMoment.daysInMonth();
// If all the days are unavailable then hide the appointments hours.
if (unavailableDates.length === numberOfDays) {
$availableHours.text(lang('no_available_hours'));
}
// Grey out unavailable dates.
$('#select-date')[0]._flatpickr.set(
'disable',
unavailableDates.map((unavailableDate) => new Date(unavailableDate)),
);
if (setDate && !vars('manage_mode')) { if (setDate && !vars('manage_mode')) {
for (let i = 1; i <= numberOfDays; i++) { for (let i = 1; i <= numberOfDays; i++) {
const currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i); const currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i);
@ -324,17 +335,6 @@ App.Http.Booking = (function () {
} }
} }
// If all the days are unavailable then hide the appointments hours.
if (unavailableDates.length === numberOfDays) {
$availableHours.text(lang('no_available_hours'));
}
// Grey out unavailable dates.
$('#select-date')[0]._flatpickr.set(
'disable',
unavailableDates.map((unavailableDate) => new Date(unavailableDate)),
);
const dateQueryParam = App.Utils.Url.queryParam('date'); const dateQueryParam = App.Utils.Url.queryParam('date');
if (dateQueryParam) { if (dateQueryParam) {

View file

@ -321,10 +321,15 @@ App.Pages.Booking = (function () {
$selectProvider.on('change', (event) => { $selectProvider.on('change', (event) => {
const $target = $(event.target); const $target = $(event.target);
const todayDateTimeObject = new Date();
const todayDateTimeMoment = moment(todayDateTimeObject);
App.Utils.UI.setDateTimePickerValue($selectDate, todayDateTimeObject);
App.Http.Booking.getUnavailableDates( App.Http.Booking.getUnavailableDates(
$target.val(), $target.val(),
$selectService.val(), $selectService.val(),
moment(App.Utils.UI.getDateTimePickerValue($selectDate)).format('YYYY-MM-DD'), todayDateTimeMoment.format('YYYY-MM-DD'),
); );
updateConfirmFrame(); updateConfirmFrame();
}); });
@ -887,7 +892,7 @@ App.Pages.Booking = (function () {
} }
if (Number(service.price) > 0) { if (Number(service.price) > 0) {
additionalInfoParts.push(`${lang('price')}: ${service.price} ${service.currency}`); additionalInfoParts.push(`${lang('price')}: ${Number(service.price).toFixed(2)} ${service.currency}`);
} }
if (service.location) { if (service.location) {