Redirect on top iframe always - This is to make sure embed redirects on top frame (#8164)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-04-11 07:50:15 +05:30
1 parent cdab9037ce
commit e465c1d71d
7 files changed
+71 -34

No files matched your search

@@ -30,6 +30,7 @@ import getBookingResponsesSchema, {
} from "@calcom/features/bookings/lib/getBookingResponsesSchema";
import getLocationOptionsForSelect from "@calcom/features/bookings/lib/getLocationOptionsForSelect";
import { FormBuilderField } from "@calcom/features/form-builder/FormBuilder";
import { bookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect";
import classNames from "@calcom/lib/classNames";
import { APP_NAME } from "@calcom/lib/constants";
import useGetBrandingColours from "@calcom/lib/getBrandColours";
@@ -264,15 +265,19 @@ const BookingPage = ({
);
}
return router.push({
pathname: `/booking/${uid}`,
query: {
isSuccessBookingPage: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventType.slug,
seatReferenceUid: "seatReferenceUid" in responseData ? responseData.seatReferenceUid : null,
...(rescheduleUid && booking?.startTime && { formerTime: booking.startTime.toString() }),
},
const query = {
isSuccessBookingPage: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventType.slug,
seatReferenceUid: "seatReferenceUid" in responseData ? responseData.seatReferenceUid : null,
...(rescheduleUid && booking?.startTime && { formerTime: booking.startTime.toString() }),
};
return bookingSuccessRedirect({
router,
successRedirectUrl: eventType.successRedirectUrl,
query,
bookingUid: uid,
});
},
});
@@ -280,16 +285,18 @@ const BookingPage = ({
const recurringMutation = useMutation(createRecurringBooking, {
onSuccess: async (responseData = []) => {
const { uid } = responseData[0] || {};
return router.push({
pathname: `/booking/${uid}`,
query: {
isSuccessBookingPage: true,
allRemainingBookings: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventType.slug,
formerTime: booking?.startTime.toString(),
},
const query = {
isSuccessBookingPage: true,
allRemainingBookings: true,
email: bookingForm.getValues("responses.email"),
eventTypeSlug: eventType.slug,
formerTime: booking?.startTime.toString(),
};
return bookingSuccessRedirect({
router,
successRedirectUrl: eventType.successRedirectUrl,
query,
bookingUid: uid,
});
},
});
-9
View File
@@ -1013,15 +1013,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
customInputs: customInputSchema.array().parse(eventTypeRaw.customInputs),
};
if (eventType.successRedirectUrl && isSuccessBookingPage && !cancel) {
return {
redirect: {
destination: eventType.successRedirectUrl,
permanent: false,
},
};
}
const profile = {
name: eventType.team?.name || eventType.users[0]?.name || null,
email: eventType.team ? null : eventType.users[0].email || null,
+1
View File
@@ -65,6 +65,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
seatsPerTimeSlot: true,
schedulingType: true,
bookingFields: true,
successRedirectUrl: true,
workflows: {
include: {
workflow: {
@@ -2,14 +2,16 @@ import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js";
import type { StripeCardElementChangeEvent, StripeElementLocale } from "@stripe/stripe-js";
import type stripejs from "@stripe/stripe-js";
import { useRouter } from "next/router";
import { stringify } from "querystring";
import type { SyntheticEvent } from "react";
import { useEffect, useState } from "react";
import type { StripePaymentData } from "@calcom/app-store/stripepayment/lib/server";
import { bookingSuccessRedirect } from "@calcom/lib/bookingSuccessRedirect";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button } from "@calcom/ui";
import type { EventType } from ".prisma/client";
const CARD_OPTIONS: stripejs.StripeCardElementOptions = {
iconStyle: "solid" as const,
classes: {
@@ -33,7 +35,7 @@ type Props = {
payment: {
data: StripePaymentData;
};
eventType: { id: number };
eventType: { id: number; successRedirectUrl: EventType["successRedirectUrl"] };
user: { username: string | null };
location?: string | null;
bookingId: number;
@@ -96,10 +98,12 @@ export default function PaymentComponent(props: Props) {
}
}
const query = stringify(params);
const successUrl = `/booking/${props.bookingUid}?${query}`;
await router.push(successUrl);
return bookingSuccessRedirect({
router,
successRedirectUrl: props.eventType.successRedirectUrl,
query: params,
bookingUid: props.bookingUid,
});
}
};
return (
@@ -74,6 +74,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
},
price: true,
currency: true,
successRedirectUrl: true,
},
},
},
+32
View File
@@ -0,0 +1,32 @@
import type { NextRouter } from "next/router";
import type { Booking, EventType } from ".prisma/client";
export const bookingSuccessRedirect = async ({
successRedirectUrl,
bookingUid,
query,
router,
}: {
successRedirectUrl: EventType["successRedirectUrl"];
bookingUid: Booking["uid"] | undefined;
query: Record<string, string | null | undefined | boolean>;
router: NextRouter;
}) => {
if (successRedirectUrl) {
const url = new URL(successRedirectUrl);
Object.entries(query).forEach(([key, value]) => {
if (value === null || value === undefined) {
return;
}
url.searchParams.append(key, String(value));
});
// Using parent ensures, Embed iframe would redirect outside of the iframe.
window.parent.location.href = url.toString();
}
return router.push({
pathname: `/booking/${bookingUid}`,
query,
});
};
+1
View File
@@ -56,6 +56,7 @@ export const bookEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
theme: true,
},
},
successRedirectUrl: true,
});
export const availiblityPageEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({