diff --git a/lib/CalEventParser.ts b/lib/CalEventParser.ts index ded6fb12b4..92ba977c92 100644 --- a/lib/CalEventParser.ts +++ b/lib/CalEventParser.ts @@ -1,32 +1,26 @@ -import dayjs from "dayjs"; import short from "short-uuid"; import { v5 as uuidv5 } from "uuid"; import { getIntegrationName } from "@lib/integrations"; -import { CalendarEvent } from "./calendarClient"; +import { CalendarEvent, Person } from "./calendarClient"; import { BASE_URL } from "./config/constants"; const translator = short(); +// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description. + export const getWhat = (calEvent: CalendarEvent) => { return ` -${calEvent.language("what")} +${calEvent.language("what")}: ${calEvent.type} `; }; export const getWhen = (calEvent: CalendarEvent) => { - const inviteeStart = dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone); - const inviteeEnd = dayjs(calEvent.endTime).tz(calEvent.attendees[0].timeZone); - return ` -${calEvent.language("when")} -${calEvent.language(inviteeStart.format("dddd").toLowerCase())}, ${calEvent.language( - inviteeStart.format("MMMM").toLowerCase() - )} ${inviteeStart.format("D")}, ${inviteeStart.format("YYYY")} | ${inviteeStart.format( - "h:mma" - )} - ${inviteeEnd.format("h:mma")} (${calEvent.attendees[0].timeZone}) +${calEvent.language("invitee_timezone")}: +${calEvent.attendees[0].timeZone} `; }; @@ -46,14 +40,14 @@ ${calEvent.organizer.email} `; return ` -${calEvent.language("who")} +${calEvent.language("who")}: ${organizer + attendees} `; }; export const getAdditionalNotes = (calEvent: CalendarEvent) => { return ` -${calEvent.language("additional_notes")} +${calEvent.language("additional_notes")}: ${calEvent.description} `; }; @@ -92,13 +86,28 @@ export const getCancelLink = (calEvent: CalendarEvent): string => { return BASE_URL + "/cancel/" + getUid(calEvent); }; -export const getRichDescription = (calEvent: CalendarEvent) => { +export const getRichDescription = (calEvent: CalendarEvent, attendee?: Person) => { + // Only the original attendee can make changes to the event + // Guests cannot + + if (attendee && attendee === calEvent.attendees[0]) { + return ` +${getWhat(calEvent)} +${getWhen(calEvent)} +${getWho(calEvent)} +${calEvent.language("where")}: +${getLocation(calEvent)} +${getAdditionalNotes(calEvent)} + `.trim(); + } + return ` - ${getWhat(calEvent)} - ${getWhen(calEvent)} - ${getWho(calEvent)} - ${getLocation(calEvent)} - ${getAdditionalNotes(calEvent)} - ${getManageLink(calEvent)} - `; +${getWhat(calEvent)} +${getWhen(calEvent)} +${getWho(calEvent)} +${calEvent.language("where")}: +${getLocation(calEvent)} +${getAdditionalNotes(calEvent)} +${getManageLink(calEvent)} + `.trim(); }; diff --git a/lib/emails/templates/attendee-scheduled-email.ts b/lib/emails/templates/attendee-scheduled-email.ts index 0e4fea8b6d..7a656291b2 100644 --- a/lib/emails/templates/attendee-scheduled-email.ts +++ b/lib/emails/templates/attendee-scheduled-email.ts @@ -6,7 +6,7 @@ import utc from "dayjs/plugin/utc"; import { createEvent, DateArray } from "ics"; import nodemailer from "nodemailer"; -import { getCancelLink } from "@lib/CalEventParser"; +import { getCancelLink, getRichDescription } from "@lib/CalEventParser"; import { CalendarEvent, Person } from "@lib/calendarClient"; import { getErrorFromUnknown } from "@lib/errors"; import { getIntegrationName } from "@lib/integrations"; @@ -113,30 +113,12 @@ export default class AttendeeScheduledEmail { } protected getTextBody(): string { - // Only the original attendee can make changes to the event - // Guests cannot - if (this.attendee === this.calEvent.attendees[0]) { - return ` - ${this.calEvent.language("your_event_has_been_scheduled")} - ${this.calEvent.language("emailed_you_and_any_other_attendees")} - ${this.getWhat()} - ${this.getWhen()} - ${this.getWho()} - ${this.getLocation()} - ${this.getAdditionalNotes()} - ${this.calEvent.language("need_to_reschedule_or_cancel")} - ${getCancelLink(this.calEvent)} - `.replace(/(<([^>]+)>)/gi, ""); - } - return ` ${this.calEvent.language("your_event_has_been_scheduled")} ${this.calEvent.language("emailed_you_and_any_other_attendees")} -${this.getWhat()} -${this.getWhen()} -${this.getLocation()} -${this.getAdditionalNotes()} -`.replace(/(<([^>]+)>)/gi, ""); + +${getRichDescription(this.calEvent)} +`.trim(); } protected printNodeMailerError(error: Error): void { @@ -364,12 +346,12 @@ ${this.getAdditionalNotes()}

${this.calEvent.language("where")}

-

${ - hangoutLink && - `` - }

+

${providerName} ${ + hangoutLink && + `` + }

${hangoutLink}
diff --git a/lib/emails/templates/organizer-scheduled-email.ts b/lib/emails/templates/organizer-scheduled-email.ts index 3dd206352c..6b28180917 100644 --- a/lib/emails/templates/organizer-scheduled-email.ts +++ b/lib/emails/templates/organizer-scheduled-email.ts @@ -6,7 +6,7 @@ import utc from "dayjs/plugin/utc"; import { createEvent, DateArray } from "ics"; import nodemailer from "nodemailer"; -import { getCancelLink } from "@lib/CalEventParser"; +import { getCancelLink, getRichDescription } from "@lib/CalEventParser"; import { CalendarEvent, Person } from "@lib/calendarClient"; import { getErrorFromUnknown } from "@lib/errors"; import { getIntegrationName } from "@lib/integrations"; @@ -123,14 +123,9 @@ export default class OrganizerScheduledEmail { return ` ${this.calEvent.language("new_event_scheduled")} ${this.calEvent.language("emailed_you_and_any_other_attendees")} -${this.getWhat()} -${this.getWhen()} -${this.getWho()} -${this.getLocation()} -${this.getAdditionalNotes()} -${this.calEvent.language("need_to_reschedule_or_cancel")} -${getCancelLink(this.calEvent)} -`.replace(/(<([^>]+)>)/gi, ""); + +${getRichDescription(this.calEvent)} +`.trim(); } protected printNodeMailerError(error: Error): void { @@ -352,12 +347,12 @@ ${getCancelLink(this.calEvent)}

${this.calEvent.language("where")}

-

${ - hangoutLink && - `` - }

+

${providerName} ${ + hangoutLink && + `` + }

${hangoutLink}