From 889ff177c1bea3d25e74aa5f8cc5ba4ee2603245 Mon Sep 17 00:00:00 2001 From: Amit Sharma <74371312+Amit91848@users.noreply.github.com> Date: Tue, 28 May 2024 20:02:12 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20{first=20name}=20variable=20to=20?= =?UTF-8?q?Organizer=20&=20Scheduler=20custom=20event=E2=80=A6=20(#14156)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add {first name} variable to Organizer & Scheduler custom event name * fix: use split name booking field * remove unwanted translation changes * Update packages/core/event.ts Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> * chore: improve code * add scheduler last name --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Udit Takkar --- .../eventtype/CustomEventTypeModal.tsx | 23 +++++++++++++++++-- .../components/eventtype/EventAdvancedTab.tsx | 4 ++++ apps/web/public/static/locales/en/common.json | 3 +++ packages/core/event.ts | 15 ++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/apps/web/components/eventtype/CustomEventTypeModal.tsx b/apps/web/components/eventtype/CustomEventTypeModal.tsx index 7cda6b7556..5a6ab8c5c4 100644 --- a/apps/web/components/eventtype/CustomEventTypeModal.tsx +++ b/apps/web/components/eventtype/CustomEventTypeModal.tsx @@ -19,11 +19,12 @@ interface CustomEventTypeModalFormProps { setValue: (value: string) => void; event: EventNameObjectType; defaultValue: string; + isNameFieldSplit: boolean; } const CustomEventTypeModalForm: FC = (props) => { const { t } = useLocale(); - const { placeHolder, close, setValue, event } = props; + const { placeHolder, close, setValue, event, isNameFieldSplit } = props; const { register, handleSubmit, watch, getValues } = useFormContext(); const onSubmit: SubmitHandler = (data) => { setValue(data.customEventName); @@ -68,10 +69,26 @@ const CustomEventTypeModalForm: FC = (props) => {

{`{Organiser}`}

{t("your_full_name")}

+
+

{`{Organiser first name}`}

+

{t("organizer_first_name")}

+

{`{Scheduler}`}

{t("scheduler_full_name")}

+ {isNameFieldSplit && ( +
+

{`{Scheduler first name}`}

+

{t("scheduler_first_name")}

+
+ )} + {isNameFieldSplit && ( +
+

{`{Scheduler last name}`}

+

{t("scheduler_last_name")}

+
+ )}

{`{Location}`}

{t("location_info")}

@@ -101,12 +118,13 @@ interface CustomEventTypeModalProps { close: () => void; setValue: (value: string) => void; event: EventNameObjectType; + isNameFieldSplit: boolean; } const CustomEventTypeModal: FC = (props) => { const { t } = useLocale(); - const { defaultValue, placeHolder, close, setValue, event } = props; + const { defaultValue, placeHolder, close, setValue, event, isNameFieldSplit } = props; const methods = useForm({ defaultValues: { @@ -128,6 +146,7 @@ const CustomEventTypeModal: FC = (props) => { setValue={setValue} placeHolder={placeHolder} defaultValue={defaultValue} + isNameFieldSplit={isNameFieldSplit} /> diff --git a/apps/web/components/eventtype/EventAdvancedTab.tsx b/apps/web/components/eventtype/EventAdvancedTab.tsx index 43ede47100..4f0a777aa8 100644 --- a/apps/web/components/eventtype/EventAdvancedTab.tsx +++ b/apps/web/components/eventtype/EventAdvancedTab.tsx @@ -65,6 +65,9 @@ export const EventAdvancedTab = ({ eventType, team }: Pick field.name === "name"); + const isSplit = (nameBookingField && nameBookingField.variant === "firstAndLastName") ?? false; + const eventNameObject: EventNameObjectType = { attendeeName: t("scheduler"), eventType: formMethods.getValues("title"), @@ -564,6 +567,7 @@ export const EventAdvancedTab = ({ eventType, team }: Pick formMethods.setValue("eventName", val, { shouldDirty: true })} defaultValue={formMethods.getValues("eventName")} placeHolder={eventNamePlaceholder} + isNameFieldSplit={isSplit} event={eventNameObject} /> )} diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 69d05a0a92..cfc8f25591 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -2385,6 +2385,9 @@ "add_email": "Add Email", "add_email_description": "Add an email address to replace your primary or to use as an alternative email on your event types.", "confirm_email": "Confirm your email", + "scheduler_first_name": "The first name of the person booking", + "scheduler_last_name": "The last name of the person booking", + "organizer_first_name": "Your first name", "confirm_email_description": "We sent an email to {{email}}. Click the link in the email to verify this address.", "send_event_details_to": "Send event details to", "schedule_tz_without_end_date": "Schedule timezone without end date", diff --git a/packages/core/event.ts b/packages/core/event.ts index 512efb92e9..0b39a1752a 100644 --- a/packages/core/event.ts +++ b/packages/core/event.ts @@ -57,11 +57,23 @@ export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView .replaceAll("{Event type title}", eventNameObj.eventType) .replaceAll("{Scheduler}", attendeeName) .replaceAll("{Organiser}", eventNameObj.host) + .replaceAll("{Organiser first name}", eventNameObj.host.split(" ")[0]) .replaceAll("{USER}", attendeeName) .replaceAll("{ATTENDEE}", attendeeName) .replaceAll("{HOST}", eventNameObj.host) .replaceAll("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : attendeeName); + 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()); + } + const customInputvariables = dynamicEventName.match(/\{(.+?)}/g)?.map((variable) => { return variable.replace("{", "").replace("}", ""); }); @@ -105,6 +117,9 @@ export const validateCustomEventName = ( "{Organiser}", "{Scheduler}", "{Location}", + "{Organiser first name}", + "{Scheduler first name}", + "{Scheduler last name}", //allowed for fallback reasons "{LOCATION}", "{HOST/ATTENDEE}",