Skip to content

Commit 2cd7dcb

Browse files
Only let you add vaccinations once vaccines added (#512)
Fixes a bug if you try to add vaccinations before setting up vaccine batches.
1 parent cfed5f5 commit 2cd7dcb

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

app/routes/helpers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ module.exports = router => {
6767
res.redirect('/vaccines')
6868
});
6969

70+
router.get('/prototype-setup/add-vaccinations', (req, res) => {
71+
const data = req.session.data
72+
73+
const vaccinesAddedCount = data.vaccineStock.length
74+
75+
76+
res.render('prototype-setup/add-vaccinations', {
77+
vaccinesAddedCount
78+
})
79+
})
7080

7181
router.post('/prototype-setup/add-vaccinations', (req, res) => {
7282
const data = req.session.data

app/views/prototype-setup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h1 class="nhsuk-heading-l">Prototype data setup</h1>
1717
<ul class="nhsuk-list">
1818
<li><a href="/prototype-setup/setup-batches">Add batches for all vaccines</a></li>
1919
<li><a href="/prototype-setup/add-users">Add users</a></li>
20-
<li><a href="/prototype-setup/add-vaccinations">Record some vaccinations</a></li>
20+
<li><a href="/prototype-setup/add-vaccinations">Add vaccinations</a></li>
2121
</ul>
2222

2323
</div>

app/views/prototype-setup/add-vaccinations.html

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,34 @@
1717
<div class="nhsuk-grid-row">
1818
<div class="nhsuk-grid-column-two-thirds">
1919

20-
<form action="/prototype-setup/add-vaccinations" method="post" novalidate>
21-
22-
{{ input({
23-
name: "numberOfVaccinationsToAdd",
24-
label: {
25-
text: "How many vaccinations would you like to add?",
26-
isPageHeading: true,
27-
classes: "nhsuk-label--l"
28-
},
29-
classes: "nhsuk-input--width-5",
30-
inputmode: "numeric"
31-
}) }}
32-
33-
{{ button({
34-
text: "Add vaccinations"
35-
}) }}
36-
37-
</form>
20+
<h1 class="nhsuk-heading-l">Add vaccinations</h1>
21+
22+
{% if vaccinesAddedCount > 0 %}
23+
24+
<p>This adds random vaccinations, distributed across the current vaccines and batches set up, in order to test the <a href="/records">Records</a> section.</p>
25+
26+
<form action="/prototype-setup/add-vaccinations" method="post" novalidate>
27+
28+
{{ input({
29+
name: "numberOfVaccinationsToAdd",
30+
label: {
31+
text: "How many would you like to add?",
32+
isPageHeading: true,
33+
classes: "nhsuk-label--m"
34+
},
35+
classes: "nhsuk-input--width-5",
36+
inputmode: "numeric"
37+
}) }}
38+
39+
{{ button({
40+
text: "Add vaccinations"
41+
}) }}
42+
43+
</form>
44+
45+
{% else %}
46+
<p>You need to add or setup some batches before vaccinations can be added.</p>
47+
{% endif %}
3848

3949
</div>
4050
</div>

0 commit comments

Comments
 (0)