diff --git a/packages/features/ee/workflows/lib/reminders/templates/customTemplate.ts b/packages/features/ee/workflows/lib/reminders/templates/customTemplate.ts index d925b01b59..bb36f646c5 100644 --- a/packages/features/ee/workflows/lib/reminders/templates/customTemplate.ts +++ b/packages/features/ee/workflows/lib/reminders/templates/customTemplate.ts @@ -48,14 +48,27 @@ const customTemplate = ( const currentTimeFormat = timeFormat || TimeFormat.TWELVE_HOUR; + const attendeeNameWords = variables.attendeeName?.trim().split(" "); + const attendeeNameWordCount = attendeeNameWords?.length ?? 0; + + const attendeeFirstName = variables.attendeeFirstName + ? variables.attendeeFirstName + : attendeeNameWords?.[0] ?? ""; + + const attendeeLastName = variables.attendeeLastName + ? variables.attendeeLastName + : attendeeNameWordCount > 1 + ? attendeeNameWords![attendeeNameWordCount - 1] + : ""; + let dynamicText = text .replaceAll("{EVENT_NAME}", variables.eventName || "") .replaceAll("{ORGANIZER}", variables.organizerName || "") .replaceAll("{ATTENDEE}", variables.attendeeName || "") .replaceAll("{ORGANIZER_NAME}", variables.organizerName || "") //old variable names .replaceAll("{ATTENDEE_NAME}", variables.attendeeName || "") //old variable names - .replaceAll("{ATTENDEE_FIRST_NAME}", variables.attendeeFirstName || "") - .replaceAll("{ATTENDEE_LAST_NAME}", variables.attendeeLastName || "") + .replaceAll("{ATTENDEE_FIRST_NAME}", attendeeFirstName) + .replaceAll("{ATTENDEE_LAST_NAME}", attendeeLastName) .replaceAll("{EVENT_DATE}", translatedDate) .replaceAll("{EVENT_TIME}", variables.eventDate?.format(currentTimeFormat) || "") .replaceAll("{START_TIME}", variables.eventDate?.format(currentTimeFormat) || "")