Implemented link generation in mails
This commit is contained in:
		
							parent
							
								
									a3a4a65a80
								
							
						
					
					
						commit
						72a07770e8
					
				
					 3 changed files with 16 additions and 14 deletions
				
			
		|  | @ -11,8 +11,8 @@ dayjs.extend(localizedFormat); | ||||||
| dayjs.extend(utc); | dayjs.extend(utc); | ||||||
| dayjs.extend(timezone); | dayjs.extend(timezone); | ||||||
| 
 | 
 | ||||||
| export default function createConfirmBookedEmail(calEvent: CalendarEvent, options: any = {}) { | export default function createConfirmBookedEmail(calEvent: CalendarEvent, uid: String, options: any = {}) { | ||||||
|   return sendEmail(calEvent, { |   return sendEmail(calEvent, uid, { | ||||||
|     provider: { |     provider: { | ||||||
|       transport: serverConfig.transport, |       transport: serverConfig.transport, | ||||||
|       from: serverConfig.from, |       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, |   provider, | ||||||
| }) => new Promise( (resolve, reject) => { | }) => new Promise( (resolve, reject) => { | ||||||
| 
 | 
 | ||||||
|  | @ -33,8 +33,8 @@ const sendEmail = (calEvent: CalendarEvent, { | ||||||
|       to: `${calEvent.attendees[0].name} <${calEvent.attendees[0].email}>`, |       to: `${calEvent.attendees[0].name} <${calEvent.attendees[0].email}>`, | ||||||
|       from: `${calEvent.organizer.name} <${from}>`, |       from: `${calEvent.organizer.name} <${from}>`, | ||||||
|       subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`, |       subject: `Confirmed: ${calEvent.type} with ${calEvent.organizer.name} on ${inviteeStart.format('dddd, LL')}`, | ||||||
|       html: html(calEvent), |       html: html(calEvent, uid), | ||||||
|       text: text(calEvent), |       text: text(calEvent, uid), | ||||||
|     }, |     }, | ||||||
|     (error, info) => { |     (error, info) => { | ||||||
|       if (error) { |       if (error) { | ||||||
|  | @ -46,11 +46,10 @@ const sendEmail = (calEvent: CalendarEvent, { | ||||||
|   ) |   ) | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| //TODO: Get links
 | const html = (calEvent: CalendarEvent, uid: String) => { | ||||||
| const cancelLink = "TODO"; |   const cancelLink = process.env.BASE_URL + '/cancel/' + uid; | ||||||
| const rescheduleLink = "TODO"; |   const rescheduleLink = process.env.BASE_URL + '/reschedule/' + uid; | ||||||
| 
 | 
 | ||||||
| const html = (calEvent: CalendarEvent) => { |  | ||||||
|   const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone); |   const inviteeStart: Dayjs = <Dayjs>dayjs(calEvent.startTime).tz(calEvent.attendees[0].timeZone); | ||||||
|   return ` |   return ` | ||||||
|     <div> |     <div> | ||||||
|  | @ -65,10 +64,10 @@ const html = (calEvent: CalendarEvent) => { | ||||||
|       ${calEvent.description}<br /> |       ${calEvent.description}<br /> | ||||||
|       <br /> |       <br /> | ||||||
|       Need to change this event?<br /> |       Need to change this event?<br /> | ||||||
|       Cancel: {cancelLink}<br /> |       Cancel: <a href="${cancelLink}">${cancelLink}</a><br /> | ||||||
|       Reschedule: {rescheduleLink} |       Reschedule: <a href="${rescheduleLink}">${rescheduleLink}</a> | ||||||
|     </div> |     </div> | ||||||
|   `;
 |   `;
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const text = (evt: CalendarEvent) => html(evt).replace('<br />', "\n").replace(/<[^>]+>/g, ''); | const text = (evt: CalendarEvent, uid: String) => html(evt, uid).replace('<br />', "\n").replace(/<[^>]+>/g, ''); | ||||||
|  | @ -4,6 +4,9 @@ const withTM = require('next-transpile-modules')(['react-timezone-select']); | ||||||
| if ( ! process.env.EMAIL_FROM ) { | 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.'); |     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) => { | const validJson = (jsonString) => { | ||||||
|     try { |     try { | ||||||
|  |  | ||||||
|  | @ -74,8 +74,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     if (!result.disableConfirmationEmail) { |     if (!result.disableConfirmationEmail) { | ||||||
|         createConfirmBookedEmail( |         await createConfirmBookedEmail( | ||||||
|             evt |             evt, hashUID | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 nicolas
						nicolas