fix: Booking Error - cannot be booked at this time (#15288)
Co-authored-by: Joe Au-Yeung <[email protected]>
This commit is contained in:
1 parent
3a22fdb428
commit
765d601ff9
5 files changed
+1345
-89
No files matched your search
@@ -16,7 +16,11 @@ import { parseBookingLimit, parseDurationLimit } from "@calcom/lib";
|
||||
import { RESERVED_SUBDOMAINS } from "@calcom/lib/constants";
|
||||
import { getUTCOffsetByTimezone } from "@calcom/lib/date-fns";
|
||||
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
|
||||
import { isDateOutOfBounds, isTimeOutOfBounds, calculatePeriodLimits } from "@calcom/lib/isOutOfBounds";
|
||||
import {
|
||||
isTimeOutOfBounds,
|
||||
calculatePeriodLimits,
|
||||
isTimeViolatingFutureLimit,
|
||||
} from "@calcom/lib/isOutOfBounds";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { performance } from "@calcom/lib/server/perfObserver";
|
||||
@@ -761,6 +765,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro
|
||||
const allDatesWithBookabilityStatus = getAllDatesWithBookabilityStatus(availableDates);
|
||||
loggerWithEventDetails.debug(safeStringify({ availableDates }));
|
||||
|
||||
const utcOffset = input.timeZone ? getUTCOffsetByTimezone(input.timeZone) ?? 0 : 0;
|
||||
const periodLimits = calculatePeriodLimits({
|
||||
periodType: eventType.periodType,
|
||||
periodDays: eventType.periodDays,
|
||||
@@ -768,27 +773,37 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro
|
||||
periodStartDate: eventType.periodStartDate,
|
||||
periodEndDate: eventType.periodEndDate,
|
||||
allDatesWithBookabilityStatus,
|
||||
utcOffset: input.timeZone ? getUTCOffsetByTimezone(input.timeZone) ?? 0 : 0,
|
||||
utcOffset,
|
||||
});
|
||||
|
||||
let foundALimitViolation = false;
|
||||
let foundAFutureLimitViolation = false;
|
||||
const withinBoundsSlotsMappedToDate = Object.entries(slotsMappedToDate).reduce(
|
||||
(withinBoundsSlotsMappedToDate, [date, slots]) => {
|
||||
// Computation Optimization: If a limit violation has been found, we just consider all slots to be out of bounds beyond that date.
|
||||
// Computation Optimization: If a future limit violation has been found, we just consider all slots to be out of bounds beyond that slot.
|
||||
// We can't do the same for periodType=RANGE because it can start from a day other than today and today will hit the violation then.
|
||||
if (foundALimitViolation && doesRangeStartFromToday(eventType.periodType)) {
|
||||
if (foundAFutureLimitViolation && doesRangeStartFromToday(eventType.periodType)) {
|
||||
return withinBoundsSlotsMappedToDate;
|
||||
}
|
||||
const isDateWithinBound = !isDateOutOfBounds({ dateString: date, periodLimits });
|
||||
if (isDateWithinBound) {
|
||||
// TODO: Slots calculation logic already seems to consider the minimum booking notice and past booking time and thus there shouldn't be need to filter out slots here.
|
||||
withinBoundsSlotsMappedToDate[date] = slots.filter(
|
||||
(slot) =>
|
||||
!isTimeOutOfBounds({ time: slot.time, minimumBookingNotice: eventType.minimumBookingNotice })
|
||||
const filteredSlots = slots.filter((slot) => {
|
||||
const isFutureLimitViolationForTheSlot = isTimeViolatingFutureLimit({
|
||||
time: slot.time,
|
||||
periodLimits,
|
||||
});
|
||||
if (isFutureLimitViolationForTheSlot) {
|
||||
foundAFutureLimitViolation = true;
|
||||
}
|
||||
return (
|
||||
!isFutureLimitViolationForTheSlot &&
|
||||
// TODO: Perf Optmization: Slots calculation logic already seems to consider the minimum booking notice and past booking time and thus there shouldn't be need to filter out slots here.
|
||||
!isTimeOutOfBounds({ time: slot.time, minimumBookingNotice: eventType.minimumBookingNotice })
|
||||
);
|
||||
} else {
|
||||
foundALimitViolation = true;
|
||||
});
|
||||
|
||||
if (!filteredSlots.length) {
|
||||
// If there are no slots available, we don't set that date, otherwise having an empty slots array makes frontend consider it as an all day OOO case
|
||||
return withinBoundsSlotsMappedToDate;
|
||||
}
|
||||
|
||||
withinBoundsSlotsMappedToDate[date] = filteredSlots;
|
||||
return withinBoundsSlotsMappedToDate;
|
||||
},
|
||||
{} as typeof slotsMappedToDate
|
||||
|
||||
Reference in new issue
Block a user