diff --git a/app.json b/app.json index 4b076a0..8fd4b71 100755 --- a/app.json +++ b/app.json @@ -12,7 +12,10 @@ "FEEDBACK_EMAIL_ADDRESS": { "required": true }, - "TEMPLATE_ID": { + "FEEDBACK_TEMPLATE_ID": { + "required": true + }, + "LINK_TEMPLATE_ID": { "required": true } }, diff --git a/config/routes.config.js b/config/routes.config.js index b7e8b7b..a86cc95 100644 --- a/config/routes.config.js +++ b/config/routes.config.js @@ -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 diff --git a/locales/en.json b/locales/en.json index 5ffb38c..db424b9 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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", @@ -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?" +} \ No newline at end of file diff --git a/routes/agreement-1/agreement-1-en.njk b/routes/agreement-1/agreement-1-en.njk index 8bb6afe..80ca164 100644 --- a/routes/agreement-1/agreement-1-en.njk +++ b/routes/agreement-1/agreement-1-en.njk @@ -9,7 +9,7 @@

- You can also email yourself a link to your answers. + You can also email yourself a link to your answers.

Research Participant Agreement

diff --git a/routes/agreement-1/agreement-1.controller.js b/routes/agreement-1/agreement-1.controller.js index 9eb1f5c..b2703b8 100644 --- a/routes/agreement-1/agreement-1.controller.js +++ b/routes/agreement-1/agreement-1.controller.js @@ -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) { @@ -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)}`, diff --git a/routes/email-link/email-link.controller.js b/routes/email-link/email-link.controller.js new file mode 100644 index 0000000..e2aaba5 --- /dev/null +++ b/routes/email-link/email-link.controller.js @@ -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 }), + ]) +} diff --git a/routes/email-link/email-link.njk b/routes/email-link/email-link.njk new file mode 100644 index 0000000..bcdbfdd --- /dev/null +++ b/routes/email-link/email-link.njk @@ -0,0 +1,19 @@ +{% extends "base.njk" %} + +{% block content %} + +{% if data.researcher_email %} +

{{ __('email-link.title') }}

+

+ {{ __('email-link.intro') }} {{data.researcher_email}}: +

+{% else %} +

{{ __('email-link.title-missing') }}

+

+ {{ __('email-link.missing') }} +

+{% endif %} + +{{data.link}} + +{% endblock %} diff --git a/routes/feedback-thanks/feedback-thanks.controller.js b/routes/feedback-thanks/feedback-thanks.controller.js index eea7ab0..f2641c9 100644 --- a/routes/feedback-thanks/feedback-thanks.controller.js +++ b/routes/feedback-thanks/feedback-thanks.controller.js @@ -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,