fix: {Organizer} placeholder in event title not updating on reschedule (#21034)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user