From 452ea6a993bd241419094e990ad8801ef6e9d08e Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:27:34 +0530 Subject: [PATCH] fix: instant meeting fixes (#14214) * fix: instant meeting fixes * chore: improvements * fix: platform type check * fix: start_video_off --- .../app-store/dailyvideo/lib/VideoApiAdapter.ts | 1 + packages/features/bookings/Booker/Booker.tsx | 4 +++- .../components/RedirectToInstantMeetingModal.tsx | 15 +++++++++++++-- .../Booker/components/hooks/useBookings.ts | 6 +++--- .../instant-meeting/handleInstantMeeting.ts | 2 -- .../atoms/booker/BookerPlatformWrapper.tsx | 1 + 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts b/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts index 3c2aa548ac..97c36059e7 100644 --- a/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts +++ b/packages/app-store/dailyvideo/lib/VideoApiAdapter.ts @@ -158,6 +158,7 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => { enable_chat: true, exp: exp, enable_recording: "cloud", + start_video_off: true, }, }; diff --git a/packages/features/bookings/Booker/Booker.tsx b/packages/features/bookings/Booker/Booker.tsx index 36eff86255..d87ba27de1 100644 --- a/packages/features/bookings/Booker/Booker.tsx +++ b/packages/features/bookings/Booker/Booker.tsx @@ -116,7 +116,7 @@ const BookerComponent = ({ const { bookerFormErrorRef, key, formEmail, bookingForm, errors: formErrors } = bookerForm; - const { handleBookEvent, errors, loadingStates, expiryTime } = bookings; + const { handleBookEvent, errors, loadingStates, expiryTime, instantVideoMeetingUrl } = bookings; const { isEmailVerificationModalVisible, @@ -181,6 +181,7 @@ const BookerComponent = ({ { onGoBackInstantMeeting(); }} @@ -193,6 +194,7 @@ const BookerComponent = ({ ); }, [ bookerFormErrorRef, + instantVideoMeetingUrl, bookerState, bookingForm, errors, diff --git a/packages/features/bookings/Booker/components/RedirectToInstantMeetingModal.tsx b/packages/features/bookings/Booker/components/RedirectToInstantMeetingModal.tsx index 44fc386f91..6311a039b5 100644 --- a/packages/features/bookings/Booker/components/RedirectToInstantMeetingModal.tsx +++ b/packages/features/bookings/Booker/components/RedirectToInstantMeetingModal.tsx @@ -1,3 +1,4 @@ +import { useRouter } from "next/navigation"; import { useState, useEffect } from "react"; import dayjs from "@calcom/dayjs"; @@ -15,14 +16,17 @@ export const RedirectToInstantMeetingModal = ({ bookingId, onGoBack, expiryTime, + instantVideoMeetingUrl, }: { bookingId: number; onGoBack: () => void; expiryTime?: Date; + instantVideoMeetingUrl?: string; }) => { const { t } = useLocale(); const [timeRemaining, setTimeRemaining] = useState(calculateTimeRemaining()); const [hasInstantMeetingTokenExpired, setHasInstantMeetingTokenExpired] = useState(false); + const router = useRouter(); function calculateTimeRemaining() { const now = dayjs(); @@ -53,7 +57,7 @@ export const RedirectToInstantMeetingModal = ({ }; useEffect(() => { - if (!expiryTime || hasInstantMeetingTokenExpired) { + if (!expiryTime || hasInstantMeetingTokenExpired || !!instantVideoMeetingUrl) { window.removeEventListener("beforeunload", handleBeforeUnload); return; } @@ -62,7 +66,14 @@ export const RedirectToInstantMeetingModal = ({ return () => { window.removeEventListener("beforeunload", handleBeforeUnload); }; - }, [expiryTime, hasInstantMeetingTokenExpired]); + }, [expiryTime, hasInstantMeetingTokenExpired, instantVideoMeetingUrl]); + + useEffect(() => { + if (!!instantVideoMeetingUrl) { + window.removeEventListener("beforeunload", handleBeforeUnload); + router.push(instantVideoMeetingUrl); + } + }, [instantVideoMeetingUrl]); return ( diff --git a/packages/features/bookings/Booker/components/hooks/useBookings.ts b/packages/features/bookings/Booker/components/hooks/useBookings.ts index 2e24ce3e2c..fd28433348 100644 --- a/packages/features/bookings/Booker/components/hooks/useBookings.ts +++ b/packages/features/bookings/Booker/components/hooks/useBookings.ts @@ -49,6 +49,7 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo const bookingSuccessRedirect = useBookingSuccessRedirect(); const bookerFormErrorRef = useRef(null); const [instantMeetingTokenExpiryTime, setExpiryTime] = useState(); + const [instantVideoMeetingUrl, setInstantVideoMeetingUrl] = useState(); const duration = useBookerStore((state) => state.selectedDuration); const isRescheduling = !!rescheduleUid && !!bookingData; @@ -71,14 +72,12 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo if (!data) return; try { - showToast(t("something_went_wrong_on_our_end"), "error"); - const locationVideoCallUrl: string | undefined = bookingMetadataSchema.parse( data.booking?.metadata || {} )?.videoCallUrl; if (locationVideoCallUrl) { - router.push(locationVideoCallUrl); + setInstantVideoMeetingUrl(locationVideoCallUrl); } else { showToast(t("something_went_wrong_on_our_end"), "error"); } @@ -254,5 +253,6 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo bookerFormErrorRef, errors, loadingStates, + instantVideoMeetingUrl, }; }; diff --git a/packages/features/instant-meeting/handleInstantMeeting.ts b/packages/features/instant-meeting/handleInstantMeeting.ts index 8e0d78f08c..c148422c2b 100644 --- a/packages/features/instant-meeting/handleInstantMeeting.ts +++ b/packages/features/instant-meeting/handleInstantMeeting.ts @@ -132,7 +132,6 @@ async function handler(req: NextApiRequest) { throw new Error("Cal Video Meeting Creation Failed"); } - eventType.team.id; const bookingReferenceToCreate = [ { type: calVideoMeeting.type, @@ -201,7 +200,6 @@ async function handler(req: NextApiRequest) { }); // Trigger Webhook - const webhookData = { triggerEvent: WebhookTriggerEvents.INSTANT_MEETING, uid: newBooking.uid, diff --git a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx index d3299715f7..5244020632 100644 --- a/packages/platform/atoms/booker/BookerPlatformWrapper.tsx +++ b/packages/platform/atoms/booker/BookerPlatformWrapper.tsx @@ -269,6 +269,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) => creatingRecurringBooking: creatingRecBooking, creatingInstantBooking: creatingInstantBooking, }, + instantVideoMeetingUrl: undefined, }} slots={slots} calendars={{