fix: get location url from metadata (#6774)

* fix: get location url from metadata

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

* fix: replace location

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

* fix: type error

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

* fix: use zod

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

---------

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
This commit is contained in:
Udit Takkar authored and GitHub committed 2023-02-05 14:43:37 +00:00
1 parent 5cf7e32852
commit f60399ca8b
1 file changed
+25 -10
+25 -10
View File
@@ -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<typeof getEventLocationValue> = Array.isArray(props.bookingInfo.location)
? props.bookingInfo.location[0]
const location: ReturnType<typeof getEventLocationValue> = 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: {