Scheduling infrastructure for absolutely everyone.
feat: add dry run events for SDK (dryRunBookingSuccessfulV2 and dryRunRescheduleBookingSuccessfulV2) (#23072)
Hariom Balhara0af62da16bdc
diff --git a/packages/embeds/embed-core/src/sdk-action-manager.ts b/packages/embeds/embed-core/src/sdk-action-manager.tsindex 151e58861d7..62921c18f80 100644--- a/packages/embeds/embed-core/src/sdk-action-manager.ts+++ b/packages/embeds/embed-core/src/sdk-action-manager.ts@@ -9,6 +9,21 @@ function _fireEvent(fullName: string, detail: CustomEventDetail) {window.dispatchEvent(event);}+type BaseBookingEventPayload = {+ title: string | undefined;+ startTime: string | undefined;+ endTime: string | undefined;+ eventTypeId: number | null | undefined;+ status: string | undefined;+ paymentRequired: boolean;+ isRecurring: boolean;+ /**+ * This is only used for recurring bookings+ */+ allBookings?: { startTime: string; endTime: string }[];+ videoCallUrl?: string;+};+export type EventDataMap = {eventTypeSelected: {// eslint-disable-next-line @typescript-eslint/no-explicit-any@@ -24,20 +39,8 @@ export type EventDataMap = {linkReady: Record<string, never>;__connectInitiated: Record<string, never>;__connectCompleted: Record<string, never>;- bookingSuccessfulV2: {+ bookingSuccessfulV2: BaseBookingEventPayload & {uid: string | undefined;- title: string | undefined;- startTime: string | undefined;- endTime: string | undefined;- eventTypeId: number | null | undefined;- status: string | undefined;- paymentRequired: boolean;- isRecurring: boolean;- /**- * This is only used for recurring bookings- */- allBookings?: { startTime: string; endTime: string }[];- videoCallUrl?: string;};/**@@ -56,20 +59,11 @@ export type EventDataMap = {};confirmed: boolean;};- rescheduleBookingSuccessfulV2: {+ rescheduleBookingSuccessfulV2: BaseBookingEventPayload & {uid: string | undefined;- title: string | undefined;- startTime: string | undefined;- endTime: string | undefined;- eventTypeId: number | null | undefined;- status: string | undefined;- paymentRequired: boolean;- isRecurring: boolean;- /**- * This is only used for recurring bookings- */- allBookings?: { startTime: string; endTime: string }[];};+ dryRunBookingSuccessfulV2: BaseBookingEventPayload;+ dryRunRescheduleBookingSuccessfulV2: BaseBookingEventPayload;/*** @deprecated Use `rescheduleBookingSuccessfulV2` instead. We restrict the data heavily there, only sending what is absolutely needed and keeping it light as well. Plus, more importantly that can be documented well.*/diff --git a/packages/features/bookings/Booker/components/hooks/useBookings.ts b/packages/features/bookings/Booker/components/hooks/useBookings.tsindex 6ca4358374b..a612d0f7283 100644--- a/packages/features/bookings/Booker/components/hooks/useBookings.ts+++ b/packages/features/bookings/Booker/components/hooks/useBookings.ts@@ -57,19 +57,17 @@ export interface IUseBookings {isBookingDryRun?: boolean;}-const getBookingSuccessfulEventPayload = (booking: {+const getBaseBookingEventPayload = (booking: {title?: string;startTime: string;endTime: string;eventTypeId?: number | null;status?: BookingStatus;paymentRequired: boolean;- uid?: string;isRecurring: boolean;videoCallUrl?: string;}) => {return {- uid: booking.uid,title: booking.title,startTime: booking.startTime,endTime: booking.endTime,@@ -81,7 +79,28 @@ const getBookingSuccessfulEventPayload = (booking: {};};+const getBookingSuccessfulEventPayload = (booking: {+ title?: string;+ startTime: string;+ endTime: string;+ eventTypeId?: number | null;+ status?: BookingStatus;+ paymentRequired: boolean;+ uid?: string;+ isRecurring: boolean;+ videoCallUrl?: string;+}) => {+ return {+ uid: booking.uid,+ ...getBaseBookingEventPayload(booking),+ };+};+const getRescheduleBookingSuccessfulEventPayload = getBookingSuccessfulEventPayload;++export const getDryRunBookingSuccessfulEventPayload = getBaseBookingEventPayload;++export const getDryRunRescheduleBookingSuccessfulEventPayload = getDryRunBookingSuccessfulEventPayload;export interface IUseBookingLoadingStates {creatingBooking: boolean;creatingRecurringBooking: boolean;@@ -196,6 +215,30 @@ export const useBookings = ({mutationFn: createBooking,onSuccess: (booking) => {if (booking.isDryRun) {+ const validDuration = event.data?.isDynamic+ ? duration || event.data?.length+ : duration && event.data?.metadata?.multipleDuration?.includes(duration)+ ? duration+ : event.data?.length;++ if (isRescheduling) {+ sdkActionManager?.fire(+ "dryRunRescheduleBookingSuccessfulV2",+ getDryRunRescheduleBookingSuccessfulEventPayload({+ ...booking,+ isRecurring: false,+ })+ );+ } else {+ sdkActionManager?.fire(+ "dryRunBookingSuccessfulV2",+ getDryRunBookingSuccessfulEventPayload({+ ...booking,+ isRecurring: false,+ })+ );+ }+router.push("/booking/dry-run-successful");return;}@@ -343,6 +386,30 @@ export const useBookings = ({const booking = bookings[0] || {};if (booking.isDryRun) {+ if (isRescheduling) {+ sdkActionManager?.fire("dryRunRescheduleBookingSuccessfulV2", {+ ...getDryRunRescheduleBookingSuccessfulEventPayload({+ ...booking,+ isRecurring: true,+ }),+ allBookings: bookings.map((booking) => ({+ startTime: booking.startTime,+ endTime: booking.endTime,+ })),+ });+ } else {+ sdkActionManager?.fire("dryRunBookingSuccessfulV2", {+ ...getDryRunBookingSuccessfulEventPayload({+ ...booking,+ isRecurring: true,+ }),+ allBookings: bookings.map((booking) => ({+ startTime: booking.startTime,+ endTime: booking.endTime,+ })),+ });+ }+router.push("/booking/dry-run-successful");return;}