Skip to content
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

feat: show ooo forwarding and emoji when not available #18054

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
bd91268
feat: show ooo when not available
kart1ka Dec 7, 2024
ca2d3a9
fix: send correct username for toUser if user belongs to org
kart1ka Dec 7, 2024
5b0a2e7
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Dec 13, 2024
fcb2e05
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Dec 13, 2024
ab8c8cc
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
Udit-takkar Dec 16, 2024
7cc53a6
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Dec 20, 2024
8baeb00
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Dec 23, 2024
924c98f
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Dec 27, 2024
cfe3ba2
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Jan 1, 2025
69f89c1
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
anikdhabal Jan 4, 2025
8cea19f
enrich ooo user with profile in getUserAvailability
kart1ka Jan 6, 2025
77529c3
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Jan 7, 2025
8b6efe4
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Jan 14, 2025
b25dbb5
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Jan 15, 2025
8e8fb31
fix: set correct ooo slots
kart1ka Jan 15, 2025
fdb7184
Merge branch 'main' into feat/show-ooo-forwarding-and-emoji-when-not-…
kart1ka Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions packages/lib/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { WorkingHours, TimeRange as DateOverride } from "@calcom/types/sche
import { getWorkingHours } from "./availability";
import { getTimeZone } from "./date-fns";
import type { DateRange } from "./date-ranges";
import { UserRepository } from "./server/repository/user";

export type GetSlots = {
inviteeDate: Dayjs;
Expand Down Expand Up @@ -185,7 +186,6 @@ function buildSlotsWithDateRanges({
}

dateRanges.forEach((range) => {
const dateYYYYMMDD = range.start.format("YYYY-MM-DD");
const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");

let slotStartTime = range.start.utc().isAfter(startTimeWithMinNotice)
Expand All @@ -207,8 +207,7 @@ function buildSlotsWithDateRanges({
slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes").tz(timeZone);

while (!slotStartTime.add(eventLength, "minutes").subtract(1, "second").utc().isAfter(rangeEnd)) {
const dateOutOfOfficeExists = datesOutOfOffice?.[dateYYYYMMDD];
let slotData: {
const slotData: {
time: Dayjs;
userIds?: number[];
away?: boolean;
Expand All @@ -220,24 +219,45 @@ function buildSlotsWithDateRanges({
time: slotStartTime,
};

if (dateOutOfOfficeExists) {
const { toUser, fromUser, reason, emoji } = dateOutOfOfficeExists;

slotData = {
time: slotStartTime,
away: true,
...(fromUser && { fromUser }),
...(toUser && { toUser }),
...(reason && { reason }),
...(emoji && { emoji }),
};
}

slots.push(slotData);
slotStartTime = slotStartTime.add(frequency + (offsetStart ?? 0), "minutes");
}
});

if (datesOutOfOffice) {
Object.keys(datesOutOfOffice).forEach(async (date) => {
const dateOutOfOffice = datesOutOfOffice[date];
const slotTime = dayjs(date).tz(timeZone).startOf("day");

const { toUser, fromUser, reason, emoji } = dateOutOfOffice;

const enrichedToUser = toUser ? await UserRepository.enrichUserWithItsProfile({ user: toUser }) : null;
Praashh marked this conversation as resolved.
Show resolved Hide resolved
Praashh marked this conversation as resolved.
Show resolved Hide resolved

const oooSlot = {
time: slotTime,
away: true,
...(fromUser && { fromUser }),
...(enrichedToUser && {
toUser: {
id: enrichedToUser.id,
username: enrichedToUser.username,
displayName: enrichedToUser.displayName,
},
}),
...(reason && { reason }),
...(emoji && { emoji }),
};

// Find the correct position to insert the out of office slot
const insertIndex = slots.findIndex((slot) => slot.time.isAfter(slotTime));
if (insertIndex === -1) {
slots.push(oooSlot);
} else {
slots.splice(insertIndex, 0, oooSlot);
}
});
}

return slots;
}

Expand Down
Loading