Skip to content

Commit

Permalink
#53 Prepopulates appointments section with saved data
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerdak committed Oct 10, 2017
1 parent b88681f commit 0f030f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
29 changes: 25 additions & 4 deletions src/controllers/appointments.js
Original file line number Diff line number Diff line change
@@ -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,
});
});
};

Expand Down
30 changes: 15 additions & 15 deletions src/views/appointments.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@

<ol>
<li> What's your home number?
<input type="text" name="telephone" placeholder="Your number">
<input type="text" name="telephone" value="{{data.telephone}}" placeholder="Your number">
</li>
<li> What's your mobile number?
<input type="text" name="mobile" placeholder="Your number">
<input type="text" name="mobile" placeholder="Your number" value="{{data.mobile}}" >
</li>
<li> What's your email address?
<input type="text" name="email" placeholder="Your email">
<input type="text" name="email" placeholder="Your email" value="{{data.email}}">
</li>
<li> How would you like us to contact you?
<input type="checkbox" name="contact_preference" value="whatsapp" aria-label="whatsapp" placeholder='Whatsapp'>Whatsapp</input>
<input type="checkbox" name="contact_preference" aria-label="email" value="email" placeholder='Email'>Email</input>
<input type="checkbox" name="contact_preference" aria-label="call" value="call" placeholder='Call'>Call</input>
<input type="checkbox" name="contact_preference" aria-label="Post" value="post" placeholder='post'>Post</input>
<input type="checkbox" name="contact_preference" value="whatsapp" {{#if checked.contactBy.whatsapp}}checked{{/if}} aria-label="whatsapp" placeholder='Whatsapp'>Whatsapp</input>
<input type="checkbox" name="contact_preference" aria-label="email" value="email" placeholder='Email' {{#if checked.contactBy.email}}checked{{/if}}>Email</input>
<input type="checkbox" name="contact_preference" aria-label="call" value="call" placeholder='Call' {{#if checked.contactBy.call}}checked{{/if}}>Call</input>
<input type="checkbox" name="contact_preference" aria-label="Post" value="post" placeholder='post' {{#if checked.contactBy.post}}checked{{/if}}>Post</input>
</li>
<li>
Do you have a preference on your new support worker?
<input type="checkbox" name="gender" value="male" aria-label='male worker'> Male </input>
<input type="checkbox" name="gender" value="female" aria-label='female worker'> female </input>
<input type="checkbox" name="gender" value="male" aria-label='male worker' {{#if checked.worker.male}}checked{{/if}}> Male </input>
<input type="checkbox" name="gender" value="female" aria-label='female worker' {{#if checked.worker.female}}checked{{/if}}> female </input>
</li>
<li>
Do you have a preferred appointment time?
<input type="checkbox" name="time" value="am" aria-label='morning appointment'> AM </input>
<input type="checkbox" name="time" value="pm" aria-label='afternoon appointment'> PM </input>
<input type="checkbox" name="time" value="am" aria-label='morning appointment' {{#if checked.time.am}} checked{{/if}}> AM </input>
<input type="checkbox" name="time" value="pm" aria-label='afternoon appointment' {{#if checked.time.pm}} checked{{/if}}> PM </input>
</li>
<li>
Would you like a parent/guardian at the appointments?
<input type="radio" name="parent" value="yes"> Yes </input>
<input type="radio" name="parent" value="no"> No </input>
<input type="radio" name="parent" value="yes" {{#if data.parent_involved}}checked{{/if}}> Yes </input>
<input type="radio" name="parent" value="no" {{#unless data.parent_involved}}checked{{/unless}}> No </input>
</li>
<li>
Do you have any concerns about moving to a different service and if so, what are they?
<input type="text" name="concerns" placeholder="Write here please" aria-label='please let us know your concerns'>
<input type="text" name="concerns" placeholder="Write here please" aria-label='please let us know your concerns' value="{{data.concerns}}">
</li>
<li>
I hope that when I leave I am...
<input type="text" name="hope" placeholder="Write here please" aria-label='please let us know your wishes for when you leave'>
<input type="text" name="hope" placeholder="Write here please" aria-label='please let us know your wishes for when you leave' value="{{data.hope}}">
</li>
</ol>
<button type="submit">OK</button>
Expand Down

0 comments on commit 0f030f5

Please sign in to comment.