@defra/fcp-sfd-frontend-engine 0.17.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) {
@@ -511,6 +542,7 @@ var formatBusinessAddress = (businessAddress) => {
511
542
  var presenters = {
512
543
  formatBackLink,
513
544
  formatNumber,
545
+ formatDateInputValues,
514
546
  formatDisplayAddress,
515
547
  formatOriginalAddress,
516
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) {
@@ -471,6 +502,7 @@ var formatBusinessAddress = (businessAddress) => {
471
502
  var presenters = {
472
503
  formatBackLink,
473
504
  formatNumber,
505
+ formatDateInputValues,
474
506
  formatDisplayAddress,
475
507
  formatOriginalAddress,
476
508
  formatChangedAddress,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.17.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
+ `
@@ -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,