Skip to content

Commit

Permalink
(freeCodeCamp#119-2)New PlaceHolder in common/placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldblanco committed Sep 25, 2017
1 parent a739577 commit 2906ea6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
27 changes: 25 additions & 2 deletions common/placeholders.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const placeholderTypes = {
PAGE: 'page',
EMAIL: 'email',
ATTACHMENT: 'attachment'
ATTACHMENT: 'attachment',
TABLE: 'table'
}

const placeholders = [
Expand Down Expand Up @@ -32,7 +33,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 @@ -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()

Expand All @@ -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 = `<table><tr><td><p>NAME</p></td><td><p>VALUE</p></td></tr>`
for (let i = 0; i < value.length; i++) {
tableFinal = tableFinal + `<tr><td><p>"${value[i].name}"</p></td><td><p>"${value[i].value}"</p></td></tr>`
}
return tableFinal + `</table>`
}

export {
placeholders as default,
placeholderTypes,
Expand Down
1 change: 1 addition & 0 deletions server/config/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions server/lib/mail/donation-receipt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Donation from '../../models/donation'
import Donor from '../../models/donor'
4 changes: 2 additions & 2 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,15 @@ export default {
},

async sendReceipt(donation) {
const {items} = donation
const {donor} = 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 2906ea6

Please sign in to comment.