@defra/forms-engine-plugin 5.0.0-alpha.8 → 5.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.server/server/constants.d.ts +1 -0
- package/.server/server/constants.js +2 -1
- package/.server/server/constants.js.map +1 -1
- package/.server/server/plugins/engine/components/ComponentCollection.js +10 -6
- package/.server/server/plugins/engine/components/ComponentCollection.js.map +1 -1
- package/.server/server/plugins/engine/components/DatePartsField.d.ts +4 -2
- package/.server/server/plugins/engine/components/DatePartsField.js +14 -11
- package/.server/server/plugins/engine/components/DatePartsField.js.map +1 -1
- package/.server/server/plugins/engine/components/DeclarationField.d.ts +4 -2
- package/.server/server/plugins/engine/components/DeclarationField.js +5 -3
- package/.server/server/plugins/engine/components/DeclarationField.js.map +1 -1
- package/.server/server/plugins/engine/components/EastingNorthingField.d.ts +24 -2
- package/.server/server/plugins/engine/components/EastingNorthingField.js +93 -52
- package/.server/server/plugins/engine/components/EastingNorthingField.js.map +1 -1
- package/.server/server/plugins/engine/components/FormComponent.d.ts +4 -1
- package/.server/server/plugins/engine/components/FormComponent.js +3 -0
- package/.server/server/plugins/engine/components/FormComponent.js.map +1 -1
- package/.server/server/plugins/engine/components/LatLongField.d.ts +24 -2
- package/.server/server/plugins/engine/components/LatLongField.js +85 -46
- package/.server/server/plugins/engine/components/LatLongField.js.map +1 -1
- package/.server/server/plugins/engine/components/LocationFieldHelpers.d.ts +3 -2
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js +10 -11
- package/.server/server/plugins/engine/components/LocationFieldHelpers.js.map +1 -1
- package/.server/server/plugins/engine/components/MonthYearField.d.ts +4 -2
- package/.server/server/plugins/engine/components/MonthYearField.js +16 -13
- package/.server/server/plugins/engine/components/MonthYearField.js.map +1 -1
- package/.server/server/plugins/engine/components/PaymentField.d.ts +1 -0
- package/.server/server/plugins/engine/components/PaymentField.js +9 -5
- package/.server/server/plugins/engine/components/PaymentField.js.map +1 -1
- package/.server/server/plugins/engine/components/UkAddressField.js +22 -7
- package/.server/server/plugins/engine/components/UkAddressField.js.map +1 -1
- package/.server/server/plugins/engine/components/YesNoField.d.ts +3 -2
- package/.server/server/plugins/engine/components/YesNoField.js +5 -3
- package/.server/server/plugins/engine/components/YesNoField.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/components.js +1 -2
- package/.server/server/plugins/engine/components/helpers/components.js.map +1 -1
- package/.server/server/plugins/engine/components/helpers/index.d.ts +7 -0
- package/.server/server/plugins/engine/components/helpers/index.js +13 -1
- package/.server/server/plugins/engine/components/helpers/index.js.map +1 -1
- package/.server/server/plugins/engine/helpers.d.ts +21 -2
- package/.server/server/plugins/engine/helpers.js +43 -5
- package/.server/server/plugins/engine/helpers.js.map +1 -1
- package/.server/server/plugins/engine/i18n/createFormTranslator.d.ts +4 -4
- package/.server/server/plugins/engine/i18n/createFormTranslator.js +27 -5
- package/.server/server/plugins/engine/i18n/createFormTranslator.js.map +1 -1
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.d.ts +1 -1
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.js +9 -0
- package/.server/server/plugins/engine/i18n/extractBaseTranslations.js.map +1 -1
- package/.server/server/plugins/engine/i18n/form.d.ts +13 -0
- package/.server/server/plugins/engine/i18n/form.js +35 -0
- package/.server/server/plugins/engine/i18n/form.js.map +1 -0
- package/.server/server/plugins/engine/i18n/languages.d.ts +10 -0
- package/.server/server/plugins/engine/i18n/languages.js +19 -0
- package/.server/server/plugins/engine/i18n/languages.js.map +1 -0
- package/.server/server/plugins/engine/i18n/translations/cy.json +3 -1
- package/.server/server/plugins/engine/i18n/translations/en-GB.json +3 -1
- package/.server/server/plugins/engine/index.d.ts +3 -0
- package/.server/server/plugins/engine/index.js +3 -0
- package/.server/server/plugins/engine/index.js.map +1 -1
- package/.server/server/plugins/engine/models/FormModel.d.ts +0 -4
- package/.server/server/plugins/engine/models/FormModel.js +9 -15
- package/.server/server/plugins/engine/models/FormModel.js.map +1 -1
- package/.server/server/plugins/engine/models/SummaryViewModel.js +2 -1
- package/.server/server/plugins/engine/models/SummaryViewModel.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js +2 -1
- package/.server/server/plugins/engine/outputFormatters/human/v1.js.map +1 -1
- package/.server/server/plugins/engine/outputFormatters/machine/v2.d.ts +2 -0
- package/.server/server/plugins/engine/outputFormatters/machine/v2.js +2 -0
- package/.server/server/plugins/engine/outputFormatters/machine/v2.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.d.ts +1 -1
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js +2 -2
- package/.server/server/plugins/engine/pageControllers/FileUploadPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.d.ts +1 -1
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js +2 -2
- package/.server/server/plugins/engine/pageControllers/QuestionPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js +6 -3
- package/.server/server/plugins/engine/pageControllers/SummaryPageController.js.map +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/submission.d.ts +1 -1
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js +3 -3
- package/.server/server/plugins/engine/pageControllers/helpers/submission.js.map +1 -1
- package/.server/server/plugins/engine/types/schema.js +1 -0
- package/.server/server/plugins/engine/types/schema.js.map +1 -1
- package/.server/server/plugins/engine/types.d.ts +1 -0
- package/.server/server/plugins/engine/types.js.map +1 -1
- package/.server/server/plugins/engine/views/components/ukaddressfield.html +1 -1
- package/.server/server/plugins/nunjucks/filters/applyUrlParam.d.ts +9 -0
- package/.server/server/plugins/nunjucks/filters/applyUrlParam.js +17 -0
- package/.server/server/plugins/nunjucks/filters/applyUrlParam.js.map +1 -0
- package/.server/server/plugins/nunjucks/filters/applyUrlParam.test.js +17 -0
- package/.server/server/plugins/nunjucks/filters/applyUrlParam.test.js.map +1 -0
- package/.server/server/plugins/nunjucks/filters/field.d.ts +1 -1
- package/.server/server/plugins/nunjucks/filters/index.d.ts +1 -0
- package/.server/server/plugins/nunjucks/filters/index.js +1 -0
- package/.server/server/plugins/nunjucks/filters/index.js.map +1 -1
- package/.server/server/plugins/payment/helper.d.ts +11 -1
- package/.server/server/plugins/payment/helper.js +18 -2
- package/.server/server/plugins/payment/helper.js.map +1 -1
- package/.server/server/plugins/payment/helper.test.js +2 -1
- package/.server/server/plugins/payment/helper.test.js.map +1 -1
- package/.server/server/plugins/payment/service.d.ts +2 -1
- package/.server/server/plugins/payment/service.js +5 -2
- package/.server/server/plugins/payment/service.js.map +1 -1
- package/.server/server/plugins/payment/service.test.js +7 -3
- package/.server/server/plugins/payment/service.test.js.map +1 -1
- package/.server/server/plugins/payment/types.d.ts +4 -0
- package/.server/server/plugins/payment/types.js +1 -0
- package/.server/server/plugins/payment/types.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/models/index.d.ts +247 -3
- package/.server/server/plugins/postcode-lookup/models/index.js +86 -33
- package/.server/server/plugins/postcode-lookup/models/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/routes/index.d.ts +15 -1
- package/.server/server/plugins/postcode-lookup/routes/index.js +47 -15
- package/.server/server/plugins/postcode-lookup/routes/index.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/routes/index.test.js +84 -0
- package/.server/server/plugins/postcode-lookup/routes/index.test.js.map +1 -0
- package/.server/server/plugins/postcode-lookup/types.d.ts +12 -0
- package/.server/server/plugins/postcode-lookup/types.js +6 -1
- package/.server/server/plugins/postcode-lookup/types.js.map +1 -1
- package/.server/server/plugins/postcode-lookup/views/postcode-lookup-details.html +3 -3
- package/package.json +2 -1
- package/src/server/constants.js +2 -1
- package/src/server/plugins/engine/components/ComponentCollection.ts +15 -9
- package/src/server/plugins/engine/components/DatePartsField.ts +16 -12
- package/src/server/plugins/engine/components/DeclarationField.ts +6 -4
- package/src/server/plugins/engine/components/EastingNorthingField.ts +156 -88
- package/src/server/plugins/engine/components/FormComponent.ts +4 -1
- package/src/server/plugins/engine/components/LatLongField.ts +129 -57
- package/src/server/plugins/engine/components/LocationFieldHelpers.ts +14 -11
- package/src/server/plugins/engine/components/MonthYearField.ts +16 -11
- package/src/server/plugins/engine/components/PaymentField.ts +9 -4
- package/src/server/plugins/engine/components/UkAddressField.ts +29 -6
- package/src/server/plugins/engine/components/YesNoField.ts +6 -5
- package/src/server/plugins/engine/components/helpers/components.ts +1 -2
- package/src/server/plugins/engine/components/helpers/index.ts +19 -0
- package/src/server/plugins/engine/helpers.ts +51 -5
- package/src/server/plugins/engine/i18n/createFormTranslator.ts +43 -12
- package/src/server/plugins/engine/i18n/extractBaseTranslations.ts +7 -1
- package/src/server/plugins/engine/i18n/form.ts +54 -0
- package/src/server/plugins/engine/i18n/languages.ts +19 -0
- package/src/server/plugins/engine/i18n/translations/cy.json +3 -1
- package/src/server/plugins/engine/i18n/translations/en-GB.json +3 -1
- package/src/server/plugins/engine/index.ts +6 -0
- package/src/server/plugins/engine/models/FormModel.ts +9 -15
- package/src/server/plugins/engine/models/SummaryViewModel.ts +2 -1
- package/src/server/plugins/engine/outputFormatters/human/v1.ts +2 -1
- package/src/server/plugins/engine/outputFormatters/machine/v2.ts +3 -0
- package/src/server/plugins/engine/pageControllers/FileUploadPageController.ts +2 -2
- package/src/server/plugins/engine/pageControllers/QuestionPageController.ts +2 -2
- package/src/server/plugins/engine/pageControllers/SummaryPageController.ts +9 -3
- package/src/server/plugins/engine/pageControllers/helpers/submission.ts +6 -3
- package/src/server/plugins/engine/types/schema.ts +1 -0
- package/src/server/plugins/engine/types.ts +1 -0
- package/src/server/plugins/engine/views/components/ukaddressfield.html +1 -1
- package/src/server/plugins/nunjucks/filters/applyUrlParam.js +17 -0
- package/src/server/plugins/nunjucks/filters/index.js +1 -0
- package/src/server/plugins/payment/helper.js +22 -2
- package/src/server/plugins/payment/service.js +6 -2
- package/src/server/plugins/payment/types.js +1 -0
- package/src/server/plugins/postcode-lookup/models/index.js +75 -43
- package/src/server/plugins/postcode-lookup/routes/index.js +73 -16
- package/src/server/plugins/postcode-lookup/types.js +6 -1
- package/src/server/plugins/postcode-lookup/views/postcode-lookup-details.html +3 -3
|
@@ -13,6 +13,7 @@ const townFieldName = 'town';
|
|
|
13
13
|
const countyFieldName = 'county';
|
|
14
14
|
const postcodeFieldName = 'postcode';
|
|
15
15
|
const GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1';
|
|
16
|
+
const COMMON_BACK = 'common.back';
|
|
16
17
|
export const steps = {
|
|
17
18
|
// Step 1: Postcode/building name input
|
|
18
19
|
details: 'details',
|
|
@@ -338,56 +339,77 @@ function getHref(step) {
|
|
|
338
339
|
/**
|
|
339
340
|
* The postcode lookup details form view model
|
|
340
341
|
* @param {PostcodeLookupSessionData} data
|
|
342
|
+
* @param {Translator} translator
|
|
341
343
|
* @param {PostcodeLookupDetailsData} [payload]
|
|
342
344
|
* @param {Error} [err]
|
|
343
345
|
*/
|
|
344
|
-
export function detailsViewModel(data, payload, err) {
|
|
346
|
+
export function detailsViewModel(data, translator, payload, err) {
|
|
345
347
|
const {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
componentId,
|
|
349
|
+
componentHint,
|
|
348
350
|
sourceUrl,
|
|
349
|
-
|
|
351
|
+
languages
|
|
350
352
|
} = data.initial;
|
|
353
|
+
const {
|
|
354
|
+
t,
|
|
355
|
+
tComponent,
|
|
356
|
+
tForm
|
|
357
|
+
} = translator;
|
|
358
|
+
const component = /** @type {ComponentDef} */{
|
|
359
|
+
id: componentId
|
|
360
|
+
};
|
|
351
361
|
const backLink = {
|
|
352
|
-
href: sourceUrl
|
|
362
|
+
href: sourceUrl,
|
|
363
|
+
text: t(COMMON_BACK)
|
|
353
364
|
};
|
|
354
365
|
const {
|
|
355
366
|
errors,
|
|
356
367
|
postcodeQueryError,
|
|
357
368
|
buildingNameQueryError
|
|
358
369
|
} = buildErrors(err);
|
|
359
|
-
const fields = getDetailsFields(payload ?? data.details, postcodeQueryError, buildingNameQueryError, language);
|
|
370
|
+
const fields = getDetailsFields(payload ?? data.details, postcodeQueryError, buildingNameQueryError, translator.language);
|
|
371
|
+
const hint = componentHint && {
|
|
372
|
+
text: tComponent(component, 'hint')
|
|
373
|
+
};
|
|
360
374
|
const continueButton = {
|
|
361
|
-
text:
|
|
375
|
+
text: t('postcodeLookup.findAddress'),
|
|
362
376
|
classes: GOVUK_MARGIN_RIGHT_1
|
|
363
377
|
};
|
|
364
378
|
const manualLink = {
|
|
365
|
-
text:
|
|
379
|
+
text: t('postcodeLookup.enterManually'),
|
|
366
380
|
href: getHref(steps.manual)
|
|
367
381
|
};
|
|
382
|
+
const selector = languages?.length ? {
|
|
383
|
+
languages
|
|
384
|
+
} : {};
|
|
368
385
|
return {
|
|
369
386
|
step: steps.details,
|
|
370
387
|
showTitle: true,
|
|
371
|
-
name:
|
|
388
|
+
name: tForm('title'),
|
|
372
389
|
serviceUrl: sourceUrl,
|
|
373
|
-
pageTitle,
|
|
390
|
+
pageTitle: tComponent(component, 'title'),
|
|
391
|
+
hint,
|
|
374
392
|
backLink,
|
|
375
393
|
errors,
|
|
376
394
|
fields,
|
|
377
395
|
buttons: {
|
|
378
396
|
continueButton,
|
|
379
397
|
manualLink
|
|
380
|
-
}
|
|
398
|
+
},
|
|
399
|
+
t,
|
|
400
|
+
language: translator.language,
|
|
401
|
+
...selector
|
|
381
402
|
};
|
|
382
403
|
}
|
|
383
404
|
|
|
384
405
|
/**
|
|
385
406
|
* The postcode lookup select form view model
|
|
386
407
|
* @param {{ session: PostcodeLookupSessionData, apiKey: string }} data
|
|
408
|
+
* @param {Translator} translator
|
|
387
409
|
* @param {PostcodeLookupSelectPayload} [payload]
|
|
388
410
|
* @param {Error} [err]
|
|
389
411
|
*/
|
|
390
|
-
export async function selectViewModel(data, payload, err) {
|
|
412
|
+
export async function selectViewModel(data, translator, payload, err) {
|
|
391
413
|
const {
|
|
392
414
|
session,
|
|
393
415
|
apiKey
|
|
@@ -400,7 +422,12 @@ export async function selectViewModel(data, payload, err) {
|
|
|
400
422
|
postcodeQuery,
|
|
401
423
|
buildingNameQuery
|
|
402
424
|
} = details;
|
|
403
|
-
const language =
|
|
425
|
+
const language = translator.language;
|
|
426
|
+
const {
|
|
427
|
+
t,
|
|
428
|
+
tComponent,
|
|
429
|
+
tForm
|
|
430
|
+
} = translator;
|
|
404
431
|
const {
|
|
405
432
|
hasAddresses,
|
|
406
433
|
hasMultipleAddresses,
|
|
@@ -408,39 +435,45 @@ export async function selectViewModel(data, payload, err) {
|
|
|
408
435
|
addresses,
|
|
409
436
|
addressCount
|
|
410
437
|
} = await getAddresses(postcodeQuery, buildingNameQuery, apiKey);
|
|
411
|
-
const title = hasAddresses ?
|
|
438
|
+
const title = hasAddresses ? tComponent(/** @type {ComponentDef} */{
|
|
439
|
+
id: initial.componentId
|
|
440
|
+
}, 'title') : t('postcodeLookup.noAddressFoundTitle');
|
|
412
441
|
const formPath = initial.sourceUrl;
|
|
413
442
|
const href = getHref();
|
|
414
443
|
const backLink = {
|
|
415
|
-
href
|
|
444
|
+
href,
|
|
445
|
+
text: t(COMMON_BACK)
|
|
416
446
|
};
|
|
417
447
|
const {
|
|
418
448
|
errors,
|
|
419
449
|
uprnError
|
|
420
450
|
} = buildErrors(err);
|
|
421
451
|
const fields = getSelectFields(details, hasMultipleAddresses, singleAddress, payload, uprnError, addresses, language);
|
|
422
|
-
const searchAgainText =
|
|
452
|
+
const searchAgainText = t('postcodeLookup.searchAgain');
|
|
423
453
|
const searchAgainLink = {
|
|
424
454
|
text: searchAgainText,
|
|
425
455
|
href
|
|
426
456
|
};
|
|
427
457
|
const continueButton = {
|
|
428
458
|
href: hasAddresses ? undefined : href,
|
|
429
|
-
text: hasAddresses ?
|
|
459
|
+
text: hasAddresses ? t('postcodeLookup.useThisAddress') : searchAgainText,
|
|
430
460
|
classes: GOVUK_MARGIN_RIGHT_1
|
|
431
461
|
};
|
|
432
462
|
const manualLink = {
|
|
433
|
-
text:
|
|
463
|
+
text: t('postcodeLookup.enterManually'),
|
|
434
464
|
href: `${href}?step=${steps.manual}`
|
|
435
465
|
};
|
|
436
|
-
const addressesFoundText = hasAddresses ?
|
|
466
|
+
const addressesFoundText = hasAddresses ? t('postcodeLookup.addressFound', {
|
|
437
467
|
count: addressCount
|
|
438
468
|
}) : undefined;
|
|
439
|
-
const noAddressFoundText = !hasAddresses ?
|
|
469
|
+
const noAddressFoundText = !hasAddresses ? t('postcodeLookup.noAddressFoundBody') : undefined;
|
|
470
|
+
const selector = initial.languages?.length ? {
|
|
471
|
+
languages: initial.languages
|
|
472
|
+
} : {};
|
|
440
473
|
return {
|
|
441
474
|
step: steps.select,
|
|
442
475
|
showTitle: true,
|
|
443
|
-
name: title,
|
|
476
|
+
name: tForm('title'),
|
|
444
477
|
serviceUrl: formPath,
|
|
445
478
|
pageTitle: title,
|
|
446
479
|
backLink,
|
|
@@ -457,27 +490,39 @@ export async function selectViewModel(data, payload, err) {
|
|
|
457
490
|
buttons: {
|
|
458
491
|
continueButton,
|
|
459
492
|
manualLink
|
|
460
|
-
}
|
|
493
|
+
},
|
|
494
|
+
language,
|
|
495
|
+
...selector
|
|
461
496
|
};
|
|
462
497
|
}
|
|
463
498
|
|
|
464
499
|
/**
|
|
465
500
|
* The postcode lookup manual form view model
|
|
466
501
|
* @param {PostcodeLookupSessionData} data
|
|
502
|
+
* @param {Translator} translator
|
|
467
503
|
* @param {PostcodeLookupManualPayload} [payload]
|
|
468
504
|
* @param {Error} [err]
|
|
469
505
|
*/
|
|
470
|
-
export function manualViewModel(data, payload, err) {
|
|
506
|
+
export function manualViewModel(data, translator, payload, err) {
|
|
471
507
|
const {
|
|
472
|
-
|
|
508
|
+
componentId,
|
|
473
509
|
sourceUrl,
|
|
474
510
|
componentHint,
|
|
475
|
-
|
|
511
|
+
languages
|
|
476
512
|
} = data.initial;
|
|
477
513
|
const formPath = sourceUrl;
|
|
478
514
|
const href = getHref();
|
|
515
|
+
const {
|
|
516
|
+
t,
|
|
517
|
+
tComponent,
|
|
518
|
+
tForm
|
|
519
|
+
} = translator;
|
|
520
|
+
const component = /** @type {ComponentDef} */{
|
|
521
|
+
id: componentId
|
|
522
|
+
};
|
|
479
523
|
const backLink = {
|
|
480
|
-
href
|
|
524
|
+
href,
|
|
525
|
+
text: t(COMMON_BACK)
|
|
481
526
|
};
|
|
482
527
|
const {
|
|
483
528
|
errors,
|
|
@@ -488,23 +533,26 @@ export function manualViewModel(data, payload, err) {
|
|
|
488
533
|
postcodeError
|
|
489
534
|
} = buildErrors(err);
|
|
490
535
|
const hint = componentHint && {
|
|
491
|
-
text:
|
|
536
|
+
text: tComponent(component, 'hint')
|
|
492
537
|
};
|
|
493
|
-
const fields = getManualFields(payload, line1Error, line2Error, townError, countyError, postcodeError, language);
|
|
538
|
+
const fields = getManualFields(payload, line1Error, line2Error, townError, countyError, postcodeError, translator.language);
|
|
494
539
|
const continueButton = {
|
|
495
|
-
text:
|
|
540
|
+
text: t('postcodeLookup.useThisAddress'),
|
|
496
541
|
classes: GOVUK_MARGIN_RIGHT_1
|
|
497
542
|
};
|
|
498
543
|
const detailsLink = {
|
|
499
|
-
text:
|
|
544
|
+
text: t('postcodeLookup.findAnAddressInstead'),
|
|
500
545
|
href
|
|
501
546
|
};
|
|
547
|
+
const selector = languages?.length ? {
|
|
548
|
+
languages
|
|
549
|
+
} : {};
|
|
502
550
|
return {
|
|
503
551
|
step: steps.manual,
|
|
504
552
|
showTitle: true,
|
|
505
|
-
name:
|
|
553
|
+
name: tForm('title'),
|
|
506
554
|
serviceUrl: formPath,
|
|
507
|
-
pageTitle:
|
|
555
|
+
pageTitle: tComponent(component, 'title'),
|
|
508
556
|
backLink,
|
|
509
557
|
errors,
|
|
510
558
|
hint,
|
|
@@ -512,7 +560,10 @@ export function manualViewModel(data, payload, err) {
|
|
|
512
560
|
buttons: {
|
|
513
561
|
continueButton,
|
|
514
562
|
detailsLink
|
|
515
|
-
}
|
|
563
|
+
},
|
|
564
|
+
t,
|
|
565
|
+
language: translator.language,
|
|
566
|
+
...selector
|
|
516
567
|
};
|
|
517
568
|
}
|
|
518
569
|
|
|
@@ -520,6 +571,8 @@ export function manualViewModel(data, payload, err) {
|
|
|
520
571
|
|
|
521
572
|
/**
|
|
522
573
|
* @import { ObjectSchema, ValidationErrorItem } from 'joi'
|
|
574
|
+
* @import { ComponentDef } from '@defra/forms-model'
|
|
523
575
|
* @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '../../../../server/plugins/postcode-lookup/types.js'
|
|
576
|
+
* @import { Translator } from '../../../../server/plugins/engine/i18n/types.js'
|
|
524
577
|
*/
|
|
525
578
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Joi","t","i18nT","service","crumbSchema","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","GOVUK_MARGIN_RIGHT_1","steps","details","select","manual","JOURNEY_BASE_URL","buildErrors","err","hasErrors","isError","length","getError","fieldName","find","item","path","postcodeQueryError","buildingNameQueryError","uprnError","line1Error","line2Error","townError","countyError","postcodeError","errors","pushError","push","text","message","href","getAddresses","postcodeQuery","buildingNameQuery","apiKey","addresses","search","addressCount","singleAddress","at","undefined","hasAddresses","hasMultipleAddresses","getDetailsFields","language","id","name","label","hint","value","errorMessage","getSelectFields","payload","selectAddressText","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","sharedPayloadSchemaKeys","crumb","step","createDetailsPayloadSchema","object","pattern","trim","messages","allow","createSelectPayloadSchema","createManualPayloadSchema","getHref","query","detailsViewModel","data","componentTitle","pageTitle","formName","sourceUrl","initial","backLink","fields","continueButton","manualLink","showTitle","serviceUrl","buttons","selectViewModel","session","title","formPath","searchAgainText","searchAgainLink","addressesFoundText","count","noAddressFoundText","manualViewModel","componentHint","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport { t as i18nT } from '~/src/server/plugins/engine/i18n/index.js'\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { crumbSchema } from '~/src/server/schemas/index.js'\n\n// Field names/ids\nconst postcodeQueryFieldName = 'postcodeQuery'\nconst buildingNameQueryFieldName = 'buildingNameQuery'\nconst uprnFieldName = 'uprn'\n\nconst line1FieldName = 'addressLine1'\nconst line2FieldName = 'addressLine2'\nconst townFieldName = 'town'\nconst countyFieldName = 'county'\nconst postcodeFieldName = 'postcode'\n\nconst GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\n\nexport const steps = {\n // Step 1: Postcode/building name input\n details: 'details',\n // Step 2: Select address\n select: 'select',\n // Step 3: Manual address\n manual: 'manual'\n}\n\nexport const JOURNEY_BASE_URL = '/postcode-lookup'\n\n/**\n * Build form errors\n * @param {Error} [err]\n */\nfunction buildErrors(err) {\n const hasErrors = Joi.isError(err) && err.details.length > 0\n\n if (!hasErrors) {\n return {}\n }\n\n /**\n * Get error by path\n * @param {string} fieldName\n */\n const getError = (fieldName) => {\n return err.details.find((item) => item.path[0] === fieldName)\n }\n\n const postcodeQueryError = getError(postcodeQueryFieldName)\n const buildingNameQueryError = getError(buildingNameQueryFieldName)\n const uprnError = getError(uprnFieldName)\n const line1Error = getError(line1FieldName)\n const line2Error = getError(line2FieldName)\n const townError = getError(townFieldName)\n const countyError = getError(countyFieldName)\n const postcodeError = getError(postcodeFieldName)\n\n /**\n * @type {{ text: string, href: string }[]}\n */\n const errors = []\n\n /**\n * Push error\n * @param {string} fieldName - the field name\n * @param {ValidationErrorItem} [item] - the joi validation error\n */\n const pushError = (fieldName, item) => {\n if (item) {\n errors.push({\n text: item.message,\n href: `#${fieldName}`\n })\n }\n }\n\n pushError(postcodeQueryFieldName, postcodeQueryError)\n pushError(buildingNameQueryFieldName, buildingNameQueryError)\n pushError(uprnFieldName, uprnError)\n pushError(line1FieldName, line1Error)\n pushError(line2FieldName, line2Error)\n pushError(townFieldName, townError)\n pushError(countyFieldName, countyError)\n pushError(postcodeFieldName, postcodeError)\n\n return {\n errors,\n postcodeQueryError,\n buildingNameQueryError,\n uprnError,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n }\n}\n\n/**\n * Search ordnance survey for addresses\n * @param {string} postcodeQuery\n * @param {string} buildingNameQuery\n * @param {string} apiKey\n */\nasync function getAddresses(postcodeQuery, buildingNameQuery, apiKey) {\n const addresses = await service.search(\n postcodeQuery,\n buildingNameQuery,\n apiKey\n )\n const addressCount = addresses.length\n const singleAddress = addressCount === 1 ? addresses.at(0) : undefined\n const hasAddresses = addressCount > 0\n const hasMultipleAddresses = addressCount > 1\n\n return {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n }\n}\n\n/**\n * Get the details view fields\n * @param {PostcodeLookupDetailsData | undefined} details\n * @param {OptionalValidationErrorItem} postcodeQueryError\n * @param {OptionalValidationErrorItem} buildingNameQueryError\n * @param {string} language\n */\nfunction getDetailsFields(\n details,\n postcodeQueryError,\n buildingNameQueryError,\n language\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.postcodeHint', language)\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.buildingNameLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.buildingNameHint', language)\n },\n value: details?.buildingNameQuery,\n errorMessage: buildingNameQueryError && {\n text: buildingNameQueryError.message\n }\n }\n }\n}\n\n/**\n * Get the select view fields\n * @param {PostcodeLookupDetailsData} details\n * @param {boolean} hasMultipleAddresses\n * @param {Address | undefined} singleAddress\n * @param {PostcodeLookupSelectPayload | undefined} payload\n * @param {OptionalValidationErrorItem} uprnError\n * @param {Address[]} addresses\n * @param {string} language\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n) {\n const selectAddressText = i18nT('postcodeLookup.selectAddress', language)\n\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n type: 'hidden',\n value: details.postcodeQuery\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n type: 'hidden',\n value: details.buildingNameQuery\n },\n [uprnFieldName]: {\n id: uprnFieldName,\n name: uprnFieldName,\n label: hasMultipleAddresses\n ? {\n text: selectAddressText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectAddressText, value: '' }].concat(\n addresses.map((item) => ({\n text: item.formatted,\n value: item.uprn\n }))\n )\n : undefined,\n type: singleAddress ? 'hidden' : undefined\n }\n }\n}\n\n/**\n * Get the manual view fields\n * @param {PostcodeLookupManualPayload | undefined} payload\n * @param {OptionalValidationErrorItem} line1Error\n * @param {OptionalValidationErrorItem} line2Error\n * @param {OptionalValidationErrorItem} townError\n * @param {OptionalValidationErrorItem} countyError\n * @param {OptionalValidationErrorItem} postcodeError\n * @param {string} language\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n language\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine1Label', language)\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine2Label', language)\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: i18nT('postcodeLookup.townLabel', language)\n },\n classes: 'govuk-!-width-two-thirds',\n value: payload?.town,\n errorMessage: townError && { text: townError.message }\n },\n [countyFieldName]: {\n id: countyFieldName,\n name: countyFieldName,\n label: {\n text: i18nT('postcodeLookup.countyLabel', language)\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n classes: 'govuk-input--width-10',\n value: payload?.postcode,\n errorMessage: postcodeError && { text: postcodeError.message }\n }\n }\n}\n\nexport const stepSchema = Joi.string()\n .valid(...Object.keys(steps))\n .required()\n\nconst sharedPayloadSchemaKeys = {\n crumb: crumbSchema,\n step: stepSchema\n}\n\n/**\n * Postcode lookup details form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport function createDetailsPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [postcodeQueryFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base': i18nT(\n 'postcodeLookup.validation.invalidPostcode',\n language\n ),\n '*': i18nT('postcodeLookup.validation.requiredPostcode', language)\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n}\n\n/**\n * Postcode lookup select form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport function createSelectPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.selectAddress', language)\n })\n })\n .required()\n}\n\n/**\n * Postcode lookup manual form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport function createManualPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredAddressLine1', language)\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredTown', language)\n }),\n [countyFieldName]: Joi.string().trim().allow('').required(),\n [postcodeFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base': i18nT(\n 'postcodeLookup.validation.invalidManualPostcode',\n language\n ),\n '*': i18nT(\n 'postcodeLookup.validation.requiredManualPostcode',\n language\n )\n })\n })\n .required()\n}\n\n/**\n * Get the postcode lookup href\n * @param {string} [step] - the postcode lookup step\n */\nfunction getHref(step) {\n const query = step ? `?step=${step}` : ''\n\n return `${JOURNEY_BASE_URL}${query}`\n}\n\n/**\n * The postcode lookup details form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, payload, err) {\n const {\n componentTitle: pageTitle,\n formName,\n sourceUrl,\n language = 'en-GB'\n } = data.initial\n\n const backLink = {\n href: sourceUrl\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError,\n language\n )\n\n const continueButton = {\n text: i18nT('postcodeLookup.findAddress', language),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: i18nT('postcodeLookup.enterManually', language),\n href: getHref(steps.manual)\n }\n\n return {\n step: steps.details,\n showTitle: true,\n name: formName,\n serviceUrl: sourceUrl,\n pageTitle,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n const language = initial.language ?? 'en-GB'\n\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses\n ? initial.componentTitle\n : i18nT('postcodeLookup.noAddressFoundTitle', language)\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = { href }\n\n const { errors, uprnError } = buildErrors(err)\n\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n )\n\n const searchAgainText = i18nT('postcodeLookup.searchAgain', language)\n\n const searchAgainLink = {\n text: searchAgainText,\n href\n }\n\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses\n ? i18nT('postcodeLookup.useThisAddress', language)\n : searchAgainText,\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: i18nT('postcodeLookup.enterManually', language),\n href: `${href}?step=${steps.manual}`\n }\n\n const addressesFoundText = hasAddresses\n ? i18nT('postcodeLookup.addressFound', language, { count: addressCount })\n : undefined\n const noAddressFoundText = !hasAddresses\n ? i18nT('postcodeLookup.noAddressFoundBody', language)\n : undefined\n\n return {\n step: steps.select,\n showTitle: true,\n name: title,\n serviceUrl: formPath,\n pageTitle: title,\n backLink,\n errors,\n searchAgainLink,\n fields,\n details,\n addressCount,\n singleAddress,\n hasAddresses,\n hasMultipleAddresses,\n addressesFoundText,\n noAddressFoundText,\n buttons: { continueButton, manualLink }\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, payload, err) {\n const {\n componentTitle,\n sourceUrl,\n componentHint,\n language = 'en-GB'\n } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const backLink = {\n href\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n const hint = componentHint && {\n text: componentHint\n }\n\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n language\n )\n\n const continueButton = {\n text: i18nT('postcodeLookup.useThisAddress', language),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: i18nT('postcodeLookup.findAnAddressInstead', language),\n href\n }\n\n return {\n step: steps.manual,\n showTitle: true,\n name: componentTitle,\n serviceUrl: formPath,\n pageTitle: componentTitle,\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink }\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,SAASC,CAAC,IAAIC,KAAK;AACnB,OAAO,KAAKC,OAAO;AACnB,SAASC,WAAW;;AAEpB;AACA,MAAMC,sBAAsB,GAAG,eAAe;AAC9C,MAAMC,0BAA0B,GAAG,mBAAmB;AACtD,MAAMC,aAAa,GAAG,MAAM;AAE5B,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,aAAa,GAAG,MAAM;AAC5B,MAAMC,eA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","postcodeQueryFieldName","buildingNameQueryFieldName","uprnFieldName","line1FieldName","line2FieldName","townFieldName","countyFieldName","postcodeFieldName","GOVUK_MARGIN_RIGHT_1","COMMON_BACK","steps","details","select","manual","JOURNEY_BASE_URL","buildErrors","err","hasErrors","isError","length","getError","fieldName","find","item","path","postcodeQueryError","buildingNameQueryError","uprnError","line1Error","line2Error","townError","countyError","postcodeError","errors","pushError","push","text","message","href","getAddresses","postcodeQuery","buildingNameQuery","apiKey","addresses","search","addressCount","singleAddress","at","undefined","hasAddresses","hasMultipleAddresses","getDetailsFields","language","id","name","label","hint","value","errorMessage","getSelectFields","payload","selectAddressText","type","uprn","items","concat","map","formatted","getManualFields","addressLine1","addressLine2","classes","town","county","postcode","stepSchema","string","valid","Object","keys","required","sharedPayloadSchemaKeys","crumb","step","createDetailsPayloadSchema","object","pattern","trim","messages","allow","createSelectPayloadSchema","createManualPayloadSchema","getHref","query","detailsViewModel","data","translator","componentId","componentHint","sourceUrl","languages","initial","tComponent","tForm","component","backLink","fields","continueButton","manualLink","selector","showTitle","serviceUrl","pageTitle","buttons","selectViewModel","session","title","formPath","searchAgainText","searchAgainLink","addressesFoundText","count","noAddressFoundText","manualViewModel","detailsLink"],"sources":["../../../../../src/server/plugins/postcode-lookup/models/index.js"],"sourcesContent":["import Joi from 'joi'\n\nimport { t as i18nT } from '~/src/server/plugins/engine/i18n/index.js'\nimport * as service from '~/src/server/plugins/postcode-lookup/service.js'\nimport { crumbSchema } from '~/src/server/schemas/index.js'\n\n// Field names/ids\nconst postcodeQueryFieldName = 'postcodeQuery'\nconst buildingNameQueryFieldName = 'buildingNameQuery'\nconst uprnFieldName = 'uprn'\n\nconst line1FieldName = 'addressLine1'\nconst line2FieldName = 'addressLine2'\nconst townFieldName = 'town'\nconst countyFieldName = 'county'\nconst postcodeFieldName = 'postcode'\n\nconst GOVUK_MARGIN_RIGHT_1 = 'govuk-!-margin-right-1'\nconst COMMON_BACK = 'common.back'\n\nexport const steps = {\n // Step 1: Postcode/building name input\n details: 'details',\n // Step 2: Select address\n select: 'select',\n // Step 3: Manual address\n manual: 'manual'\n}\n\nexport const JOURNEY_BASE_URL = '/postcode-lookup'\n\n/**\n * Build form errors\n * @param {Error} [err]\n */\nfunction buildErrors(err) {\n const hasErrors = Joi.isError(err) && err.details.length > 0\n\n if (!hasErrors) {\n return {}\n }\n\n /**\n * Get error by path\n * @param {string} fieldName\n */\n const getError = (fieldName) => {\n return err.details.find((item) => item.path[0] === fieldName)\n }\n\n const postcodeQueryError = getError(postcodeQueryFieldName)\n const buildingNameQueryError = getError(buildingNameQueryFieldName)\n const uprnError = getError(uprnFieldName)\n const line1Error = getError(line1FieldName)\n const line2Error = getError(line2FieldName)\n const townError = getError(townFieldName)\n const countyError = getError(countyFieldName)\n const postcodeError = getError(postcodeFieldName)\n\n /**\n * @type {{ text: string, href: string }[]}\n */\n const errors = []\n\n /**\n * Push error\n * @param {string} fieldName - the field name\n * @param {ValidationErrorItem} [item] - the joi validation error\n */\n const pushError = (fieldName, item) => {\n if (item) {\n errors.push({\n text: item.message,\n href: `#${fieldName}`\n })\n }\n }\n\n pushError(postcodeQueryFieldName, postcodeQueryError)\n pushError(buildingNameQueryFieldName, buildingNameQueryError)\n pushError(uprnFieldName, uprnError)\n pushError(line1FieldName, line1Error)\n pushError(line2FieldName, line2Error)\n pushError(townFieldName, townError)\n pushError(countyFieldName, countyError)\n pushError(postcodeFieldName, postcodeError)\n\n return {\n errors,\n postcodeQueryError,\n buildingNameQueryError,\n uprnError,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n }\n}\n\n/**\n * Search ordnance survey for addresses\n * @param {string} postcodeQuery\n * @param {string} buildingNameQuery\n * @param {string} apiKey\n */\nasync function getAddresses(postcodeQuery, buildingNameQuery, apiKey) {\n const addresses = await service.search(\n postcodeQuery,\n buildingNameQuery,\n apiKey\n )\n const addressCount = addresses.length\n const singleAddress = addressCount === 1 ? addresses.at(0) : undefined\n const hasAddresses = addressCount > 0\n const hasMultipleAddresses = addressCount > 1\n\n return {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n }\n}\n\n/**\n * Get the details view fields\n * @param {PostcodeLookupDetailsData | undefined} details\n * @param {OptionalValidationErrorItem} postcodeQueryError\n * @param {OptionalValidationErrorItem} buildingNameQueryError\n * @param {string} language\n */\nfunction getDetailsFields(\n details,\n postcodeQueryError,\n buildingNameQueryError,\n language\n) {\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.postcodeHint', language)\n },\n value: details?.postcodeQuery,\n errorMessage: postcodeQueryError && { text: postcodeQueryError.message }\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n label: {\n text: i18nT('postcodeLookup.buildingNameLabel', language)\n },\n hint: {\n text: i18nT('postcodeLookup.buildingNameHint', language)\n },\n value: details?.buildingNameQuery,\n errorMessage: buildingNameQueryError && {\n text: buildingNameQueryError.message\n }\n }\n }\n}\n\n/**\n * Get the select view fields\n * @param {PostcodeLookupDetailsData} details\n * @param {boolean} hasMultipleAddresses\n * @param {Address | undefined} singleAddress\n * @param {PostcodeLookupSelectPayload | undefined} payload\n * @param {OptionalValidationErrorItem} uprnError\n * @param {Address[]} addresses\n * @param {string} language\n */\nfunction getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n) {\n const selectAddressText = i18nT('postcodeLookup.selectAddress', language)\n\n return {\n [postcodeQueryFieldName]: {\n id: postcodeQueryFieldName,\n name: postcodeQueryFieldName,\n type: 'hidden',\n value: details.postcodeQuery\n },\n [buildingNameQueryFieldName]: {\n id: buildingNameQueryFieldName,\n name: buildingNameQueryFieldName,\n type: 'hidden',\n value: details.buildingNameQuery\n },\n [uprnFieldName]: {\n id: uprnFieldName,\n name: uprnFieldName,\n label: hasMultipleAddresses\n ? {\n text: selectAddressText\n }\n : undefined,\n value: singleAddress ? singleAddress.uprn : payload?.uprn,\n errorMessage: uprnError && { text: uprnError.message },\n items: hasMultipleAddresses\n ? [{ text: selectAddressText, value: '' }].concat(\n addresses.map((item) => ({\n text: item.formatted,\n value: item.uprn\n }))\n )\n : undefined,\n type: singleAddress ? 'hidden' : undefined\n }\n }\n}\n\n/**\n * Get the manual view fields\n * @param {PostcodeLookupManualPayload | undefined} payload\n * @param {OptionalValidationErrorItem} line1Error\n * @param {OptionalValidationErrorItem} line2Error\n * @param {OptionalValidationErrorItem} townError\n * @param {OptionalValidationErrorItem} countyError\n * @param {OptionalValidationErrorItem} postcodeError\n * @param {string} language\n */\nfunction getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n language\n) {\n return {\n [line1FieldName]: {\n id: line1FieldName,\n name: line1FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine1Label', language)\n },\n value: payload?.addressLine1,\n errorMessage: line1Error && { text: line1Error.message }\n },\n [line2FieldName]: {\n id: line2FieldName,\n name: line2FieldName,\n label: {\n text: i18nT('postcodeLookup.addressLine2Label', language)\n },\n value: payload?.addressLine2,\n errorMessage: line2Error && { text: line2Error.message }\n },\n [townFieldName]: {\n id: townFieldName,\n name: townFieldName,\n label: {\n text: i18nT('postcodeLookup.townLabel', language)\n },\n classes: 'govuk-!-width-two-thirds',\n value: payload?.town,\n errorMessage: townError && { text: townError.message }\n },\n [countyFieldName]: {\n id: countyFieldName,\n name: countyFieldName,\n label: {\n text: i18nT('postcodeLookup.countyLabel', language)\n },\n value: payload?.county,\n errorMessage: countyError && { text: countyError.message }\n },\n [postcodeFieldName]: {\n id: postcodeFieldName,\n name: postcodeFieldName,\n label: {\n text: i18nT('postcodeLookup.postcodeLabel', language)\n },\n classes: 'govuk-input--width-10',\n value: payload?.postcode,\n errorMessage: postcodeError && { text: postcodeError.message }\n }\n }\n}\n\nexport const stepSchema = Joi.string()\n .valid(...Object.keys(steps))\n .required()\n\nconst sharedPayloadSchemaKeys = {\n crumb: crumbSchema,\n step: stepSchema\n}\n\n/**\n * Postcode lookup details form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupDetailsPayload>}\n */\nexport function createDetailsPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [postcodeQueryFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base': i18nT(\n 'postcodeLookup.validation.invalidPostcode',\n language\n ),\n '*': i18nT('postcodeLookup.validation.requiredPostcode', language)\n }),\n [buildingNameQueryFieldName]: Joi.string()\n .trim()\n .required()\n .allow('')\n .trim()\n })\n .required()\n}\n\n/**\n * Postcode lookup select form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupSelectPayload>}\n */\nexport function createSelectPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [uprnFieldName]: Joi.string()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.selectAddress', language)\n })\n })\n .required()\n}\n\n/**\n * Postcode lookup manual form payload schema\n * @param {string} [language]\n * @returns {ObjectSchema<PostcodeLookupManualPayload>}\n */\nexport function createManualPayloadSchema(language = 'en-GB') {\n return Joi.object()\n .keys({\n ...sharedPayloadSchemaKeys,\n [line1FieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredAddressLine1', language)\n }),\n [line2FieldName]: Joi.string().trim().allow('').required(),\n [townFieldName]: Joi.string()\n .trim()\n .required()\n .messages({\n '*': i18nT('postcodeLookup.validation.requiredTown', language)\n }),\n [countyFieldName]: Joi.string().trim().allow('').required(),\n [postcodeFieldName]: Joi.string()\n .pattern(/^[a-zA-Z]{1,2}\\d[a-zA-Z\\d]?\\s?\\d[a-zA-Z]{2}$/)\n .trim()\n .required()\n .messages({\n 'string.pattern.base': i18nT(\n 'postcodeLookup.validation.invalidManualPostcode',\n language\n ),\n '*': i18nT(\n 'postcodeLookup.validation.requiredManualPostcode',\n language\n )\n })\n })\n .required()\n}\n\n/**\n * Get the postcode lookup href\n * @param {string} [step] - the postcode lookup step\n */\nfunction getHref(step) {\n const query = step ? `?step=${step}` : ''\n\n return `${JOURNEY_BASE_URL}${query}`\n}\n\n/**\n * The postcode lookup details form view model\n * @param {PostcodeLookupSessionData} data\n * @param {Translator} translator\n * @param {PostcodeLookupDetailsData} [payload]\n * @param {Error} [err]\n */\nexport function detailsViewModel(data, translator, payload, err) {\n const { componentId, componentHint, sourceUrl, languages } = data.initial\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href: sourceUrl,\n text: t(COMMON_BACK)\n }\n\n const { errors, postcodeQueryError, buildingNameQueryError } =\n buildErrors(err)\n\n const fields = getDetailsFields(\n payload ?? data.details,\n postcodeQueryError,\n buildingNameQueryError,\n translator.language\n )\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const continueButton = {\n text: t('postcodeLookup.findAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: getHref(steps.manual)\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.details,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: sourceUrl,\n pageTitle: tComponent(component, 'title'),\n hint,\n backLink,\n errors,\n fields,\n buttons: { continueButton, manualLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup select form view model\n * @param {{ session: PostcodeLookupSessionData, apiKey: string }} data\n * @param {Translator} translator\n * @param {PostcodeLookupSelectPayload} [payload]\n * @param {Error} [err]\n */\nexport async function selectViewModel(data, translator, payload, err) {\n const { session, apiKey } = data\n const { details, initial } = session\n const { postcodeQuery, buildingNameQuery } = details\n const language = translator.language\n const { t, tComponent, tForm } = translator\n\n const {\n hasAddresses,\n hasMultipleAddresses,\n singleAddress,\n addresses,\n addressCount\n } = await getAddresses(postcodeQuery, buildingNameQuery, apiKey)\n\n const title = hasAddresses\n ? tComponent(\n /** @type {ComponentDef} */ ({ id: initial.componentId }),\n 'title'\n )\n : t('postcodeLookup.noAddressFoundTitle')\n const formPath = initial.sourceUrl\n const href = getHref()\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const { errors, uprnError } = buildErrors(err)\n\n const fields = getSelectFields(\n details,\n hasMultipleAddresses,\n singleAddress,\n payload,\n uprnError,\n addresses,\n language\n )\n\n const searchAgainText = t('postcodeLookup.searchAgain')\n\n const searchAgainLink = {\n text: searchAgainText,\n href\n }\n\n const continueButton = {\n href: hasAddresses ? undefined : href,\n text: hasAddresses ? t('postcodeLookup.useThisAddress') : searchAgainText,\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const manualLink = {\n text: t('postcodeLookup.enterManually'),\n href: `${href}?step=${steps.manual}`\n }\n\n const addressesFoundText = hasAddresses\n ? t('postcodeLookup.addressFound', { count: addressCount })\n : undefined\n const noAddressFoundText = !hasAddresses\n ? t('postcodeLookup.noAddressFoundBody')\n : undefined\n\n const selector = initial.languages?.length\n ? { languages: initial.languages }\n : {}\n\n return {\n step: steps.select,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: formPath,\n pageTitle: title,\n backLink,\n errors,\n searchAgainLink,\n fields,\n details,\n addressCount,\n singleAddress,\n hasAddresses,\n hasMultipleAddresses,\n addressesFoundText,\n noAddressFoundText,\n buttons: { continueButton, manualLink },\n language,\n ...selector\n }\n}\n\n/**\n * The postcode lookup manual form view model\n * @param {PostcodeLookupSessionData} data\n * @param {Translator} translator\n * @param {PostcodeLookupManualPayload} [payload]\n * @param {Error} [err]\n */\nexport function manualViewModel(data, translator, payload, err) {\n const { componentId, sourceUrl, componentHint, languages } = data.initial\n const formPath = sourceUrl\n const href = getHref()\n\n const { t, tComponent, tForm } = translator\n\n const component = /** @type {ComponentDef} */ ({ id: componentId })\n\n const backLink = {\n href,\n text: t(COMMON_BACK)\n }\n\n const {\n errors,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError\n } = buildErrors(err)\n\n const hint = componentHint && {\n text: tComponent(component, 'hint')\n }\n\n const fields = getManualFields(\n payload,\n line1Error,\n line2Error,\n townError,\n countyError,\n postcodeError,\n translator.language\n )\n\n const continueButton = {\n text: t('postcodeLookup.useThisAddress'),\n classes: GOVUK_MARGIN_RIGHT_1\n }\n const detailsLink = {\n text: t('postcodeLookup.findAnAddressInstead'),\n href\n }\n\n const selector = languages?.length ? { languages } : {}\n\n return {\n step: steps.manual,\n showTitle: true,\n name: tForm('title'),\n serviceUrl: formPath,\n pageTitle: tComponent(component, 'title'),\n backLink,\n errors,\n hint,\n fields,\n buttons: { continueButton, detailsLink },\n t,\n language: translator.language,\n ...selector\n }\n}\n\n/** @typedef { ValidationErrorItem | undefined } OptionalValidationErrorItem */\n\n/**\n * @import { ObjectSchema, ValidationErrorItem } from 'joi'\n * @import { ComponentDef } from '@defra/forms-model'\n * @import { Address, PostcodeLookupDetailsData, PostcodeLookupDetailsPayload, PostcodeLookupManualPayload, PostcodeLookupSelectPayload, PostcodeLookupSessionData } from '~/src/server/plugins/postcode-lookup/types.js'\n * @import { Translator } from '~/src/server/plugins/engine/i18n/types.js'\n */\n"],"mappings":"AAAA,OAAOA,GAAG,MAAM,KAAK;AAErB,SAASC,CAAC,IAAIC,KAAK;AACnB,OAAO,KAAKC,OAAO;AACnB,SAASC,WAAW;;AAEpB;AACA,MAAMC,sBAAsB,GAAG,eAAe;AAC9C,MAAMC,0BAA0B,GAAG,mBAAmB;AACtD,MAAMC,aAAa,GAAG,MAAM;AAE5B,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,cAAc,GAAG,cAAc;AACrC,MAAMC,aAAa,GAAG,MAAM;AAC5B,MAAMC,eAAe,GAAG,Q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,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the session state associated with this journey
|
|
3
|
+
* @param {PostcodeLookupRequest} request
|
|
4
|
+
*/
|
|
5
|
+
export function getSessionState(request: PostcodeLookupRequest): PostcodeLookupSessionData;
|
|
6
|
+
/**
|
|
7
|
+
* Get a cached translator, or create a new one if not in the cache
|
|
8
|
+
* @param {PostcodeLookupRequest} request
|
|
9
|
+
* @param {PostcodeLookupDispatchData} initial
|
|
10
|
+
* @param { string | string[] | undefined } language
|
|
11
|
+
*/
|
|
12
|
+
export function getDispatchTranslator(request: PostcodeLookupRequest, initial: PostcodeLookupDispatchData, language: string | string[] | undefined): Promise<import("../../engine/i18n/types.js").Translator>;
|
|
1
13
|
/**
|
|
2
14
|
* Initialises and dispatches the request to the postcode lookup journey
|
|
3
15
|
* @param {FormRequestPayload} request - the source page
|
|
@@ -10,9 +22,11 @@ export function dispatch(request: FormRequestPayload, h: FormResponseToolkit, in
|
|
|
10
22
|
* @param {PostcodeLookupConfiguration} options - ordnance survey api key
|
|
11
23
|
*/
|
|
12
24
|
export function getRoutes(options: PostcodeLookupConfiguration): (ServerRoute<PostcodeLookupGetRequestRefs> | ServerRoute<PostcodeLookupPostRequestRefs>)[];
|
|
25
|
+
import type { PostcodeLookupRequest } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
26
|
+
import type { PostcodeLookupSessionData } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
27
|
+
import type { PostcodeLookupDispatchData } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
13
28
|
import type { FormRequestPayload } from '../../../../server/routes/types.js';
|
|
14
29
|
import type { FormResponseToolkit } from '../../../../server/routes/types.js';
|
|
15
|
-
import type { PostcodeLookupDispatchData } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
16
30
|
import type { PostcodeLookupConfiguration } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
17
31
|
import type { PostcodeLookupGetRequestRefs } from '../../../../server/plugins/postcode-lookup/types.js';
|
|
18
32
|
import type { ServerRoute } from '@hapi/hapi';
|
|
@@ -2,15 +2,17 @@ import Boom from '@hapi/boom';
|
|
|
2
2
|
import { StatusCodes } from 'http-status-codes';
|
|
3
3
|
import Joi from 'joi';
|
|
4
4
|
import { EXTERNAL_STATE_APPENDAGE } from "../../../constants.js";
|
|
5
|
+
import { getCachedPluginTranslator } from "../../engine/i18n/form.js";
|
|
5
6
|
import { JOURNEY_BASE_URL, createDetailsPayloadSchema, createManualPayloadSchema, createSelectPayloadSchema, detailsViewModel, manualViewModel, selectViewModel, stepSchema, steps } from "../models/index.js";
|
|
6
7
|
import * as service from "../service.js";
|
|
8
|
+
import { resolveLanguage } from "../../../utils/utils.js";
|
|
7
9
|
const viewName = 'postcode-lookup-details';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Get the session state associated with this journey
|
|
11
13
|
* @param {PostcodeLookupRequest} request
|
|
12
14
|
*/
|
|
13
|
-
function getSessionState(request) {
|
|
15
|
+
export function getSessionState(request) {
|
|
14
16
|
/**
|
|
15
17
|
* @type {PostcodeLookupSessionData | null | undefined}
|
|
16
18
|
*/
|
|
@@ -46,6 +48,29 @@ function flashComponentState(request, componentName, address) {
|
|
|
46
48
|
};
|
|
47
49
|
request.yar.flash(EXTERNAL_STATE_APPENDAGE, appendage, true);
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Get a cached translator, or create a new one if not in the cache
|
|
53
|
+
* @param {PostcodeLookupRequest} request
|
|
54
|
+
* @param {PostcodeLookupDispatchData} initial
|
|
55
|
+
* @param { string | string[] | undefined } language
|
|
56
|
+
*/
|
|
57
|
+
export async function getDispatchTranslator(request, initial, language) {
|
|
58
|
+
const {
|
|
59
|
+
formId,
|
|
60
|
+
formStatus
|
|
61
|
+
} = initial;
|
|
62
|
+
|
|
63
|
+
// Override language if passed as a query param
|
|
64
|
+
if (language) {
|
|
65
|
+
request.yar.set('language', language);
|
|
66
|
+
}
|
|
67
|
+
const typedReq = /** @type {AnyFormRequest} */ /** @type {any} */request;
|
|
68
|
+
const lang = resolveLanguage(typedReq);
|
|
69
|
+
const translator = await getCachedPluginTranslator(typedReq, /** @type {FormMetadata} */{
|
|
70
|
+
id: formId
|
|
71
|
+
}, formStatus, lang);
|
|
72
|
+
return translator;
|
|
73
|
+
}
|
|
49
74
|
|
|
50
75
|
/**
|
|
51
76
|
* Initialises and dispatches the request to the postcode lookup journey
|
|
@@ -84,21 +109,24 @@ function getRoute() {
|
|
|
84
109
|
return {
|
|
85
110
|
method: 'GET',
|
|
86
111
|
path: JOURNEY_BASE_URL,
|
|
87
|
-
handler(request, h) {
|
|
112
|
+
async handler(request, h) {
|
|
88
113
|
const {
|
|
89
114
|
query
|
|
90
115
|
} = request;
|
|
91
116
|
const {
|
|
92
|
-
step
|
|
117
|
+
step,
|
|
118
|
+
language
|
|
93
119
|
} = query;
|
|
94
120
|
const session = getSessionState(request);
|
|
95
|
-
const
|
|
121
|
+
const translator = await getDispatchTranslator(request, session.initial, language);
|
|
122
|
+
const model = step === steps.manual ? manualViewModel(session, translator) : detailsViewModel(session, translator);
|
|
96
123
|
return h.view(viewName, model);
|
|
97
124
|
},
|
|
98
125
|
options: {
|
|
99
126
|
validate: {
|
|
100
127
|
query: Joi.object().keys({
|
|
101
|
-
step: Joi.string().allow(steps.details, steps.manual).optional()
|
|
128
|
+
step: Joi.string().allow(steps.details, steps.manual).optional(),
|
|
129
|
+
language: Joi.string().allow('en-GB', 'cy').optional()
|
|
102
130
|
}).optional()
|
|
103
131
|
}
|
|
104
132
|
}
|
|
@@ -158,14 +186,15 @@ async function detailsPostHandler(request, h, options) {
|
|
|
158
186
|
const {
|
|
159
187
|
ordnanceSurveyApiKey: apiKey
|
|
160
188
|
} = options;
|
|
161
|
-
const
|
|
189
|
+
const translator = await getDispatchTranslator(request, session.initial, request.query.language);
|
|
190
|
+
const language = translator.language;
|
|
162
191
|
const {
|
|
163
192
|
value: details,
|
|
164
193
|
error
|
|
165
194
|
} = createDetailsPayloadSchema(language).validate(request.payload);
|
|
166
195
|
let model;
|
|
167
196
|
if (error) {
|
|
168
|
-
model = detailsViewModel(session, details, error);
|
|
197
|
+
model = detailsViewModel(session, translator, details, error);
|
|
169
198
|
return h.view(viewName, model);
|
|
170
199
|
}
|
|
171
200
|
const {
|
|
@@ -182,7 +211,7 @@ async function detailsPostHandler(request, h, options) {
|
|
|
182
211
|
model = await selectViewModel({
|
|
183
212
|
session,
|
|
184
213
|
apiKey
|
|
185
|
-
});
|
|
214
|
+
}, translator);
|
|
186
215
|
return h.view(viewName, model);
|
|
187
216
|
}
|
|
188
217
|
|
|
@@ -197,7 +226,8 @@ async function selectPostHandler(request, h, options) {
|
|
|
197
226
|
const {
|
|
198
227
|
ordnanceSurveyApiKey: apiKey
|
|
199
228
|
} = options;
|
|
200
|
-
const
|
|
229
|
+
const translator = await getDispatchTranslator(request, session.initial, request.query.language);
|
|
230
|
+
const language = translator.language;
|
|
201
231
|
const {
|
|
202
232
|
value: select,
|
|
203
233
|
error
|
|
@@ -206,7 +236,7 @@ async function selectPostHandler(request, h, options) {
|
|
|
206
236
|
const model = await selectViewModel({
|
|
207
237
|
session,
|
|
208
238
|
apiKey
|
|
209
|
-
}, select, error);
|
|
239
|
+
}, translator, select, error);
|
|
210
240
|
return h.view(viewName, model);
|
|
211
241
|
}
|
|
212
242
|
const addresses = await service.searchByUPRN(select.uprn, apiKey);
|
|
@@ -229,9 +259,10 @@ async function selectPostHandler(request, h, options) {
|
|
|
229
259
|
* @param {PostcodeLookupPostRequest} request
|
|
230
260
|
* @param {ResponseToolkit<PostcodeLookupPostRequestRefs>} h
|
|
231
261
|
*/
|
|
232
|
-
function manualPostHandler(request, h) {
|
|
262
|
+
async function manualPostHandler(request, h) {
|
|
233
263
|
const session = getSessionState(request);
|
|
234
|
-
const
|
|
264
|
+
const translator = await getDispatchTranslator(request, session.initial, request.query.language);
|
|
265
|
+
const language = translator.language;
|
|
235
266
|
const {
|
|
236
267
|
value: manual,
|
|
237
268
|
error
|
|
@@ -239,7 +270,7 @@ function manualPostHandler(request, h) {
|
|
|
239
270
|
abortEarly: false
|
|
240
271
|
});
|
|
241
272
|
if (error) {
|
|
242
|
-
const model = manualViewModel(session, manual, error);
|
|
273
|
+
const model = manualViewModel(session, translator, manual, error);
|
|
243
274
|
return h.view(viewName, model);
|
|
244
275
|
}
|
|
245
276
|
const {
|
|
@@ -254,8 +285,9 @@ function manualPostHandler(request, h) {
|
|
|
254
285
|
|
|
255
286
|
/**
|
|
256
287
|
* @import { ResponseToolkit, ServerRoute } from '@hapi/hapi'
|
|
257
|
-
* @import {
|
|
288
|
+
* @import { FormMetadata } from '@defra/forms-model'
|
|
289
|
+
* @import { PostcodeLookupManualPayload, Address, PostcodeLookupGetRequestRefs, PostcodeLookupPostRequestRefs, PostcodeLookupRequest, PostcodeLookupPostRequest, PostcodeLookupConfiguration, PostcodeLookupDispatchData, PostcodeLookupSessionData } from '../../../../server/plugins/postcode-lookup/types.js'
|
|
258
290
|
* @import { FormRequestPayload, FormResponseToolkit } from '../../../../server/routes/types.js'
|
|
259
|
-
* @import { ExternalStateAppendage } from '../../../../server/plugins/engine/types.js'
|
|
291
|
+
* @import { AnyFormRequest, ExternalStateAppendage } from '../../../../server/plugins/engine/types.js'
|
|
260
292
|
*/
|
|
261
293
|
//# sourceMappingURL=index.js.map
|