@@ -3,6 +3,7 @@ import { cloneDeep } from "lodash";
3
3
4
4
import type EventManager from "@calcom/core/EventManager" ;
5
5
import { sendRescheduledSeatEmail } from "@calcom/emails" ;
6
+ import { getTranslation } from "@calcom/lib/server/i18n" ;
6
7
import prisma from "@calcom/prisma" ;
7
8
import type { Person , CalendarEvent } from "@calcom/types/Calendar" ;
8
9
@@ -17,11 +18,28 @@ const attendeeRescheduleSeatedBooking = async (
17
18
originalBookingEvt : CalendarEvent ,
18
19
eventManager : EventManager
19
20
) => {
20
- const { tAttendees, bookingSeat, bookerEmail, rescheduleUid , evt } = rescheduleSeatedBookingObject ;
21
+ const { tAttendees, bookingSeat, bookerEmail, evt } = rescheduleSeatedBookingObject ;
21
22
let { originalRescheduledBooking } = rescheduleSeatedBookingObject ;
22
23
23
24
seatAttendee [ "language" ] = { translate : tAttendees , locale : bookingSeat ?. attendee . locale ?? "en" } ;
24
25
26
+ // Update the original calendar event by removing the attendee that is rescheduling
27
+ if ( originalBookingEvt && originalRescheduledBooking ) {
28
+ // Event would probably be deleted so we first check than instead of updating references
29
+ const filteredAttendees = originalRescheduledBooking ?. attendees . filter ( ( attendee ) => {
30
+ return attendee . email !== bookerEmail ;
31
+ } ) ;
32
+ const deletedReference = await lastAttendeeDeleteBooking (
33
+ originalRescheduledBooking ,
34
+ filteredAttendees ,
35
+ originalBookingEvt
36
+ ) ;
37
+
38
+ if ( ! deletedReference ) {
39
+ await eventManager . updateCalendarAttendees ( originalBookingEvt , originalRescheduledBooking ) ;
40
+ }
41
+ }
42
+
25
43
// If there is no booking then remove the attendee from the old booking and create a new one
26
44
if ( ! newTimeSlotBooking ) {
27
45
await prisma . attendee . delete ( {
@@ -30,23 +48,6 @@ const attendeeRescheduleSeatedBooking = async (
30
48
} ,
31
49
} ) ;
32
50
33
- // Update the original calendar event by removing the attendee that is rescheduling
34
- if ( originalBookingEvt && originalRescheduledBooking ) {
35
- // Event would probably be deleted so we first check than instead of updating references
36
- const filteredAttendees = originalRescheduledBooking ?. attendees . filter ( ( attendee ) => {
37
- return attendee . email !== bookerEmail ;
38
- } ) ;
39
- const deletedReference = await lastAttendeeDeleteBooking (
40
- originalRescheduledBooking ,
41
- filteredAttendees ,
42
- originalBookingEvt
43
- ) ;
44
-
45
- if ( ! deletedReference ) {
46
- await eventManager . updateCalendarAttendees ( originalBookingEvt , originalRescheduledBooking ) ;
47
- }
48
- }
49
-
50
51
// We don't want to trigger rescheduling logic of the original booking
51
52
originalRescheduledBooking = null ;
52
53
@@ -76,17 +77,19 @@ const attendeeRescheduleSeatedBooking = async (
76
77
] ) ;
77
78
}
78
79
79
- const copyEvent = cloneDeep ( evt ) ;
80
-
81
- const updateManager = await eventManager . reschedule ( copyEvent , rescheduleUid , newTimeSlotBooking . id ) ;
82
-
83
- const results = updateManager . results ;
80
+ // Add the new attendees to the new time slot booking attendees
81
+ for ( const attendee of newTimeSlotBooking . attendees ) {
82
+ const language = await getTranslation ( attendee . locale ?? "en" , "common" ) ;
83
+ evt . attendees . push ( {
84
+ email : attendee . email ,
85
+ name : attendee . name ,
86
+ language,
87
+ } ) ;
88
+ }
84
89
85
- const calendarResult = results . find ( ( result ) => result . type . includes ( "_calendar" ) ) ;
90
+ const copyEvent = cloneDeep ( { ... evt , iCalUID : newTimeSlotBooking . iCalUID } ) ;
86
91
87
- evt . iCalUID = Array . isArray ( calendarResult ?. updatedEvent )
88
- ? calendarResult ?. updatedEvent [ 0 ] ?. iCalUID
89
- : calendarResult ?. updatedEvent ?. iCalUID || undefined ;
92
+ await eventManager . updateCalendarAttendees ( copyEvent , newTimeSlotBooking ) ;
90
93
91
94
await sendRescheduledSeatEmail ( copyEvent , seatAttendee as Person ) ;
92
95
const filteredAttendees = originalRescheduledBooking ?. attendees . filter ( ( attendee ) => {
0 commit comments