From 377cae9fd8dcf312c14e0b44aee1816a934671d4 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Sat, 26 Oct 2024 00:19:13 +0530 Subject: [PATCH] chore: Add scheduler first name to event title (#17309) * chore: Add scheduler first name to event title * Update event.ts * add test * minor --- packages/core/event.test.ts | 34 +++++++++---------- packages/core/event.ts | 10 +++--- .../tabs/advanced/CustomEventTypeModal.tsx | 12 +++---- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/packages/core/event.test.ts b/packages/core/event.test.ts index 02c8a9cb0f..6d1168a5af 100644 --- a/packages/core/event.test.ts +++ b/packages/core/event.test.ts @@ -72,7 +72,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("example event name"); }); @@ -88,7 +87,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("event type: example event type"); }); @@ -104,7 +102,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("scheduler: example attendee"); }); @@ -120,7 +117,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("organiser: example host"); }); @@ -136,7 +132,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("user: example attendee"); }); @@ -152,7 +147,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("attendee: example attendee"); }); @@ -168,7 +162,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("host: example host"); }); @@ -184,7 +177,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("host or attendee: example attendee"); }); @@ -203,7 +195,6 @@ describe("event tests", () => { true ); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("host or attendee: example host"); }); @@ -221,7 +212,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("custom field: example custom field"); }); @@ -242,7 +232,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("custom field: example custom field"); }); @@ -263,7 +252,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("custom field: 808"); }); @@ -284,7 +272,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("custom field: "); }); @@ -301,7 +288,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("location: in_person_attendee_address"); }); @@ -318,7 +304,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("location: in_person_attendee_address"); }); @@ -334,7 +319,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("location: "); }); @@ -351,7 +335,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("location: "); }); @@ -368,7 +351,6 @@ describe("event tests", () => { t: tFunc as TFunction, }); - expect(tFunc).not.toHaveBeenCalled(); expect(result).toBe("location: unknownNonsense"); }); }); @@ -387,6 +369,22 @@ describe("event tests", () => { expect(result).toBe("event duration: 15 mins"); }); + it("should support templating of Scheduler first name", () => { + const tFunc = vi.fn(() => "foo"); + + const result = event.getEventName({ + attendeeName: "example attendee", + eventType: "example event type", + host: "example host", + location: "attendeeInPerson", + eventName: "Scheduler first name: {Scheduler first name}", + eventDuration: 15, + t: tFunc as TFunction, + }); + + expect(result).toBe("Scheduler first name: example"); + }); + describe("fn: validateCustomEventName", () => { it("should be valid when no variables used", () => { expect(event.validateCustomEventName("foo")).toBe(true); diff --git a/packages/core/event.ts b/packages/core/event.ts index 6dc9653c5a..aea32029cc 100644 --- a/packages/core/event.ts +++ b/packages/core/event.ts @@ -63,15 +63,15 @@ export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView .replaceAll("{ATTENDEE}", attendeeName) .replaceAll("{HOST}", eventNameObj.host) .replaceAll("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : attendeeName) - .replaceAll("{Event duration}", `${String(eventNameObj.eventDuration)} mins`); + .replaceAll("{Event duration}", `${String(eventNameObj.eventDuration)} mins`) + .replaceAll( + "{Scheduler first name}", + attendeeName === eventNameObj.t("scheduler") ? "{Scheduler first name}" : attendeeName.split(" ")[0] + ); const { bookingFields } = eventNameObj || {}; const { name } = bookingFields || {}; - if (name && typeof name === "object" && !Array.isArray(name) && typeof name.firstName === "string") { - dynamicEventName = dynamicEventName.replaceAll("{Scheduler first name}", name.firstName.toString()); - } - if (name && typeof name === "object" && !Array.isArray(name) && typeof name.lastName === "string") { dynamicEventName = dynamicEventName.replaceAll("{Scheduler last name}", name.lastName.toString()); } diff --git a/packages/features/eventtypes/components/tabs/advanced/CustomEventTypeModal.tsx b/packages/features/eventtypes/components/tabs/advanced/CustomEventTypeModal.tsx index 94cbc33836..05efd11671 100644 --- a/packages/features/eventtypes/components/tabs/advanced/CustomEventTypeModal.tsx +++ b/packages/features/eventtypes/components/tabs/advanced/CustomEventTypeModal.tsx @@ -86,12 +86,12 @@ const CustomEventTypeModalForm: FC = (props) => {

{`{Scheduler}`}

{t("scheduler_full_name")}

- {isNameFieldSplit && ( -
-

{`{Scheduler first name}`}

-

{t("scheduler_first_name")}

-
- )} + +
+

{`{Scheduler first name}`}

+

{t("scheduler_first_name")}

+
+ {isNameFieldSplit && (

{`{Scheduler last name}`}