Recurring event fixes (#3030)

* Incorporates recurringEvent into calEvent

* Recurrent event fixes

* Update event.ts

* type fixes

* Update zod-utils.ts

* Adding more recurringEvent to calEvent and other fixes

* Moving away from heavy 3rd party enum

* Fixing test

* Renaming as suggested and fixes

Co-authored-by: Leo Giovanetti <[email protected]>
This commit is contained in:
Omar LópezandLeo Giovanetti authored and GitHub committed 2022-06-09 18:32:34 -06:00
1 parent 8cd420173c
commit b11398f551
55 files changed
+315 -333

No files matched your search

+28 -56
View File
@@ -1,4 +1,4 @@
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import AttendeeAwaitingPaymentEmail from "./templates/attendee-awaiting-payment-email";
import AttendeeCancelledEmail from "./templates/attendee-cancelled-email";
@@ -20,14 +20,14 @@ import OrganizerRescheduledEmail from "./templates/organizer-rescheduled-email";
import OrganizerScheduledEmail from "./templates/organizer-scheduled-email";
import TeamInviteEmail, { TeamInvite } from "./templates/team-invite-email";
export const sendScheduledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
export const sendScheduledEmails = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const scheduledEmail = new AttendeeScheduledEmail(calEvent, attendee, recurringEvent);
const scheduledEmail = new AttendeeScheduledEmail(calEvent, attendee);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
@@ -39,7 +39,7 @@ export const sendScheduledEmails = async (calEvent: CalendarEvent, recurringEven
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const scheduledEmail = new OrganizerScheduledEmail(calEvent, recurringEvent);
const scheduledEmail = new OrganizerScheduledEmail(calEvent);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
@@ -50,14 +50,14 @@ export const sendScheduledEmails = async (calEvent: CalendarEvent, recurringEven
await Promise.all(emailsToSend);
};
export const sendRescheduledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
export const sendRescheduledEmails = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const scheduledEmail = new AttendeeRescheduledEmail(calEvent, attendee, recurringEvent);
const scheduledEmail = new AttendeeRescheduledEmail(calEvent, attendee);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
@@ -69,7 +69,7 @@ export const sendRescheduledEmails = async (calEvent: CalendarEvent, recurringEv
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const scheduledEmail = new OrganizerRescheduledEmail(calEvent, recurringEvent);
const scheduledEmail = new OrganizerRescheduledEmail(calEvent);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerScheduledEmail.sendEmail failed", e));
@@ -80,13 +80,10 @@ export const sendRescheduledEmails = async (calEvent: CalendarEvent, recurringEv
await Promise.all(emailsToSend);
};
export const sendOrganizerRequestEmail = async (
calEvent: CalendarEvent,
recurringEvent: RecurringEvent = {}
) => {
export const sendOrganizerRequestEmail = async (calEvent: CalendarEvent) => {
await new Promise((resolve, reject) => {
try {
const organizerRequestEmail = new OrganizerRequestEmail(calEvent, recurringEvent);
const organizerRequestEmail = new OrganizerRequestEmail(calEvent);
resolve(organizerRequestEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerRequestEmail.sendEmail failed", e));
@@ -94,14 +91,10 @@ export const sendOrganizerRequestEmail = async (
});
};
export const sendAttendeeRequestEmail = async (
calEvent: CalendarEvent,
attendee: Person,
recurringEvent: RecurringEvent = {}
) => {
export const sendAttendeeRequestEmail = async (calEvent: CalendarEvent, attendee: Person) => {
await new Promise((resolve, reject) => {
try {
const attendeeRequestEmail = new AttendeeRequestEmail(calEvent, attendee, recurringEvent);
const attendeeRequestEmail = new AttendeeRequestEmail(calEvent, attendee);
resolve(attendeeRequestEmail.sendEmail());
} catch (e) {
reject(console.error("AttendRequestEmail.sendEmail failed", e));
@@ -109,14 +102,14 @@ export const sendAttendeeRequestEmail = async (
});
};
export const sendDeclinedEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
export const sendDeclinedEmails = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const declinedEmail = new AttendeeDeclinedEmail(calEvent, attendee, recurringEvent);
const declinedEmail = new AttendeeDeclinedEmail(calEvent, attendee);
resolve(declinedEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeRescheduledEmail.sendEmail failed", e));
@@ -128,14 +121,14 @@ export const sendDeclinedEmails = async (calEvent: CalendarEvent, recurringEvent
await Promise.all(emailsToSend);
};
export const sendCancelledEmails = async (calEvent: CalendarEvent, recurringEvent: RecurringEvent = {}) => {
export const sendCancelledEmails = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const scheduledEmail = new AttendeeCancelledEmail(calEvent, attendee, recurringEvent);
const scheduledEmail = new AttendeeCancelledEmail(calEvent, attendee);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeCancelledEmail.sendEmail failed", e));
@@ -147,7 +140,7 @@ export const sendCancelledEmails = async (calEvent: CalendarEvent, recurringEven
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const scheduledEmail = new OrganizerCancelledEmail(calEvent, recurringEvent);
const scheduledEmail = new OrganizerCancelledEmail(calEvent);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerCancelledEmail.sendEmail failed", e));
@@ -158,13 +151,10 @@ export const sendCancelledEmails = async (calEvent: CalendarEvent, recurringEven
await Promise.all(emailsToSend);
};
export const sendOrganizerRequestReminderEmail = async (
calEvent: CalendarEvent,
recurringEvent: RecurringEvent = {}
) => {
export const sendOrganizerRequestReminderEmail = async (calEvent: CalendarEvent) => {
await new Promise((resolve, reject) => {
try {
const organizerRequestReminderEmail = new OrganizerRequestReminderEmail(calEvent, recurringEvent);
const organizerRequestReminderEmail = new OrganizerRequestReminderEmail(calEvent);
resolve(organizerRequestReminderEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerRequestReminderEmail.sendEmail failed", e));
@@ -172,17 +162,14 @@ export const sendOrganizerRequestReminderEmail = async (
});
};
export const sendAwaitingPaymentEmail = async (
calEvent: CalendarEvent,
recurringEvent: RecurringEvent = {}
) => {
export const sendAwaitingPaymentEmail = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const paymentEmail = new AttendeeAwaitingPaymentEmail(calEvent, attendee, recurringEvent);
const paymentEmail = new AttendeeAwaitingPaymentEmail(calEvent, attendee);
resolve(paymentEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeAwaitingPaymentEmail.sendEmail failed", e));
@@ -194,13 +181,10 @@ export const sendAwaitingPaymentEmail = async (
await Promise.all(emailsToSend);
};
export const sendOrganizerPaymentRefundFailedEmail = async (
calEvent: CalendarEvent,
recurringEvent: RecurringEvent = {}
) => {
export const sendOrganizerPaymentRefundFailedEmail = async (calEvent: CalendarEvent) => {
await new Promise((resolve, reject) => {
try {
const paymentRefundFailedEmail = new OrganizerPaymentRefundFailedEmail(calEvent, recurringEvent);
const paymentRefundFailedEmail = new OrganizerPaymentRefundFailedEmail(calEvent);
resolve(paymentRefundFailedEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerPaymentRefundFailedEmail.sendEmail failed", e));
@@ -232,19 +216,14 @@ export const sendTeamInviteEmail = async (teamInviteEvent: TeamInvite) => {
export const sendRequestRescheduleEmail = async (
calEvent: CalendarEvent,
metadata: { rescheduleLink: string },
recurringEvent: RecurringEvent = {}
metadata: { rescheduleLink: string }
) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const requestRescheduleEmail = new AttendeeRequestRescheduledEmail(
calEvent,
metadata,
recurringEvent
);
const requestRescheduleEmail = new AttendeeRequestRescheduledEmail(calEvent, metadata);
resolve(requestRescheduleEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeRequestRescheduledEmail.sendEmail failed", e));
@@ -255,11 +234,7 @@ export const sendRequestRescheduleEmail = async (
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const requestRescheduleEmail = new OrganizerRequestRescheduleEmail(
calEvent,
metadata,
recurringEvent
);
const requestRescheduleEmail = new OrganizerRequestRescheduleEmail(calEvent, metadata);
resolve(requestRescheduleEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerRequestRescheduledEmail.sendEmail failed", e));
@@ -270,17 +245,14 @@ export const sendRequestRescheduleEmail = async (
await Promise.all(emailsToSend);
};
export const sendLocationChangeEmails = async (
calEvent: CalendarEvent,
recurringEvent: RecurringEvent = {}
) => {
export const sendLocationChangeEmails = async (calEvent: CalendarEvent) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(
...calEvent.attendees.map((attendee) => {
return new Promise((resolve, reject) => {
try {
const scheduledEmail = new AttendeeLocationChangeEmail(calEvent, attendee, recurringEvent);
const scheduledEmail = new AttendeeLocationChangeEmail(calEvent, attendee);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("AttendeeLocationChangeEmail.sendEmail failed", e));
@@ -292,7 +264,7 @@ export const sendLocationChangeEmails = async (
emailsToSend.push(
new Promise((resolve, reject) => {
try {
const scheduledEmail = new OrganizerLocationChangeEmail(calEvent, recurringEvent);
const scheduledEmail = new OrganizerLocationChangeEmail(calEvent);
resolve(scheduledEmail.sendEmail());
} catch (e) {
reject(console.error("OrganizerLocationChangeEmail.sendEmail failed", e));
+11 -16
View File
@@ -3,31 +3,26 @@ import timezone from "dayjs/plugin/timezone";
import { TFunction } from "next-i18next";
import rrule from "rrule";
import type { CalendarEvent, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { Info } from "./Info";
dayjs.extend(timezone);
function getRecurringWhen(props: { calEvent: CalendarEvent; recurringEvent: RecurringEvent }) {
function getRecurringWhen(props: { calEvent: CalendarEvent }) {
const t = props.calEvent.attendees[0].language.translate;
return props.recurringEvent?.count && props.recurringEvent?.freq
const { calEvent: { recurringEvent } = {} } = props;
return recurringEvent?.count && recurringEvent?.freq
? ` - ${t("every_for_freq", {
freq: t(`${rrule.FREQUENCIES[props.recurringEvent.freq].toString().toLowerCase()}`),
})} ${props.recurringEvent.count} ${t(
`${rrule.FREQUENCIES[props.recurringEvent.freq].toString().toLowerCase()}`,
{ count: props.recurringEvent.count }
)}`
freq: t(`${rrule.FREQUENCIES[recurringEvent.freq].toString().toLowerCase()}`),
})} ${recurringEvent.count} ${t(`${rrule.FREQUENCIES[recurringEvent.freq].toString().toLowerCase()}`, {
count: recurringEvent.count,
})}`
: "";
}
export function WhenInfo(props: {
calEvent: CalendarEvent;
recurringEvent: RecurringEvent;
timeZone: string;
t: TFunction;
}) {
const { timeZone, t } = props;
export function WhenInfo(props: { calEvent: CalendarEvent; timeZone: string; t: TFunction }) {
const { timeZone, t, calEvent: { recurringEvent } = {} } = props;
function getRecipientStart(format: string) {
return dayjs(props.calEvent.startTime).tz(timeZone).format(format);
@@ -44,7 +39,7 @@ export function WhenInfo(props: {
lineThrough={!!props.calEvent.cancellationReason}
description={
<>
{props.recurringEvent?.count ? `${t("starting")} ` : ""}
{recurringEvent?.count ? `${t("starting")} ` : ""}
{t(getRecipientStart("dddd").toLowerCase())}, {t(getRecipientStart("MMMM").toLowerCase())}{" "}
{getRecipientStart("D, YYYY | h:mma")} - {getRecipientEnd("h:mma")}{" "}
<span style={{ color: "#888888" }}>({timeZone})</span>
@@ -2,7 +2,9 @@ import { AttendeeScheduledEmail } from "./AttendeeScheduledEmail";
export const AttendeeDeclinedEmail = (props: React.ComponentProps<typeof AttendeeScheduledEmail>) => (
<AttendeeScheduledEmail
title={props.recurringEvent?.count ? "event_request_declined_recurring" : "event_request_declined"}
title={
props.calEvent.recurringEvent?.count ? "event_request_declined_recurring" : "event_request_declined"
}
headerType="xCircle"
subject="event_declined_subject"
callToAction={null}
@@ -3,10 +3,10 @@ import { AttendeeScheduledEmail } from "./AttendeeScheduledEmail";
export const AttendeeRequestEmail = (props: React.ComponentProps<typeof AttendeeScheduledEmail>) => (
<AttendeeScheduledEmail
title={props.calEvent.organizer.language.translate(
props.recurringEvent?.count ? "booking_submitted_recurring" : "booking_submitted"
props.calEvent.recurringEvent?.count ? "booking_submitted_recurring" : "booking_submitted"
)}
subtitle={props.calEvent.organizer.language.translate(
props.recurringEvent.count
props.calEvent.recurringEvent?.count
? "user_needs_to_confirm_or_reject_booking_recurring"
: "user_needs_to_confirm_or_reject_booking",
{ user: props.calEvent.organizer.name }
@@ -1,4 +1,4 @@
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { BaseScheduledEmail } from "./BaseScheduledEmail";
@@ -6,7 +6,6 @@ export const AttendeeScheduledEmail = (
props: {
calEvent: CalendarEvent;
attendee: Person;
recurringEvent: RecurringEvent;
} & Partial<React.ComponentProps<typeof BaseScheduledEmail>>
) => {
return (
@@ -5,7 +5,7 @@ import toArray from "dayjs/plugin/toArray";
import utc from "dayjs/plugin/utc";
import type { TFunction } from "next-i18next";
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import {
BaseEmailHtml,
@@ -26,7 +26,6 @@ export const BaseScheduledEmail = (
props: {
calEvent: CalendarEvent;
attendee: Person;
recurringEvent: RecurringEvent;
timeZone: string;
t: TFunction;
} & Partial<React.ComponentProps<typeof BaseEmailHtml>>
@@ -56,7 +55,7 @@ export const BaseScheduledEmail = (
title={t(
props.title
? props.title
: props.recurringEvent?.count
: props.calEvent.recurringEvent?.count
? "your_event_has_been_scheduled_recurring"
: "your_event_has_been_scheduled"
)}
@@ -69,7 +68,7 @@ export const BaseScheduledEmail = (
<Info label={t("cancellation_reason")} description={props.calEvent.cancellationReason} withSpacer />
<Info label={t("rejection_reason")} description={props.calEvent.rejectionReason} withSpacer />
<Info label={t("what")} description={props.calEvent.type} withSpacer />
<WhenInfo calEvent={props.calEvent} recurringEvent={props.recurringEvent} t={t} timeZone={timeZone} />
<WhenInfo calEvent={props.calEvent} t={t} timeZone={timeZone} />
<WhoInfo calEvent={props.calEvent} t={t} />
<LocationInfo calEvent={props.calEvent} t={t} />
<Info label={t("description")} description={props.calEvent.description} withSpacer />
@@ -4,7 +4,7 @@ import { OrganizerScheduledEmail } from "./OrganizerScheduledEmail";
export const OrganizerRequestEmail = (props: React.ComponentProps<typeof OrganizerScheduledEmail>) => (
<OrganizerScheduledEmail
title={
props.title || props.recurringEvent?.count
props.title || props.calEvent.recurringEvent?.count
? "event_awaiting_approval_recurring"
: "event_awaiting_approval"
}
@@ -1,4 +1,4 @@
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { BaseScheduledEmail } from "./BaseScheduledEmail";
@@ -6,7 +6,6 @@ export const OrganizerScheduledEmail = (
props: {
calEvent: CalendarEvent;
attendee: Person;
recurringEvent: RecurringEvent;
} & Partial<React.ComponentProps<typeof BaseScheduledEmail>>
) => {
const t = props.calEvent.organizer.language.translate;
@@ -15,7 +14,9 @@ export const OrganizerScheduledEmail = (
timeZone={props.calEvent.organizer.timeZone}
t={t}
subject={t("confirmed_event_type_subject")}
title={t(props.recurringEvent?.count ? "new_event_scheduled_recurring" : "new_event_scheduled")}
title={t(
props.calEvent.recurringEvent?.count ? "new_event_scheduled_recurring" : "new_event_scheduled"
)}
{...props}
/>
);
@@ -15,7 +15,6 @@ export default class AttendeeAwaitingPaymentEmail extends AttendeeScheduledEmail
html: renderEmail("AttendeeAwaitingPaymentEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("meeting_awaiting_payment"),
};
@@ -15,7 +15,6 @@ export default class AttendeeCancelledEmail extends AttendeeScheduledEmail {
html: renderEmail("AttendeeCancelledEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_request_cancelled", "emailed_you_and_any_other_attendees"),
};
@@ -15,10 +15,9 @@ export default class AttendeeDeclinedEmail extends AttendeeScheduledEmail {
html: renderEmail("AttendeeDeclinedEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(
this.recurringEvent?.count ? "event_request_declined_recurring" : "event_request_declined"
this.calEvent.recurringEvent?.count ? "event_request_declined_recurring" : "event_request_declined"
),
};
}
@@ -19,7 +19,6 @@ export default class AttendeeLocationChangeEmail extends AttendeeScheduledEmail
html: renderEmail("AttendeeLocationChangeEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_location_changed"),
};
@@ -24,7 +24,6 @@ export default class AttendeeRequestEmail extends AttendeeScheduledEmail {
html: renderEmail("AttendeeRequestEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(
this.calEvent.attendees[0].language.translate("booking_submitted", {
@@ -5,10 +5,10 @@ import toArray from "dayjs/plugin/toArray";
import utc from "dayjs/plugin/utc";
import { createEvent, DateArray, Person } from "ics";
import { renderEmail } from "../";
import { getCancelLink } from "@calcom/lib/CalEventParser";
import { CalendarEvent, RecurringEvent } from "@calcom/types/Calendar";
import { CalendarEvent } from "@calcom/types/Calendar";
import { renderEmail } from "../";
import OrganizerScheduledEmail from "./organizer-scheduled-email";
dayjs.extend(utc);
@@ -18,8 +18,8 @@ dayjs.extend(toArray);
export default class AttendeeRequestRescheduledEmail extends OrganizerScheduledEmail {
private metadata: { rescheduleLink: string };
constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }, recurringEvent: RecurringEvent) {
super(calEvent, recurringEvent);
constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }) {
super(calEvent);
this.metadata = metadata;
}
protected getNodeMailerPayload(): Record<string, unknown> {
@@ -40,7 +40,6 @@ export default class AttendeeRequestRescheduledEmail extends OrganizerScheduledE
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
metadata: this.metadata,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(),
};
@@ -19,7 +19,6 @@ export default class AttendeeRescheduledEmail extends AttendeeScheduledEmail {
html: renderEmail("AttendeeCancelledEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_has_been_rescheduled", "emailed_you_and_any_other_attendees"),
};
@@ -8,7 +8,7 @@ import { TFunction } from "next-i18next";
import rrule from "rrule";
import { getRichDescription } from "@calcom/lib/CalEventParser";
import type { CalendarEvent, Person, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import { renderEmail } from "../";
import BaseEmail from "./_base-email";
@@ -21,23 +21,22 @@ dayjs.extend(toArray);
export default class AttendeeScheduledEmail extends BaseEmail {
calEvent: CalendarEvent;
attendee: Person;
recurringEvent: RecurringEvent;
t: TFunction;
constructor(calEvent: CalendarEvent, attendee: Person, recurringEvent: RecurringEvent) {
constructor(calEvent: CalendarEvent, attendee: Person) {
super();
this.name = "SEND_BOOKING_CONFIRMATION";
this.calEvent = calEvent;
this.attendee = attendee;
this.t = attendee.language.translate;
this.recurringEvent = recurringEvent;
}
protected getiCalEventAsString(): string | undefined {
// Taking care of recurrence rule beforehand
let recurrenceRule: string | undefined = undefined;
if (this.recurringEvent?.count) {
recurrenceRule = new rrule(this.recurringEvent).toString().replace("RRULE:", "");
if (this.calEvent.recurringEvent?.count) {
// ics appends "RRULE:" already, so removing it from RRule generated string
recurrenceRule = new rrule(this.calEvent.recurringEvent).toString().replace("RRULE:", "");
}
const icsEvent = createEvent({
start: dayjs(this.calEvent.startTime)
@@ -84,7 +83,6 @@ export default class AttendeeScheduledEmail extends BaseEmail {
html: renderEmail("AttendeeScheduledEmail", {
calEvent: this.calEvent,
attendee: this.attendee,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(),
};
@@ -93,7 +91,7 @@ export default class AttendeeScheduledEmail extends BaseEmail {
protected getTextBody(title = "", subtitle = "emailed_you_and_any_other_attendees"): string {
return `
${this.t(
title || this.recurringEvent?.count
title || this.calEvent.recurringEvent?.count
? "your_event_has_been_scheduled_recurring"
: "your_event_has_been_scheduled"
)}
@@ -24,7 +24,6 @@ export default class OrganizerCancelledEmail extends OrganizerScheduledEmail {
html: renderEmail("OrganizerCancelledEmail", {
attendee: this.calEvent.organizer,
calEvent: this.calEvent,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_request_cancelled"),
};
@@ -28,7 +28,6 @@ export default class OrganizerLocationChangeEmail extends OrganizerScheduledEmai
html: renderEmail("OrganizerLocationChangeEmail", {
attendee: this.calEvent.organizer,
calEvent: this.calEvent,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_location_changed"),
};
@@ -1,5 +1,4 @@
import { renderEmail } from "../";
import OrganizerScheduledEmail from "./organizer-scheduled-email";
export default class OrganizerPaymentRefundFailedEmail extends OrganizerScheduledEmail {
@@ -25,7 +24,6 @@ export default class OrganizerPaymentRefundFailedEmail extends OrganizerSchedule
html: renderEmail("OrganizerPaymentRefundFailedEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(
"a_refund_failed",
@@ -24,7 +24,6 @@ export default class OrganizerRequestEmail extends OrganizerScheduledEmail {
html: renderEmail("OrganizerRequestEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_awaiting_approval"),
};
@@ -24,7 +24,6 @@ export default class OrganizerRequestReminderEmail extends OrganizerRequestEmail
html: renderEmail("OrganizerRequestReminderEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_still_awaiting_approval"),
};
@@ -5,9 +5,9 @@ import toArray from "dayjs/plugin/toArray";
import utc from "dayjs/plugin/utc";
import { createEvent, DateArray, Person } from "ics";
import { renderEmail } from "../";
import { CalendarEvent, RecurringEvent } from "@calcom/types/Calendar";
import { CalendarEvent } from "@calcom/types/Calendar";
import { renderEmail } from "../";
import OrganizerScheduledEmail from "./organizer-scheduled-email";
dayjs.extend(utc);
@@ -17,8 +17,8 @@ dayjs.extend(toArray);
export default class OrganizerRequestRescheduledEmail extends OrganizerScheduledEmail {
private metadata: { rescheduleLink: string };
constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }, recurringEvent: RecurringEvent) {
super(calEvent, recurringEvent);
constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }) {
super(calEvent);
this.metadata = metadata;
}
protected getNodeMailerPayload(): Record<string, unknown> {
@@ -39,7 +39,6 @@ export default class OrganizerRequestRescheduledEmail extends OrganizerScheduled
html: renderEmail("OrganizerScheduledEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(
this.t("request_reschedule_title_organizer", {
@@ -34,7 +34,6 @@ export default class OrganizerRescheduledEmail extends OrganizerScheduledEmail {
html: renderEmail("OrganizerRescheduledEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody("event_has_been_rescheduled"),
};
@@ -8,7 +8,7 @@ import { TFunction } from "next-i18next";
import rrule from "rrule";
import { getRichDescription } from "@calcom/lib/CalEventParser";
import type { CalendarEvent, RecurringEvent } from "@calcom/types/Calendar";
import type { CalendarEvent } from "@calcom/types/Calendar";
import { renderEmail } from "../";
import BaseEmail from "./_base-email";
@@ -20,22 +20,22 @@ dayjs.extend(toArray);
export default class OrganizerScheduledEmail extends BaseEmail {
calEvent: CalendarEvent;
recurringEvent: RecurringEvent;
t: TFunction;
constructor(calEvent: CalendarEvent, recurringEvent: RecurringEvent) {
constructor(calEvent: CalendarEvent) {
super();
this.name = "SEND_BOOKING_CONFIRMATION";
this.calEvent = calEvent;
this.recurringEvent = recurringEvent;
this.t = this.calEvent.organizer.language.translate;
}
protected getiCalEventAsString(): string | undefined {
// Taking care of recurrence rule beforehand
let recurrenceRule: string | undefined = undefined;
if (this.recurringEvent?.count) {
recurrenceRule = new rrule(this.recurringEvent).toString().replace("RRULE:", "");
if (this.calEvent.recurringEvent?.count) {
// ics appends "RRULE:" already, so removing it from RRule generated string
recurrenceRule = new rrule(this.calEvent.recurringEvent).toString().replace("RRULE:", "");
}
const icsEvent = createEvent({
start: dayjs(this.calEvent.startTime)
@@ -91,7 +91,6 @@ export default class OrganizerScheduledEmail extends BaseEmail {
html: renderEmail("OrganizerScheduledEmail", {
calEvent: this.calEvent,
attendee: this.calEvent.organizer,
recurringEvent: this.recurringEvent,
}),
text: this.getTextBody(),
};
@@ -104,7 +103,9 @@ export default class OrganizerScheduledEmail extends BaseEmail {
callToAction = ""
): string {
return `
${this.t(title || this.recurringEvent?.count ? "new_event_scheduled_recurring" : "new_event_scheduled")}
${this.t(
title || this.calEvent.recurringEvent?.count ? "new_event_scheduled_recurring" : "new_event_scheduled"
)}
${this.t(subtitle)}
${extraInfo}
${getRichDescription(this.calEvent)}
+1 -1
View File
@@ -58,7 +58,7 @@ const commons = {
},
isWeb3Active: false,
hideCalendarNotes: false,
recurringEvent: {},
recurringEvent: null,
destinationCalendar: null,
team: null,
requiresConfirmation: false,
+1
View File
@@ -1 +1,2 @@
export { default as isPrismaObj, isPrismaObjOrUndefined } from "./isPrismaObj";
export * from "./isRecurringEvent";
+13
View File
@@ -0,0 +1,13 @@
import { recurringEventType as recurringEventSchema } from "@calcom/prisma/zod-utils";
import type { RecurringEvent } from "@calcom/types/Calendar";
export function isRecurringEvent(obj: unknown): obj is RecurringEvent {
const parsedRecuEvt = recurringEventSchema.safeParse(obj);
return parsedRecuEvt.success;
}
export function parseRecurringEvent(obj: unknown): RecurringEvent | null {
let recurringEvent: RecurringEvent | null = null;
if (isRecurringEvent(obj)) recurringEvent = obj;
return recurringEvent;
}
+1 -1
View File
@@ -59,7 +59,7 @@ model EventType {
periodDays Int?
periodCountCalendarDays Boolean?
requiresConfirmation Boolean @default(false)
/// @zod.custom(imports.recurringEvent)
/// @zod.custom(imports.recurringEventType)
recurringEvent Json?
disableGuests Boolean @default(false)
hideCalendarNotes Boolean @default(false)
+39 -10
View File
@@ -1,9 +1,20 @@
import { Frequency as RRuleFrequency } from "rrule";
import dayjs from "dayjs";
import { z } from "zod";
import { LocationType } from "@calcom/core/location";
import { slugify } from "@calcom/lib/slugify";
// Let's not import 118kb just to get an enum
export enum Frequency {
YEARLY = 0,
MONTHLY = 1,
WEEKLY = 2,
DAILY = 3,
HOURLY = 4,
MINUTELY = 5,
SECONDLY = 6,
}
export const eventTypeLocations = z.array(
z.object({
type: z.nativeEnum(LocationType),
@@ -15,15 +26,33 @@ export const eventTypeLocations = z.array(
);
// Matching RRule.Options: rrule/dist/esm/src/types.d.ts
export const recurringEvent = z.object({
dtstart: z.date().optional(),
interval: z.number().optional(),
count: z.number().optional(),
freq: z.nativeEnum(RRuleFrequency).optional(),
until: z.date().optional(),
tzid: z.string().optional(),
});
export const recurringEventType = z
.object({
dtstart: z.date().optional(),
interval: z.number(),
count: z.number(),
freq: z.nativeEnum(Frequency),
until: z.date().optional(),
tzid: z.string().optional(),
})
.nullable();
export const eventTypeSlug = z.string().transform((val) => slugify(val.trim()));
export const stringToDate = z.string().transform((a) => new Date(a));
export const stringOrNumber = z.union([z.string().transform((v) => parseInt(v, 10)), z.number().int()]);
export const stringOrNumber = z.union([
z.string().transform((v, ctx) => {
const parsed = parseInt(v);
if (isNaN(parsed)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Not a number",
});
}
return parsed;
}),
z.number().int(),
]);
export const stringToDayjs = z.string().transform((val) => dayjs(val));
+6 -4
View File
@@ -3,7 +3,8 @@ import type { Dayjs } from "dayjs";
import type { calendar_v3 } from "googleapis";
import type { Time } from "ical.js";
import type { TFunction } from "next-i18next";
import type { Frequency as RRuleFrequency } from "rrule";
import type { Frequency } from "@calcom/prisma/zod-utils";
import type { Event } from "./Event";
import type { Ensure } from "./utils";
@@ -87,9 +88,9 @@ export interface AdditionalInformation {
export interface RecurringEvent {
dtstart?: Date | undefined;
interval?: number;
count?: number;
freq?: RRuleFrequency;
interval: number;
count: number;
freq: Frequency;
until?: Date | undefined;
tzid?: string | undefined;
}
@@ -120,6 +121,7 @@ export interface CalendarEvent {
rejectionReason?: string | null;
hideCalendarNotes?: boolean;
recurrence?: string;
recurringEvent?: RecurringEvent | null;
}
export interface EntryPoint {