From 7517feb62a535bac174d23cca4204bc715afc5fc Mon Sep 17 00:00:00 2001 From: alannnc Date: Sat, 5 Nov 2022 11:47:29 -0700 Subject: [PATCH] fix/success-page-seats-description-5338 (#5390) * Add validations for server side loading of bookingInfo for seats event types * Fix prop used for validating if booking has seats enabled * Fix types * Removed frontend filter for seatsShowAttendees as not needed anymore Co-authored-by: Alex van Andel --- apps/web/pages/success.tsx | 49 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/apps/web/pages/success.tsx b/apps/web/pages/success.tsx index 9a0bf0f740..5fb9fa8172 100644 --- a/apps/web/pages/success.tsx +++ b/apps/web/pages/success.tsx @@ -369,23 +369,12 @@ export default function Success(props: SuccessProps) {

{bookingInfo.user.email}

)} - {!eventType.seatsShowAttendees - ? bookingInfo?.attendees - .filter((attendee) => attendee.email === email) - .map((attendee) => ( -
-

{attendee.name}

-

{attendee.email}

-
- )) - : bookingInfo?.attendees.map((attendee, index) => ( -
-

{attendee.name}

-

{attendee.email}

-
- ))} + {bookingInfo?.attendees.map((attendee, index) => ( +
+

{attendee.name}

+

{attendee.email}

+
+ ))} @@ -786,6 +775,28 @@ const schema = z.object({ bookingId: strToNumber, }); +const handleSeatsEventTypeOnBooking = ( + eventType: { + seatsPerTimeSlot?: boolean | null; + seatsShowAttendees: boolean | null; + [x: string | number | symbol]: unknown; + }, + booking: Partial< + Prisma.BookingGetPayload<{ include: { attendees: { select: { name: true; email: true } } } }> + >, + email: string +) => { + if (eventType?.seatsPerTimeSlot !== null) { + // @TODO: right now bookings with seats doesn't save every description that its entered by every user + delete booking.description; + } + if (!eventType.seatsShowAttendees) { + const attendee = booking?.attendees?.find((a) => a.email === email); + booking["attendees"] = attendee ? [attendee] : []; + } + return; +}; + export async function getServerSideProps(context: GetServerSidePropsContext) { const ssr = await ssrInit(context); const parsedQuery = schema.safeParse(context.query); @@ -884,6 +895,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { }, }, }); + if (bookingInfo !== null && email) { + handleSeatsEventTypeOnBooking(eventType, bookingInfo, email); + } + let recurringBookings = null; if (recurringEventIdQuery) { // We need to get the dates for the bookings to be able to show them in the UI