Skip to content

Commit

Permalink
Email link (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Oct 10, 2019
1 parent a696e23 commit ee7b49c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 16 deletions.
5 changes: 4 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"FEEDBACK_EMAIL_ADDRESS": {
"required": true
},
"TEMPLATE_ID": {
"FEEDBACK_TEMPLATE_ID": {
"required": true
},
"LINK_TEMPLATE_ID": {
"required": true
}
},
Expand Down
1 change: 1 addition & 0 deletions config/routes.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const routes = [
{ name: 'agreement-2', path: '/agreement-2' },
{ name: 'feedback', path: '/feedback' },
{ name: 'feedback-thanks', path: '/feedback-thanks' },
{ name: 'email-link', path: '/email-link' },
]

// note: you can define and export a custom configRoutes function here
Expand Down
12 changes: 8 additions & 4 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"landing-page.intro": "This service will generate customized forms and privacy statements for you based on the type of design research you're doing. Ask your policy colleagues if you need one.",
"landing-page.steps-lead-in": "Once you've made the forms and statements, take them to your department's ATIP office for approval. You also need to tell them:",
"landing-page.steps-atip": "",
"landing-page.steps-recruit": "how you're planning to recruit participants",
"landing-page.steps-tools": "which tools you'll be using (e.g. a voice recorder, notepad or camera)",
"landing-page.steps-recruit": "how you're planning to recruit participants",
"landing-page.steps-tools": "which tools you'll be using (e.g. a voice recorder, notepad or camera)",
"landing-page.steps-activities": "the activities you'll be asking the partipant to do",
"landing-page.leadin": "Choose from a:",
"landing-page.option1": "Make a consent form for intercept recruiting",
Expand Down Expand Up @@ -164,5 +164,9 @@
"form.what_went_wrong.desc": "Don't put any identifiable personal information in the text box.",
"feedback-thanks.title": "Thank you",
"feedback-thanks.intro": "Thank you for your feedback.",
"feedback_link_text": "Did something go wrong?"
}
"feedback_link_text": "Did something go wrong?",
"email-link.title": "Your link has been emailed",
"email-link.title-missing": "Your link has not been emailed",
"email-link.intro": "We have emailed your link to",
"email-link.missing": "We were unable to email your link - did you provide an email address?"
}
2 changes: 1 addition & 1 deletion routes/agreement-1/agreement-1-en.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<p>
You can also <a href= {{ data.link }}>email yourself a link to your answers</a>.
You can also <a target="_blank" href="email-link">email yourself a link to your answers</a>.
</p>

<h2>Research Participant Agreement</h2>
Expand Down
9 changes: 0 additions & 9 deletions routes/agreement-1/agreement-1.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const path = require('path')
const { getNextRoute, routeUtils } = require('./../../utils')
const nodePandoc = require('node-pandoc')
const i18n = require('i18n')
const url = require('url')

var callback = (err, result) => {
if (err) {
Expand Down Expand Up @@ -56,14 +55,6 @@ module.exports = app => {
}
queryParams[`${key}`] = data[`${key}`]
})
const link = url.format({
protocol: req.protocol,
host: req.get('Host'),
pathname: routeUtils.getRouteByName('questions-1').path,
query: queryParams,
})
data.link = link
console.log(`length of link: ${link.length}`)

res.render(
name + `-${i18n.getLocale(req)}`,
Expand Down
53 changes: 53 additions & 0 deletions routes/email-link/email-link.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const path = require('path')
const url = require('url')
const { getNextRoute, routeUtils, sendNotification } = require('./../../utils')

module.exports = app => {
const name = 'email-link'
const route = routeUtils.getRouteByName(name)

routeUtils.addViewPath(app, path.join(__dirname, './'))

app
.get(route.path, (req, res) => {
const data = routeUtils.getViewData(req, {}).data
var queryParams = {}
Object.keys(data)
.filter(
key =>
!['_csrf', 'what_went_wrong'].includes(key) &&
data[`${key}`] !== '',
)
.forEach(key => {
queryParams[`${key}`] = data[`${key}`]
})
const link = url.format({
protocol: req.protocol,
host: req.get('Host'),
pathname: routeUtils.getRouteByName('questions-1').path,
query: queryParams,
})
data.link = link
console.log(`length of link: ${link.length}`)
try {
sendNotification({
email: data.researcher_email,
templateId: process.env.LINK_TEMPLATE_ID,
options: {
personalisation: {
link,
},
},
})
} catch (err) {
console.log(`Error: ${err}`)
}
res.render(name, {
data,
nextRoute: getNextRoute(name).path,
})
})
.post(route.path, [
...routeUtils.getDefaultMiddleware({ schema: {}, name: name }),
])
}
19 changes: 19 additions & 0 deletions routes/email-link/email-link.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.njk" %}

{% block content %}

{% if data.researcher_email %}
<h1>{{ __('email-link.title') }}</h1>
<p>
{{ __('email-link.intro') }} {{data.researcher_email}}:
</p>
{% else %}
<h1>{{ __('email-link.title-missing') }}</h1>
<p>
{{ __('email-link.missing') }}
</p>
{% endif %}

{{data.link}}

{% endblock %}
2 changes: 1 addition & 1 deletion routes/feedback-thanks/feedback-thanks.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = app => {
try {
sendNotification({
email: process.env.FEEDBACK_EMAIL_ADDRESS,
templateId: process.env.TEMPLATE_ID,
templateId: process.env.FEEDBACK_TEMPLATE_ID,
options: {
personalisation: {
feedback: data.what_went_wrong,
Expand Down

0 comments on commit ee7b49c

Please sign in to comment.