Scheduling infrastructure for absolutely everyone.
feat: add name and email url params when rescheduling past bookings (#18318)
Kartik Saini6b5e144042d1
diff --git a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts b/apps/web/lib/reschedule/[uid]/getServerSideProps.tsindex 11fc4aa184e..fe3974642fb 100644--- a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts+++ b/apps/web/lib/reschedule/[uid]/getServerSideProps.ts@@ -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,},};diff --git a/packages/lib/bookingSuccessRedirect.ts b/packages/lib/bookingSuccessRedirect.tsindex 8c630127ec9..2e90e973d7a 100644--- a/packages/lib/bookingSuccessRedirect.ts+++ b/packages/lib/bookingSuccessRedirect.ts@@ -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 };diff --git a/packages/lib/server/maybeGetBookingUidFromSeat.ts b/packages/lib/server/maybeGetBookingUidFromSeat.tsindex a6a4b8587c4..010fee20957 100644--- a/packages/lib/server/maybeGetBookingUidFromSeat.ts+++ b/packages/lib/server/maybeGetBookingUidFromSeat.ts@@ -13,8 +13,9 @@ export async function maybeGetBookingUidFromSeat(prisma: PrismaClient, uid: striuid: true,},},+ data: true,},});- if (bookingSeat) return { uid: bookingSeat.booking.uid, seatReferenceUid: uid };+ if (bookingSeat) return { uid: bookingSeat.booking.uid, seatReferenceUid: uid, bookingSeat };return { uid };}