Fixing multiple duration default issues (#6114)

* Fixing multiple duration default issues

* Ensure that when calculation time slots we use 1 as a minimum interval, since 0 min meetings would result in an infinite loop.

Co-authored-by: Jeroen Reumkens <hello@jeroenreumkens.nl>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
fix/direct-link-encoding
Leo Giovanetti 2022-12-20 14:49:24 -03:00 committed by GitHub
parent ccbf3b1e54
commit 344f16d6cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -262,12 +262,14 @@ export const EventSetupTab = (
if (!newOptions.find((opt) => opt.value === defaultDuration?.value)) {
if (newOptions.length > 0) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
} else {
setDefaultDuration(null);
}
}
if (newOptions.length === 1 && defaultDuration === null) {
setDefaultDuration(newOptions[0]);
formMethods.setValue("length", newOptions[0].value);
}
formMethods.setValue("metadata.multipleDuration", values);
}}

View File

@ -283,7 +283,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
if (metadata?.multipleDuration.length < 1) {
throw new Error(t("event_setup_multiple_duration_error"));
} else {
if (input.length && !metadata?.multipleDuration?.includes(input.length)) {
if (!input.length && !metadata?.multipleDuration?.includes(input.length)) {
throw new Error(t("event_setup_multiple_duration_default_error"));
}
}

View File

@ -13,6 +13,8 @@ export type GetSlots = {
};
export type TimeFrame = { startTime: number; endTime: number };
const minimumOfOne = (input: number) => (input < 1 ? 1 : input);
/**
* TODO: What does this function do?
* Why is it needed?
@ -26,16 +28,24 @@ const splitAvailableTime = (
let initialTime = startTimeMinutes;
const finalizationTime = endTimeMinutes;
const result = [] as TimeFrame[];
// Ensure that both the frequency and event length are at least 1 minute, if they
// would be zero, we would have an infinite loop in this while!
const frequencyMinimumOne = minimumOfOne(frequency);
const eventLengthMinimumOne = minimumOfOne(eventLength);
while (initialTime < finalizationTime) {
const periodTime = initialTime + frequency;
const slotEndTime = initialTime + eventLength;
const periodTime = initialTime + frequencyMinimumOne;
const slotEndTime = initialTime + eventLengthMinimumOne;
/*
check if the slot end time surpasses availability end time of the user
1 minute is added to round up the hour mark so that end of the slot is considered in the check instead of x9
eg: if finalization time is 11:59, slotEndTime is 12:00, we ideally want the slot to be available
*/
if (slotEndTime <= finalizationTime + 1) result.push({ startTime: initialTime, endTime: periodTime });
initialTime += frequency;
// Ensure that both the frequency and event length are at least 1 minute, if they
// would be zero, we would have an infinite loop in this while!
initialTime += frequencyMinimumOne;
}
return result;
};