From 2906ea63e182cef89bc3fdeef19bd87fc8f289e2 Mon Sep 17 00:00:00 2001 From: Ronald Blanco Date: Thu, 21 Sep 2017 16:33:16 -0400 Subject: [PATCH] (#119-2)New PlaceHolder in common/placeholders --- common/placeholders.js | 27 +++++++++++++++++++++++++-- server/config/mailer.js | 1 + server/lib/mail/donation-receipt.js | 2 ++ server/lib/mail/mail-helpers.js | 4 ++-- server/lib/seed/seed-data.js | 6 ++++-- 5 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 server/lib/mail/donation-receipt.js diff --git a/common/placeholders.js b/common/placeholders.js index e230a763..d5d7caa2 100644 --- a/common/placeholders.js +++ b/common/placeholders.js @@ -1,7 +1,8 @@ const placeholderTypes = { PAGE: 'page', EMAIL: 'email', - ATTACHMENT: 'attachment' + ATTACHMENT: 'attachment', + TABLE: 'table' } const placeholders = [ @@ -32,7 +33,14 @@ const placeholders = [ label: 'Signature', type: placeholderTypes.ATTACHMENT, format: () => 'Signature' - } + }, + { + id: 'items', + label: 'Donation Receipt Information', + type: placeholderTypes.EMAIL, + required: true, + format: value => table(value) + }, ] function getPagePlaceholders() { @@ -47,6 +55,10 @@ function getAttachmentPlaceholders() { return placeholders.filter(pl => pl.type === placeholderTypes.ATTACHMENT) } +function getTablePlaceholders() { + return placeholders.filter(pl => pl.type === placeholderTypes.TABLE) +} + function getPlaceholders(types) { let placeholders = getPagePlaceholders() @@ -56,9 +68,20 @@ function getPlaceholders(types) { if (types.find(type => type === placeholderTypes.ATTACHMENT)) placeholders = placeholders.concat(getAttachmentPlaceholders()) + if (types.find(type => type === placeholderTypes.TABLE)) + placeholders = placeholders.concat(getTablePlaceholders()) + return placeholders } +function table(value) { + let tableFinal = `` + for (let i = 0; i < value.length; i++) { + tableFinal = tableFinal + `` + } + return tableFinal + `

NAME

VALUE

"${value[i].name}"

"${value[i].value}"

` +} + export { placeholders as default, placeholderTypes, diff --git a/server/config/mailer.js b/server/config/mailer.js index 42c4119f..ef81d463 100644 --- a/server/config/mailer.js +++ b/server/config/mailer.js @@ -49,6 +49,7 @@ export default async function sendEmail( path: '/v3/mail/send', body: mail.toJSON() }) + //console.log(content) //For the table placeholder check only. return sg.API(request) } diff --git a/server/lib/mail/donation-receipt.js b/server/lib/mail/donation-receipt.js new file mode 100644 index 00000000..f82f507f --- /dev/null +++ b/server/lib/mail/donation-receipt.js @@ -0,0 +1,2 @@ +import Donation from '../../models/donation' +import Donor from '../../models/donor' diff --git a/server/lib/mail/mail-helpers.js b/server/lib/mail/mail-helpers.js index c05b8d2e..9bc60759 100644 --- a/server/lib/mail/mail-helpers.js +++ b/server/lib/mail/mail-helpers.js @@ -15,7 +15,6 @@ export default { async send(toEmail, toName, identifier, bindings = null) { const settings = await Settings.findOne().lean() const mail = await mailGenerator(identifier, {...settings, ...bindings}) - if (!mail) return try { @@ -90,6 +89,7 @@ export default { }, async sendReceipt(donation) { + const {items} = donation const {donor} = donation const {firstName, lastName, email} = donor const fullName = `${firstName} ${lastName}` @@ -97,7 +97,7 @@ export default { email, fullName, pageIdentifiers.DONATION_RECEIPT, - {firstName, lastName, fullName} + {firstName, lastName, fullName, items} ) } } diff --git a/server/lib/seed/seed-data.js b/server/lib/seed/seed-data.js index 84411cab..aebd9c80 100644 --- a/server/lib/seed/seed-data.js +++ b/server/lib/seed/seed-data.js @@ -174,14 +174,16 @@ export const pages = [{

is committed to protecting your personal information by following responsible information handling practices and in keeping with privacy laws. All information remains strictly confidential as outlined by 's Privacy Policy that can be accessed at .

-

If you have any questions or concerns, feel free to contact us.

` +

If you have any questions or concerns, feel free to contact us.

+` }, { identifier: pageIdentifiers.DONATION_RECEIPT, title: 'Donation Receipt', type: pageTypes.EMAIL, subject: '

Receipt for Your Donation to

', body: `

Dear ,

-` +

Here you have a list of the donations our organization recibed from you:

+

` }] const commonFields = [