fix: calendar event description (#1266)

This commit is contained in:
Mihai C 2021-12-07 17:32:07 +02:00 committed by GitHub
parent c43e6783a7
commit d76ef4a007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 65 deletions

View file

@ -1,32 +1,26 @@
import dayjs from "dayjs";
import short from "short-uuid"; import short from "short-uuid";
import { v5 as uuidv5 } from "uuid"; import { v5 as uuidv5 } from "uuid";
import { getIntegrationName } from "@lib/integrations"; import { getIntegrationName } from "@lib/integrations";
import { CalendarEvent } from "./calendarClient"; import { CalendarEvent, Person } from "./calendarClient";
import { BASE_URL } from "./config/constants"; import { BASE_URL } from "./config/constants";
const translator = short(); 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) => { export const getWhat = (calEvent: CalendarEvent) => {
return ` return `
${calEvent.language("what")} ${calEvent.language("what")}:
${calEvent.type} ${calEvent.type}
`; `;
}; };
export const getWhen = (calEvent: CalendarEvent) => { 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 ` return `
${calEvent.language("when")} ${calEvent.language("invitee_timezone")}:
${calEvent.language(inviteeStart.format("dddd").toLowerCase())}, ${calEvent.language( ${calEvent.attendees[0].timeZone}
inviteeStart.format("MMMM").toLowerCase()
)} ${inviteeStart.format("D")}, ${inviteeStart.format("YYYY")} | ${inviteeStart.format(
"h:mma"
)} - ${inviteeEnd.format("h:mma")} (${calEvent.attendees[0].timeZone})
`; `;
}; };
@ -46,14 +40,14 @@ ${calEvent.organizer.email}
`; `;
return ` return `
${calEvent.language("who")} ${calEvent.language("who")}:
${organizer + attendees} ${organizer + attendees}
`; `;
}; };
export const getAdditionalNotes = (calEvent: CalendarEvent) => { export const getAdditionalNotes = (calEvent: CalendarEvent) => {
return ` return `
${calEvent.language("additional_notes")} ${calEvent.language("additional_notes")}:
${calEvent.description} ${calEvent.description}
`; `;
}; };
@ -92,13 +86,28 @@ export const getCancelLink = (calEvent: CalendarEvent): string => {
return BASE_URL + "/cancel/" + getUid(calEvent); 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 ` return `
${getWhat(calEvent)} ${getWhat(calEvent)}
${getWhen(calEvent)} ${getWhen(calEvent)}
${getWho(calEvent)} ${getWho(calEvent)}
${getLocation(calEvent)} ${calEvent.language("where")}:
${getAdditionalNotes(calEvent)} ${getLocation(calEvent)}
${getManageLink(calEvent)} ${getAdditionalNotes(calEvent)}
`; ${getManageLink(calEvent)}
`.trim();
}; };

View file

@ -6,7 +6,7 @@ import utc from "dayjs/plugin/utc";
import { createEvent, DateArray } from "ics"; import { createEvent, DateArray } from "ics";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { getCancelLink } from "@lib/CalEventParser"; import { getCancelLink, getRichDescription } from "@lib/CalEventParser";
import { CalendarEvent, Person } from "@lib/calendarClient"; import { CalendarEvent, Person } from "@lib/calendarClient";
import { getErrorFromUnknown } from "@lib/errors"; import { getErrorFromUnknown } from "@lib/errors";
import { getIntegrationName } from "@lib/integrations"; import { getIntegrationName } from "@lib/integrations";
@ -113,30 +113,12 @@ export default class AttendeeScheduledEmail {
} }
protected getTextBody(): string { 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 ` return `
${this.calEvent.language("your_event_has_been_scheduled")} ${this.calEvent.language("your_event_has_been_scheduled")}
${this.calEvent.language("emailed_you_and_any_other_attendees")} ${this.calEvent.language("emailed_you_and_any_other_attendees")}
${this.getWhat()}
${this.getWhen()} ${getRichDescription(this.calEvent)}
${this.getLocation()} `.trim();
${this.getAdditionalNotes()}
`.replace(/(<([^>]+)>)/gi, "");
} }
protected printNodeMailerError(error: Error): void { protected printNodeMailerError(error: Error): void {
@ -364,12 +346,12 @@ ${this.getAdditionalNotes()}
<p style="height: 6px"></p> <p style="height: 6px"></p>
<div style="line-height: 6px;"> <div style="line-height: 6px;">
<p style="color: #494949;">${this.calEvent.language("where")}</p> <p style="color: #494949;">${this.calEvent.language("where")}</p>
<p style="color: #494949; font-weight: 400; line-height: 24px;">${ <p style="color: #494949; font-weight: 400; line-height: 24px;">${providerName} ${
hangoutLink && hangoutLink &&
`<a href="${hangoutLink}" target="_blank" alt="${this.calEvent.language( `<a href="${hangoutLink}" target="_blank" alt="${this.calEvent.language(
"meeting_url" "meeting_url"
)}"><img src="${linkIcon()}" width="12px"></img></a>` )}"><img src="${linkIcon()}" width="12px"></img></a>`
}</p> }</p>
<div style="color: #494949; font-weight: 400; line-height: 24px;"><a href="${hangoutLink}" alt="${this.calEvent.language( <div style="color: #494949; font-weight: 400; line-height: 24px;"><a href="${hangoutLink}" alt="${this.calEvent.language(
"meeting_url" "meeting_url"
)}" style="color: #3E3E3E" target="_blank">${hangoutLink}</a></div> )}" style="color: #3E3E3E" target="_blank">${hangoutLink}</a></div>

View file

@ -6,7 +6,7 @@ import utc from "dayjs/plugin/utc";
import { createEvent, DateArray } from "ics"; import { createEvent, DateArray } from "ics";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import { getCancelLink } from "@lib/CalEventParser"; import { getCancelLink, getRichDescription } from "@lib/CalEventParser";
import { CalendarEvent, Person } from "@lib/calendarClient"; import { CalendarEvent, Person } from "@lib/calendarClient";
import { getErrorFromUnknown } from "@lib/errors"; import { getErrorFromUnknown } from "@lib/errors";
import { getIntegrationName } from "@lib/integrations"; import { getIntegrationName } from "@lib/integrations";
@ -123,14 +123,9 @@ export default class OrganizerScheduledEmail {
return ` return `
${this.calEvent.language("new_event_scheduled")} ${this.calEvent.language("new_event_scheduled")}
${this.calEvent.language("emailed_you_and_any_other_attendees")} ${this.calEvent.language("emailed_you_and_any_other_attendees")}
${this.getWhat()}
${this.getWhen()} ${getRichDescription(this.calEvent)}
${this.getWho()} `.trim();
${this.getLocation()}
${this.getAdditionalNotes()}
${this.calEvent.language("need_to_reschedule_or_cancel")}
${getCancelLink(this.calEvent)}
`.replace(/(<([^>]+)>)/gi, "");
} }
protected printNodeMailerError(error: Error): void { protected printNodeMailerError(error: Error): void {
@ -352,12 +347,12 @@ ${getCancelLink(this.calEvent)}
<p style="height: 6px"></p> <p style="height: 6px"></p>
<div style="line-height: 6px;"> <div style="line-height: 6px;">
<p style="color: #494949;">${this.calEvent.language("where")}</p> <p style="color: #494949;">${this.calEvent.language("where")}</p>
<p style="color: #494949; font-weight: 400; line-height: 24px;">${ <p style="color: #494949; font-weight: 400; line-height: 24px;">${providerName} ${
hangoutLink && hangoutLink &&
`<a href="${hangoutLink}" target="_blank" alt="${this.calEvent.language( `<a href="${hangoutLink}" target="_blank" alt="${this.calEvent.language(
"meeting_url" "meeting_url"
)}"><img src="${linkIcon()}" width="12px"></img></a>` )}"><img src="${linkIcon()}" width="12px"></img></a>`
}</p> }</p>
<div style="color: #494949; font-weight: 400; line-height: 24px;"><a href="${hangoutLink}" alt="${this.calEvent.language( <div style="color: #494949; font-weight: 400; line-height: 24px;"><a href="${hangoutLink}" alt="${this.calEvent.language(
"meeting_url" "meeting_url"
)}" style="color: #3E3E3E" target="_blank">${hangoutLink}</a></div> )}" style="color: #3E3E3E" target="_blank">${hangoutLink}</a></div>