From a622c7b624c0802268081dd54b3b101028b1a156 Mon Sep 17 00:00:00 2001 From: Somay Chauhan Date: Thu, 19 Dec 2024 13:37:40 +0530 Subject: [PATCH] fix: seats option not working for booker atom (#18265) --- .../transformApiEventTypeForAtom.ts | 89 ++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts b/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts index 0f11a4115f..8fc19ff0da 100644 --- a/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts +++ b/packages/platform/atoms/event-types/atom-api-transformers/transformApiEventTypeForAtom.ts @@ -8,6 +8,11 @@ import { systemBeforeFieldLocation, systemAfterFieldRescheduleReason, transformRecurrenceApiToInternal, + transformIntervalLimitsApiToInternal, + transformSeatsApiToInternal, + transformEventColorsApiToInternal, + transformConfirmationPolicyApiToInternal, + transformFutureBookingLimitsApiToInternal, } from "@calcom/lib/event-types/transformers"; import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client"; import type { @@ -33,11 +38,28 @@ export function transformApiEventTypeForAtom( entity: BookerPlatformWrapperAtomProps["entity"] | undefined, defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined ) { - const { lengthInMinutes, locations, bookingFields, users, recurrence, ...rest } = eventType; + const { + lengthInMinutes, + lengthInMinutesOptions, + locations, + bookingFields, + users, + recurrence, + bookingLimitsCount, + bookingLimitsDuration, + seats, + color, + confirmationPolicy, + customName, + useDestinationCalendarEmail, + bookingWindow, + ...rest + } = eventType; const isDefault = isDefaultEvent(rest.title); const user = users[0]; + const confirmationPolicyTransformed = transformConfirmationPolicyApiToInternal(confirmationPolicy); const defaultEventBookerLayouts = { enabledLayouts: [...bookerLayoutOptions], defaultLayout: BookerLayouts.MONTH_VIEW, @@ -101,7 +123,27 @@ export function transformApiEventTypeForAtom( upId: `usr-${user.id}`, }, })), + bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined, + durationLimits: bookingLimitsDuration + ? transformIntervalLimitsApiToInternal(bookingLimitsDuration) + : undefined, + + metadata: { + requiresConfirmationThreshold: + confirmationPolicyTransformed?.requiresConfirmationThreshold ?? undefined, + multipleDuration: lengthInMinutesOptions, + }, + + requiresConfirmation: confirmationPolicyTransformed?.requiresConfirmation ?? undefined, + requiresConfirmationWillBlockSlot: + confirmationPolicyTransformed?.requiresConfirmationWillBlockSlot ?? undefined, + + eventTypeColor: transformEventColorsApiToInternal(color), recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null, + ...transformSeatsApiToInternal(seats), + eventName: customName, + useEventTypeDestinationCalendarEmail: useDestinationCalendarEmail, + ...getBookingWindow(bookingWindow), }; } @@ -110,10 +152,28 @@ export function transformApiTeamEventTypeForAtom( entity: BookerPlatformWrapperAtomProps["entity"] | undefined, defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined ) { - const { lengthInMinutes, locations, hosts, bookingFields, recurrence, team, ...rest } = eventType; + const { + lengthInMinutes, + lengthInMinutesOptions, + locations, + hosts, + bookingFields, + recurrence, + team, + bookingLimitsCount, + bookingLimitsDuration, + seats, + color, + confirmationPolicy, + customName, + useDestinationCalendarEmail, + bookingWindow, + ...rest + } = eventType; const isDefault = isDefaultEvent(rest.title); + const confirmationPolicyTransformed = transformConfirmationPolicyApiToInternal(confirmationPolicy); const defaultEventBookerLayouts = { enabledLayouts: [...bookerLayoutOptions], defaultLayout: BookerLayouts.MONTH_VIEW, @@ -191,6 +251,26 @@ export function transformApiTeamEventTypeForAtom( }, })), recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null, + bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined, + durationLimits: bookingLimitsDuration + ? transformIntervalLimitsApiToInternal(bookingLimitsDuration) + : undefined, + + metadata: { + requiresConfirmationThreshold: + confirmationPolicyTransformed?.requiresConfirmationThreshold ?? undefined, + multipleDuration: lengthInMinutesOptions, + }, + + requiresConfirmation: confirmationPolicyTransformed?.requiresConfirmation ?? undefined, + requiresConfirmationWillBlockSlot: + confirmationPolicyTransformed?.requiresConfirmationWillBlockSlot ?? undefined, + + eventTypeColor: transformEventColorsApiToInternal(color), + ...transformSeatsApiToInternal(seats), + eventName: customName, + useEventTypeDestinationCalendarEmail: useDestinationCalendarEmail, + ...getBookingWindow(bookingWindow), }; } @@ -298,6 +378,11 @@ function isCustomField( return field.type !== "unknown" && !field.isDefault; } +function getBookingWindow(inputBookingWindow: EventTypeOutput_2024_06_14["bookingWindow"]) { + const res = transformFutureBookingLimitsApiToInternal(inputBookingWindow); + return !!res ? res : {}; +} + function isDefaultEditableField( field: EventTypeOutput_2024_06_14["bookingFields"][number] ): field is NameDefaultFieldOutput_2024_06_14 | EmailDefaultFieldOutput_2024_06_14 {