hof-behaviour-address-lookup
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,2 +0,2 @@ | ||
/* eslint max-len: 0 */ | ||
/* eslint max-len: 0, no-process-env: 0 */ | ||
@@ -8,3 +8,3 @@ 'use strict'; | ||
CHANGE: 'Change', | ||
POSTCODE_LABEL: 'Postcode', | ||
POSTCODE_ENTERED: 'Postcode you entered: ', | ||
POSTCODE_ERROR: { | ||
@@ -14,5 +14,6 @@ 'not-found': 'Sorry – we couldn’t find any addresses for that postcode, enter your address manually', | ||
}, | ||
ENTER_MANUALLY: 'Enter address manually', | ||
POSTCODE_API: { | ||
hostname: 'https://postcodeinfo.service.justice.gov.uk', | ||
authorization: '', | ||
authorization: process.env.POSTCODE_AUTH || '', | ||
paths: { | ||
@@ -19,0 +20,0 @@ lookup: 'addresses', |
@@ -10,4 +10,13 @@ 'use strict'; | ||
const getFields = key => ({ | ||
const conditionalTranslate = (key, t) => { | ||
let result = t(key); | ||
if (result === key) { | ||
result = null; | ||
} | ||
return result; | ||
}; | ||
const getFields = (key, t) => ({ | ||
[`${key}-postcode`]: { | ||
label: conditionalTranslate(`fields.${key}-postcode.label`, t) || 'Postcode', | ||
mixin: 'input-text-code', | ||
@@ -37,3 +46,4 @@ validate: ['required', 'postcode'], | ||
postcode: { | ||
fields: [`${key}-postcode`] | ||
fields: [`${key}-postcode`], | ||
template: 'postcode' | ||
}, | ||
@@ -54,4 +64,2 @@ lookup: { | ||
const getStep = req => req.form.options.subSteps[req.query.step]; | ||
module.exports = config => { | ||
@@ -68,7 +76,2 @@ const addressKey = config.addressKey; | ||
return superclass => class extends superclass { | ||
constructor(options) { | ||
options.fields = getFields(addressKey); | ||
options.subSteps = getConfig(addressKey); | ||
super(options); | ||
} | ||
@@ -78,5 +81,7 @@ configure(req, res, callback) { | ||
req.query.step = req.query.step || 'postcode'; | ||
const step = getStep(req); | ||
const subSteps = getConfig(addressKey); | ||
const step = subSteps[req.query.step]; | ||
Object.assign(req.form.options, { | ||
fields: _.pick(this.options.fields, step.fields), | ||
subSteps, | ||
fields: _.pick(getFields(addressKey, req.translate), step.fields), | ||
apiError: null | ||
@@ -109,3 +114,3 @@ }); | ||
req.sessionModel.unset([ | ||
`${addressKey}-postcode`, | ||
addressKey, | ||
`${addressKey}-postcodeApiMeta` | ||
@@ -135,4 +140,4 @@ ]); | ||
const section = this.options.route.replace(/^\//, ''); | ||
const editLink = req.translate('pages.address-lookup.edit', { default: null }) || defaults.CHANGE; | ||
const cantFind = req.translate('pages.address-lookup.cantfind', { default: null }) || defaults.CANT_FIND; | ||
const editLink = conditionalTranslate('pages.address-lookup.edit', req.translate) || defaults.CHANGE; | ||
const cantFind = conditionalTranslate('pages.address-lookup.cantfind', req.translate) || defaults.CANT_FIND; | ||
@@ -148,3 +153,3 @@ let postcodeApiMessageKey; | ||
const key = `pages.address-lookup.postcode-api.${postcodeApiMessageKey}`; | ||
postcodeError = req.translate(key, req.translate, { default: null }) || | ||
postcodeError = conditionalTranslate(key, req.translate) || | ||
defaults.POSTCODE_ERROR[postcodeApiMessageKey]; | ||
@@ -154,4 +159,6 @@ } | ||
return Object.assign({}, locals, { | ||
postcodeLabel: req.translate(`fields.${addressKey}-postcode.label`, { default: null }) || | ||
defaults.POSTCODE_LABEL, | ||
postcodeEntered: conditionalTranslate('pages.address-lookup.postcode-entered', req.translate) || | ||
defaults.POSTCODE_ENTERED, | ||
enterManually: conditionalTranslate('pages.address.lookup.enter-manually', req.translate) || | ||
defaults.ENTER_MANUALLY, | ||
route: this.options.route, | ||
@@ -158,0 +165,0 @@ editLink, |
{ | ||
"name": "hof-behaviour-address-lookup", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A HOF Behaviour for a multi-step postcode lookup", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23571
22
476