diff --git a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts b/apps/web/lib/reschedule/[uid]/getServerSideProps.ts index fe3974642fb30c..6dcee9ab629e81 100644 --- a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts +++ b/apps/web/lib/reschedule/[uid]/getServerSideProps.ts @@ -95,6 +95,18 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { } as const; } + const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef); + + const enrichedBookingUser = booking.user + ? await UserRepository.enrichUserWithItsProfile({ user: booking.user }) + : null; + + const eventUrl = await buildEventUrlFromBooking({ + eventType, + dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null, + profileEnrichedBookingUser: enrichedBookingUser, + }); + // If booking is already CANCELLED or REJECTED, we can't reschedule this booking. Take the user to the booking page which would show it's correct status and other details. // A booking that has been rescheduled to a new booking will also have a status of CANCELLED if ( @@ -103,7 +115,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { ) { return { redirect: { - destination: `/booking/${uid}`, + destination: booking.status === BookingStatus.CANCELLED ? `${eventUrl}` : `/booking/${uid}`, permanent: false, }, }; @@ -118,18 +130,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { }; } - const eventType = booking.eventType ? booking.eventType : getDefaultEvent(dynamicEventSlugRef); - - const enrichedBookingUser = booking.user - ? await UserRepository.enrichUserWithItsProfile({ user: booking.user }) - : null; - - const eventUrl = await buildEventUrlFromBooking({ - eventType, - dynamicGroupSlugRef: booking.dynamicGroupSlugRef ?? null, - profileEnrichedBookingUser: enrichedBookingUser, - }); - const isBookingInPast = booking.endTime && new Date(booking.endTime) < new Date(); if (isBookingInPast) { const destinationUrlSearchParams = new URLSearchParams(); @@ -180,6 +180,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { destinationUrlSearchParams.set("rescheduleUid", seatReferenceUid || bookingUid); + if (allowRescheduleForCancelledBooking) { + destinationUrlSearchParams.set("allowRescheduleForCancelledBooking", "true"); + } + // TODO: I think we should just forward all the query params here including coep flag if (coepFlag) { destinationUrlSearchParams.set("flag.coep", coepFlag as string); diff --git a/apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx b/apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx index fd0fa3ab48ac9d..dcb75b30c0364a 100644 --- a/apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx +++ b/apps/web/lib/team/[slug]/[type]/getServerSideProps.tsx @@ -29,6 +29,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => const session = await getServerSession({ req }); const { slug: teamSlug, type: meetingSlug } = paramsSchema.parse(params); const { rescheduleUid, isInstantMeeting: queryIsInstantMeeting, email } = query; + const allowRescheduleForCancelledBooking = query.allowRescheduleForCancelledBooking === "true"; const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(req, params?.orgSlug); const isOrgContext = currentOrgDomain && isValidOrgDomain; @@ -162,7 +163,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => let booking: GetBookingType | null = null; if (rescheduleUid) { booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id); - if (booking?.status === BookingStatus.CANCELLED) { + if (booking?.status === BookingStatus.CANCELLED && !allowRescheduleForCancelledBooking) { return { redirect: { permanent: false, diff --git a/apps/web/server/lib/[user]/[type]/getServerSideProps.ts b/apps/web/server/lib/[user]/[type]/getServerSideProps.ts index 04e295dc1d2d81..a2c184b086883b 100644 --- a/apps/web/server/lib/[user]/[type]/getServerSideProps.ts +++ b/apps/web/server/lib/[user]/[type]/getServerSideProps.ts @@ -51,10 +51,12 @@ async function processReschedule({ props, rescheduleUid, session, + allowRescheduleForCancelledBooking, }: { props: Props; session: Session | null; rescheduleUid: string | string[] | undefined; + allowRescheduleForCancelledBooking?: boolean; }) { if (!rescheduleUid) return; const booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id); @@ -62,7 +64,8 @@ async function processReschedule({ if ( booking === null || !booking.eventTypeId || - (booking?.eventTypeId === props.eventData?.id && booking.status !== BookingStatus.CANCELLED) + (booking?.eventTypeId === props.eventData?.id && + (booking.status !== BookingStatus.CANCELLED || allowRescheduleForCancelledBooking)) ) { props.booking = booking; props.rescheduleUid = Array.isArray(rescheduleUid) ? rescheduleUid[0] : rescheduleUid; @@ -93,13 +96,15 @@ async function processReschedule({ async function processSeatedEvent({ props, bookingUid, + allowRescheduleForCancelledBooking, }: { props: Props; bookingUid: string | string[] | undefined; + allowRescheduleForCancelledBooking?: boolean; }) { if (!bookingUid) return; const booking = await getBookingForSeatedEvent(`${bookingUid}`); - if (booking?.status === BookingStatus.CANCELLED) { + if (booking?.status === BookingStatus.CANCELLED && !allowRescheduleForCancelledBooking) { return { redirect: { permanent: false, @@ -116,7 +121,7 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) { const session = await getServerSession(context); const { user: usernames, type: slug } = paramsSchema.parse(context.params); const { rescheduleUid, bookingUid } = context.query; - + const allowRescheduleForCancelledBooking = context.query.allowRescheduleForCancelledBooking === "true"; const { ssrInit } = await import("@server/lib/ssr"); const ssr = await ssrInit(context); const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug); @@ -192,12 +197,21 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) { }; if (rescheduleUid) { - const processRescheduleResult = await processReschedule({ props, rescheduleUid, session }); + const processRescheduleResult = await processReschedule({ + props, + rescheduleUid, + session, + allowRescheduleForCancelledBooking, + }); if (processRescheduleResult) { return processRescheduleResult; } } else if (bookingUid) { - const processSeatResult = await processSeatedEvent({ props, bookingUid }); + const processSeatResult = await processSeatedEvent({ + props, + bookingUid, + allowRescheduleForCancelledBooking, + }); if (processSeatResult) { return processSeatResult; } @@ -213,6 +227,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) { const { user: usernames, type: slug } = paramsSchema.parse(context.params); const username = usernames[0]; const { rescheduleUid, bookingUid } = context.query; + const allowRescheduleForCancelledBooking = context.query.allowRescheduleForCancelledBooking === "true"; const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug); const isOrgContext = currentOrgDomain && isValidOrgDomain; @@ -289,14 +304,22 @@ async function getUserPageProps(context: GetServerSidePropsContext) { rescheduleUid: null, orgBannerUrl: eventData?.owner?.profile?.organization?.bannerUrl ?? null, }; - if (rescheduleUid) { - const processRescheduleResult = await processReschedule({ props, rescheduleUid, session }); + const processRescheduleResult = await processReschedule({ + props, + rescheduleUid, + session, + allowRescheduleForCancelledBooking, + }); if (processRescheduleResult) { return processRescheduleResult; } } else if (bookingUid) { - const processSeatResult = await processSeatedEvent({ props, bookingUid }); + const processSeatResult = await processSeatedEvent({ + props, + bookingUid, + allowRescheduleForCancelledBooking, + }); if (processSeatResult) { return processSeatResult; }