Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to load tabs as pages in view licence #953

Merged
5 changes: 3 additions & 2 deletions app/controllers/licences.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ async function returnsRequired (request, h) {
return h.redirect(`/system/return-requirements/${session.id}/start-date`)
}

async function view (request, h) {
async function viewSummary (request, h) {
const { params: { id }, auth } = request

const data = await ViewLicenceService.go(id, auth)

return h.view('licences/view.njk', {
activeNavBar: 'search',
activeTab: 'summary',
...data
})
}

module.exports = {
noReturnsRequired,
returnsRequired,
view
viewSummary
}
4 changes: 2 additions & 2 deletions app/routes/licence.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const LicencesController = require('../controllers/licences.controller.js')
const routes = [
{
method: 'GET',
path: '/licences/{id}',
handler: LicencesController.view,
path: '/licences/{id}/summary',
handler: LicencesController.viewSummary,
options: {
auth: {
access: {
Expand Down
119 changes: 52 additions & 67 deletions app/views/licences/view.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,12 @@
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}

{% block breadcrumbs %}
{{
govukBackLink({
text: 'Go back to search',
href: "/licences"
})
}}
{{ govukBackLink({
text: 'Go back to search',
href: "/licences"
}) }}
{% endblock %}

{% set summaryTabHtml %}
{% include "licences/tabs/summary.njk" %}
{% endset %}

{% set contactDetailsTabHtml %}
{% endset %}

{% set returnsTabHtml %}
{% endset %}

{% set communicationsTabHtml %}
{% endset %}

{% set billsTabHtml %}
{% endset %}

{% set chargeInformationTabHtml %}
{% endset %}

{% block content %}
{% if warning %}
{{ govukWarningText({
Expand All @@ -52,48 +31,54 @@
<h1 class="govuk-heading-l">Licence number {{ licenceRef }}</h1>

{% if registeredTo %}
<p>Registered to <a href="/user/{{primaryUser.userId}}/status">{{ registeredTo }}</a></p>
<p>Registered to <a href="/user/{{ primaryUser.userId }}/status">{{ registeredTo }}</a></p>
{% endif %}

{{ govukTabs({
items: [
{
label: "Summary",
id: "summary",
panel: {
html: summaryTabHtml
}
}, {
label: "Contact details",
id: "contact-details",
panel: {
html: contactDetailsTabHtml
}
}, {
label: "Returns",
id: "returns",
panel: {
html: returnsTabHtml
}
}, {
label: "Communications",
id: "communications",
panel: {
html: communicationsTabHtml
}
}, {
label: "Bills",
id: "bills",
panel: {
html: billsTabHtml
}
} if roles and 'billing' in roles, {
label: "Charge information",
id: "charge-information",
panel: {
html: chargeInformationTabHtml
}
} if roles and 'view_charge_versions' in roles
]
}) }}
<div class="govuk-tabs">
<h2 class="govuk-tabs__title">
Contents
</h2>
<ul class="govuk-tabs__list">
<li class="govuk-tabs__list-item {% if activeTab === 'summary' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="summary">
Summary
</a>
</li>
<li class="govuk-tabs__list-item {% if activeTab === 'contact-details' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="contact-details">
Contact details
</a>
</li>
<li class="govuk-tabs__list-item {% if activeTab === 'returns' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="returns">
Returns
</a>
</li>
<li class="govuk-tabs__list-item {% if activeTab === 'communications' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="communications">
Communications
</a>
</li>
{% if roles and 'billing' in roles %}
<li class="govuk-tabs__list-item {% if activeTab === 'bills' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="bills">
Bills
</a>
</li>
{% endif %}
{% if roles and 'view_charge_versions' in roles %}
<li class="govuk-tabs__list-item {% if activeTab === 'charge-information' %} govuk-tabs__list-item--selected {% endif %}">
<a class="govuk-tabs__tab" href="charge-information">
Charge information
</a>
</li>
{% endif %}
</ul>

<div class="govuk-tabs__panel" id="{{ activeTab }}">
{% if activeTab === 'summary' %}
{% include "licences/tabs/summary.njk" %}
{% endif %}
</div>
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions test/controllers/licences.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ describe('Licences controller', () => {
})
})

describe('GET /licences/{id}/', () => {
describe('GET /licences/{id}/summary', () => {
beforeEach(async () => {
options = {
method: 'GET',
url: '/licences/7861814c-ca19-43f2-be11-3c612f0d744b',
url: '/licences/7861814c-ca19-43f2-be11-3c612f0d744b/summary',
auth: {
strategy: 'session',
credentials: { scope: ['billing'] }
Expand Down
Loading