@defra/fcp-sfd-frontend-engine 0.20.0 → 0.22.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
@@ -100,6 +100,7 @@ var MONTH_MAP = {
100
100
  // src/constants/success-messages.js
101
101
  var BUSINESS_EMAIL_ADDRESS = "You have updated your business email address";
102
102
  var BUSINESS_NAME = "You have updated your business name";
103
+ var BUSINESS_PHONE_NUMBERS = "You have updated your business phone numbers";
103
104
 
104
105
  // src/constants/index.js
105
106
  var constants = {
@@ -136,7 +137,8 @@ var constants = {
136
137
  monthMap: MONTH_MAP,
137
138
  successMessages: {
138
139
  BUSINESS_EMAIL_ADDRESS,
139
- BUSINESS_NAME
140
+ BUSINESS_NAME,
141
+ BUSINESS_PHONE_NUMBERS
140
142
  }
141
143
  };
142
144
 
@@ -704,7 +706,7 @@ var mappers = {
704
706
 
705
707
  // src/mutations/business/update-business-email.js
706
708
  var updateBusinessEmailMutation = `
707
- mutation Mutation($input: UpdateBusinessEmailInput!) {
709
+ mutation UpdateBusinessEmail($input: UpdateBusinessEmailInput!) {
708
710
  updateBusinessEmail(input: $input) {
709
711
  business {
710
712
  info {
@@ -732,6 +734,22 @@ var updateBusinessNameMutation = `
732
734
  }
733
735
  `;
734
736
 
737
+ // src/mutations/business/update-business-phone-numbers.js
738
+ var updateBusinessPhoneNumbersMutation = `
739
+ mutation UpdateBusinessPhoneNumbers($input: UpdateBusinessPhoneNumbersInput!) {
740
+ updateBusinessPhone(input: $input) {
741
+ business {
742
+ info {
743
+ phone {
744
+ landline
745
+ mobile
746
+ }
747
+ }
748
+ }
749
+ }
750
+ }
751
+ `;
752
+
735
753
  // src/mutations/personal/update-customer-name.js
736
754
  var updateCustomerNameMutation = `
737
755
  mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
@@ -853,12 +871,13 @@ var updateBusinessAddressMutation = `
853
871
  var mutations = {
854
872
  updateBusinessEmail: updateBusinessEmailMutation,
855
873
  updateBusinessName: updateBusinessNameMutation,
874
+ updateBusinessPhoneNumbers: updateBusinessPhoneNumbersMutation,
875
+ updateBusinessAddress: updateBusinessAddressMutation,
856
876
  updateCustomerName: updateCustomerNameMutation,
857
877
  updateCustomerDob: updateCustomerDobMutation,
858
878
  updateCustomerPhone: updateCustomerPhoneMutation,
859
879
  updateCustomerEmail: updateCustomerEmailMutation,
860
- updateCustomerAddress: updateCustomerAddressMutation,
861
- updateBusinessAddress: updateBusinessAddressMutation
880
+ updateCustomerAddress: updateCustomerAddressMutation
862
881
  };
863
882
 
864
883
  // src/presenters/base-presenter.js
@@ -895,6 +914,21 @@ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
895
914
  year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
896
915
  };
897
916
  };
917
+ var formatLongDate = (date) => {
918
+ if (date === null || date === void 0 || date === "") {
919
+ return null;
920
+ }
921
+ const localDate = new Date(date);
922
+ if (Number.isNaN(localDate.getTime())) {
923
+ return null;
924
+ }
925
+ return localDate.toLocaleDateString("en-GB", {
926
+ day: "numeric",
927
+ month: "long",
928
+ year: "numeric",
929
+ timeZone: "UTC"
930
+ });
931
+ };
898
932
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
899
933
  const sortedErrors = [];
900
934
  for (const section of orderedSectionsToFix) {
@@ -1071,6 +1105,7 @@ var presenters = {
1071
1105
  formatBackLink,
1072
1106
  formatNumber,
1073
1107
  formatDateInputValues,
1108
+ formatLongDate,
1074
1109
  formatDisplayAddress,
1075
1110
  formatOriginalAddress,
1076
1111
  formatChangedAddress,
@@ -1129,12 +1164,26 @@ var buildUpdateBusinessNameVariables = (name, sbi) => {
1129
1164
  return { input: { name, sbi } };
1130
1165
  };
1131
1166
 
1167
+ // src/utils/build-update-business-phone-numbers-variables.js
1168
+ var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1169
+ return {
1170
+ input: {
1171
+ phone: {
1172
+ landline: businessTelephone ?? null,
1173
+ mobile: businessMobile ?? null
1174
+ },
1175
+ sbi
1176
+ }
1177
+ };
1178
+ };
1179
+
1132
1180
  // src/utils/utils.js
1133
1181
  var utils = {
1134
1182
  formatFullName,
1135
1183
  formatValidationErrors,
1136
1184
  buildUpdateBusinessEmailVariables,
1137
- buildUpdateBusinessNameVariables
1185
+ buildUpdateBusinessNameVariables,
1186
+ buildUpdateBusinessPhoneNumbersVariables
1138
1187
  };
1139
1188
 
1140
1189
  // src/services/os-places/address-lookup-service.js
package/dist/index.js CHANGED
@@ -59,6 +59,7 @@ var MONTH_MAP = {
59
59
  // src/constants/success-messages.js
60
60
  var BUSINESS_EMAIL_ADDRESS = "You have updated your business email address";
61
61
  var BUSINESS_NAME = "You have updated your business name";
62
+ var BUSINESS_PHONE_NUMBERS = "You have updated your business phone numbers";
62
63
 
63
64
  // src/constants/index.js
64
65
  var constants = {
@@ -95,7 +96,8 @@ var constants = {
95
96
  monthMap: MONTH_MAP,
96
97
  successMessages: {
97
98
  BUSINESS_EMAIL_ADDRESS,
98
- BUSINESS_NAME
99
+ BUSINESS_NAME,
100
+ BUSINESS_PHONE_NUMBERS
99
101
  }
100
102
  };
101
103
 
@@ -663,7 +665,7 @@ var mappers = {
663
665
 
664
666
  // src/mutations/business/update-business-email.js
665
667
  var updateBusinessEmailMutation = `
666
- mutation Mutation($input: UpdateBusinessEmailInput!) {
668
+ mutation UpdateBusinessEmail($input: UpdateBusinessEmailInput!) {
667
669
  updateBusinessEmail(input: $input) {
668
670
  business {
669
671
  info {
@@ -691,6 +693,22 @@ var updateBusinessNameMutation = `
691
693
  }
692
694
  `;
693
695
 
696
+ // src/mutations/business/update-business-phone-numbers.js
697
+ var updateBusinessPhoneNumbersMutation = `
698
+ mutation UpdateBusinessPhoneNumbers($input: UpdateBusinessPhoneNumbersInput!) {
699
+ updateBusinessPhone(input: $input) {
700
+ business {
701
+ info {
702
+ phone {
703
+ landline
704
+ mobile
705
+ }
706
+ }
707
+ }
708
+ }
709
+ }
710
+ `;
711
+
694
712
  // src/mutations/personal/update-customer-name.js
695
713
  var updateCustomerNameMutation = `
696
714
  mutation UpdateCustomerName($input: UpdateCustomerNameInput!) {
@@ -812,12 +830,13 @@ var updateBusinessAddressMutation = `
812
830
  var mutations = {
813
831
  updateBusinessEmail: updateBusinessEmailMutation,
814
832
  updateBusinessName: updateBusinessNameMutation,
833
+ updateBusinessPhoneNumbers: updateBusinessPhoneNumbersMutation,
834
+ updateBusinessAddress: updateBusinessAddressMutation,
815
835
  updateCustomerName: updateCustomerNameMutation,
816
836
  updateCustomerDob: updateCustomerDobMutation,
817
837
  updateCustomerPhone: updateCustomerPhoneMutation,
818
838
  updateCustomerEmail: updateCustomerEmailMutation,
819
- updateCustomerAddress: updateCustomerAddressMutation,
820
- updateBusinessAddress: updateBusinessAddressMutation
839
+ updateCustomerAddress: updateCustomerAddressMutation
821
840
  };
822
841
 
823
842
  // src/presenters/base-presenter.js
@@ -854,6 +873,21 @@ var formatDateInputValues = (payloadDob, changedDob, originalDob) => {
854
873
  year: formatDatePart(changedDob == null ? void 0 : changedDob.year, originalDob == null ? void 0 : originalDob.year)
855
874
  };
856
875
  };
876
+ var formatLongDate = (date) => {
877
+ if (date === null || date === void 0 || date === "") {
878
+ return null;
879
+ }
880
+ const localDate = new Date(date);
881
+ if (Number.isNaN(localDate.getTime())) {
882
+ return null;
883
+ }
884
+ return localDate.toLocaleDateString("en-GB", {
885
+ day: "numeric",
886
+ month: "long",
887
+ year: "numeric",
888
+ timeZone: "UTC"
889
+ });
890
+ };
857
891
  var sortErrorsBySectionOrder = (errors, orderedSectionsToFix, SECTION_FIELD_ORDER) => {
858
892
  const sortedErrors = [];
859
893
  for (const section of orderedSectionsToFix) {
@@ -1030,6 +1064,7 @@ var presenters = {
1030
1064
  formatBackLink,
1031
1065
  formatNumber,
1032
1066
  formatDateInputValues,
1067
+ formatLongDate,
1033
1068
  formatDisplayAddress,
1034
1069
  formatOriginalAddress,
1035
1070
  formatChangedAddress,
@@ -1088,12 +1123,26 @@ var buildUpdateBusinessNameVariables = (name, sbi) => {
1088
1123
  return { input: { name, sbi } };
1089
1124
  };
1090
1125
 
1126
+ // src/utils/build-update-business-phone-numbers-variables.js
1127
+ var buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
1128
+ return {
1129
+ input: {
1130
+ phone: {
1131
+ landline: businessTelephone ?? null,
1132
+ mobile: businessMobile ?? null
1133
+ },
1134
+ sbi
1135
+ }
1136
+ };
1137
+ };
1138
+
1091
1139
  // src/utils/utils.js
1092
1140
  var utils = {
1093
1141
  formatFullName,
1094
1142
  formatValidationErrors,
1095
1143
  buildUpdateBusinessEmailVariables,
1096
- buildUpdateBusinessNameVariables
1144
+ buildUpdateBusinessNameVariables,
1145
+ buildUpdateBusinessPhoneNumbersVariables
1097
1146
  };
1098
1147
 
1099
1148
  // src/services/os-places/address-lookup-service.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/fcp-sfd-frontend-engine",
3
- "version": "0.20.0",
3
+ "version": "0.22.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": {
@@ -33,7 +33,11 @@ import { PHONE_NUMBER_PATTERN, NO_CONTROL_CHARS_PATTERN } from './patterns.js'
33
33
  import { MONTH_MAP } from './month-map.js'
34
34
 
35
35
  // Success messages
36
- import { BUSINESS_EMAIL_ADDRESS, BUSINESS_NAME } from './success-messages.js'
36
+ import {
37
+ BUSINESS_EMAIL_ADDRESS,
38
+ BUSINESS_NAME,
39
+ BUSINESS_PHONE_NUMBERS
40
+ } from './success-messages.js'
37
41
 
38
42
  export const constants = {
39
43
  statusCodes: {
@@ -69,6 +73,7 @@ export const constants = {
69
73
  monthMap: MONTH_MAP,
70
74
  successMessages: {
71
75
  BUSINESS_EMAIL_ADDRESS,
72
- BUSINESS_NAME
76
+ BUSINESS_NAME,
77
+ BUSINESS_PHONE_NUMBERS
73
78
  }
74
79
  }
@@ -1,2 +1,3 @@
1
1
  export const BUSINESS_EMAIL_ADDRESS = 'You have updated your business email address'
2
2
  export const BUSINESS_NAME = 'You have updated your business name'
3
+ export const BUSINESS_PHONE_NUMBERS = 'You have updated your business phone numbers'
@@ -1,5 +1,5 @@
1
1
  export const updateBusinessEmailMutation = `
2
- mutation Mutation($input: UpdateBusinessEmailInput!) {
2
+ mutation UpdateBusinessEmail($input: UpdateBusinessEmailInput!) {
3
3
  updateBusinessEmail(input: $input) {
4
4
  business {
5
5
  info {
@@ -0,0 +1,14 @@
1
+ export const updateBusinessPhoneNumbersMutation = `
2
+ mutation UpdateBusinessPhoneNumbers($input: UpdateBusinessPhoneNumbersInput!) {
3
+ updateBusinessPhone(input: $input) {
4
+ business {
5
+ info {
6
+ phone {
7
+ landline
8
+ mobile
9
+ }
10
+ }
11
+ }
12
+ }
13
+ }
14
+ `
@@ -1,5 +1,6 @@
1
1
  import { updateBusinessEmailMutation } from './business/update-business-email.js'
2
2
  import { updateBusinessNameMutation } from './business/update-business-name.js'
3
+ import { updateBusinessPhoneNumbersMutation } from './business/update-business-phone-numbers.js'
3
4
  import { updateCustomerNameMutation } from './personal/update-customer-name.js'
4
5
  import { updateCustomerDobMutation } from './personal/update-customer-dob.js'
5
6
  import { updateCustomerPhoneMutation } from './personal/update-customer-phone.js'
@@ -10,10 +11,11 @@ import { updateBusinessAddressMutation } from './business/update-business-addres
10
11
  export const mutations = {
11
12
  updateBusinessEmail: updateBusinessEmailMutation,
12
13
  updateBusinessName: updateBusinessNameMutation,
14
+ updateBusinessPhoneNumbers: updateBusinessPhoneNumbersMutation,
15
+ updateBusinessAddress: updateBusinessAddressMutation,
13
16
  updateCustomerName: updateCustomerNameMutation,
14
17
  updateCustomerDob: updateCustomerDobMutation,
15
18
  updateCustomerPhone: updateCustomerPhoneMutation,
16
19
  updateCustomerEmail: updateCustomerEmailMutation,
17
- updateCustomerAddress: updateCustomerAddressMutation,
18
- updateBusinessAddress: updateBusinessAddressMutation,
20
+ updateCustomerAddress: updateCustomerAddressMutation
19
21
  }
@@ -69,6 +69,31 @@ export const formatDateInputValues = (payloadDob, changedDob, originalDob) => {
69
69
  }
70
70
  }
71
71
 
72
+ /**
73
+ * Formats a date as a long-form UK date string, e.g. "5 April 1990".
74
+ * Accepts a Date object or any value that can be passed to new Date().
75
+ * Returns null if no date is provided.
76
+ */
77
+ export const formatLongDate = (date) => {
78
+ if (date === null || date === undefined || date === '') {
79
+ return null
80
+ }
81
+
82
+ const localDate = new Date(date)
83
+
84
+ // new Date() on an unrecognisable value doesn't throw, it just produces NaN when you call getTime()
85
+ if (Number.isNaN(localDate.getTime())) {
86
+ return null
87
+ }
88
+
89
+ return localDate.toLocaleDateString('en-GB', {
90
+ day: 'numeric',
91
+ month: 'long',
92
+ year: 'numeric',
93
+ timeZone: 'UTC'
94
+ })
95
+ }
96
+
72
97
  /**
73
98
  * Shared helper used by base presenters to sort validation errors so they
74
99
  * appear in the same order as the sections and fields shown on a Fix List page.
@@ -2,6 +2,7 @@ import {
2
2
  formatBackLink,
3
3
  formatNumber,
4
4
  formatDateInputValues,
5
+ formatLongDate,
5
6
  sortErrorsBySectionOrder
6
7
  } from './base-presenter.js'
7
8
 
@@ -25,6 +26,7 @@ export const presenters = {
25
26
  formatBackLink,
26
27
  formatNumber,
27
28
  formatDateInputValues,
29
+ formatLongDate,
28
30
  formatDisplayAddress,
29
31
  formatOriginalAddress,
30
32
  formatChangedAddress,
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Builds the GraphQL variables for the `updateBusinessPhoneNumbers` mutation.
3
+ *
4
+ * @param {string|null} businessTelephone - The new business landline number
5
+ * @param {string|null} businessMobile - The new business mobile number
6
+ * @param {string} sbi = The Single Business Identifier of the business being updated
7
+ * @returns {object} The mutation variables in the shape `{ input: { phone { landline, mobile }, sbi } }
8
+ */
9
+
10
+ export const buildUpdateBusinessPhoneNumbersVariables = (businessTelephone, businessMobile, sbi) => {
11
+ return {
12
+ input: {
13
+ phone: {
14
+ landline: businessTelephone ?? null,
15
+ mobile: businessMobile ?? null
16
+ },
17
+ sbi
18
+ }
19
+ }
20
+ }
@@ -2,10 +2,12 @@ import { formatFullName } from './format-full-name.js'
2
2
  import { formatValidationErrors } from './format-validation-errors.js'
3
3
  import { buildUpdateBusinessEmailVariables } from './build-update-business-email-variables.js'
4
4
  import { buildUpdateBusinessNameVariables } from './build-update-business-name-variables.js'
5
+ import { buildUpdateBusinessPhoneNumbersVariables } from './build-update-business-phone-numbers-variables.js'
5
6
 
6
7
  export const utils = {
7
8
  formatFullName,
8
9
  formatValidationErrors,
9
10
  buildUpdateBusinessEmailVariables,
10
- buildUpdateBusinessNameVariables
11
+ buildUpdateBusinessNameVariables,
12
+ buildUpdateBusinessPhoneNumbersVariables
11
13
  }