Skip to content

Commit 5169ddd

Browse files
Add error messages to apply journey (#350)
This adds some error messages to the pharmacy select page: Pharmacy already onboarded: ![Screenshot 2025-06-13 at 14 19 49](https://github.com/user-attachments/assets/0118b2da-b71e-438a-8473-210a8186c9eb) Pharmacy not selected: ![Screenshot 2025-06-13 at 14 11 39](https://github.com/user-attachments/assets/ef316fe7-3313-4aa8-b42f-4f915f0fda15)
1 parent feef124 commit 5169ddd

File tree

2 files changed

+82
-32
lines changed

2 files changed

+82
-32
lines changed

app/routes/apply.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
module.exports = router => {
22

3+
router.get('/apply/start', (req, res) => {
4+
let errors = []
5+
6+
const error = req.query.error
7+
8+
if (error === "no-pharmacy") {
9+
errors.push({
10+
text: "Select pharmacy",
11+
href: "#organisation-code"
12+
})
13+
} else if (error === "existing-account") {
14+
errors.push({
15+
text: "This pharmacy already has access to the service.",
16+
href: "#organisation-code"
17+
})
18+
}
19+
20+
res.render('apply/start', {
21+
errors
22+
})
23+
})
24+
25+
26+
router.post('/apply/answer-pharmacy', (req, res) => {
27+
const data = req.session.data
28+
const organisationCode = data.organisationCode
29+
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
30+
31+
if (!organisation) {
32+
res.redirect('/apply/start?error=no-pharmacy');
33+
} else if (organisation.id === "FA424") {
34+
res.redirect('/apply/start?error=existing-account');
35+
} else {
36+
res.redirect('/apply/check-pharmacy')
37+
}
38+
39+
res.render('apply/start', {
40+
errors
41+
})
42+
43+
})
44+
345

446
// Show organisation check page
547
router.get('/apply/check-pharmacy', (req, res) => {

app/views/apply/start.html

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,53 @@
1717
<div class="nhsuk-grid-row">
1818
<div class="nhsuk-grid-column-two-thirds">
1919

20+
{% if (errors | length) > 0 %}
21+
{{ errorSummary({
22+
titleText: "There is a problem",
23+
errorList: errors
24+
}) }}
25+
{% endif %}
26+
2027
<h1 class="nhsuk-heading-l">{{ pageName }}</h1>
2128

2229
<p>You can sign up if you are a community pharmacy offering NHS vaccinations.</p>
2330

2431
<p>If you need to sign up for more than 1 pharmacy, you can use this form multiple times or <a href="/contact">contact us</a>.</li>
2532
</p>
2633

27-
<form action="/apply/check-pharmacy" method="post">
28-
29-
30-
<div class="nhsuk-form-group">
31-
<h2 class="nhsuk-label-wrapper">
32-
<label class="nhsuk-label nhsuk-label--m nhsuk-u-margin-bottom-1" for="organisationCode">
33-
Find your pharmacy
34-
</label>
35-
</h2>
36-
<div class="nhsuk-hint" id="organisationName-hint">
37-
Search by name or ODS code
38-
</div>
39-
<select class="nhsuk-select" id="organisationCode" name="organisationCode"
40-
data-module="autocomplete" data-autoselect="" data-display-menu="" data-min-length="" data-show-all-values="" data-show-no-options-found="">
41-
<option selected value=""></option>
42-
43-
{% set options = [] %}
44-
45-
{% for organisation in data.organisations %}
46-
{% if organisation.type == "Community Pharmacy" %}
47-
{% set options = (options.push({
48-
label: organisation.name + ", " + organisation.address.line1 + ", " + (organisation.address.postcode | upper) + " (" + organisation.id + ")",
49-
value: organisation.id
50-
}), options) %}
51-
{% endif %}
52-
{% endfor %}
53-
54-
{% for option in (options | sort(false, true, "label")) %}
55-
<option value="{{ option.value }}">{{ option.label }}</option>
56-
{% endfor %}
57-
</select>
58-
</div>
34+
<form action="/apply/answer-pharmacy" method="post">
35+
36+
{% set options = [] %}
37+
{% set items = [{ text: "", value: ""}] %}
38+
39+
{% for organisation in data.organisations %}
40+
{% if organisation.type == "Community Pharmacy" %}
41+
{% set items = (items.push({
42+
text: organisation.name + ", " + organisation.address.line1 + ", " + (organisation.address.postcode | upper) + " (" + organisation.id + ")",
43+
value: organisation.id,
44+
selected: (organisation.id === data.organisationCode)
45+
}), items) %}
46+
{% endif %}
47+
{% endfor %}
48+
49+
{{ select({
50+
id: "organisation-code",
51+
name: "organisationCode",
52+
label: {
53+
text: "Find your pharmacy",
54+
classes: "nhsuk-label--m nhsuk-u-margin-bottom-1"
55+
},
56+
hint: {
57+
text: "Search by name or ODS code"
58+
},
59+
items: items,
60+
errorMessage: {
61+
text: (errors | first).text
62+
} if (errors | length),
63+
attributes: {
64+
"data-module": "autocomplete"
65+
}
66+
}) }}
5967

6068
{{ button({
6169
"text": "Continue"

0 commit comments

Comments
 (0)