fix: instant meeting fixes (#14214)

* fix: instant meeting fixes

* chore: improvements

* fix: platform type check

* fix: start_video_off
This commit is contained in:
Udit Takkar
2024-03-26 09:57:34 +00:00
committed by GitHub
parent 0223db1f7c
commit 452ea6a993
6 changed files with 21 additions and 8 deletions
@@ -158,6 +158,7 @@ const DailyVideoApiAdapter = (): VideoApiAdapter => {
enable_chat: true,
exp: exp,
enable_recording: "cloud",
start_video_off: true,
},
};
+3 -1
View File
@@ -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 = ({
<RedirectToInstantMeetingModal
expiryTime={expiryTime}
bookingId={parseInt(getQueryParam("bookingId") || "0")}
instantVideoMeetingUrl={instantVideoMeetingUrl}
onGoBack={() => {
onGoBackInstantMeeting();
}}
@@ -193,6 +194,7 @@ const BookerComponent = ({
);
}, [
bookerFormErrorRef,
instantVideoMeetingUrl,
bookerState,
bookingForm,
errors,
@@ -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 (
<Dialog open={!!bookingId && !!expiryTime}>
@@ -49,6 +49,7 @@ export const useBookings = ({ event, hashedLink, bookingForm, metadata }: IUseBo
const bookingSuccessRedirect = useBookingSuccessRedirect();
const bookerFormErrorRef = useRef<HTMLDivElement>(null);
const [instantMeetingTokenExpiryTime, setExpiryTime] = useState<Date | undefined>();
const [instantVideoMeetingUrl, setInstantVideoMeetingUrl] = useState<string | undefined>();
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,
};
};
@@ -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,
@@ -269,6 +269,7 @@ export const BookerPlatformWrapper = (props: BookerPlatformWrapperAtomProps) =>
creatingRecurringBooking: creatingRecBooking,
creatingInstantBooking: creatingInstantBooking,
},
instantVideoMeetingUrl: undefined,
}}
slots={slots}
calendars={{