From e82bd45b558becfe32e2868b24fd0423acdb6628 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Wed, 11 Jun 2025 16:51:21 +0530 Subject: [PATCH] fix: Incorrect RR host is shown in the email and calendar event for a seated RR event (#21684) * fix: seated rr event * Update packages/features/bookings/lib/handleNewBooking.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * update * Update handleNewBooking.ts --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- .../features/bookings/lib/handleNewBooking.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 7003f1a290..eab92f03cc 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -650,9 +650,31 @@ async function handler( startTime: new Date(dayjs(reqBody.start).utc().format()), status: BookingStatus.ACCEPTED, }, + select: { + userId: true, + attendees: { select: { email: true } }, + }, }); - if (booking) isFirstSeat = false; + if (booking) { + isFirstSeat = false; + if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) { + const fixedHosts = users.filter((user) => user.isFixed); + const originalNonFixedHost = users.find((user) => !user.isFixed && user.id === booking.userId); + + if (originalNonFixedHost) { + users = [...fixedHosts, originalNonFixedHost]; + } else { + const attendeeEmailSet = new Set(booking.attendees.map((attendee) => attendee.email)); + + // In this case, the first booking user is a fixed host, so the chosen non-fixed host is added as an attendee of the booking + const nonFixedAttendeeHost = users.find( + (user) => !user.isFixed && attendeeEmailSet.has(user.email) + ); + users = [...fixedHosts, ...(nonFixedAttendeeHost ? [nonFixedAttendeeHost] : [])]; + } + } + } } //checks what users are available