Skip to content

Scheduling infrastructure for absolutely everyone.

fix: {Organizer} placeholder in event title not updating on reschedule (#21034)

Anik Dhabal Babufe4ae3ae628c
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts
index 53bd75e1509..0820df55c49 100644
--- a/packages/features/bookings/lib/handleNewBooking.ts
+++ b/packages/features/bookings/lib/handleNewBooking.ts
@@ -53,7 +53,7 @@ import {
} from "@calcom/lib/delegationCredential/server";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { getErrorFromUnknown } from "@calcom/lib/errors";
-import { getEventName } from "@calcom/lib/event";
+import { getEventName, updateHostInEventName } from "@calcom/lib/event";
import { extractBaseEmail } from "@calcom/lib/extract-base-email";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
@@ -1262,6 +1262,19 @@ async function handler(
!!originalRescheduledBooking.rescheduled &&
originalRescheduledBooking.status === BookingStatus.CANCELLED;
+ if (
+ changedOrganizer &&
+ originalRescheduledBooking &&
+ originalRescheduledBooking?.user?.name &&
+ organizerUser?.name
+ ) {
+ evt.title = updateHostInEventName(
+ originalRescheduledBooking.title,
+ originalRescheduledBooking.user.name,
+ organizerUser.name
+ );
+ }
+
let results: EventResult<AdditionalInformation & { url?: string; iCalUID?: string }>[] = [];
let referencesToCreate: PartialReference[] = [];
@@ -1430,7 +1443,6 @@ async function handler(
: [];
if (changedOrganizer) {
- evt.title = getEventName(eventNameObject);
// location might changed and will be new created in eventManager.create (organizer default location)
evt.videoCallData = undefined;
// To prevent "The requested identifier already exists" error while updating event, we need to remove iCalUID
diff --git a/packages/features/bookings/lib/handleNewBooking/createBooking.ts b/packages/features/bookings/lib/handleNewBooking/createBooking.ts
index 35434cd634b..a1f2897b471 100644
--- a/packages/features/bookings/lib/handleNewBooking/createBooking.ts
+++ b/packages/features/bookings/lib/handleNewBooking/createBooking.ts
@@ -57,7 +57,6 @@ function updateEventDetails(
originalRescheduledBooking: OriginalRescheduledBooking | null
) {
if (originalRescheduledBooking) {
- evt.title = originalRescheduledBooking?.title || evt.title;
evt.description = originalRescheduledBooking?.description || evt.description;
evt.location = evt.location || originalRescheduledBooking?.location;
}
diff --git a/packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts b/packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
index c3bb7489b07..a3611c0c913 100644
--- a/packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
+++ b/packages/features/bookings/lib/handleNewBooking/test/reschedule.test.ts
@@ -2034,6 +2034,8 @@ describe("handleNewBooking", () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const uidOfBookingToBeRescheduled = "n5Wv3eHgconAED2j4gcVhP";
+ const dynamicEventName = "{Scheduler} and {Organiser}: Team Meeting";
+
await createBookingScenario(
getScenarioData({
eventTypes: [
@@ -2041,6 +2043,7 @@ describe("handleNewBooking", () => {
id: 1,
slotInterval: 15,
length: 15,
+ eventName: dynamicEventName,
users: [
{
id: 101,
@@ -2131,6 +2134,8 @@ describe("handleNewBooking", () => {
expect(createdBooking.startTime?.toISOString()).toBe(`${plus1DateString}T04:00:00.000Z`);
expect(createdBooking.endTime?.toISOString()).toBe(`${plus1DateString}T04:15:00.000Z`);
+ expect(createdBooking.title).toBe(`${booker.name} and ${roundRobinHost1.name}: Team Meeting`);
+
await expectBookingInDBToBeRescheduledFromTo({
from: {
uid: uidOfBookingToBeRescheduled,
diff --git a/packages/lib/event.ts b/packages/lib/event.ts
index d06af4d894e..3dbb89192d7 100644
--- a/packages/lib/event.ts
+++ b/packages/lib/event.ts
@@ -110,6 +110,23 @@ export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView
return dynamicEventName;
}
+export function updateHostInEventName(eventName: string, oldHost: string, newHost: string) {
+ const oldHostFirstName = oldHost.split(" ")[0];
+ const newHostFirstName = newHost.split(" ")[0];
+
+ if (!eventName.includes(oldHost) && !eventName.includes(oldHostFirstName)) {
+ return eventName;
+ }
+
+ let updatedEventName = eventName;
+
+ updatedEventName = updatedEventName.replace(oldHost, newHost);
+
+ updatedEventName = updatedEventName.replace(oldHostFirstName, newHostFirstName);
+
+ return updatedEventName;
+}
+
export const validateCustomEventName = (value: string, bookingFields?: Prisma.JsonObject | null) => {
let customInputVariables: string[] = [];
if (bookingFields) {