Add status as param

refactor/generate-ics-event
Joe Au-Yeung 2023-10-30 16:46:56 -04:00
parent 397f6eba01
commit 7ed31c441c
6 changed files with 39 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import type { DateArray, ParticipationStatus, ParticipationRole } from "ics"; import type { DateArray, ParticipationStatus, ParticipationRole, EventStatus } from "ics";
import { createEvent } from "ics"; import { createEvent } from "ics";
import type { TFunction } from "next-i18next"; import type { TFunction } from "next-i18next";
import { RRule } from "rrule"; import { RRule } from "rrule";
@ -11,10 +11,12 @@ const generateIcsString = ({
event, event,
t, t,
role, role,
status,
}: { }: {
event: CalendarEvent; event: CalendarEvent;
t: TFunction; t: TFunction;
role: "attendee" | "organizer"; role: "attendee" | "organizer";
status: EventStatus;
}) => { }) => {
// Taking care of recurrence rule // Taking care of recurrence rule
let recurrenceRule: string | undefined = undefined; let recurrenceRule: string | undefined = undefined;
@ -79,7 +81,7 @@ ${getRichDescription(event, t)}
: []), : []),
], ],
method: "REQUEST", method: "REQUEST",
status: "CONFIRMED", status,
}); });
if (icsEvent.error) { if (icsEvent.error) {
throw icsEvent.error; throw icsEvent.error;

View File

@ -7,7 +7,12 @@ export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
return { return {
icalEvent: { icalEvent: {
filename: "event.ics", filename: "event.ics",
content: generateIcsString({ event: this.calEvent, t: this.t, role: "attendee" }), content: generateIcsString({
event: this.calEvent,
t: this.t,
role: "attendee",
status: "CONFIRMED",
}),
}, },
to: `${this.attendee.name} <${this.attendee.email}>`, to: `${this.attendee.name} <${this.attendee.email}>`,
from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`, from: `${this.calEvent.organizer.name} <${this.getMailerOptions().from}>`,

View File

@ -35,7 +35,12 @@ export default class AttendeeScheduledEmail extends BaseEmail {
return { return {
icalEvent: { icalEvent: {
filename: "event.ics", filename: "event.ics",
content: generateIcsString({ event: this.calEvent, t: this.t, role: "attendee" }), content: generateIcsString({
event: this.calEvent,
t: this.t,
role: "attendee",
status: "CONFIRMED",
}),
method: "REQUEST", method: "REQUEST",
}, },
to: `${this.attendee.name} <${this.attendee.email}>`, to: `${this.attendee.name} <${this.attendee.email}>`,

View File

@ -1,6 +1,7 @@
import { APP_NAME } from "@calcom/lib/constants"; import { APP_NAME } from "@calcom/lib/constants";
import { renderEmail } from "../"; import { renderEmail } from "../";
import generateIcsString from "../lib/generateIcsString";
import OrganizerScheduledEmail from "./organizer-scheduled-email"; import OrganizerScheduledEmail from "./organizer-scheduled-email";
export default class OrganizerCancelledEmail extends OrganizerScheduledEmail { export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
@ -8,6 +9,16 @@ export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
const toAddresses = [this.teamMember?.email || this.calEvent.organizer.email]; const toAddresses = [this.teamMember?.email || this.calEvent.organizer.email];
return { return {
icalEvent: {
filename: "event.ics",
content: generateIcsString({
event: this.calEvent,
t: this.t,
role: "organizer",
status: "CANCELLED",
}),
method: "request",
},
from: `${APP_NAME} <${this.getMailerOptions().from}>`, from: `${APP_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","), to: toAddresses.join(","),
subject: `${this.t("event_cancelled_subject", { subject: `${this.t("event_cancelled_subject", {

View File

@ -11,7 +11,12 @@ export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
return { return {
icalEvent: { icalEvent: {
filename: "event.ics", filename: "event.ics",
content: generateIcsString({ event: this.calEvent, t: this.t, role: "organizer" }), content: generateIcsString({
event: this.calEvent,
t: this.t,
role: "organizer",
status: "CONFIRMED",
}),
}, },
from: `${APP_NAME} <${this.getMailerOptions().from}>`, from: `${APP_NAME} <${this.getMailerOptions().from}>`,
to: toAddresses.join(","), to: toAddresses.join(","),

View File

@ -33,7 +33,12 @@ export default class OrganizerScheduledEmail extends BaseEmail {
return { return {
icalEvent: { icalEvent: {
filename: "event.ics", filename: "event.ics",
content: generateIcsString({ event: this.calEvent, t: this.t, role: "organizer" }), content: generateIcsString({
event: this.calEvent,
t: this.t,
role: "organizer",
status: "CONFIRMED",
}),
method: "REQUEST", method: "REQUEST",
}, },
from: `${APP_NAME} <${this.getMailerOptions().from}>`, from: `${APP_NAME} <${this.getMailerOptions().from}>`,