feat: add name and email url params when rescheduling past bookings (#18318)

* feat: add name and email as url params when rescheduling past bookings

* remove logs

* pass booking seat name and email as url params
This commit is contained in:
Kartik Saini
2024-12-26 19:23:28 +00:00
committed by GitHub
parent cd7b93a51e
commit 6b5e144042
3 changed files with 26 additions and 13 deletions
@@ -4,6 +4,7 @@ import { URLSearchParams } from "url";
import { z } from "zod";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getSafe } from "@calcom/lib/bookingSuccessRedirect";
import { buildEventUrlFromBooking } from "@calcom/lib/bookings/buildEventUrlFromBooking";
import { getDefaultEvent } from "@calcom/lib/defaultEvents";
import { maybeGetBookingUidFromSeat } from "@calcom/lib/server/maybeGetBookingUidFromSeat";
@@ -35,10 +36,11 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
} = querySchema.parse(context.query);
const coepFlag = context.query["flag.coep"];
const { uid, seatReferenceUid: maybeSeatReferenceUid } = await maybeGetBookingUidFromSeat(
prisma,
bookingUid
);
const {
uid,
seatReferenceUid: maybeSeatReferenceUid,
bookingSeat,
} = await maybeGetBookingUidFromSeat(prisma, bookingUid);
const booking = await prisma.booking.findUnique({
where: {
@@ -46,6 +48,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
},
select: {
...bookingMinimalSelect,
responses: true,
eventType: {
select: {
users: {
@@ -129,9 +132,18 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
const isBookingInPast = booking.endTime && new Date(booking.endTime) < new Date();
if (isBookingInPast) {
const destinationUrlSearchParams = new URLSearchParams();
const responses = bookingSeat ? getSafe<string>(bookingSeat.data, ["responses"]) : booking.responses;
const name = getSafe<string>(responses, ["name"]);
const email = getSafe<string>(responses, ["email"]);
if (name) destinationUrlSearchParams.set("name", name);
if (email) destinationUrlSearchParams.set("email", email);
const searchParamsString = destinationUrlSearchParams.toString();
return {
redirect: {
destination: eventUrl,
destination: searchParamsString ? `${eventUrl}?${searchParamsString}` : eventUrl,
permanent: false,
},
};
+7 -7
View File
@@ -43,6 +43,13 @@ type ResultType = {
attendeeLastName?: string | null;
};
export function getSafe<T>(obj: unknown, path: (string | number)[]): T | undefined {
return path.reduce(
(acc, key) => (typeof acc === "object" && acc !== null ? (acc as any)[key] : undefined),
obj
) as T | undefined;
}
export const getBookingRedirectExtraParams = (booking: SuccessRedirectBookingType) => {
const redirectQueryParamKeys: BookingResponseKey[] = [
"title",
@@ -55,13 +62,6 @@ export const getBookingRedirectExtraParams = (booking: SuccessRedirectBookingTyp
"responses",
];
function getSafe<T>(obj: unknown, path: (string | number)[]): T | undefined {
return path.reduce(
(acc, key) => (typeof acc === "object" && acc !== null ? (acc as any)[key] : undefined),
obj
) as T | undefined;
}
// Helper function to extract response details (e.g., phone, attendee's first and last name)
function extractResponseDetails(booking: SuccessRedirectBookingType, obj: ResultType): ResultType {
const result: ResultType = { ...obj };
@@ -13,8 +13,9 @@ export async function maybeGetBookingUidFromSeat(prisma: PrismaClient, uid: stri
uid: true,
},
},
data: true,
},
});
if (bookingSeat) return { uid: bookingSeat.booking.uid, seatReferenceUid: uid };
if (bookingSeat) return { uid: bookingSeat.booking.uid, seatReferenceUid: uid, bookingSeat };
return { uid };
}