diff --git a/apps/web/components/booking/CancelBooking.tsx b/apps/web/components/booking/CancelBooking.tsx index 693cd7ba34..655a28ae91 100644 --- a/apps/web/components/booking/CancelBooking.tsx +++ b/apps/web/components/booking/CancelBooking.tsx @@ -1,6 +1,7 @@ import { useRouter } from "next/navigation"; import { useCallback, useState } from "react"; +import { sdkActionManager } from "@calcom/embed-core/embed-iframe"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import type { RecurringEvent } from "@calcom/types/Calendar"; @@ -23,13 +24,22 @@ type Props = { theme: string | null; allRemainingBookings: boolean; seatReferenceUid?: string; + bookingCancelledEventProps: { + booking: unknown; + organizer: { + name: string; + email: string; + timeZone?: string; + }; + eventType: unknown; + }; }; export default function CancelBooking(props: Props) { const [cancellationReason, setCancellationReason] = useState(""); const { t } = useLocale(); const router = useRouter(); - const { booking, allRemainingBookings, seatReferenceUid } = props; + const { booking, allRemainingBookings, seatReferenceUid, bookingCancelledEventProps } = props; const [loading, setLoading] = useState(false); const telemetry = useTelemetry(); const [error, setError] = useState(booking ? null : t("booking_already_cancelled")); @@ -97,8 +107,17 @@ export default function CancelBooking(props: Props) { method: "POST", }); + const bookingWithCancellationReason = { + ...(bookingCancelledEventProps.booking as object), + cancellationReason, + } as unknown; + if (res.status >= 200 && res.status < 300) { // tested by apps/web/playwright/booking-pages.e2e.ts + sdkActionManager?.fire("bookingCancelled", { + ...bookingCancelledEventProps, + booking: bookingWithCancellationReason, + }); router.refresh(); } else { setLoading(false); diff --git a/apps/web/modules/bookings/views/bookings-single-view.tsx b/apps/web/modules/bookings/views/bookings-single-view.tsx index dc492623d5..8a7a1c5512 100644 --- a/apps/web/modules/bookings/views/bookings-single-view.tsx +++ b/apps/web/modules/bookings/views/bookings-single-view.tsx @@ -19,7 +19,6 @@ import { getEventName } from "@calcom/core/event"; import type { ConfigType } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import { - sdkActionManager, useEmbedNonStylesConfig, useIsBackgroundTransparent, useIsEmbed, @@ -193,22 +192,6 @@ export default function Success(props: PageProps) { }, [telemetry]); */ useEffect(() => { - const users = eventType.users; - if (!sdkActionManager) return; - // TODO: We should probably make it consistent with Webhook payload. Some data is not available here, as and when requirement comes we can add - sdkActionManager.fire("bookingSuccessful", { - booking: bookingInfo, - eventType, - date: date.toString(), - duration: calculatedDuration, - organizer: { - name: users[0].name || "Nameless", - email: bookingInfo?.userPrimaryEmail || users[0].email || "Email-less", - timeZone: users[0].timeZone, - }, - confirmed: !needsConfirmation, - // TODO: Add payment details - }); setDate( date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess() || "Europe/London") ); @@ -294,6 +277,16 @@ export default function Success(props: PageProps) { const providerName = guessEventLocationType(location)?.label; const rescheduleProviderName = guessEventLocationType(rescheduleLocation)?.label; + const bookingCancelledEventProps = { + booking: bookingInfo, + organizer: { + name: bookingInfo?.user?.name || "Nameless", + email: bookingInfo?.userPrimaryEmail || bookingInfo?.user?.email || "Email-less", + timeZone: bookingInfo?.user?.timeZone, + }, + eventType, + }; + return (
{!isEmbed && ( @@ -610,6 +603,7 @@ export default function Success(props: PageProps) { theme={isSuccessBookingPage ? props.profile.theme : "light"} allRemainingBookings={allRemainingBookings} seatReferenceUid={seatReferenceUid} + bookingCancelledEventProps={bookingCancelledEventProps} /> ))} diff --git a/packages/embeds/embed-core/src/sdk-action-manager.ts b/packages/embeds/embed-core/src/sdk-action-manager.ts index 59adefe567..305685b796 100644 --- a/packages/embeds/embed-core/src/sdk-action-manager.ts +++ b/packages/embeds/embed-core/src/sdk-action-manager.ts @@ -35,6 +35,27 @@ export type EventDataMap = { }; confirmed: boolean; }; + rescheduleBookingSuccessful: { + booking: unknown; + eventType: unknown; + date: string; + duration: number | undefined; + organizer: { + name: string; + email: string; + timeZone: string; + }; + confirmed: boolean; + }; + bookingCancelled: { + booking: unknown; + organizer: { + name: string; + email: string; + timeZone?: string | undefined; + }; + eventType: unknown; + }; "*": Record; __routeChanged: Record; __windowLoadComplete: Record; diff --git a/packages/features/bookings/Booker/components/hooks/useBookings.ts b/packages/features/bookings/Booker/components/hooks/useBookings.ts index 29410e9a02..e4daf08bdb 100644 --- a/packages/features/bookings/Booker/components/hooks/useBookings.ts +++ b/packages/features/bookings/Booker/components/hooks/useBookings.ts @@ -4,6 +4,7 @@ import { useRef, useState, useEffect } from "react"; import { createPaymentLink } from "@calcom/app-store/stripepayment/lib/client"; import dayjs from "@calcom/dayjs"; +import { sdkActionManager } from "@calcom/embed-core/embed-iframe"; import { useBookerStore } from "@calcom/features/bookings/Booker/store"; import type { useEventReturnType } from "@calcom/features/bookings/Booker/utils/event"; import { updateQueryParam, getQueryParam } from "@calcom/features/bookings/Booker/utils/query-param"; @@ -18,6 +19,7 @@ import { import { getFullName } from "@calcom/features/form-builder/utils"; import { useBookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect"; import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { BookingStatus } from "@calcom/prisma/enums"; import { bookingMetadataSchema } from "@calcom/prisma/zod-utils"; import { trpc } from "@calcom/trpc"; import { showToast } from "@calcom/ui"; @@ -103,6 +105,45 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo onSuccess: (responseData) => { const { uid, paymentUid } = responseData; const fullName = getFullName(bookingForm.getValues("responses.name")); + + const users = !!event.data?.hosts?.length + ? event.data?.hosts.map((host) => host.user) + : event.data?.users; + + const validDuration = event.data?.isDynamic + ? duration || event.data?.length + : duration && event.data?.metadata?.multipleDuration?.includes(duration) + ? duration + : event.data?.length; + + if (isRescheduling) { + sdkActionManager?.fire("rescheduleBookingSuccessful", { + booking: responseData, + eventType: event.data, + date: responseData?.startTime?.toString() || "", + duration: validDuration, + organizer: { + name: users?.[0].name || "Nameless", + email: responseData?.userPrimaryEmail || responseData.user?.email || "Email-less", + timeZone: responseData.user?.timeZone || "Europe/London", + }, + confirmed: !(responseData.status === BookingStatus.PENDING && event.data?.requiresConfirmation), + }); + } else { + sdkActionManager?.fire("bookingSuccessful", { + booking: responseData, + eventType: event.data, + date: responseData?.startTime?.toString() || "", + duration: validDuration, + organizer: { + name: users?.[0].name || "Nameless", + email: responseData?.userPrimaryEmail || responseData.user?.email || "Email-less", + timeZone: responseData.user?.timeZone || "Europe/London", + }, + confirmed: !(responseData.status === BookingStatus.PENDING && event.data?.requiresConfirmation), + }); + } + if (paymentUid) { router.push( createPaymentLink({ diff --git a/packages/features/eventtypes/lib/getPublicEvent.ts b/packages/features/eventtypes/lib/getPublicEvent.ts index 4a4fbda0c2..5878b3db6d 100644 --- a/packages/features/eventtypes/lib/getPublicEvent.ts +++ b/packages/features/eventtypes/lib/getPublicEvent.ts @@ -25,6 +25,18 @@ import { } from "@calcom/prisma/zod-utils"; import type { UserProfile } from "@calcom/types/UserProfile"; +const userSelect = { + id: true, + avatarUrl: true, + username: true, + name: true, + weekStart: true, + brandColor: true, + darkBrandColor: true, + theme: true, + metadata: true, +}; + const publicEventSelect = Prisma.validator()({ id: true, title: true, @@ -78,32 +90,12 @@ const publicEventSelect = Prisma.validator()({ hosts: { select: { user: { - select: { - id: true, - avatarUrl: true, - username: true, - name: true, - weekStart: true, - brandColor: true, - darkBrandColor: true, - theme: true, - metadata: true, - }, + select: userSelect, }, }, }, owner: { - select: { - id: true, - avatarUrl: true, - weekStart: true, - username: true, - name: true, - theme: true, - metadata: true, - brandColor: true, - darkBrandColor: true, - }, + select: userSelect, }, hidden: true, assignAllTeamMembers: true,