Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/server/plugins/engine/components/UkAddressField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ export class UkAddressField extends FormComponent {
componentHint: component.hint,
componentTitle: component.title || controller.title,
step: args.actionArgs.step,
sourceUrl: args.sourceUrl
sourceUrl: args.sourceUrl,
inputSearchParams: {
postcode: request.payload.postcodeQueryField as string,
buildingName: request.payload.buildingNameQueryField as string
}
})
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/server/plugins/engine/views/components/ukaddressfield.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% from "govuk/components/hint/macro.njk" import govukHint %}
{% from "govuk/components/button/macro.njk" import govukButton %}
{% from "govuk/components/inset-text/macro.njk" import govukInsetText %}
{% from "govuk/components/input/macro.njk" import govukInput %}

{% macro UkAddressField(component) %}
{% set fieldset = component.model.fieldset %}
Expand Down Expand Up @@ -52,7 +53,31 @@
classes: "govuk-!-margin-top-2"
}) }}
{% else %}


{{ govukInput({
id: "postcodeQueryField",
name: "postcodeQueryField",
label: {
text: 'Postcode'
},
hint: {
text: 'For example, AA3 1AB'
}
}) }}

{{ govukInput({
id: "buildingNameQueryField",
name: "buildingNameQueryField",
label: {
text: 'Building name or number (optional)'
},
hint: {
text: 'For example, 15 or Prospect Cottage'
}
}) }}
<div class="govuk-button-group govuk-!-margin-bottom-0">

{{ govukButton({
text: "Find an address",
attributes: {
Expand Down
22 changes: 18 additions & 4 deletions src/server/plugins/postcode-lookup/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export function dispatch(request, h, initial) {
*/
const data = {
initial,
details: { postcodeQuery: '', buildingNameQuery: '' }
details: {
postcodeQuery: initial.inputSearchParams.postcode,
buildingNameQuery: initial.inputSearchParams.buildingName ?? ''
}
}

request.yar.set(JOURNEY_BASE_URL, data)
Expand All @@ -89,13 +92,14 @@ export function dispatch(request, h, initial) {
* @param {PostcodeLookupConfiguration} options - ordnance survey api key
*/
export function getRoutes(options) {
return [getRoute(), postRoute(options)]
return [getRoute(options), postRoute(options)]
}

/**
* @param {PostcodeLookupConfiguration} options
* @returns {ServerRoute<PostcodeLookupGetRequestRefs>}
*/
function getRoute() {
function getRoute(options) {
return {
method: 'GET',
path: JOURNEY_BASE_URL,
Expand All @@ -104,6 +108,11 @@ function getRoute() {
const { step } = query
const session = getSessionState(request)

if (session.details.postcodeQuery) {
// @ts-expect-error testioptudfiogfhfdkghfdkljghdfkljghnfd
return detailsPostHandler(request, h, options)
}

const model =
step === steps.manual
? manualViewModel(session)
Expand Down Expand Up @@ -171,7 +180,12 @@ async function detailsPostHandler(request, h, options) {
const { payload } = request
const session = getSessionState(request)
const { ordnanceSurveyApiKey: apiKey } = options
const { value: details, error } = detailsPayloadSchema.validate(payload)

const { value: details, error } = detailsPayloadSchema.validate(
session.details.postcodeQuery
? { ...session.details, step: 'details' }
: payload
)

let model

Expand Down
6 changes: 5 additions & 1 deletion src/server/plugins/postcode-lookup/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
* componentName: string
* componentTitle: string,
* componentHint?: string
* step?: string
* step?: string,
* inputSearchParams: {
* postcode: string,
* buildingName?: string
* }
* }} PostcodeLookupDispatchData
*/

Expand Down
Loading