wickes-css2 2.106.0-develop.7 → 2.106.0-develop.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.
Files changed (69) hide show
  1. package/Readme.md +1 -1
  2. package/build/css/components/checkout-payment-details-v2.css +1 -1
  3. package/build/css/pages/page_checkout_delivery-new.css +1 -1
  4. package/build/img/billie-pay-later.svg +13 -0
  5. package/build/img/giftcard.svg +28 -0
  6. package/build/js/account-members.min.js +1 -1
  7. package/build/js/add-project-list-id.min.js +1 -1
  8. package/build/js/address-book.min.js +1 -1
  9. package/build/js/basket.min.js +2 -2
  10. package/build/js/bundle.min.js +1 -1
  11. package/build/js/change-password.min.js +1 -1
  12. package/build/js/checkout.min.js +2 -2
  13. package/build/js/emulation.min.js +2110 -1841
  14. package/build/js/general.bundle.min.js +1 -1
  15. package/build/js/gift-cards.min.js +1 -0
  16. package/build/js/merged-checkout.min.js +2 -2
  17. package/build/js/mini-basket-slider.min.js +1 -1
  18. package/build/js/page/basket/basket-update-cart-action.js +4 -1
  19. package/build/js/page/basket/klarna.js +13 -3
  20. package/build/js/page/basket-v2.js +6 -2
  21. package/build/js/page/components/gift-cards.js +915 -0
  22. package/build/js/page/components/order-summary.js +42 -25
  23. package/build/js/page/components/toggle-password-visibility.js +22 -0
  24. package/build/js/page/components/voucher.js +52 -47
  25. package/build/js/page/utils/gift-cards-utils.js +188 -0
  26. package/build/js/page/utils/input-handling.js +92 -0
  27. package/build/js/page/utils/show-hide-input.js +28 -0
  28. package/build/js/page/utils/validation.js +46 -1
  29. package/build/js/pdp.bundle.min.js +1 -1
  30. package/build/js/personal-details.min.js +1 -1
  31. package/build/js/plp.bundle.min.js +1 -1
  32. package/build/js/project-list.min.js +44 -1
  33. package/build/js/quiz.min.js +1 -1
  34. package/build/js/track-my-order.min.js +1 -1
  35. package/package.json +1 -1
  36. package/src/components/checkout-payment-details-v2.hbs +4 -3
  37. package/src/components/gift-cards-hint.hbs +9 -0
  38. package/src/components/gift-cards.hbs +90 -0
  39. package/src/components/giftcard-chip.hbs +23 -0
  40. package/src/components/giftcard-summary.hbs +6 -0
  41. package/src/elements/form-row.hbs +1 -1
  42. package/src/elements/input.hbs +31 -2
  43. package/src/img/billie-pay-later.svg +13 -0
  44. package/src/img/giftcard.svg +28 -0
  45. package/src/js/components/general/notification.js +2 -1
  46. package/src/js/emulation/basket-data.js +2126 -2038
  47. package/src/js/emulation/checkLocalEnv.js +6 -5
  48. package/src/js/emulation/checkout-data.js +35 -0
  49. package/src/js/emulation/checkout-payment-details.js +28 -26
  50. package/src/js/emulation/forms.js +16 -10
  51. package/src/js/emulation/gift-cards.js +205 -0
  52. package/src/js/page/basket/basket-update-cart-action.js +4 -1
  53. package/src/js/page/basket/klarna.js +13 -3
  54. package/src/js/page/basket-v2.js +6 -2
  55. package/src/js/page/components/gift-cards.js +915 -0
  56. package/src/js/page/components/order-summary.js +42 -25
  57. package/src/js/page/components/toggle-password-visibility.js +22 -0
  58. package/src/js/page/components/voucher.js +52 -47
  59. package/src/js/page/utils/gift-cards-utils.js +188 -0
  60. package/src/js/page/utils/input-handling.js +92 -0
  61. package/src/js/page/utils/show-hide-input.js +28 -0
  62. package/src/js/page/utils/validation.js +46 -1
  63. package/src/layouts/checkout.hbs +1 -5
  64. package/src/page_my-account_change-password.html +1 -0
  65. package/src/page_payment-details-with-gift-card.html +8 -5
  66. package/src/scss/components/_gift-cards.scss +360 -0
  67. package/src/scss/components/checkout-payment-details-v2.scss +6 -2
  68. package/src/scss/pages/page_checkout_delivery-new.scss +26 -0
  69. package/src/js/components/toggle-password-visibility.js +0 -58
@@ -13,31 +13,46 @@ const osEl = {
13
13
  }
14
14
 
15
15
  export function updateOrderSummary(data, equalMap, isVoucher) {
16
- equalMap.forEach((obj) => {
17
- if ($(obj.item).length) {
18
- $(obj.item).show();
19
- } else {
20
- if ($(osEl.checkoutWidgetDetailsDiscount).length) {
21
- $(osEl.checkoutWidgetDetailsDiscount).before(createCheckoutWidgetItem(obj))
22
- } else {
23
- $(osEl.checkoutWidgetDetails).append(createCheckoutWidgetItem(obj))
24
- }
25
- }
16
+ equalMap.forEach((obj) => {
17
+ if (typeof obj.dataValue === 'undefined') return;
26
18
 
27
- $(obj.item).find(obj.itemValue).text(obj.dataValue);
28
- if (isVoucher ? obj.dataValue : obj.value && obj.dataValue) {
29
- $(obj.item).find(obj.itemValue).show();
30
- } else {
31
- $(obj.item).hide();
32
- }
33
- })
19
+ if ($(obj.item).length) {
20
+ $(obj.item).show();
21
+ } else {
22
+ if ($(osEl.checkoutWidgetDetailsDiscount).length) {
23
+ $(osEl.checkoutWidgetDetailsDiscount).before(createCheckoutWidgetItem(obj));
24
+ } else {
25
+ $(osEl.checkoutWidgetDetails).append(createCheckoutWidgetItem(obj));
26
+ }
27
+ }
34
28
 
35
- const value = data.totalPrice?.formattedValue || data.total;
29
+ $(obj.item).find(obj.itemValue).text(obj.dataValue);
30
+ if (isVoucher ? obj.dataValue : obj.value && obj.dataValue) {
31
+ $(obj.item).find(obj.itemValue).show();
32
+ } else {
33
+ $(obj.item).hide();
34
+ }
35
+ });
36
36
 
37
+ const keys = new Set(Object.keys(data || {}));
38
+ const hasAny = (...arr) => arr.some(k => keys.has(k));
39
+
40
+ const value = data.totalPrice?.formattedValue || data.total;
41
+ if (typeof value !== 'undefined' && hasAny('total', 'totalPrice')) {
42
+ updateSummaryMobileBarTotal(value);
43
+ }
44
+
45
+ if (hasAny('promotionsInfo')) {
37
46
  updateDiscount(data, isVoucher);
47
+ }
48
+
49
+ if (hasAny('deliveryOrder', 'clickAndCollectOrder', 'clickAndCollectOnly', 'deliveryItemsQuantity', 'pickupItemsQuantity')) {
38
50
  hideUnusedDeliveryTypeCost(data, isVoucher);
51
+ }
52
+
53
+ if (hasAny('freeDelivery', 'messageForFreeDelivery', 'clickAndCollectOnly')) {
39
54
  calculateFreeDelivery(data);
40
- updateSummaryMobileBarTotal(value);
55
+ }
41
56
  }
42
57
 
43
58
  function createCheckoutWidgetItem(obj) {
@@ -53,12 +68,14 @@ function hideUnusedDeliveryTypeCost(data, isVoucher) {
53
68
  $(osEl.delivery).show()
54
69
  $(osEl.cc).show()
55
70
  if (isVoucher) {
56
- if (!data.deliveryOrder) {
57
- $(osEl.delivery).hide()
58
- } else if (!data.clickAndCollectOrder) {
59
- $(osEl.cc).hide()
60
- }
61
- } else {
71
+ if ('deliveryOrder' in data && data.deliveryOrder === false) {
72
+ $(osEl.delivery).hide();
73
+ }
74
+
75
+ if ('clickAndCollectOrder' in data && data.clickAndCollectOrder === false) {
76
+ $(osEl.cc).hide();
77
+ }
78
+ } else {
62
79
  if (data.clickAndCollectOnly) {
63
80
  $(osEl.delivery).hide()
64
81
  } else if (data.deliveryItemsQuantity > 0 && data.pickupItemsQuantity === 0) {
@@ -0,0 +1,22 @@
1
+ import { initializeInputToggle } from "../utils/show-hide-input";
2
+
3
+ var Wick = window.Wick || {};
4
+
5
+ Wick.TogglePasswordVisibility = {
6
+ el: {
7
+ $containers: $('.form-row[data-show-content] .input-wrap'),
8
+ },
9
+
10
+ init() {
11
+ if (!this.el.$containers.length) {
12
+ return;
13
+ }
14
+ this.el.$containers.each(function () {
15
+ initializeInputToggle($(this));
16
+ });
17
+ },
18
+ };
19
+
20
+ $(document).ready(function () {
21
+ Wick.TogglePasswordVisibility.init();
22
+ });
@@ -1,11 +1,11 @@
1
- import {updateOrderSummary} from './order-summary';
2
- import {callAction} from '../utils/http-action';
3
- import {retryAction, retryHelpers} from "./retry-action";
4
- import {showValidationErrors} from '../utils/validation'
5
- import {updateKlarnaPlacements} from '../basket/klarna';
6
- import {getCSRFToken, CSRF} from "./csrf";
7
- import {ROUTES} from '../utils/routes';
8
- import {updateClearpayPlacements, updateClearpayVisibility} from '../basket/clearpay';
1
+ import { updateOrderSummary } from './order-summary';
2
+ import { callAction } from '../utils/http-action';
3
+ import { retryAction, retryHelpers } from './retry-action';
4
+ import { showValidationErrors } from '../utils/validation';
5
+ import { updateKlarnaPlacements } from '../basket/klarna';
6
+ import { getCSRFToken, CSRF } from './csrf';
7
+ import { ROUTES } from '../utils/routes';
8
+ import { updateClearpayPlacements, updateClearpayVisibility } from '../basket/clearpay';
9
9
 
10
10
  const voucherEl = {
11
11
  $basketVoucher: $('.checkout-voucher'),
@@ -30,8 +30,10 @@ const voucherEl = {
30
30
  };
31
31
 
32
32
  export function checkVoucherCode(e, current) {
33
- e && e.preventDefault()
34
- const context = current ? $(current).closest(voucherEl.voucher) : $(this).closest(voucherEl.voucher),
33
+ e && e.preventDefault();
34
+ const context = current
35
+ ? $(current).closest(voucherEl.voucher)
36
+ : $(this).closest(voucherEl.voucher),
35
37
  value = context.find('input').val().trim(),
36
38
  encodedValue = encodeURIComponent(value),
37
39
  errorMsg = {
@@ -39,8 +41,8 @@ export function checkVoucherCode(e, current) {
39
41
  responseJSON: {
40
42
  globalMessage: {
41
43
  message: 'Please enter a voucher code',
42
- }
43
- }
44
+ },
45
+ },
44
46
  };
45
47
 
46
48
  if (value && value.length) {
@@ -59,7 +61,7 @@ function executionVoucherApplying(value, context) {
59
61
  url: `${ROUTES.VOUCHER_UPDATE}/${value}`,
60
62
  type: 'POST',
61
63
  headers: {
62
- 'CSRFToken': CSRF.getToken(),
64
+ CSRFToken: CSRF.getToken(),
63
65
  },
64
66
  retryLimit: retryHelpers.retryLimit,
65
67
  error: notApplyVoucher,
@@ -79,7 +81,7 @@ export function voucherRemove() {
79
81
  let voucher = $(this).parent(),
80
82
  voucherCode = voucher.attr('data-coupon-code');
81
83
  voucher.addClass('checkout-widget__voucher-removed').text('Voucher removed');
82
- voucherRemoveAction(voucherCode, voucher)
84
+ voucherRemoveAction(voucherCode, voucher);
83
85
  }
84
86
 
85
87
  function voucherRemoveAction(code) {
@@ -90,7 +92,7 @@ function voucherRemoveAction(code) {
90
92
  type: 'DELETE',
91
93
  headers: {
92
94
  'Content-Type': 'application/json',
93
- 'CSRFToken': CSRF.getToken(),
95
+ CSRFToken: CSRF.getToken(),
94
96
  },
95
97
  error: handleVoucherRemovingError,
96
98
  };
@@ -106,12 +108,11 @@ function formattedTotalPriceWithoutSymbol(val) {
106
108
  }
107
109
 
108
110
  function executionVoucherRemoving(data) {
109
- updateOrderSummary(
110
- data,
111
- getEqualMapForVoucherUpdate(data),
112
- true
111
+ updateOrderSummary(data, getEqualMapForVoucherUpdate(data), true);
112
+ updateKlarnaPlacements(
113
+ formattedTotalPriceWithoutSymbol(data.total),
114
+ data.paymentInfos.klarnaPaymentInfo.customPaymentMethodIds
113
115
  );
114
- updateKlarnaPlacements(formattedTotalPriceWithoutSymbol(data.total));
115
116
  updateClearpayPlacements(data.total);
116
117
  updateClearpayVisibility(data.total);
117
118
  }
@@ -123,19 +124,18 @@ function applyVoucher(data, context) {
123
124
 
124
125
  clearValidationErrors($voucherForm);
125
126
  voucherEl.$basketVoucher.toggle(voucherEl.voucherHide);
126
- updateOrderSummary(
127
- data,
128
- getEqualMapForVoucherUpdate(data),
129
- true
127
+ updateOrderSummary(data, getEqualMapForVoucherUpdate(data), true);
128
+ updateKlarnaPlacements(
129
+ formattedTotalPriceWithoutSymbol(data.total),
130
+ data.paymentInfos.klarnaPaymentInfo.customPaymentMethodIds
130
131
  );
131
- updateKlarnaPlacements(formattedTotalPriceWithoutSymbol(data.total));
132
132
  updateClearpayPlacements(data.total);
133
133
  updateClearpayVisibility(data.total);
134
134
  setTimeout(function () {
135
135
  voucherButton.attr('disabled', false);
136
136
  $voucherFormInput.val('');
137
137
  voucherEl.$basketVoucher.toggle(voucherEl.voucherHide);
138
- }, 5000)
138
+ }, 5000);
139
139
  }
140
140
 
141
141
  function notApplyVoucher(xhr, context) {
@@ -158,21 +158,25 @@ function notApplyVoucher(xhr, context) {
158
158
  function retryVoucherAction(voucherForm) {
159
159
  return new Promise((resolve) => {
160
160
  getCSRFToken(resolve);
161
- }).then(() => {
162
- retryAction(checkVoucherCode, retryHelpers.retryLimit, ...Array(1), voucherForm)
163
- }).catch(() => {
164
- showDefaultError();
165
161
  })
162
+ .then(() => {
163
+ retryAction(checkVoucherCode, retryHelpers.retryLimit, ...Array(1), voucherForm);
164
+ })
165
+ .catch(() => {
166
+ showDefaultError();
167
+ });
166
168
  }
167
169
 
168
170
  function retryVoucherRemoving(code) {
169
171
  return new Promise((resolve) => {
170
172
  getCSRFToken(resolve);
171
- }).then(() => {
172
- retryAction(voucherRemoveAction, retryHelpers.retryLimit, code);
173
- }).catch(() => {
174
- console.log('remove failed');
175
173
  })
174
+ .then(() => {
175
+ retryAction(voucherRemoveAction, retryHelpers.retryLimit, code);
176
+ })
177
+ .catch(() => {
178
+ console.log('remove failed');
179
+ });
176
180
  }
177
181
 
178
182
  function handleVoucherRemovingError(xhr, code) {
@@ -182,7 +186,7 @@ function handleVoucherRemovingError(xhr, code) {
182
186
  }
183
187
 
184
188
  function showDefaultError(error = retryHelpers.errorMsg) {
185
- const voucher = getNotAppliedVoucher()
189
+ const voucher = getNotAppliedVoucher();
186
190
  showValidationErrors(voucher.find('form'), error);
187
191
  }
188
192
 
@@ -195,9 +199,12 @@ function getNotAppliedVoucher() {
195
199
  function clearValidationErrors(form) {
196
200
  var $form = $(form);
197
201
  if ($form.hasClass(voucherEl.formInvalid)) {
198
- $form.removeClass(voucherEl.formInvalid)
199
- .find(voucherEl.fieldRow).removeClass(voucherEl.rowValidationError)
200
- .find(voucherEl.fieldError).remove();
202
+ $form
203
+ .removeClass(voucherEl.formInvalid)
204
+ .find(voucherEl.fieldRow)
205
+ .removeClass(voucherEl.rowValidationError)
206
+ .find(voucherEl.fieldError)
207
+ .remove();
201
208
  }
202
209
  }
203
210
 
@@ -207,48 +214,46 @@ function getEqualMapForVoucherUpdate(data) {
207
214
  item: voucherEl.subtotal,
208
215
  itemValue: voucherEl.value,
209
216
  dataValue: data.subTotal,
210
- title: 'Items subtotal:'
211
-
217
+ title: 'Items subtotal:',
212
218
  },
213
219
  {
214
220
  item: voucherEl.vat,
215
221
  itemValue: voucherEl.value,
216
222
  dataValue: data.vat,
217
- title: 'VAT:'
223
+ title: 'VAT:',
218
224
  },
219
225
  {
220
226
  item: voucherEl.cc,
221
227
  itemValue: voucherEl.value,
222
228
  dataValue: data.clickAndCollectCost,
223
- title: 'Click & Collect:'
229
+ title: 'Click & Collect:',
224
230
  },
225
231
  {
226
232
  item: voucherEl.delivery,
227
233
  itemValue: voucherEl.value,
228
234
  dataValue: data.deliveryCost,
229
- title: 'Delivery:'
235
+ title: 'Delivery:',
230
236
  },
231
237
  {
232
238
  item: voucherEl.charity,
233
239
  itemValue: voucherEl.value,
234
240
  dataValue: data.charityPrice,
235
- title: 'Charity donation:'
241
+ title: 'Charity donation:',
236
242
  },
237
243
  {
238
244
  item: voucherEl.discountItem,
239
245
  itemValue: voucherEl.discountValue,
240
- dataValue: data.discountTotal
246
+ dataValue: data.discountTotal,
241
247
  },
242
248
  {
243
249
  item: voucherEl.orderTotal,
244
250
  itemValue: voucherEl.orderTotalValue,
245
- dataValue: data.total
251
+ dataValue: data.total,
246
252
  },
247
253
  ];
248
254
  }
249
255
 
250
256
  $(document).ready(function () {
251
-
252
257
  function init() {
253
258
  if (!$('.checkout-voucher').length) {
254
259
  return;
@@ -0,0 +1,188 @@
1
+ import { showLoader, hideLoader } from "./loader";
2
+
3
+ const SUMMARY_SELECTORS = {
4
+ subTotal: { item: '.checkout-widget__item-bold', value: '.checkout-widget__item-value', title: 'Items subtotal:' },
5
+ vat: { item: '.checkout-widget__item-vat', value: '.checkout-widget__item-value', title: 'VAT:' },
6
+ clickAndCollectCost: { item: '.checkout-widget__item-cc', value: '.checkout-widget__item-value', title: 'Click & Collect:' },
7
+ deliveryCost: { item: '.checkout-widget__item-delivery', value: '.checkout-widget__item-value', title: 'Delivery:' },
8
+ charityPrice: { item: '.checkout-widget__item-charity', value: '.checkout-widget__item-value', title: 'Charity donation:' },
9
+ discountTotal: { item: '.checkout-widget__details-discount', value: '.checkout-widget__detail-value' },
10
+ giftCardApplied: { item: '.checkout-widget__gift-card', value: '.checkout-widget__item-value', title: 'Gift Card:' },
11
+ total: { item: '.checkout-widget__total', value: '.checkout-widget__total-value' },
12
+ };
13
+
14
+ const CURRENCY_KEYS = new Set([
15
+ 'subTotal','vat','clickAndCollectCost','deliveryCost',
16
+ 'charityPrice','discountTotal','total','giftCardApplied'
17
+ ]);
18
+
19
+ const GIFT_CARD_ALREADY_ADDED = 'GIFT_CARD_ALREADY_ADDED';
20
+ const PIS_REQUEST_TIMEOUT = 'PIS-REQUEST-TIMEOUT';
21
+ const PIS_INTEGRATION_ERROR = 'PIS-INTEGRATION-ERROR';
22
+ const PIS_INSUFFICIENT_AMOUNT = 'PIS-INSUFFICIENT-AMOUNT';
23
+ const PIS_PROCESSING_ERROR = 'PIS_PROCESSING_ERROR';
24
+ const HYBRIS_REQUEST_TIMEOUT = 'HYBRIS-REQUEST-TIMEOUT';
25
+ const HYBRIS_PIS_INTEGRATION_ERROR = 'HYBRIS-PIS_INTEGRATION-ERROR';
26
+ const HYBRIS_PIS_CONNECTION_ERROR = 'HYBRIS-PIS_CONNECTION-ERROR';
27
+ const ZERO_BALANCE = 'ZERO_BALANCE';
28
+ const SPLIT_PAYMENT_CARD_ERROR = 'SPLIT_PAYMENT_CARD_ERROR';
29
+
30
+ export const DEFAULT_ERROR_MESSAGE =
31
+ 'Unable to use Gift Card at this time, please try later or click here for support.';
32
+
33
+ export const DEFAULT_PAY_ERROR_MESSAGE =
34
+ 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.';
35
+
36
+ export const OK_CODE = 0;
37
+
38
+ export const MESSAGE_BY_CODE = {
39
+ 10: 'Gift Card number and / or PIN not recognised. A Gift Card will be locked following three unsuccessful PIN attempts.',
40
+ 16: 'Card locked due to three unsuccessful PIN entries. For support click here.',
41
+ 20: 'Unable to use Gift Card at this time, please try later or click here for support.',
42
+ 21: 'Gift Card number not recognised.',
43
+ 40: 'Unable to use Gift Card at this time, please try later or click here for support.',
44
+ 60: 'The entered Gift Card has expired. For support click here.',
45
+ 75: 'The entered Gift Card is invalid. For support click here.',
46
+ [GIFT_CARD_ALREADY_ADDED]: 'Gift Card already added, please use a different card.',
47
+ [PIS_REQUEST_TIMEOUT]: 'Unable to use Gift Card at this time, please try later or click here for support.',
48
+ [PIS_INTEGRATION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
49
+ [PIS_INSUFFICIENT_AMOUNT]: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
50
+ [PIS_PROCESSING_ERROR]: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
51
+ [HYBRIS_REQUEST_TIMEOUT]: 'Unable to use Gift Card at this time, please try later or click here for support.',
52
+ [HYBRIS_PIS_INTEGRATION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
53
+ [HYBRIS_PIS_CONNECTION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
54
+ [ZERO_BALANCE]: 'Insufficient funds available, please try another Gift Card or alternate payment method.',
55
+ 99: 'The entered Gift Card is invalid. For support click here.',
56
+ [-1]: 'Gift Card is unavailable at this time, please try later. For support click here.',
57
+ };
58
+
59
+ export const PAY_MESSAGE_BY_CODE = {
60
+ 101: 'Unable to use Gift Cards at this time, please try later or click here for support.',
61
+ 102: 'Unfortunately there was a problem with requesting your card details from the payment provider. Available funds on your Gift Card are unchanged.',
62
+ 103: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
63
+ 104: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
64
+ [PIS_REQUEST_TIMEOUT]: 'Unable to use Gift Card at this time, please try later or click here for support.',
65
+ [PIS_INTEGRATION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
66
+ [PIS_INSUFFICIENT_AMOUNT]: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
67
+ [PIS_PROCESSING_ERROR]: 'Unfortunately there was a problem placing your order with Gift Card(s). Please click here for support.',
68
+ [HYBRIS_REQUEST_TIMEOUT]: 'Unable to use Gift Card at this time, please try later or click here for support.',
69
+ [HYBRIS_PIS_INTEGRATION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
70
+ [HYBRIS_PIS_CONNECTION_ERROR]: 'Unable to use Gift Card at this time, please try later or click here for support.',
71
+ [SPLIT_PAYMENT_CARD_ERROR]: 'Unfortunately there was a problem with requesting your card details from the payment provider. Available funds on your Gift Card are unchanged.',
72
+ };
73
+
74
+ export const ADD_GIFT_CARD = 'addGiftCard';
75
+ export const REMOVE_GIFT_CARD = 'removeGiftCard';
76
+ export const PAY_WITH_GIFT_CARD = 'payWithGiftCard';
77
+
78
+ export const FAQ_URL = 'https://www.wickes.co.uk/gifts';
79
+
80
+ export const escapeHtml = (s) => $('<div>').text(String(s || '')).html();
81
+
82
+ export const linkifyClickHere = (msg) =>
83
+ escapeHtml(msg).replace(
84
+ /\bclick here\b/gi,
85
+ `<a href="${FAQ_URL}" target="_blank" rel="noopener" class="notification_link">click here</a>`
86
+ );
87
+
88
+ export function formatGc16(raw) {
89
+ const digits = String(raw || '').replace(/\D/g, '').slice(0, 16);
90
+ return digits.replace(/(\d{4})(?=\d)/g, '$1-');
91
+ }
92
+
93
+ function formatGBP(value) {
94
+ if (value === null || typeof value === 'undefined' || String(value).trim() === '') {
95
+ return value;
96
+ }
97
+
98
+ const cleanedValue = String(value).replace(/[^\d.-]/g, '');
99
+ const numberValue = Number(cleanedValue);
100
+
101
+ if (Number.isFinite(numberValue)) {
102
+ return `£${numberValue.toFixed(2)}`;
103
+ }
104
+
105
+ return value;
106
+ }
107
+
108
+ export function buildHintContext(count, limit) {
109
+ const max = count >= limit;
110
+
111
+ return {
112
+ canAdd: !max,
113
+ max,
114
+ hintClass: `giftcard-summary__hint${max ? ' giftcard-summary__hint--max' : ''}`,
115
+ };
116
+ }
117
+
118
+ export function buildSummaryEqualMap(data) {
119
+ return Object.entries(SUMMARY_SELECTORS).map(([key, d]) => {
120
+ const raw = data[key];
121
+ let dataValue = raw;
122
+
123
+ if (key === 'giftCardApplied') {
124
+ if (isZeroAmount(raw)) {
125
+ dataValue = '';
126
+ } else if (raw != null && raw !== '') {
127
+ dataValue = formatGBP(raw);
128
+ if (typeof dataValue === 'string' && dataValue.startsWith('£')) {
129
+ dataValue = `-${dataValue}`;
130
+ }
131
+ }
132
+ } else {
133
+ if (CURRENCY_KEYS.has(key) && raw != null && raw !== '') {
134
+ dataValue = formatGBP(raw);
135
+ }
136
+ }
137
+
138
+ return {
139
+ item: d.item,
140
+ itemValue: d.value,
141
+ dataValue,
142
+ ...(d.title ? { title: d.title } : {}),
143
+ };
144
+ });
145
+ }
146
+
147
+ export function isZeroAmount(val) {
148
+ const cleaned = String(val ?? '').replace(/[^\d.]/g, '');
149
+ if (!cleaned) {
150
+ return false;
151
+ }
152
+ const num = Number(cleaned);
153
+ return Number.isFinite(num) && num === 0;
154
+ }
155
+
156
+ // --- API/Event-Dispatching Functions ---
157
+
158
+ export function verifyGiftCard($loader, giftCardNumber, pin) {
159
+ showLoader($loader);
160
+ return new Promise((resolve, reject) => {
161
+ const payload = { giftCardNumber, pin };
162
+ const detail = { resolve, reject, payload };
163
+ const evt = createEvent(ADD_GIFT_CARD, payload, detail);
164
+ window.dispatchEvent(evt);
165
+ }).finally(() => {
166
+ hideLoader($loader);
167
+ });
168
+ }
169
+
170
+ export function removeGiftCard($loader, index) {
171
+ showLoader($loader);
172
+ return new Promise((resolve, reject) => {
173
+ const payload = { index };
174
+ const detail = { resolve, reject, payload };
175
+ const evt = createEvent(REMOVE_GIFT_CARD, payload, detail);
176
+ window.dispatchEvent(evt);
177
+ }).finally(() => {
178
+ hideLoader($loader);
179
+ });
180
+ }
181
+
182
+ export function payWithGiftCard() {
183
+ return new Promise((resolve, reject) => {
184
+ const detail = { resolve, reject };
185
+ const evt = createEvent(PAY_WITH_GIFT_CARD, undefined, detail);
186
+ window.dispatchEvent(evt);
187
+ });
188
+ }
@@ -0,0 +1,92 @@
1
+ import {formatGc16} from './gift-cards-utils';
2
+ import {clearErrorText, showErrorText} from './validation';
3
+
4
+
5
+ export function createGcNumberInputHandler({
6
+ fieldSelector,
7
+ fieldErrorClass,
8
+ errorTextSelector,
9
+ ariaInvalidAttr
10
+ }) {
11
+ return function handleGcNumberInput(e) {
12
+ const input = e.currentTarget;
13
+ const $input = $(input);
14
+
15
+ const canTrack = typeof input.selectionStart === 'number';
16
+ const atEnd = canTrack && input.selectionStart === input.value.length;
17
+
18
+ const hadErr = $input.closest(fieldSelector).hasClass(fieldErrorClass);
19
+
20
+ input.value = formatGc16(input.value);
21
+
22
+ if (hadErr) {
23
+ clearErrorText($input, fieldSelector, errorTextSelector, fieldErrorClass, ariaInvalidAttr);
24
+ }
25
+
26
+ if (atEnd && typeof input.setSelectionRange === 'function') {
27
+ input.setSelectionRange(input.value.length, input.value.length);
28
+ }
29
+ };
30
+ }
31
+
32
+ export function digitsOnlyKeypress(e) {
33
+ if (!/\d/.test(String.fromCharCode(e.which || e.keyCode))) {
34
+ e.preventDefault();
35
+ }
36
+ }
37
+
38
+ export function handleGcNumberBlur(e, {
39
+ fieldSelector,
40
+ errorTextSelector,
41
+ errorClass,
42
+ ariaInvalidAttr,
43
+ numberMessage,
44
+ }) {
45
+ const $input = $(e.currentTarget);
46
+ const len = String($input.val() || '').replace(/\D/g, '').length;
47
+
48
+ clearErrorText($input, fieldSelector, errorTextSelector, errorClass, ariaInvalidAttr);
49
+
50
+ if (len < 16) {
51
+ showErrorText($input, numberMessage, fieldSelector, errorTextSelector, errorClass, ariaInvalidAttr);
52
+ }
53
+ }
54
+
55
+ export function handleGcPinInput(e, {
56
+ fieldSelector,
57
+ errorTextSelector,
58
+ errorClass,
59
+ ariaInvalidAttr,
60
+ }) {
61
+ const input = e.currentTarget;
62
+ const $input = $(input);
63
+
64
+ const hadErr = $input.closest(fieldSelector).hasClass(errorClass);
65
+ input.value = String(input.value || '').replace(/\D/g, '').slice(0, 8);
66
+
67
+ if (hadErr) {
68
+ clearErrorText($input, fieldSelector, errorTextSelector, errorClass, ariaInvalidAttr);
69
+ }
70
+ }
71
+
72
+
73
+ export function handleGcPinKeypress(e) {
74
+ if (!/\d/.test(String.fromCharCode(e.which || e.keyCode))) e.preventDefault();
75
+ }
76
+
77
+ export function handleGcPinBlur(e, {
78
+ fieldSelector,
79
+ errorTextSelector,
80
+ errorClass,
81
+ ariaInvalidAttr,
82
+ pinMessage,
83
+ }) {
84
+ const $input = $(e.currentTarget);
85
+ const length = String($input.val() || '').replace(/\D/g, '').length;
86
+
87
+ clearErrorText($input, fieldSelector, errorTextSelector, errorClass, ariaInvalidAttr);
88
+
89
+ if (length < 8) {
90
+ showErrorText($input, pinMessage, fieldSelector, errorTextSelector, errorClass, ariaInvalidAttr);
91
+ }
92
+ }
@@ -0,0 +1,28 @@
1
+ export function initializeInputToggle($container) {
2
+ const $input = $container.find('input');
3
+ const $toggle = $container.find('.toggle-show');
4
+
5
+ if (!$input.length || !$toggle.length) return;
6
+
7
+ const handleToggleClick = (e) => {
8
+ e.preventDefault();
9
+
10
+ const isPassword = String($input.attr('type')) === 'password';
11
+ $input.attr('type', isPassword ? 'text' : 'password');
12
+ const $icon = $toggle.find('svg, i').first();
13
+
14
+ if ($icon.length) {
15
+ $icon.removeClass('fa-eye fa-eye-slash').addClass(isPassword ? 'fa-eye' : 'fa-eye-slash');
16
+ }
17
+ };
18
+
19
+ const updateToggleVisibility = () => {
20
+ $toggle.toggle(($input.val() || '').length > 0);
21
+ };
22
+
23
+ $toggle.off('click.passwordToggle mousedown.passwordToggle')
24
+ .on('mousedown.passwordToggle', handleToggleClick);
25
+
26
+ $input.off('input.passwordToggle').on('input.passwordToggle', updateToggleVisibility);
27
+ updateToggleVisibility();
28
+ }