diff --git a/lib/emails/confirm-booked.ts b/lib/emails/confirm-booked.ts index c792e4f5..22aa7b12 100644 --- a/lib/emails/confirm-booked.ts +++ b/lib/emails/confirm-booked.ts @@ -11,8 +11,8 @@ dayjs.extend(localizedFormat); dayjs.extend(utc); dayjs.extend(timezone); -export default function createConfirmBookedEmail(calEvent: CalendarEvent, options: any = {}) { - return sendEmail(calEvent, { +export default function createConfirmBookedEmail(calEvent: CalendarEvent, uid: String, options: any = {}) { + return sendEmail(calEvent, uid, { provider: { transport: serverConfig.transport, from: serverConfig.from, @@ -21,7 +21,7 @@ export default function createConfirmBookedEmail(calEvent: CalendarEvent, option }); } -const sendEmail = (calEvent: CalendarEvent, { +const sendEmail = (calEvent: CalendarEvent, uid: String, { provider, }) => new Promise( (resolve, reject) => { @@ -33,8 +33,8 @@ const sendEmail = (calEvent: CalendarEvent, { to: `${calEvent.attendees[0].name} <${calEvent.attendees[0].email}>`, from: `${calEvent.organizer.name} <${from}>`, subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`, - html: html(calEvent), - text: text(calEvent), + html: html(calEvent, uid), + text: text(calEvent, uid), }, (error, info) => { if (error) { @@ -46,11 +46,10 @@ const sendEmail = (calEvent: CalendarEvent, { ) }); -//TODO: Get links -const cancelLink = "TODO"; -const rescheduleLink = "TODO"; +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) => { const inviteeStart: Dayjs = dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone); return `
@@ -65,10 +64,10 @@ const html = (calEvent: CalendarEvent) => { ${calEvent.description}

Need to change this event?
- Cancel: {cancelLink}
- Reschedule: {rescheduleLink} + Cancel: ${cancelLink}
+ Reschedule: ${rescheduleLink}
`; }; -const text = (evt: CalendarEvent) => html(evt).replace('
', "\n").replace(/<[^>]+>/g, ''); \ No newline at end of file +const text = (evt: CalendarEvent, uid: String) => html(evt, uid).replace('
', "\n").replace(/<[^>]+>/g, ''); \ No newline at end of file diff --git a/next.config.js b/next.config.js index e8b36e89..78aada02 100644 --- a/next.config.js +++ b/next.config.js @@ -4,6 +4,9 @@ const withTM = require('next-transpile-modules')(['react-timezone-select']); if ( ! process.env.EMAIL_FROM ) { console.warn('\x1b[33mwarn', '\x1b[0m', 'EMAIL_FROM environment variable is not set, this may indicate mailing is currently disabled. Please refer to the .env.example file.'); } +if (process.env.BASE_URL) { + process.env.NEXTAUTH_URL = process.env.BASE_URL + '/api/auth'; +} const validJson = (jsonString) => { try { diff --git a/pages/api/book/[user].ts b/pages/api/book/[user].ts index 7e8de525..970a33c1 100644 --- a/pages/api/book/[user].ts +++ b/pages/api/book/[user].ts @@ -74,8 +74,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }); if (!result.disableConfirmationEmail) { - createConfirmBookedEmail( - evt + await createConfirmBookedEmail( + evt, hashUID ); }