Scheduling infrastructure for absolutely everyone.
Append reschedule/cancel also to event description
nicolas8227e733e6bb
diff --git a/lib/emails/confirm-booked.ts b/lib/emails/confirm-booked.tsindex 4641efbefe1..6d7898aa47f 100644--- a/lib/emails/confirm-booked.ts+++ b/lib/emails/confirm-booked.ts@@ -1,8 +1,7 @@-import nodemailer from 'nodemailer';-import { serverConfig } from "../serverConfig";-import { CalendarEvent } from "../calendarClient";-import dayjs, { Dayjs } from "dayjs";+import {serverConfig} from "../serverConfig";+import {CalendarEvent} from "../calendarClient";+import dayjs, {Dayjs} from "dayjs";import localizedFormat from "dayjs/plugin/localizedFormat";import utc from "dayjs/plugin/utc";import timezone from "dayjs/plugin/timezone";@@ -11,8 +10,8 @@ dayjs.extend(localizedFormat);dayjs.extend(utc);dayjs.extend(timezone);-export default function createConfirmBookedEmail(calEvent: CalendarEvent, uid: String, options: any = {}) {- return sendEmail(calEvent, uid, {+export default function createConfirmBookedEmail(calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, options: any = {}) {+ return sendEmail(calEvent, cancelLink, rescheduleLink, {provider: {transport: serverConfig.transport,from: serverConfig.from,@@ -21,7 +20,7 @@ export default function createConfirmBookedEmail(calEvent: CalendarEvent, uid: S});}-const sendEmail = (calEvent: CalendarEvent, uid: String, {+const sendEmail = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string, {provider,}) => new Promise( (resolve, reject) => {@@ -34,8 +33,8 @@ const sendEmail = (calEvent: CalendarEvent, uid: String, {from: `${calEvent.organizer.name} <${from}>`,replyTo: calEvent.organizer.email,subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`,- html: html(calEvent, uid),- text: text(calEvent, uid),+ html: html(calEvent, cancelLink, rescheduleLink),+ text: text(calEvent, cancelLink, rescheduleLink),},(error, info) => {if (error) {@@ -47,10 +46,7 @@ const sendEmail = (calEvent: CalendarEvent, uid: String, {)});-const html = (calEvent: CalendarEvent, uid: String) => {- const cancelLink = process.env.BASE_URL + '/cancel/' + uid;- const rescheduleLink = process.env.BASE_URL + '/reschedule/' + uid;-+const html = (calEvent: CalendarEvent, cancelLink: string, rescheduleLink: string) => {const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone);return `<div>@@ -71,4 +67,4 @@ const html = (calEvent: CalendarEvent, uid: String) => {`;};-const text = (evt: CalendarEvent, uid: String) => html(evt, uid).replace('<br />', "\n").replace(/<[^>]+>/g, '');\ No newline at end of file+const text = (evt: CalendarEvent, cancelLink: string, rescheduleLink: string) => html(evt, cancelLink, rescheduleLink).replace('<br />', "\n").replace(/<[^>]+>/g, '');\ No newline at end of filediff --git a/pages/api/book/[user].ts b/pages/api/book/[user].tsindex 669c8c203ea..53ae3db23b6 100644--- a/pages/api/book/[user].ts+++ b/pages/api/book/[user].ts@@ -39,7 +39,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)]};- const hashUID = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));+ const hashUID: string = translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));+ const cancelLink: string = process.env.BASE_URL + '/cancel/' + hashUID;+ const rescheduleLink:string = process.env.BASE_URL + '/reschedule/' + hashUID;+ const appendLinksToEvents = (event: CalendarEvent) => {+ const eventCopy = {...event};+ eventCopy.description += "\n\n"+ + "Need to change this event?\n"+ + "Cancel: " + cancelLink + "\n"+ + "Reschedule:" + rescheduleLink;++ return eventCopy;+ }const eventType = await prisma.eventType.findFirst({where: {@@ -75,7 +86,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)// Use all integrationsresults = await async.mapLimit(currentUser.credentials, 5, async (credential) => {const bookingRefUid = booking.references.filter((ref) => ref.type === credential.type)[0].uid;- return await updateEvent(credential, bookingRefUid, evt)+ return await updateEvent(credential, bookingRefUid, appendLinksToEvents(evt))});// Clone elements@@ -106,7 +117,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)} else {// Schedule eventresults = await async.mapLimit(currentUser.credentials, 5, async (credential) => {- const response = await createEvent(credential, evt);+ const response = await createEvent(credential, appendLinksToEvents(evt));return {type: credential.type,response@@ -144,7 +155,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)// If one of the integrations allows email confirmations or no integrations are added, send it.if (currentUser.credentials.length === 0 || !results.every((result) => result.disableConfirmationEmail)) {await createConfirmBookedEmail(- evt, hashUID+ evt, cancelLink, rescheduleLink);}