Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
(#119-2)New PlaceHolder in common/placeholders (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldblanco authored and jspaine committed Sep 25, 2017
1 parent 0ae77bb commit ed5d42b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
19 changes: 18 additions & 1 deletion common/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ const placeholders = [
label: 'Signature',
type: placeholderTypes.ATTACHMENT,
format: () => '<img src="cid:signature" alt="Signature" />'
}
},
{
id: 'items',
label: 'Donation Receipt Information',
type: placeholderTypes.EMAIL,
required: true,
format: value => table(value)
},
]

function getPagePlaceholders() {
Expand All @@ -59,6 +66,16 @@ function getPlaceholders(types) {
return placeholders
}

function table(value) {
let tableFinal = `<table><tr><td><p>Item</p></td><td><p>Value</p></td></tr>`
let total = 0
for (let i = 0; i < value.length; i++) {
tableFinal += `<tr><td><p>"${value[i].name}"</p></td><td><p>"${value[i].value}"</p></td></tr>`
total += value[i].value
}
return tableFinal + `<tr><td><p>Total:</p></td><td><p>"${total}"</p></td></tr></table>`
}

export {
placeholders as default,
placeholderTypes,
Expand Down
5 changes: 2 additions & 3 deletions server/lib/mail/mail-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -90,14 +89,14 @@ export default {
},

async sendReceipt(donation) {
const {donor} = donation
const {donor, items} = donation
const {firstName, lastName, email} = donor
const fullName = `${firstName} ${lastName}`
await this.send(
email,
fullName,
pageIdentifiers.DONATION_RECEIPT,
{firstName, lastName, fullName}
{firstName, lastName, fullName, items}
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions server/lib/seed/seed-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ export const pages = [{
<p>
<span class="ql-placeholder-content" data-id="organization" data-label="Foodbank Name"></span> 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 <span class="ql-placeholder-content" data-id="organization" data-label="Foodbank Name"></span>'s Privacy Policy that can be accessed at <span class="ql-placeholder-content" data-id="url" data-label="Foodbank Website"></span>.
</p>
<p>If you have any questions or concerns, feel free to contact us.</p>`
<p>If you have any questions or concerns, feel free to contact us.</p>
`
}, {
identifier: pageIdentifiers.DONATION_RECEIPT,
title: 'Donation Receipt',
type: pageTypes.EMAIL,
subject: '<p>Receipt for Your Donation to <span class="ql-placeholder-content" data-id="organization" data-label="Foodbank Name"></span></p>',
body: `<p>Dear <span class="ql-placeholder-content" data-id="fullName" data-label="User Full Name"></span>,</p>
`
<p>Here you have a list of the donations our organization recibed from you:</p>
<p><span class="ql-placeholder-content" data-id="items" data-label="Donation Receipt information" data-required="true"></span></p>`
}]

const commonFields = [
Expand Down

0 comments on commit ed5d42b

Please sign in to comment.