From 98d9cd105b5e427f20aa17433387fdc8bf55a849 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Tue, 4 Feb 2025 12:08:14 +0530 Subject: [PATCH] Revert "feat: show ooo forwarding and emoji when not available (#18054)" (#19073) This reverts commit a0f6e50d5bcf0b16a7500e4ff9951c907811bae5. Co-authored-by: Hariom Balhara --- packages/core/getUserAvailability.ts | 27 +++++++++------------------ packages/lib/slots.ts | 22 +--------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts index fff5dd73eb..1b38dacc5e 100644 --- a/packages/core/getUserAvailability.ts +++ b/packages/core/getUserAvailability.ts @@ -22,7 +22,8 @@ import { safeStringify } from "@calcom/lib/safeStringify"; import { EventTypeRepository } from "@calcom/lib/server/repository/eventType"; import { UserRepository } from "@calcom/lib/server/repository/user"; import prisma from "@calcom/prisma"; -import { BookingStatus, SchedulingType } from "@calcom/prisma/enums"; +import { SchedulingType } from "@calcom/prisma/enums"; +import { BookingStatus } from "@calcom/prisma/enums"; import { EventTypeMetaDataSchema, stringToDayjsZod } from "@calcom/prisma/zod-utils"; import type { EventBusyDetails, IntervalLimitUnit } from "@calcom/types/Calendar"; import type { TimeRange } from "@calcom/types/schedule"; @@ -541,7 +542,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA }, })); - const datesOutOfOffice: IOutOfOfficeData = await calculateOutOfOfficeRanges(outOfOfficeDays, availability); + const datesOutOfOffice: IOutOfOfficeData = calculateOutOfOfficeRanges(outOfOfficeDays, availability); const { dateRanges, oooExcludedDateRanges } = buildDateRanges({ dateFrom, @@ -628,17 +629,15 @@ export interface IOutOfOfficeData { }; } -const calculateOutOfOfficeRanges = async ( +const calculateOutOfOfficeRanges = ( outOfOfficeDays: GetUserAvailabilityInitialData["outOfOfficeDays"], availability: GetUserAvailabilityParamsDTO["availability"] -): Promise => { +): IOutOfOfficeData => { if (!outOfOfficeDays || outOfOfficeDays.length === 0) { return {}; } - const acc: IOutOfOfficeData = {}; - - for (const { start, end, toUser, user, reason } of outOfOfficeDays) { + return outOfOfficeDays.reduce((acc: IOutOfOfficeData, { start, end, toUser, user, reason }) => { // here we should use startDate or today if start is before today // consider timezone in start and end date range const startDateRange = dayjs(start).utc().isBefore(dayjs().startOf("day").utc()) @@ -659,27 +658,19 @@ const calculateOutOfOfficeRanges = async ( continue; // Skip to the next iteration if day not found in flattenDays } - const enrichedToUser = toUser ? await UserRepository.enrichUserWithItsProfile({ user: toUser }) : null; - acc[date.format("YYYY-MM-DD")] = { // @TODO: would be good having start and end availability time here, but for now should be good // you can obtain that from user availability defined outside of here fromUser: { id: user.id, displayName: user.name }, // optional chaining destructuring toUser - ...(!!enrichedToUser && { - toUser: { - id: enrichedToUser.id, - username: enrichedToUser.username, - displayName: enrichedToUser.name, - }, - }), + toUser: !!toUser ? { id: toUser.id, displayName: toUser.name, username: toUser.username } : null, reason: !!reason ? reason.reason : null, emoji: !!reason ? reason.emoji : null, }; } - } - return acc; + return acc; + }, {}); }; type GetUsersAvailabilityProps = { diff --git a/packages/lib/slots.ts b/packages/lib/slots.ts index 94a087c927..645c71fa0a 100644 --- a/packages/lib/slots.ts +++ b/packages/lib/slots.ts @@ -184,7 +184,6 @@ function buildSlotsWithDateRanges({ } } - const processedOOODates = new Set(); dateRanges.forEach((range) => { const dateYYYYMMDD = range.start.format("YYYY-MM-DD"); const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute"); @@ -207,25 +206,6 @@ function buildSlotsWithDateRanges({ slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes").tz(timeZone); - // Add OOO slot if exists and is before current range - if (datesOutOfOffice) { - Object.entries(datesOutOfOffice).forEach(([dateStr, oooData]) => { - const oooDate = dayjs(dateStr); - if (oooDate.isBefore(dateYYYYMMDD, "day") && !processedOOODates.has(dateStr)) { - slots.push({ - time: oooDate.startOf("day"), - away: true, - ...(oooData.fromUser && { fromUser: oooData.fromUser }), - ...(oooData.toUser && { toUser: oooData.toUser }), - ...(oooData.reason && { reason: oooData.reason }), - ...(oooData.emoji && { emoji: oooData.emoji }), - }); - // when the date range increases in the next iteration, we don't want to process this date again - processedOOODates.add(dateStr); - } - }); - } - while (!slotStartTime.add(eventLength, "minutes").subtract(1, "second").utc().isAfter(rangeEnd)) { const dateOutOfOfficeExists = datesOutOfOffice?.[dateYYYYMMDD]; let slotData: { @@ -251,8 +231,8 @@ function buildSlotsWithDateRanges({ ...(reason && { reason }), ...(emoji && { emoji }), }; - processedOOODates.add(dateYYYYMMDD); } + slots.push(slotData); slotStartTime = slotStartTime.add(frequency + (offsetStart ?? 0), "minutes"); }