@defra/fcp-sfd-frontend-engine 0.16.0 → 0.18.0

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/dist/index.cjs CHANGED
@@ -279,15 +279,13 @@ var updateCustomerNameMutation = `
279
279
  }
280
280
  `;
281
281
 
282
- // src/mutations/personal/update-customer-email.js
283
- var updateCustomerEmailMutation = `
284
- mutation UpdateCustomerEmail($input: UpdateCustomerEmailInput!) {
285
- updateCustomerEmail(input: $input) {
282
+ // src/mutations/personal/update-customer-dob.js
283
+ var updateCustomerDobMutation = `
284
+ mutation UpdateCustomerDateOfBirth($input: UpdateCustomerDateOfBirthInput!) {
285
+ updateCustomerDateOfBirth(input: $input) {
286
286
  customer {
287
287
  info {
288
- email {
289
- address
290
- }
288
+ dateOfBirth
291
289
  }
292
290
  }
293
291
  }
@@ -310,13 +308,29 @@ var updateCustomerPhoneMutation = `
310
308
  }
311
309
  `;
312
310
 
311
+ // src/mutations/personal/update-customer-email.js
312
+ var updateCustomerEmailMutation = `
313
+ mutation UpdateCustomerEmail($input: UpdateCustomerEmailInput!) {
314
+ updateCustomerEmail(input: $input) {
315
+ customer {
316
+ info {
317
+ email {
318
+ address
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ `;
325
+
313
326
  // src/mutations/mutations.js
314
327
  var mutations = {
315
328
  updateBusinessEmail: updateBusinessEmailMutation,
316
329
  updateBusinessName: updateBusinessNameMutation,
317
330
  updateCustomerName: updateCustomerNameMutation,
318
- updateCustomerEmail: updateCustomerEmailMutation,
319
- updateCustomerPhone: updateCustomerPhoneMutation
331
+ updateCustomerDob: updateCustomerDobMutation,
332
+ updateCustomerPhone: updateCustomerPhoneMutation,
333
+ updateCustomerEmail: updateCustomerEmailMutation
320
334
  };
321
335
 
322
336
  // src/presenters/base-presenter.js
@@ -336,6 +350,23 @@ var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
336
350
  }
337
351
  return originalNumber;
338
352
  };
353
+ var formatDatePart = (changed, original) => {
354
+ return changed ?? (original == null ? void 0 : original.toString()) ?? "";
355
+ };
356
+ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
357
+ if (payloadDob) {
358
+ return {
359
+ day: payloadDob.day ?? "",
360
+ month: payloadDob.month ?? "",
361
+ year: payloadDob.year ?? ""
362
+ };
363
+ }
364
+ return {
365
+ day: formatDatePart(changedDob == null ? void 0 : changedDob.day, originalDob == null ? void 0 : originalDob.day),
366
+ month: formatDatePart(changedDob == null ? void 0 : changedDob.month, originalDob == null ? void 0 : originalDob.month),
367
+ year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
368
+ };
369
+ };
339
370
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
340
371
  const sortedErrors = [];
341
372
  for (const section of orderedSectionsToFix) {
@@ -353,19 +384,35 @@ var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDE
353
384
  };
354
385
 
355
386
  // src/presenters/address-presenter.js
356
- var addressChangeLink = (postcodeLookup) => {
357
- if (postcodeLookup) {
358
- return "/account-address-change";
359
- } else {
387
+ var addressChangeLink = (postcodeLookup, context) => {
388
+ if (context === "business") {
389
+ if (postcodeLookup) {
390
+ return "/business-address-change";
391
+ }
392
+ return "/business-address-enter";
393
+ }
394
+ if (context === "personal") {
395
+ if (postcodeLookup) {
396
+ return "/account-address-change";
397
+ }
360
398
  return "/account-address-enter";
361
399
  }
400
+ return null;
362
401
  };
363
- var addressBackLink = (postcodeLookup) => {
364
- if (postcodeLookup) {
365
- return { href: "/account-address-select" };
366
- } else {
402
+ var addressBackLink = (postcodeLookup, context) => {
403
+ if (context === "business") {
404
+ if (postcodeLookup) {
405
+ return { href: "/business-address-select" };
406
+ }
407
+ return { href: "/business-address-enter" };
408
+ }
409
+ if (context === "personal") {
410
+ if (postcodeLookup) {
411
+ return { href: "/account-address-select" };
412
+ }
367
413
  return { href: "/account-address-enter" };
368
414
  }
415
+ return null;
369
416
  };
370
417
  var buildAddressLine = (parts) => {
371
418
  return parts.filter(Boolean).join(", ") || null;
@@ -495,6 +542,7 @@ var formatBusinessAddress = (businessAddress) => {
495
542
  var presenters = {
496
543
  formatBackLink,
497
544
  formatNumber,
545
+ formatDateInputValues,
498
546
  formatDisplayAddress,
499
547
  formatOriginalAddress,
500
548
  formatChangedAddress,
package/dist/index.js CHANGED
@@ -239,15 +239,13 @@ var updateCustomerNameMutation = `
239
239
  }
240
240
  `;
241
241
 
242
- // src/mutations/personal/update-customer-email.js
243
- var updateCustomerEmailMutation = `
244
- mutation UpdateCustomerEmail($input: UpdateCustomerEmailInput!) {
245
- updateCustomerEmail(input: $input) {
242
+ // src/mutations/personal/update-customer-dob.js
243
+ var updateCustomerDobMutation = `
244
+ mutation UpdateCustomerDateOfBirth($input: UpdateCustomerDateOfBirthInput!) {
245
+ updateCustomerDateOfBirth(input: $input) {
246
246
  customer {
247
247
  info {
248
- email {
249
- address
250
- }
248
+ dateOfBirth
251
249
  }
252
250
  }
253
251
  }
@@ -270,13 +268,29 @@ var updateCustomerPhoneMutation = `
270
268
  }
271
269
  `;
272
270
 
271
+ // src/mutations/personal/update-customer-email.js
272
+ var updateCustomerEmailMutation = `
273
+ mutation UpdateCustomerEmail($input: UpdateCustomerEmailInput!) {
274
+ updateCustomerEmail(input: $input) {
275
+ customer {
276
+ info {
277
+ email {
278
+ address
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ `;
285
+
273
286
  // src/mutations/mutations.js
274
287
  var mutations = {
275
288
  updateBusinessEmail: updateBusinessEmailMutation,
276
289
  updateBusinessName: updateBusinessNameMutation,
277
290
  updateCustomerName: updateCustomerNameMutation,
278
- updateCustomerEmail: updateCustomerEmailMutation,
279
- updateCustomerPhone: updateCustomerPhoneMutation
291
+ updateCustomerDob: updateCustomerDobMutation,
292
+ updateCustomerPhone: updateCustomerPhoneMutation,
293
+ updateCustomerEmail: updateCustomerEmailMutation
280
294
  };
281
295
 
282
296
  // src/presenters/base-presenter.js
@@ -296,6 +310,23 @@ var formatNumber = (payloadNumber, changedNumber, originalNumber) => {
296
310
  }
297
311
  return originalNumber;
298
312
  };
313
+ var formatDatePart = (changed, original) => {
314
+ return changed ?? (original == null ? void 0 : original.toString()) ?? "";
315
+ };
316
+ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
317
+ if (payloadDob) {
318
+ return {
319
+ day: payloadDob.day ?? "",
320
+ month: payloadDob.month ?? "",
321
+ year: payloadDob.year ?? ""
322
+ };
323
+ }
324
+ return {
325
+ day: formatDatePart(changedDob == null ? void 0 : changedDob.day, originalDob == null ? void 0 : originalDob.day),
326
+ month: formatDatePart(changedDob == null ? void 0 : changedDob.month, originalDob == null ? void 0 : originalDob.month),
327
+ year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
328
+ };
329
+ };
299
330
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
300
331
  const sortedErrors = [];
301
332
  for (const section of orderedSectionsToFix) {
@@ -313,19 +344,35 @@ var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDE
313
344
  };
314
345
 
315
346
  // src/presenters/address-presenter.js
316
- var addressChangeLink = (postcodeLookup) => {
317
- if (postcodeLookup) {
318
- return "/account-address-change";
319
- } else {
347
+ var addressChangeLink = (postcodeLookup, context) => {
348
+ if (context === "business") {
349
+ if (postcodeLookup) {
350
+ return "/business-address-change";
351
+ }
352
+ return "/business-address-enter";
353
+ }
354
+ if (context === "personal") {
355
+ if (postcodeLookup) {
356
+ return "/account-address-change";
357
+ }
320
358
  return "/account-address-enter";
321
359
  }
360
+ return null;
322
361
  };
323
- var addressBackLink = (postcodeLookup) => {
324
- if (postcodeLookup) {
325
- return { href: "/account-address-select" };
326
- } else {
362
+ var addressBackLink = (postcodeLookup, context) => {
363
+ if (context === "business") {
364
+ if (postcodeLookup) {
365
+ return { href: "/business-address-select" };
366
+ }
367
+ return { href: "/business-address-enter" };
368
+ }
369
+ if (context === "personal") {
370
+ if (postcodeLookup) {
371
+ return { href: "/account-address-select" };
372
+ }
327
373
  return { href: "/account-address-enter" };
328
374
  }
375
+ return null;
329
376
  };
330
377
  var buildAddressLine = (parts) => {
331
378
  return parts.filter(Boolean).join(", ") || null;
@@ -455,6 +502,7 @@ var formatBusinessAddress = (businessAddress) => {
455
502
  var presenters = {
456
503
  formatBackLink,
457
504
  formatNumber,
505
+ formatDateInputValues,
458
506
  formatDisplayAddress,
459
507
  formatOriginalAddress,
460
508
  formatChangedAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Shared frontend engine used by both the internal and external frontend applications.",
5
5
  "main": "./dist/index.cjs",
6
6
  "exports": {
@@ -1,13 +1,15 @@
1
1
  import { updateBusinessEmailMutation } from './business/update-business-email.js'
2
2
  import { updateBusinessNameMutation } from './business/update-business-name.js'
3
3
  import { updateCustomerNameMutation } from './personal/update-customer-name.js'
4
- import { updateCustomerEmailMutation } from './personal/update-customer-email.js'
4
+ import { updateCustomerDobMutation } from './personal/update-customer-dob.js'
5
5
  import { updateCustomerPhoneMutation } from './personal/update-customer-phone.js'
6
+ import { updateCustomerEmailMutation } from './personal/update-customer-email.js'
6
7
 
7
8
  export const mutations = {
8
9
  updateBusinessEmail: updateBusinessEmailMutation,
9
10
  updateBusinessName: updateBusinessNameMutation,
10
11
  updateCustomerName: updateCustomerNameMutation,
11
- updateCustomerEmail: updateCustomerEmailMutation,
12
- updateCustomerPhone: updateCustomerPhoneMutation
12
+ updateCustomerDob: updateCustomerDobMutation,
13
+ updateCustomerPhone: updateCustomerPhoneMutation,
14
+ updateCustomerEmail: updateCustomerEmailMutation
13
15
  }
@@ -0,0 +1,11 @@
1
+ export const updateCustomerDobMutation = `
2
+ mutation UpdateCustomerDateOfBirth($input: UpdateCustomerDateOfBirthInput!) {
3
+ updateCustomerDateOfBirth(input: $input) {
4
+ customer {
5
+ info {
6
+ dateOfBirth
7
+ }
8
+ }
9
+ }
10
+ }
11
+ `
@@ -6,14 +6,23 @@
6
6
  * Otherwise, they navigate to the manual address entry page.
7
7
  *
8
8
  * @param {boolean} postcodeLookup - Whether the user used a postcode lookup to find their address
9
+ * @param {string} context - The context for the address change ('business' or 'personal')
9
10
  * @returns {string} The URL path for the address change page
10
11
  */
11
- export const addressChangeLink = (postcodeLookup) => {
12
- if (postcodeLookup) {
13
- return '/account-address-change'
14
- } else {
12
+ export const addressChangeLink = (postcodeLookup, context) => {
13
+ if (context === 'business') {
14
+ if (postcodeLookup) {
15
+ return '/business-address-change'
16
+ }
17
+ return '/business-address-enter'
18
+ }
19
+ if (context === 'personal') {
20
+ if (postcodeLookup) {
21
+ return '/account-address-change'
22
+ }
15
23
  return '/account-address-enter'
16
24
  }
25
+ return null
17
26
  }
18
27
 
19
28
  /**
@@ -23,14 +32,23 @@ export const addressChangeLink = (postcodeLookup) => {
23
32
  * If they manually entered the address, the back link returns to the manual entry page.
24
33
  *
25
34
  * @param {boolean} postcodeLookup - Whether the user used a postcode lookup to find their address
35
+ * @param {string} context - The context for the address change ('business' or 'personal')
26
36
  * @returns {Object} An object with an `href` property containing the back link URL
27
37
  */
28
- export const addressBackLink = (postcodeLookup) => {
29
- if (postcodeLookup) {
30
- return { href: '/account-address-select' }
31
- } else {
38
+ export const addressBackLink = (postcodeLookup, context) => {
39
+ if (context === 'business') {
40
+ if (postcodeLookup) {
41
+ return { href: '/business-address-select' }
42
+ }
43
+ return { href: '/business-address-enter' }
44
+ }
45
+ if (context === 'personal') {
46
+ if (postcodeLookup) {
47
+ return { href: '/account-address-select' }
48
+ }
32
49
  return { href: '/account-address-enter' }
33
50
  }
51
+ return null
34
52
  }
35
53
 
36
54
  /**
@@ -37,6 +37,38 @@ export const formatNumber = (payloadNumber, changedNumber, originalNumber) => {
37
37
  return originalNumber
38
38
  }
39
39
 
40
+ /**
41
+ * Builds date of birth values for the form inputs.
42
+ *
43
+ * Values coming from `payloadDob` are always strings (they come from the form).
44
+ * `changedDob` is saved payload data, so these values are also strings.
45
+ *
46
+ * The original date of birth value comes from the DAL and isn’t a string.
47
+ * When falling back to those values we explicitly convert them to strings
48
+ * so all sources are normalised and safe to use in inputs.
49
+ *
50
+ * Null values are handled to avoid showing 'null' in the UI.
51
+ */
52
+ const formatDatePart = (changed, original) => {
53
+ return changed ?? original?.toString() ?? ''
54
+ }
55
+
56
+ export const formatDateInputValues = (payloadDob, changedDob, originalDob) => {
57
+ if (payloadDob) {
58
+ return {
59
+ day: payloadDob.day ?? '',
60
+ month: payloadDob.month ?? '',
61
+ year: payloadDob.year ?? ''
62
+ }
63
+ }
64
+
65
+ return {
66
+ day: formatDatePart(changedDob?.day, originalDob?.day),
67
+ month: formatDatePart(changedDob?.month, originalDob?.month),
68
+ year: formatDatePart(changedDob?.year, originalDob?.year)
69
+ }
70
+ }
71
+
40
72
  /**
41
73
  * Shared helper used by base presenters to sort validation errors so they
42
74
  * appear in the same order as the sections and fields shown on a Fix List page.
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  formatBackLink,
3
3
  formatNumber,
4
+ formatDateInputValues,
4
5
  sortErrorsBySectionOrder
5
6
  } from './base-presenter.js'
6
7
 
@@ -23,6 +24,7 @@ import {
23
24
  export const presenters = {
24
25
  formatBackLink,
25
26
  formatNumber,
27
+ formatDateInputValues,
26
28
  formatDisplayAddress,
27
29
  formatOriginalAddress,
28
30
  formatChangedAddress,