@financial-times/n-conversion-forms 27.7.1 → 28.0.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/.eslintignore +1 -0
- package/build-state/npm-shrinkwrap.json +1808 -1324
- package/components/__snapshots__/payment-type.spec.js.snap +0 -2
- package/components/accept-terms.jsx +18 -16
- package/components/app-banner.jsx +1 -1
- package/components/b2c-partnership-confirmation.jsx +1 -1
- package/components/billing-city.jsx +1 -1
- package/components/billing-country.jsx +1 -1
- package/components/billing-postcode.jsx +1 -1
- package/components/company-name.jsx +1 -1
- package/components/confirmation.jsx +5 -4
- package/components/continue-reading.jsx +1 -1
- package/components/continue-reading.stories.js +1 -1
- package/components/country.jsx +1 -1
- package/components/customer-care.jsx +1 -1
- package/components/debug.jsx +1 -1
- package/components/decision-maker.jsx +1 -1
- package/components/decision-maker.spec.js +1 -1
- package/components/deferred-billing-terms.jsx +92 -76
- package/components/deferred-billing-terms.spec.js +5 -1
- package/components/deferred-billing-terms.stories.js +3 -3
- package/components/delivery-address-type.jsx +4 -4
- package/components/delivery-address.jsx +1 -1
- package/components/delivery-city.jsx +9 -5
- package/components/delivery-county.jsx +1 -1
- package/components/delivery-instructions.jsx +30 -21
- package/components/delivery-option.jsx +5 -2
- package/components/delivery-po-box.jsx +1 -1
- package/components/delivery-postcode.jsx +32 -28
- package/components/delivery-security-instructions.jsx +1 -1
- package/components/delivery-start-date.jsx +1 -1
- package/components/education-job-title.jsx +1 -1
- package/components/email.jsx +1 -1
- package/components/error-page.jsx +1 -1
- package/components/fieldset.jsx +1 -1
- package/components/first-name.jsx +1 -1
- package/components/form.jsx +1 -1
- package/components/google-sign-in.jsx +1 -1
- package/components/graduation-date.jsx +1 -1
- package/components/industry.jsx +1 -1
- package/components/job-title.jsx +1 -1
- package/components/last-name.jsx +1 -1
- package/components/licence-confirmation.jsx +10 -8
- package/components/licence-header.jsx +3 -3
- package/components/licence-sign-in.jsx +2 -2
- package/components/licence-title.jsx +2 -2
- package/components/lite-sub-confirmation.jsx +1 -1
- package/components/loader.jsx +1 -1
- package/components/message.jsx +1 -1
- package/components/organisation.jsx +1 -1
- package/components/package-change.jsx +1 -1
- package/components/password.jsx +1 -1
- package/components/payment-term.jsx +52 -43
- package/components/payment-term.spec.js +15 -9
- package/components/payment-term.stories.js +63 -63
- package/components/payment-type.jsx +4 -4
- package/components/personal-title.jsx +1 -1
- package/components/phone.jsx +1 -1
- package/components/position.jsx +1 -1
- package/components/progress-indicator.jsx +3 -3
- package/components/province.jsx +1 -1
- package/components/registration-confirmation.jsx +1 -1
- package/components/responsibility.jsx +1 -1
- package/components/section.jsx +1 -1
- package/components/state.jsx +1 -1
- package/components/submit.jsx +1 -1
- package/components/text-input.jsx +1 -1
- package/components/trial-banner.jsx +1 -1
- package/dist/deferred-billing-terms.js +2 -3
- package/dist/payment-term.js +1 -1
- package/dist/payment-type.js +2 -2
- package/helpers/index.js +11 -8
- package/helpers/ncf-countries.spec.js +1 -1
- package/helpers/supportedCountries.js +12 -5
- package/helpers/supportedPostcodeExamples.js +5 -5
- package/helpers/supportedPostcodeValidators.js +5 -5
- package/helpers/supportedPostcodeValidators.spec.js +30 -10
- package/helpers/utilities.js +4 -4
- package/jest.config.js +1 -5
- package/package.json +14 -17
- package/styles/message.scss +0 -16
- package/test-jest/helpers/expect-to-render-correctly.js +1 -1
- package/utils/app-banner.js +1 -1
- package/utils/apple-pay.js +15 -15
- package/utils/billing-city.js +1 -1
- package/utils/billing-country.js +3 -3
- package/utils/billing-postcode.js +1 -1
- package/utils/company-name.js +1 -1
- package/utils/countries.js +2 -2
- package/utils/country.js +3 -3
- package/utils/delivery-address-type.js +3 -3
- package/utils/delivery-address-type.spec.js +6 -2
- package/utils/delivery-address.js +1 -1
- package/utils/delivery-instructions.js +1 -1
- package/utils/delivery-option-messages.js +11 -11
- package/utils/delivery-option-messages.spec.js +4 -13
- package/utils/delivery-option.js +5 -5
- package/utils/delivery-po-box.js +1 -1
- package/utils/delivery-postcode.js +1 -1
- package/utils/delivery-start-date.js +4 -4
- package/utils/delivery-start-date.spec.js +3 -2
- package/utils/email.js +4 -4
- package/utils/email.spec.js +2 -1
- package/utils/event-notifier.js +1 -1
- package/utils/form-element.js +8 -8
- package/utils/loader.js +10 -10
- package/utils/password.js +2 -2
- package/utils/payment-term.js +16 -15
- package/utils/payment-type.js +14 -14
- package/utils/postcode.js +3 -3
- package/utils/postcode.spec.js +21 -12
- package/utils/province.js +1 -1
- package/utils/salesforce.js +2 -2
- package/utils/state.js +1 -1
- package/utils/submit.js +5 -5
- package/utils/tracking.js +7 -7
- package/utils/validation.js +18 -11
- package/utils/zuora-error-map.js +5 -5
- package/utils/zuora.js +17 -12
|
@@ -64,7 +64,7 @@ const deliveryOptionMessages = [
|
|
|
64
64
|
country: [USA_COUNTRY_CODE, CAN_COUNTRY_CODE],
|
|
65
65
|
title: 'Hand delivery',
|
|
66
66
|
description:
|
|
67
|
-
|
|
67
|
+
"Enjoy delivery of the newspaper daily to your home or office address. \nPlease note: We fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside of the FT's control. In those circumstances, your newspaper will be delivered on the next delivery day.",
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
deliveryFrequency: [
|
|
@@ -90,7 +90,7 @@ const deliveryOptionMessages = [
|
|
|
90
90
|
country: [USA_COUNTRY_CODE, CAN_COUNTRY_CODE],
|
|
91
91
|
title: 'Hand delivery',
|
|
92
92
|
description:
|
|
93
|
-
|
|
93
|
+
"Enjoy delivery of the newspaper daily to your home or office address. \nPlease note: We fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside of the FT's control. In those circumstances, your newspaper will be delivered on the next delivery day. Please also be aware that your FT Weekend will be delivered on Sunday.",
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
deliveryFrequency: [
|
|
@@ -184,7 +184,7 @@ const deliveryOptionMessages = [
|
|
|
184
184
|
title: 'Mail',
|
|
185
185
|
customId: 'ML',
|
|
186
186
|
description:
|
|
187
|
-
|
|
187
|
+
"We can only deliver the newspaper to your location by postal mail which means your delivery will arrive up to 5 business days after the date of publication and will not include the HTSI Magazine. We also fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside the FT's control. If you prefer to read the printed content on the day of publication, please proceed to subscribe to the FT ePaper - a digital replica of the print edition.",
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
deliveryFrequency: [ONLY_WEEKEND_DELIVERY_FREQ],
|
|
@@ -194,7 +194,7 @@ const deliveryOptionMessages = [
|
|
|
194
194
|
country: [USA_COUNTRY_CODE, CAN_COUNTRY_CODE],
|
|
195
195
|
title: 'Hand delivery',
|
|
196
196
|
description:
|
|
197
|
-
|
|
197
|
+
"Enjoy delivery of the newspaper daily to your home or office address. \nPlease note: We fly the newspapers to your location which means delivery is subject to flight delays/cancellations outside of the FT's control. In those circumstances, your newspaper will be delivered the next delivery day.",
|
|
198
198
|
},
|
|
199
199
|
{
|
|
200
200
|
deliveryFrequency: [ONLY_WEEKEND_DELIVERY_FREQ],
|
|
@@ -214,7 +214,7 @@ const deliveryOptionMessages = [
|
|
|
214
214
|
country: [USA_COUNTRY_CODE, CAN_COUNTRY_CODE],
|
|
215
215
|
title: 'Hand delivery',
|
|
216
216
|
description:
|
|
217
|
-
|
|
217
|
+
"Enjoy delivery of the newspaper daily to your home or office address. \nPlease note we fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside of the FT's control. In those circumstances, your newspaper will be delivered on the next delivery day. Please also be aware that your FT Weekend will be delivered on Sunday.",
|
|
218
218
|
},
|
|
219
219
|
{
|
|
220
220
|
deliveryFrequency: [ONLY_WEEKEND_DELIVERY_FREQ],
|
|
@@ -233,18 +233,18 @@ const deliveryOptionMessages = [
|
|
|
233
233
|
title: 'Mail',
|
|
234
234
|
customId: 'ML',
|
|
235
235
|
description:
|
|
236
|
-
|
|
236
|
+
"We can only deliver the FT Weekend newspaper to your location by postal mail which means your delivery will arrive up to 5 business days after the date of publication and will not include the HTSI Magazine. We also fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside the FT's control. If you prefer to read the printed content on the day of publication, please proceed to subscribe to the FT ePaper - a digital replica of the print edition.",
|
|
237
237
|
},
|
|
238
238
|
];
|
|
239
239
|
|
|
240
|
-
function includesDeliveryFrequency
|
|
240
|
+
function includesDeliveryFrequency(productCode = '', item) {
|
|
241
241
|
return item.deliveryFrequency.find((freq) => {
|
|
242
242
|
const productCodePattern = deliveryFrequencyProductsMapping[freq];
|
|
243
243
|
return productCode.includes(productCodePattern);
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
function mailStrategy
|
|
247
|
+
function mailStrategy(productCode, option, FTShippingZone, item) {
|
|
248
248
|
return (
|
|
249
249
|
includesDeliveryFrequency(productCode, item) &&
|
|
250
250
|
item.distributorType === MAIL &&
|
|
@@ -252,7 +252,7 @@ function mailStrategy (productCode, option, FTShippingZone, item) {
|
|
|
252
252
|
);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
function handDeliveryStrategy
|
|
255
|
+
function handDeliveryStrategy(productCode, option, FTShippingZone, item) {
|
|
256
256
|
return (
|
|
257
257
|
includesDeliveryFrequency(productCode, item) &&
|
|
258
258
|
item.distributorType === HAND_DELIVERY &&
|
|
@@ -268,7 +268,7 @@ function handDeliveryStrategy (productCode, option, FTShippingZone, item) {
|
|
|
268
268
|
* Both cases are represented by system option code 'HD', but differ on the mailDelivery property value.
|
|
269
269
|
* If no message matchs, then undefined is returned.
|
|
270
270
|
*/
|
|
271
|
-
function findCustomDeliveryOption
|
|
271
|
+
function findCustomDeliveryOption(productCode, option, FTShippingZone) {
|
|
272
272
|
let deliveryOption;
|
|
273
273
|
|
|
274
274
|
if (option.value === HAND_DELIVERY) {
|
|
@@ -287,7 +287,7 @@ function findCustomDeliveryOption (productCode, option, FTShippingZone) {
|
|
|
287
287
|
return deliveryOption;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
function getDeliveryOption
|
|
290
|
+
function getDeliveryOption(productCode, option, FTShippingZone) {
|
|
291
291
|
return FTShippingZone === UK_COUNTRY_CODE
|
|
292
292
|
? UKDeliveryOptions[option.value]
|
|
293
293
|
: findCustomDeliveryOption(productCode, option, FTShippingZone);
|
|
@@ -86,7 +86,7 @@ describe('Find Custom Delivery Option', () => {
|
|
|
86
86
|
title: 'Mail',
|
|
87
87
|
customId: 'ML',
|
|
88
88
|
description:
|
|
89
|
-
|
|
89
|
+
"We can only deliver the newspaper to your location by postal mail which means your delivery will arrive up to 5 business days after the date of publication and will not include the HTSI Magazine. We also fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside the FT's control. If you prefer to read the printed content on the day of publication, please proceed to subscribe to the FT ePaper - a digital replica of the print edition.",
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
const deliveryOption = getDeliveryOption(
|
|
@@ -103,7 +103,7 @@ describe('Find Custom Delivery Option', () => {
|
|
|
103
103
|
title: 'Mail',
|
|
104
104
|
customId: 'ML',
|
|
105
105
|
description:
|
|
106
|
-
|
|
106
|
+
"We can only deliver the FT Weekend newspaper to your location by postal mail which means your delivery will arrive up to 5 business days after the date of publication and will not include the HTSI Magazine. We also fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside the FT's control. If you prefer to read the printed content on the day of publication, please proceed to subscribe to the FT ePaper - a digital replica of the print edition.",
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const deliveryOption = getDeliveryOption(
|
|
@@ -135,7 +135,6 @@ describe('Find Custom Delivery Option', () => {
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
describe('Find CEMEA/APAC Delivery Option', () => {
|
|
138
|
-
|
|
139
138
|
it('returns CEMEA/APAC HD delivery option', () => {
|
|
140
139
|
stubOption.flightMarket = true;
|
|
141
140
|
stubOption.deliveryOnPublicationDate = false;
|
|
@@ -146,11 +145,7 @@ describe('Find Custom Delivery Option', () => {
|
|
|
146
145
|
'Enjoy the delivery of the newspaper to your home or office address. Please note we fly the newspaper to your location which means delivery is subject to flight delays/cancellations outside of the FT’s control. In those circumstances, your newspaper will be delivered the next delivery day. Please also be aware that your FT weekend will be delivered on Sunday.',
|
|
147
146
|
};
|
|
148
147
|
|
|
149
|
-
const deliveryOption = getDeliveryOption(
|
|
150
|
-
'N6D',
|
|
151
|
-
stubOption,
|
|
152
|
-
'CEMEA_V1'
|
|
153
|
-
);
|
|
148
|
+
const deliveryOption = getDeliveryOption('N6D', stubOption, 'CEMEA_V1');
|
|
154
149
|
|
|
155
150
|
expect(deliveryOption).toEqual(expected);
|
|
156
151
|
});
|
|
@@ -165,11 +160,7 @@ describe('Find Custom Delivery Option', () => {
|
|
|
165
160
|
'Enjoy delivery of the newspaper to your home or office address. Note this is a postal delivery - expect delivery after the day of publication. If you would prefer to read the newspaper on the day of publication, purchase an FT ePaper subscription, our digital replica of the each daily edition.',
|
|
166
161
|
};
|
|
167
162
|
|
|
168
|
-
const deliveryOption = getDeliveryOption(
|
|
169
|
-
'N6D',
|
|
170
|
-
stubOption,
|
|
171
|
-
'APAC'
|
|
172
|
-
);
|
|
163
|
+
const deliveryOption = getDeliveryOption('N6D', stubOption, 'APAC');
|
|
173
164
|
|
|
174
165
|
expect(deliveryOption).toEqual(expected);
|
|
175
166
|
});
|
package/utils/delivery-option.js
CHANGED
|
@@ -9,7 +9,7 @@ class DeliveryOption {
|
|
|
9
9
|
* @param {Element} element Usually the window.document
|
|
10
10
|
* @throws If the element not passed
|
|
11
11
|
*/
|
|
12
|
-
constructor
|
|
12
|
+
constructor(element) {
|
|
13
13
|
if (!element) {
|
|
14
14
|
throw new Error('Please supply the DOM element');
|
|
15
15
|
}
|
|
@@ -27,7 +27,7 @@ class DeliveryOption {
|
|
|
27
27
|
* Binds the given callback to the field's onchange event.
|
|
28
28
|
* @param {Function} callback The callback function to call when a change event occurs.
|
|
29
29
|
*/
|
|
30
|
-
handleDeliveryOptionChange
|
|
30
|
+
handleDeliveryOptionChange(callback) {
|
|
31
31
|
if (this.$form.elements['deliveryOption'].length === undefined) {
|
|
32
32
|
this.$form.elements['deliveryOption'].addEventListener(
|
|
33
33
|
'change',
|
|
@@ -43,7 +43,7 @@ class DeliveryOption {
|
|
|
43
43
|
/**
|
|
44
44
|
* Hide a specific radio input item.
|
|
45
45
|
*/
|
|
46
|
-
hideItem
|
|
46
|
+
hideItem(itemId) {
|
|
47
47
|
const labelNodes = this.$form.querySelectorAll(
|
|
48
48
|
'.ncf__delivery-option__item'
|
|
49
49
|
);
|
|
@@ -56,7 +56,7 @@ class DeliveryOption {
|
|
|
56
56
|
/**
|
|
57
57
|
* Show a specific radio input item.
|
|
58
58
|
*/
|
|
59
|
-
showItem
|
|
59
|
+
showItem(itemId) {
|
|
60
60
|
const labelNodes = this.$form.querySelectorAll(
|
|
61
61
|
'.ncf__delivery-option__item'
|
|
62
62
|
);
|
|
@@ -69,7 +69,7 @@ class DeliveryOption {
|
|
|
69
69
|
/**
|
|
70
70
|
* Mark an input item as checked
|
|
71
71
|
*/
|
|
72
|
-
checkItem
|
|
72
|
+
checkItem(itemId) {
|
|
73
73
|
const inputNodes = this.$form.elements['deliveryOption'];
|
|
74
74
|
const item = Array.from(inputNodes).find((node) => node.id === itemId);
|
|
75
75
|
if (item) {
|
package/utils/delivery-po-box.js
CHANGED
|
@@ -11,7 +11,7 @@ class DeliveryStartDate {
|
|
|
11
11
|
* @param {Element} element Usually the window.document
|
|
12
12
|
* @throws If the element not passed
|
|
13
13
|
*/
|
|
14
|
-
constructor
|
|
14
|
+
constructor(element) {
|
|
15
15
|
if (!element) {
|
|
16
16
|
throw new Error('Please supply the DOM element');
|
|
17
17
|
}
|
|
@@ -60,7 +60,7 @@ class DeliveryStartDate {
|
|
|
60
60
|
* @returns {boolean} Whether or not the start date is valid.
|
|
61
61
|
* @throws If there was an error calling the endpoint to check this.
|
|
62
62
|
*/
|
|
63
|
-
async handleDeliveryStartDateChange
|
|
63
|
+
async handleDeliveryStartDateChange(url, getData) {
|
|
64
64
|
const isNewValue =
|
|
65
65
|
this.previousDeliveryDateValue !== this.$deliveryStartDate.value;
|
|
66
66
|
this.previousDeliveryDateValue = this.$deliveryStartDate.value;
|
|
@@ -103,14 +103,14 @@ class DeliveryStartDate {
|
|
|
103
103
|
/**
|
|
104
104
|
* Enables the start date field
|
|
105
105
|
*/
|
|
106
|
-
enable
|
|
106
|
+
enable() {
|
|
107
107
|
this.$deliveryStartDate.removeAttribute('disabled');
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Disables the start date field
|
|
112
112
|
*/
|
|
113
|
-
disable
|
|
113
|
+
disable() {
|
|
114
114
|
this.$deliveryStartDate.setAttribute('disabled', 'true');
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -73,7 +73,7 @@ describe('DeliveryStartDate', () => {
|
|
|
73
73
|
let startDateUtil;
|
|
74
74
|
let startDateChangeResult;
|
|
75
75
|
|
|
76
|
-
async function setup
|
|
76
|
+
async function setup() {
|
|
77
77
|
global.fetch = jest.fn(() =>
|
|
78
78
|
Promise.resolve({
|
|
79
79
|
json: () =>
|
|
@@ -136,7 +136,8 @@ describe('DeliveryStartDate', () => {
|
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it('displays an error and return false if the fetch call errors', async () => {
|
|
139
|
-
|
|
139
|
+
const fetchError = new Error('API is down');
|
|
140
|
+
global.fetch = jest.fn(() => Promise.reject(fetchError));
|
|
140
141
|
startDateUtil = new DeliveryStartDate(document);
|
|
141
142
|
|
|
142
143
|
let startDateChangeResult =
|
package/utils/email.js
CHANGED
|
@@ -12,7 +12,7 @@ class Email {
|
|
|
12
12
|
* @throws If the element not passed
|
|
13
13
|
* @throws When the email element not found
|
|
14
14
|
*/
|
|
15
|
-
constructor
|
|
15
|
+
constructor(element) {
|
|
16
16
|
if (!element) {
|
|
17
17
|
throw new Error('Please supply the DOM element');
|
|
18
18
|
}
|
|
@@ -35,7 +35,7 @@ class Email {
|
|
|
35
35
|
/**
|
|
36
36
|
* Check the values of the two fields and update error state accordingly.
|
|
37
37
|
*/
|
|
38
|
-
checkMatch
|
|
38
|
+
checkMatch() {
|
|
39
39
|
if (this.$emailConfirm.value) {
|
|
40
40
|
if (this.$email.value !== this.$emailConfirm.value) {
|
|
41
41
|
this.$emailConfirmField.classList.add('o-forms--error');
|
|
@@ -54,7 +54,7 @@ class Email {
|
|
|
54
54
|
* @param {Function} onNotFound Callback function to run if email does *not* exist.
|
|
55
55
|
* @returns {Function} The handler function so the caller can unregister it if they need.
|
|
56
56
|
*/
|
|
57
|
-
registerEmailExistsCheck
|
|
57
|
+
registerEmailExistsCheck(url, onFound, onNotFound) {
|
|
58
58
|
const handler = () => {
|
|
59
59
|
this.handleEmailExistsChange(url, onFound, onNotFound);
|
|
60
60
|
};
|
|
@@ -71,7 +71,7 @@ class Email {
|
|
|
71
71
|
* @param {Function} onNotFound Function to call when not found
|
|
72
72
|
* @return {Promise}
|
|
73
73
|
*/
|
|
74
|
-
handleEmailExistsChange
|
|
74
|
+
handleEmailExistsChange(url, onFound, onNotFound) {
|
|
75
75
|
if (this.$email.value) {
|
|
76
76
|
return fetch(url, {
|
|
77
77
|
method: 'POST',
|
package/utils/email.spec.js
CHANGED
|
@@ -170,7 +170,8 @@ describe('Email', () => {
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it('calls the onNotFound callback if the call to the url fails', async () => {
|
|
173
|
-
|
|
173
|
+
const fetchError = new Error('API is down');
|
|
174
|
+
global.fetch = jest.fn(() => Promise.reject(fetchError));
|
|
174
175
|
|
|
175
176
|
emailElement.value = 'test@example.com';
|
|
176
177
|
await email.handleEmailExistsChange(url, onFound, onNotFound);
|
package/utils/event-notifier.js
CHANGED
package/utils/form-element.js
CHANGED
|
@@ -10,7 +10,7 @@ class FormElement {
|
|
|
10
10
|
* @param {object} document The global document object
|
|
11
11
|
* @param {string} querySelector The selector for the main element used by this component.
|
|
12
12
|
*/
|
|
13
|
-
constructor
|
|
13
|
+
constructor(document, querySelector) {
|
|
14
14
|
this.$document = document;
|
|
15
15
|
|
|
16
16
|
if (!this.$document) {
|
|
@@ -31,21 +31,21 @@ class FormElement {
|
|
|
31
31
|
/**
|
|
32
32
|
* Hides the form element.
|
|
33
33
|
*/
|
|
34
|
-
hide
|
|
34
|
+
hide() {
|
|
35
35
|
this.$el.classList.add('ncf__hidden');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Shows the form element.
|
|
40
40
|
*/
|
|
41
|
-
show
|
|
41
|
+
show() {
|
|
42
42
|
this.$el.classList.remove('ncf__hidden');
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Disable any inputs or selects inside form element
|
|
47
47
|
*/
|
|
48
|
-
disable
|
|
48
|
+
disable() {
|
|
49
49
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
50
50
|
this.inputs[i].disabled = true;
|
|
51
51
|
}
|
|
@@ -54,7 +54,7 @@ class FormElement {
|
|
|
54
54
|
/**
|
|
55
55
|
* Enable any inputs or selects inside form element
|
|
56
56
|
*/
|
|
57
|
-
enable
|
|
57
|
+
enable() {
|
|
58
58
|
for (let i = 0; i < this.inputs.length; i++) {
|
|
59
59
|
this.inputs[i].disabled = false;
|
|
60
60
|
}
|
|
@@ -64,14 +64,14 @@ class FormElement {
|
|
|
64
64
|
* Get the value of the form element
|
|
65
65
|
* Assumes the first input or select is what's required
|
|
66
66
|
*/
|
|
67
|
-
value
|
|
67
|
+
value() {
|
|
68
68
|
return this.$el.querySelector('input,select').value;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Make first input element required
|
|
73
73
|
*/
|
|
74
|
-
makeRequired
|
|
74
|
+
makeRequired() {
|
|
75
75
|
if (this.inputs && this.inputs.length) {
|
|
76
76
|
this.inputs[0].required = true;
|
|
77
77
|
}
|
|
@@ -81,7 +81,7 @@ class FormElement {
|
|
|
81
81
|
/**
|
|
82
82
|
* Make first input element not required (optional)
|
|
83
83
|
*/
|
|
84
|
-
makeOptional
|
|
84
|
+
makeOptional() {
|
|
85
85
|
if (this.inputs && this.inputs.length) {
|
|
86
86
|
this.inputs[0].required = false;
|
|
87
87
|
}
|
package/utils/loader.js
CHANGED
|
@@ -12,7 +12,7 @@ class Loader {
|
|
|
12
12
|
* @throws If the document not passed
|
|
13
13
|
* @throws When the loader element not found
|
|
14
14
|
*/
|
|
15
|
-
constructor
|
|
15
|
+
constructor(element) {
|
|
16
16
|
if (!element) {
|
|
17
17
|
throw new Error('Please supply a DOM element');
|
|
18
18
|
}
|
|
@@ -38,7 +38,7 @@ class Loader {
|
|
|
38
38
|
/**
|
|
39
39
|
* Clear the content.
|
|
40
40
|
*/
|
|
41
|
-
clearContent
|
|
41
|
+
clearContent() {
|
|
42
42
|
this.$loaderContent.innerHTML = '';
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -48,7 +48,7 @@ class Loader {
|
|
|
48
48
|
* @param {string} title The HTML markup/string containing the title of the message.
|
|
49
49
|
* @param {string} content The HTML markup/string containing the main content of the message.
|
|
50
50
|
*/
|
|
51
|
-
setContent
|
|
51
|
+
setContent({ title, content }) {
|
|
52
52
|
if (title) {
|
|
53
53
|
if (!this.$loaderContentTitle) {
|
|
54
54
|
this.$loaderContentTitle = document.createElement('div');
|
|
@@ -70,7 +70,7 @@ class Loader {
|
|
|
70
70
|
*
|
|
71
71
|
* @param {object} content The optional content to set *before* showing the loader.
|
|
72
72
|
*/
|
|
73
|
-
show
|
|
73
|
+
show(content) {
|
|
74
74
|
this._previouslyFocused = document.activeElement;
|
|
75
75
|
|
|
76
76
|
if (content) {
|
|
@@ -88,7 +88,7 @@ class Loader {
|
|
|
88
88
|
*
|
|
89
89
|
* @param {object} content The optional content to set *before* showing the loader.
|
|
90
90
|
*/
|
|
91
|
-
showAndPreventTabbing
|
|
91
|
+
showAndPreventTabbing(content) {
|
|
92
92
|
this.show(content);
|
|
93
93
|
|
|
94
94
|
this.element.addEventListener('keydown', this.interceptTab);
|
|
@@ -97,7 +97,7 @@ class Loader {
|
|
|
97
97
|
/**
|
|
98
98
|
* Hide the loader
|
|
99
99
|
*/
|
|
100
|
-
hide
|
|
100
|
+
hide() {
|
|
101
101
|
this.$loader.classList.add(this.HIDDEN_CLASS);
|
|
102
102
|
this.$loader.classList.remove(this.VISIBLE_CLASS);
|
|
103
103
|
this.$loader.removeAttribute('tabindex');
|
|
@@ -114,7 +114,7 @@ class Loader {
|
|
|
114
114
|
* Intercepts Tab key events that normally navigate through the content on the page.
|
|
115
115
|
* @param {object} event The event object for the keypress.
|
|
116
116
|
*/
|
|
117
|
-
interceptTab
|
|
117
|
+
interceptTab(event) {
|
|
118
118
|
if (event.keyCode === 9) {
|
|
119
119
|
event.preventDefault();
|
|
120
120
|
}
|
|
@@ -125,7 +125,7 @@ class Loader {
|
|
|
125
125
|
* @param {DOMElement} element Show loader over this
|
|
126
126
|
* @param {Object} content Content for the loader in standard format
|
|
127
127
|
*/
|
|
128
|
-
showOnElement
|
|
128
|
+
showOnElement(element, content) {
|
|
129
129
|
const existingLoader = element.querySelector('.ncf__loader');
|
|
130
130
|
const loader = new DOMParser()
|
|
131
131
|
.parseFromString(this.template(content), 'text/html')
|
|
@@ -142,7 +142,7 @@ class Loader {
|
|
|
142
142
|
* Remove loader from a given element
|
|
143
143
|
* @param {DOMElement} element Loader inside
|
|
144
144
|
*/
|
|
145
|
-
removeFromElement
|
|
145
|
+
removeFromElement(element) {
|
|
146
146
|
element.querySelector('.ncf__loader').remove();
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -151,7 +151,7 @@ class Loader {
|
|
|
151
151
|
* @param {String} title
|
|
152
152
|
* @param {String} content
|
|
153
153
|
*/
|
|
154
|
-
template
|
|
154
|
+
template({ title = 'Loading', content = '' }) {
|
|
155
155
|
return `
|
|
156
156
|
<div class="ncf__loader is-visible ncf__loader--element"
|
|
157
157
|
role="dialog"
|
package/utils/password.js
CHANGED
|
@@ -13,7 +13,7 @@ class Password {
|
|
|
13
13
|
* @throws If the document not passed
|
|
14
14
|
* @throws When the password element not found
|
|
15
15
|
*/
|
|
16
|
-
constructor
|
|
16
|
+
constructor(element) {
|
|
17
17
|
if (!element) {
|
|
18
18
|
throw new Error('Please supply a DOM element');
|
|
19
19
|
}
|
|
@@ -34,7 +34,7 @@ class Password {
|
|
|
34
34
|
* Toggle whether the password is shown in plain text or not
|
|
35
35
|
* @param {Boolean} mask Pass false to show plain text
|
|
36
36
|
*/
|
|
37
|
-
toggleMask
|
|
37
|
+
toggleMask(mask) {
|
|
38
38
|
this.$password.type = mask ? 'password' : 'text';
|
|
39
39
|
}
|
|
40
40
|
}
|
package/utils/payment-term.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Period,
|
|
3
|
-
Monthly,
|
|
4
|
-
} = require('@financial-times/n-pricing');
|
|
1
|
+
const { Period, Monthly } = require('@financial-times/n-pricing');
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* Utility for the `n-conversion-forms/partial/payment-term.html` partial
|
|
@@ -33,7 +30,7 @@ class PaymentTerm {
|
|
|
33
30
|
* @throws If the document not passed
|
|
34
31
|
* @throws When the paymentTermField element not found
|
|
35
32
|
*/
|
|
36
|
-
constructor
|
|
33
|
+
constructor(element) {
|
|
37
34
|
if (!element) {
|
|
38
35
|
throw new Error('Please supply a DOM element');
|
|
39
36
|
}
|
|
@@ -51,7 +48,7 @@ class PaymentTerm {
|
|
|
51
48
|
* @return {String}
|
|
52
49
|
* @throws If nothing has been selected
|
|
53
50
|
*/
|
|
54
|
-
getSelected
|
|
51
|
+
getSelected() {
|
|
55
52
|
const checked = this.$paymentTerm.querySelector('input:checked');
|
|
56
53
|
if (!checked) {
|
|
57
54
|
throw new Error('No payment term has been selected');
|
|
@@ -64,7 +61,7 @@ class PaymentTerm {
|
|
|
64
61
|
* @return {Number}
|
|
65
62
|
* @throws If no payment term has been selected
|
|
66
63
|
*/
|
|
67
|
-
getBaseAmount
|
|
64
|
+
getBaseAmount() {
|
|
68
65
|
const checked = this.$paymentTerm.querySelector('input:checked');
|
|
69
66
|
if (!checked) {
|
|
70
67
|
throw new Error('No payment term has been selected');
|
|
@@ -76,11 +73,11 @@ class PaymentTerm {
|
|
|
76
73
|
* Register on change an event listener
|
|
77
74
|
* @param {Function} callback Called with event when changed
|
|
78
75
|
*/
|
|
79
|
-
onChange
|
|
76
|
+
onChange(callback = () => {}) {
|
|
80
77
|
return this.$paymentTerm.addEventListener('change', callback);
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
isValidPeriod
|
|
80
|
+
isValidPeriod(period) {
|
|
84
81
|
try {
|
|
85
82
|
// Period should throw an error if it is not properly provided
|
|
86
83
|
// in order to validate it, we just send in case type is string
|
|
@@ -89,9 +86,9 @@ class PaymentTerm {
|
|
|
89
86
|
} catch (e) {
|
|
90
87
|
return false;
|
|
91
88
|
}
|
|
92
|
-
}
|
|
89
|
+
}
|
|
93
90
|
|
|
94
|
-
getMontlyPriceFromPeriod
|
|
91
|
+
getMontlyPriceFromPeriod(amount, currency, period) {
|
|
95
92
|
const periodObj = new Period(period);
|
|
96
93
|
const monthlyPrice = periodObj.calculatePrice('P1M', amount);
|
|
97
94
|
return new Monthly({ value: monthlyPrice, currency }).getAmount('monthly');
|
|
@@ -101,7 +98,7 @@ class PaymentTerm {
|
|
|
101
98
|
* Update the payment term options
|
|
102
99
|
* @param {Array} options Array of objects contain terms information
|
|
103
100
|
*/
|
|
104
|
-
updateOptions
|
|
101
|
+
updateOptions(options) {
|
|
105
102
|
const terms = this.$paymentTerm.querySelectorAll(ITEM_CLASS);
|
|
106
103
|
for (let i = 0; i < terms.length; i++) {
|
|
107
104
|
const term = terms[i];
|
|
@@ -126,9 +123,13 @@ class PaymentTerm {
|
|
|
126
123
|
trialPrice.innerHTML = update.trialPrice;
|
|
127
124
|
}
|
|
128
125
|
if (monthlyPrice) {
|
|
129
|
-
monthlyPrice.innerHTML = this.isValidPeriod(update.value)
|
|
130
|
-
this.getMontlyPriceFromPeriod(
|
|
131
|
-
|
|
126
|
+
monthlyPrice.innerHTML = this.isValidPeriod(update.value)
|
|
127
|
+
? this.getMontlyPriceFromPeriod(
|
|
128
|
+
update.amount,
|
|
129
|
+
update.currency,
|
|
130
|
+
update.value
|
|
131
|
+
)
|
|
132
|
+
: update.monthlyPrice;
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
}
|