From 0f030f5e7f5dc2471fc81de96e67716a722f57e2 Mon Sep 17 00:00:00 2001 From: Dakshina Scott Date: Tue, 10 Oct 2017 16:45:28 +0100 Subject: [PATCH] #53 Prepopulates appointments section with saved data --- src/controllers/appointments.js | 29 +++++++++++++++++++++++++---- src/views/appointments.hbs | 30 +++++++++++++++--------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/controllers/appointments.js b/src/controllers/appointments.js index 138facd..94ed114 100644 --- a/src/controllers/appointments.js +++ b/src/controllers/appointments.js @@ -1,9 +1,30 @@ -const { saveAppointments, saveClosing } = require('../model/form_queries'); +const { + saveAppointments, + saveClosing, + getSection, +} = require('../model/form_queries'); exports.get = (req, res) => { - res.render('appointments', { - activePage: { appointments: true }, - pageTitle: 'Your appointment', + Promise.all([ + getSection(req.session.id, 'appointments'), + getSection(req.session.id, 'closing')]).then((dataArr) => { + const data = Object.assign(dataArr[0], dataArr[1]); + // for ticking correct checkbox based on previously saved answer + const contactMethods = data.contact_preference.replace(/\{|\}/g, '').split(','); + let checked = { + contactBy: {}, + worker: { [data.worker_preferences]: true }, + time: { [data.appointment_preferences]: true }, + }; + contactMethods.forEach((method) => { + checked.contactBy[method] = true; + }); + res.render('appointments', { + activePage: { appointments: true }, + pageTitle: 'Your appointment', + data, + checked, + }); }); }; diff --git a/src/views/appointments.hbs b/src/views/appointments.hbs index 72b5b66..5aa24ec 100644 --- a/src/views/appointments.hbs +++ b/src/views/appointments.hbs @@ -4,42 +4,42 @@
  1. What's your home number? - +
  2. What's your mobile number? - +
  3. What's your email address? - +
  4. How would you like us to contact you? - Whatsapp - Email - Call - Post + Whatsapp + Email + Call + Post
  5. Do you have a preference on your new support worker? - Male - female + Male + female
  6. Do you have a preferred appointment time? - AM - PM + AM + PM
  7. Would you like a parent/guardian at the appointments? - Yes - No + Yes + No
  8. Do you have any concerns about moving to a different service and if so, what are they? - +
  9. I hope that when I leave I am... - +