Skip to content

Commit c4a4082

Browse files
Make tabs dynamic depending on clinic status
1 parent 202728a commit c4a4082

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

app/routes/clinics.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,20 @@ module.exports = router => {
278278
return res.redirect('/clinics')
279279
}
280280

281+
let defaultFilter = 'remaining'
282+
let remainingCount = filterEventsByStatus(clinicData.events, 'remaining').length
283+
284+
if (clinicData.clinic?.status == 'scheduled') {
285+
defaultFilter = 'all'
286+
}
287+
else if (clinicData.clinic?.status == 'closed' || remainingCount == 0) {
288+
defaultFilter = 'complete'
289+
}
290+
291+
console.log(clinicData)
292+
281293
// Check filter from either URL param or query string
282-
const filter = req.params.filter || req.query.filter || 'remaining'
294+
const filter = req.params.filter || req.query.filter || defaultFilter
283295

284296
// Validate filter
285297
if (!VALID_FILTERS.includes(filter)) {

app/views/clinics/show.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{# {% set events = data.events | getClinicEvents(clinicId) %} #}
1414
{% set events = allEvents %}
1515

16-
{{ clinic | log }}
16+
{{ clinic | log("Clinic") }}
1717

1818
{% set clinicRiskType %}
1919
{% if clinic.riskLevels | length == 1 %}
@@ -44,13 +44,27 @@ <h1 class="nhsuk-heading-l">
4444

4545
{% set secondaryNavItems = [] %}
4646

47-
{# { id: 'scheduled', label: 'Scheduled' }, #}
48-
{% for filter in [
47+
{% set tabItems = [
4948
{ id: 'remaining', label: 'Remaining' },
5049
{ id: 'checked-in', label: 'Checked in' },
5150
{ id: 'complete', label: 'Complete' },
5251
{ id: 'all', label: 'All' }
5352
] %}
53+
54+
{% set remainingCount = events | filterEventsByStatus(filter.id) | length %}
55+
56+
{% if clinic.status == 'closed' or remainingCount == 0 %}
57+
{% set tabItems = [
58+
{ id: 'complete', label: 'Complete' },
59+
{ id: 'all', label: 'All' }
60+
] %}
61+
{% elseif clinic.status == "scheduled" %}
62+
{% set tabItems = [
63+
{ id: 'all', label: 'All' }
64+
] %}
65+
{% endif %}
66+
67+
{% for filter in tabItems %}
5468
{% set href -%}
5569
/clinics/{{ clinicId }}/{{ filter.id if filter.id !== 'remaining' }}
5670
{% endset %}
@@ -59,13 +73,14 @@ <h1 class="nhsuk-heading-l">
5973
href: href | trim,
6074
current: true if filter.id == status
6175
}) %}
62-
6376
{% endfor %}
6477

65-
{{ appSecondaryNavigation({
66-
visuallyHiddenTitle: "Secondary menu",
67-
items: secondaryNavItems
68-
}) }}
78+
{% if clinic.status !== "scheduled" %}
79+
{{ appSecondaryNavigation({
80+
visuallyHiddenTitle: "Secondary menu",
81+
items: secondaryNavItems
82+
}) }}
83+
{% endif %}
6984

7085
{# This probably shouldn't occur #}
7186
{% if filteredEvents.length === 0 %}

0 commit comments

Comments
 (0)