-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: OOO for team events #14503
fix: OOO for team events #14503
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import type { IOutOfOfficeData } from "@calcom/core/getUserAvailability"; | ||
import type { Dayjs } from "@calcom/dayjs"; | ||
import dayjs from "@calcom/dayjs"; | ||
import type { Availability } from "@calcom/prisma/client"; | ||
|
@@ -103,17 +104,31 @@ export function processDateOverride({ | |
}; | ||
} | ||
|
||
function processOOO(outOfOffice: Dayjs, timeZone: string) { | ||
const utcOffset = outOfOffice.tz(timeZone).utcOffset(); | ||
const utcDate = outOfOffice.subtract(utcOffset, "minute"); | ||
|
||
const OOOdate = utcDate.tz(timeZone); | ||
|
||
return { | ||
start: OOOdate, | ||
end: OOOdate, | ||
}; | ||
} | ||
|
||
export function buildDateRanges({ | ||
availability, | ||
timeZone /* Organizer timeZone */, | ||
dateFrom /* Attendee dateFrom */, | ||
dateTo /* `` dateTo */, | ||
outOfOffice, | ||
}: { | ||
timeZone: string; | ||
availability: (DateOverride | WorkingHours)[]; | ||
dateFrom: Dayjs; | ||
dateTo: Dayjs; | ||
}): DateRange[] { | ||
outOfOffice?: IOutOfOfficeData; | ||
}): { dateRanges: DateRange[]; dateRangesWithoutOOO: DateRange[] } { | ||
const dateFromOrganizerTZ = dateFrom.tz(timeZone); | ||
const groupedWorkingHours = groupByDate( | ||
availability.reduce((processed: DateRange[], item) => { | ||
|
@@ -125,6 +140,11 @@ export function buildDateRanges({ | |
return processed; | ||
}, []) | ||
); | ||
const OOOdates = outOfOffice | ||
? Object.keys(outOfOffice).map((outOfOffice) => processOOO(dayjs(outOfOffice), timeZone)) | ||
: []; | ||
|
||
const groupedOOO = groupByDate(OOOdates); | ||
|
||
const groupedDateOverrides = groupByDate( | ||
availability.reduce((processed: DateRange[], item) => { | ||
|
@@ -158,7 +178,16 @@ export function buildDateRanges({ | |
(ranges) => ranges.filter((range) => range.start.valueOf() !== range.end.valueOf()) | ||
); | ||
|
||
return dateRanges.flat(); | ||
const dateRangesWithoutOOO = Object.values({ | ||
...groupedWorkingHours, | ||
...groupedDateOverrides, | ||
...groupedOOO, | ||
}).map( | ||
// remove 0-length overrides && OOO dates that were kept to cancel out working dates until now. | ||
(ranges) => ranges.filter((range) => range.start.valueOf() !== range.end.valueOf()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOO always starts and end on the same time (handled the same way as a full-day date override) |
||
); | ||
|
||
return { dateRanges: dateRanges.flat(), dateRangesWithoutOOO: dateRangesWithoutOOO.flat() }; | ||
} | ||
|
||
export function groupByDate(ranges: DateRange[]): { [x: string]: DateRange[] } { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,6 +461,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro | |
const { | ||
busy, | ||
dateRanges, | ||
dateRangesWithoutOOO, | ||
currentSeats: _currentSeats, | ||
timeZone, | ||
datesOutOfOffice, | ||
|
@@ -496,6 +497,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro | |
return { | ||
timeZone, | ||
dateRanges, | ||
dateRangesWithoutOOO, | ||
busy, | ||
user: currentUser, | ||
datesOutOfOffice, | ||
|
@@ -523,6 +525,11 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro | |
const checkForAvailabilityCount = 0; | ||
const aggregatedAvailability = getAggregatedAvailability(allUsersAvailability, eventType.schedulingType); | ||
|
||
const isTeamEvent = | ||
eventType.schedulingType === SchedulingType.COLLECTIVE || | ||
eventType.schedulingType === SchedulingType.ROUND_ROBIN || | ||
allUsersAvailability.length > 1; | ||
|
||
const timeSlots = getSlots({ | ||
inviteeDate: startTime, | ||
eventLength: input.duration || eventType.length, | ||
|
@@ -532,7 +539,7 @@ export async function getAvailableSlots({ input, ctx }: GetScheduleOptions): Pro | |
frequency: eventType.slotInterval || input.duration || eventType.length, | ||
organizerTimeZone: | ||
eventType.timeZone || eventType?.schedule?.timeZone || allUsersAvailability?.[0]?.timeZone, | ||
datesOutOfOffice: allUsersAvailability[0]?.datesOutOfOffice, | ||
datesOutOfOffice: !isTeamEvent ? allUsersAvailability[0]?.datesOutOfOffice : undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For team events, OOO days are already included |
||
}); | ||
|
||
let availableTimeSlots: typeof timeSlots = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for team events we want to use the date ranges that already take into account OOO days