From f60399ca8bd1b63ad41025d77f501345b6b6e85d Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Sun, 5 Feb 2023 20:13:37 +0530 Subject: [PATCH] fix: get location url from metadata (#6774) * fix: get location url from metadata Signed-off-by: Udit Takkar * fix: replace location Signed-off-by: Udit Takkar * fix: type error Signed-off-by: Udit Takkar * fix: use zod Signed-off-by: Udit Takkar --------- Signed-off-by: Udit Takkar --- apps/web/pages/booking/[uid].tsx | 35 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/apps/web/pages/booking/[uid].tsx b/apps/web/pages/booking/[uid].tsx index 8fee2fd5df..bcea85e953 100644 --- a/apps/web/pages/booking/[uid].tsx +++ b/apps/web/pages/booking/[uid].tsx @@ -34,6 +34,7 @@ import { getIs24hClockFromLocalStorage, isBrowserLocale24h } from "@calcom/lib/t import { localStorage } from "@calcom/lib/webstorage"; import prisma from "@calcom/prisma"; import { Prisma } from "@calcom/prisma/client"; +import { bookingMetadataSchema } from "@calcom/prisma/zod-utils"; import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils"; import { Button, EmailInput, HeadSeo } from "@calcom/ui"; import { FiX, FiChevronLeft, FiCheck, FiCalendar } from "@calcom/ui/components/icon"; @@ -188,16 +189,19 @@ export default function Success(props: SuccessProps) { window.scrollTo(0, document.body.scrollHeight); } - const location: ReturnType = Array.isArray(props.bookingInfo.location) - ? props.bookingInfo.location[0] + const location: ReturnType = props.bookingInfo.location + ? props.bookingInfo.location : // If there is no location set then we default to Cal Video "integrations:daily"; + const locationVideoCallUrl: string | undefined = bookingMetadataSchema.parse( + props?.bookingInfo?.metadata || {} + )?.videoCallUrl; + if (!location) { // Can't use logger.error because it throws error on client. stdout isn't available to it. console.error(`No location found `); } - const status = props.bookingInfo?.status; const reschedule = props.bookingInfo.status === BookingStatus.ACCEPTED; const cancellationReason = props.bookingInfo.cancellationReason; @@ -281,8 +285,8 @@ export default function Success(props: SuccessProps) { function eventLink(): string { const optional: { location?: string } = {}; - if (location) { - optional["location"] = location; + if (locationVideoCallUrl) { + optional["location"] = locationVideoCallUrl; } const event = createEvent({ @@ -332,7 +336,11 @@ export default function Success(props: SuccessProps) { ); const customInputs = bookingInfo?.customInputs; - const locationToDisplay = getSuccessPageLocationMessage(location, t); + const locationToDisplay = getSuccessPageLocationMessage( + locationVideoCallUrl ? locationVideoCallUrl : location, + t, + bookingInfo.status + ); const hasSMSAttendeeAction = eventType.workflows.find((workflowEventType) => @@ -632,8 +640,8 @@ export default function Success(props: SuccessProps) { .format("YYYYMMDDTHHmmss[Z]")}&text=${eventName}&details=${ props.eventType.description }` + - (typeof location === "string" - ? "&location=" + encodeURIComponent(location) + (typeof locationVideoCallUrl === "string" + ? "&location=" + encodeURIComponent(locationVideoCallUrl) : "") + (props.eventType.recurringEvent ? "&recur=" + @@ -661,7 +669,10 @@ export default function Success(props: SuccessProps) { date.utc().format() + "&subject=" + eventName - ) + (location ? "&location=" + location : "") + ) + + (locationVideoCallUrl + ? "&location=" + encodeURIComponent(locationVideoCallUrl) + : "") } className="mx-2 h-10 w-10 rounded-sm border border-gray-200 px-3 py-2 dark:border-gray-700 dark:text-white" target="_blank"> @@ -685,7 +696,10 @@ export default function Success(props: SuccessProps) { date.utc().format() + "&subject=" + eventName - ) + (location ? "&location=" + location : "") + ) + + (locationVideoCallUrl + ? "&location=" + encodeURIComponent(locationVideoCallUrl) + : "") } className="mx-2 h-10 w-10 rounded-sm border border-gray-200 px-3 py-2 dark:border-gray-700 dark:text-white" target="_blank"> @@ -984,6 +998,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { endTime: true, location: true, status: true, + metadata: true, cancellationReason: true, user: { select: {