diff --git a/server/views/components/search-by-crn-or-name-form/macro.njk b/server/views/components/search-by-crn-or-name-form/macro.njk new file mode 100644 index 000000000..a652868fe --- /dev/null +++ b/server/views/components/search-by-crn-or-name-form/macro.njk @@ -0,0 +1,38 @@ +{% from "govuk/components/input/macro.njk" import govukInput %} +{% from "govuk/components/button/macro.njk" import govukButton %} + + +{# params - Type of Object - Description #} +{# uiStatus - String - Specific status the record would be in #} +{# type - String - Either "bookings" or "referrals" #} +{# basePath - String - URL used to define where form should be submitted to and the link the "Clear" should take the user too #} +{# crnOrName - String - Either a CRN or Name which the user would like to search for#} + + +{% macro searchByCrnOrNameForm(params) %} + {% set searchLabel = 'Search ' + params.uiStatus + ' ' + params.type + ' by CRN (case reference number)' %} + +
+ + {{ govukInput( + { + label: { + classes: 'govuk-label--m', + text: searchLabel + }, + hint: { + text: 'For example, XD7364CD' + }, + name: 'crn', + id: 'crn', + value: params.crnOrName + } + ) }} + +
+ {{ govukButton({ text: "Search", attributes: { id: 'search-button' }, preventDoubleClick: true}) }} + + Clear +
+
+{% endmacro %} diff --git a/server/views/components/search-by-crn-or-name-results/macro.njk b/server/views/components/search-by-crn-or-name-results/macro.njk new file mode 100644 index 000000000..f877005c3 --- /dev/null +++ b/server/views/components/search-by-crn-or-name-results/macro.njk @@ -0,0 +1,37 @@ +{%- from "moj/components/pagination/macro.njk" import mojPagination -%} + + +{# params - Type of Object - Description #} +{# errors - Object - Errors object from the view, soon to be removed #} +{# resultsHtml - String - HTML string containing the pagination and results. Currently parent view is responsible for this. We will look to moving that logic into this component #} +{# crnOrName - String - Either a CRN or Name which the user would like to search for #} +{# uiStatus - String - Specific status the record would be in #} +{# type - String - Either "bookings" or "referrals". #} + + +{% macro searchByCrnOrNameResults(params) %} + {% if params.errors.crn %} +

You have not entered any search terms

+ +

Enter a CRN. This can be found in nDelius.

+ + {% elif (params.resultsHtml| trim |length > 0) or (not params.crnOrName) %} + {{ params.resultsHtml | safe | trim | indent(8)}} + + {% else %} +

There are no results for ‘{{ params.crnOrName }}’ in {{ params.uiStatus }} {{ params.type }}.

+ +

Check the other lists.

+ + {% if params.type === 'bookings' %} + {% set type_name = 'booking' %} + {% elif params.type ==='referrals' %} + {% set type_name = 'referral' %} + {% endif %} + +

+ If the {{ type_name }} is missing from every list, contact + support for help. +

+ {% endif %} +{% endmacro %} diff --git a/server/views/temporary-accommodation/assessments/index.njk b/server/views/temporary-accommodation/assessments/index.njk index caa9aaca0..44f6d70f9 100644 --- a/server/views/temporary-accommodation/assessments/index.njk +++ b/server/views/temporary-accommodation/assessments/index.njk @@ -1,6 +1,7 @@ {% from "govuk/components/table/macro.njk" import govukTable %} {% from "govuk/components/button/macro.njk" import govukButton %} -{% from "govuk/components/input/macro.njk" import govukInput %} +{% from "../../components/search-by-crn-or-name-form/macro.njk" import searchByCrnOrNameForm%} +{% from "../../components/search-by-crn-or-name-results/macro.njk" import searchByCrnOrNameResults%} {% from "moj/components/sub-navigation/macro.njk" import mojSubNavigation %} {%- from "moj/components/pagination/macro.njk" import mojPagination -%} {% from "../../partials/breadCrumb.njk" import breadCrumb %} @@ -11,6 +12,24 @@ {% set pageTitle = title + " - " + applicationName %} {% set mainClasses = "app-container govuk-body" %} +{# TODO Move this HTML to the searchByCrnOrNameResult once HTML can be standardised between referrals and bookings #} +{% set resultsHtml %} + {% if (not context.errors.prn) and ((tableRows|length > 0) or (not crn)) %} +
+ {{ mojPagination(pagination) }} +
+ + {{ govukTable({ + firstCellIsHeader: true, + head: tableHeaders, + rows: tableRows + }) }} + + {{ mojPagination(pagination) | replace('Pagination navigation', 'Pagination navigation after results') }} + {% endif %} +{% endset %} + + {% block beforeContent %} {{ breadCrumb('Referrals', []) }} {% endblock %} @@ -44,58 +63,22 @@ {% endblock %}
-
- - {{ govukInput( - { - label: { - classes: 'govuk-label--m', - text: 'Search ' + uiStatus + ' referrals by CRN (case reference number)' - }, - hint: { - text: 'For example, XD7364CD' - }, - name: 'crn', - id: 'crn', - value: crn - } - ) }} - -
- {{ govukButton({ text: "Search", attributes: { id: 'search-button' }, preventDoubleClick: true}) }} - - Clear -
-
+ {{ searchByCrnOrNameForm({ + type: 'referrals', + basePath: basePath, + uiStatus: uiStatus, + crnOrName: crn + })}}
- {% if context.errors.crn %} -

You have not entered any search terms

- -

Enter a CRN. This can be found in nDelius.

- - {% elif (tableRows|length > 0) or (not crn) %} - -
- {{ mojPagination(pagination) }} -
- - {{ govukTable({ - firstCellIsHeader: true, - head: tableHeaders, - rows: tableRows - }) }} - - {{ mojPagination(pagination) | replace('Pagination navigation', 'Pagination navigation after results') }} - - {% else %} -

There are no results for ‘{{ crn }}’ in {{ uiStatus }} referrals.

- -

Check the other lists.

- -

If the referral is missing from every list, contact - support for help.

- {% endif %} + {{ searchByCrnOrNameResults({ + type: 'referrals', + errors: context.errors, + uiStatus: uiStatus, + tableRows: tableRows, + resultsHtml: resultsHtml, + crnOrName: crn + })}} {% block archivedLink %}
diff --git a/server/views/temporary-accommodation/booking-search/results.njk b/server/views/temporary-accommodation/booking-search/results.njk index aa6d0d34f..b0c6e4f4d 100644 --- a/server/views/temporary-accommodation/booking-search/results.njk +++ b/server/views/temporary-accommodation/booking-search/results.njk @@ -1,6 +1,6 @@ {% from "govuk/components/table/macro.njk" import govukTable %} -{% from "govuk/components/button/macro.njk" import govukButton %} -{% from "govuk/components/input/macro.njk" import govukInput %} +{% from "../../components/search-by-crn-or-name-form/macro.njk" import searchByCrnOrNameForm%} +{% from "../../components/search-by-crn-or-name-results/macro.njk" import searchByCrnOrNameResults%} {%- from "moj/components/sub-navigation/macro.njk" import mojSubNavigation -%} {%- from "moj/components/pagination/macro.njk" import mojPagination -%} @@ -9,6 +9,19 @@ {% set pageTitle = "View bookings - " + applicationName %} {% set mainClasses = "app-container govuk-body" %} +{# TODO Move this HTML to the searchByCrnOrNameResult once HTML can be standardised between referrals and bookings #} +{% set resultsHtml %} + {% if (not context.errors.prn) and ((response.data|length > 0) or (not crn)) %} + {{ govukTable({ + captionClasses: "govuk-table__caption--m", + head: tableHeadings, + rows: response.data + }) }} + + {{ mojPagination(pagination) }} + {% endif %} +{% endset %} + {% block beforeContent %} {{ breadCrumb('View bookings', []) }} {% endblock %} @@ -24,49 +37,20 @@ }) }}
-
- - {{ govukInput( - { - label: { - classes: 'govuk-label--m', - text: 'Search ' + uiStatus + ' bookings by CRN (case reference number)' - }, - hint: { - text: 'For example, XD7364CD' - }, - name: 'crn', - id: 'crn', - value: crn - } - ) }} - -
- {{ govukButton({ text: "Search", attributes: { id: 'search-button' }, preventDoubleClick: true}) }} - - Clear -
-
+ {{ searchByCrnOrNameForm({ + type: 'bookings', + basePath: paths.bookings.search[uiStatus].index(), + uiStatus: uiStatus, + crnOrName: crn + })}}
- {% if context.errors.crn %} -

You have not entered any search terms

+ {{ searchByCrnOrNameResults({ + type: 'bookings', + errors: context.errors, + resultsHtml: resultsHtml, + uiStatus: uiStatus, + crnOrName: crn + })}} -

Enter a CRN. This can be found in nDelius.

- {% elif (response.data|length > 0) or (not crn) %} - {{ govukTable({ - captionClasses: "govuk-table__caption--m", - head: tableHeadings, - rows: response.data - }) }} - - {{ mojPagination(pagination) }} - {% else %} -

There are no results for ‘{{ crn }}’ in {{ uiStatus }} bookings.

- -

Check the other lists.

- -

If the booking is missing from every list, contact - support for help.

- {% endif %} {% endblock %}