@ikas/storefront 4.0.0-alpha.4 → 4.0.0-alpha.40

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 (63) hide show
  1. package/package.json +13 -13
  2. package/src/analytics/analytics.ts +2 -1
  3. package/src/analytics/googleUniversal.ts +12 -2
  4. package/src/analytics/head/index.tsx +1 -2
  5. package/src/analytics/ikas.ts +24 -6
  6. package/src/components/checkout/components/address-form/index.tsx +1 -1
  7. package/src/components/checkout/components/cart-summary/cart-item/index.tsx +11 -9
  8. package/src/components/checkout/components/cart-summary/cart-item/style.module.scss +7 -10
  9. package/src/components/checkout/components/cart-summary/index.tsx +41 -17
  10. package/src/components/checkout/components/customer-addresses/index.tsx +6 -2
  11. package/src/components/checkout/components/form-item/index.tsx +9 -11
  12. package/src/components/checkout/components/master-pass/credit-card-form/index.tsx +2 -0
  13. package/src/components/checkout/components/offer-product/index.tsx +16 -19
  14. package/src/components/checkout/components/offer-product/style.module.scss +1 -3
  15. package/src/components/checkout/components/phone-number-input/get-countries.ts +37 -5
  16. package/src/components/checkout/components/phone-number-input/index.tsx +15 -10
  17. package/src/components/checkout/index.tsx +14 -12
  18. package/src/components/checkout/model.ts +95 -61
  19. package/src/components/checkout/modelMasterPass.ts +2 -2
  20. package/src/components/checkout/steps/step-payment/index.tsx +6 -1
  21. package/src/components/checkout/steps/step-payment/payment-gateways/index.tsx +12 -3
  22. package/src/components/checkout/steps/step-payment/payment-gateways/installments/index.tsx +5 -3
  23. package/src/components/checkout/steps/step-payment/style.module.scss +5 -0
  24. package/src/components/checkout/steps/step-shipping/index.tsx +9 -4
  25. package/src/components/checkout/steps/step-success/index.tsx +4 -3
  26. package/src/components/page/head.tsx +12 -0
  27. package/src/components/page/index.tsx +10 -9
  28. package/src/components/page-editor/ThemeComponentEditor.tsx +15 -8
  29. package/src/components/page-editor/model.ts +44 -107
  30. package/src/models/data/cart/campaign-offer/index.ts +13 -2
  31. package/src/models/data/cart/index.ts +1 -1
  32. package/src/models/data/category/path-item/index.ts +4 -0
  33. package/src/models/data/checkout/index.ts +11 -3
  34. package/src/models/data/checkout-settings/price/index.ts +2 -0
  35. package/src/models/data/index.ts +3 -0
  36. package/src/models/data/merchant-settings/index.ts +9 -0
  37. package/src/models/data/order/index.ts +51 -32
  38. package/src/models/data/order/line-item/index.ts +34 -13
  39. package/src/models/data/order/line-item/variant/value/index.ts +1 -1
  40. package/src/models/data/order/transaction/index.ts +2 -5
  41. package/src/models/data/product/filter/index.ts +4 -13
  42. package/src/models/data/product/index.ts +21 -3
  43. package/src/models/data/product/option-set/index.ts +4 -0
  44. package/src/models/data/product/option-set/option/index.ts +33 -10
  45. package/src/models/data/product/variant/index.ts +23 -1
  46. package/src/models/data/product/variant/price/index.ts +23 -9
  47. package/src/models/data/product/variant-type/index.ts +2 -0
  48. package/src/models/data/raffle/index.ts +9 -7
  49. package/src/models/data/state/index.ts +6 -2
  50. package/src/models/data/storefront/index.ts +2 -0
  51. package/src/models/ui/product-list/index.ts +26 -17
  52. package/src/models/ui/raffle-list/index.ts +1 -1
  53. package/src/models/ui/validator/form/raffle-form.ts +16 -3
  54. package/src/models/ui/validator/rules/index.ts +14 -13
  55. package/src/page-data-init/index.ts +159 -404
  56. package/src/pages/checkout.tsx +2 -1
  57. package/src/pages/editor.tsx +5 -2
  58. package/src/store/cart/index.ts +2 -2
  59. package/src/store/customer/index.ts +7 -17
  60. package/src/store/raffle/index.ts +7 -10
  61. package/src/utils/constants.ts +1 -1
  62. package/src/utils/currency.ts +9 -183
  63. package/src/components/checkout/components/phone-number-input/locale/en.ts +0 -257
@@ -1,5 +1,6 @@
1
1
  import { saveRaffleParticipant } from "@ikas/storefront-api";
2
2
  import { action, computed, makeObservable, observable } from "mobx";
3
+ import { GraphQLError } from "graphql";
3
4
 
4
5
  import { Validator } from "..";
5
6
  import { IkasBaseStore } from "../../../../store";
@@ -237,7 +238,11 @@ export class RaffleForm {
237
238
  }
238
239
 
239
240
  async submit() {
240
- const response = { isFormError: false, isSuccess: false };
241
+ const response: {
242
+ isFormError: boolean;
243
+ isSuccess: boolean;
244
+ errors?: readonly GraphQLError[];
245
+ } = { isFormError: false, isSuccess: false };
241
246
  const hasFormError = await this.validateAll();
242
247
  if (hasFormError) {
243
248
  response.isFormError = true;
@@ -246,7 +251,7 @@ export class RaffleForm {
246
251
 
247
252
  try {
248
253
  const selectedVariant = this.raffle.products[0].selectedVariant;
249
- const isRaffleFormSuccess = await saveRaffleParticipant({
254
+ const saveRaffleParticipantResponse = await saveRaffleParticipant({
250
255
  input: {
251
256
  appliedProduct: {
252
257
  productId: selectedVariant.productId,
@@ -264,12 +269,20 @@ export class RaffleForm {
264
269
  },
265
270
  });
266
271
 
267
- if (isRaffleFormSuccess) {
272
+ if (saveRaffleParticipantResponse?.graphQLErrors) {
273
+ response.errors = saveRaffleParticipantResponse.graphQLErrors;
274
+ response.isSuccess = false;
275
+ }
276
+
277
+ if (saveRaffleParticipantResponse.data) {
268
278
  response.isSuccess = true;
269
279
  }
270
280
 
271
281
  return response;
272
282
  } catch (error) {
283
+ if (error) {
284
+ response.errors = error;
285
+ }
273
286
  return response;
274
287
  }
275
288
  }
@@ -183,6 +183,16 @@ export class EmailRule<T> extends ValidationRule<T> {
183
183
  }
184
184
  }
185
185
 
186
+ /**
187
+ * 1) start with plus(+) or digit
188
+ * 2) any digit or one char white space
189
+ * 3) end with digit
190
+ *
191
+ * For example:
192
+ * ✅ Valid +90535 555 5555
193
+ * ✅ valid 905355555555
194
+ * 🚫 Unvalid +90535 5 55 5555
195
+ */
186
196
  export class PhoneRule<T> extends ValidationRule<T> {
187
197
  get errorMessage() {
188
198
  if (!this.message) return "";
@@ -193,10 +203,8 @@ export class PhoneRule<T> extends ValidationRule<T> {
193
203
  async run(): Promise<boolean> {
194
204
  if (!this.value) return true;
195
205
 
196
- const result = this.value.match(/\d/g);
197
- return (
198
- (!!result && result.length <= 11) || !!/^\+(\d{12})$/gm.test(this.value)
199
- );
206
+ const result = this.value.match(/^[\+\d](\d+\s)*\d+$/g);
207
+ return !!result;
200
208
  }
201
209
  }
202
210
 
@@ -246,15 +254,8 @@ export class IdentityNumberRule<T> extends ValidationRule<T> {
246
254
  TCSum = 0;
247
255
 
248
256
  const incorrect = [
249
- 11111111110,
250
- 22222222220,
251
- 33333333330,
252
- 44444444440,
253
- 55555555550,
254
- 66666666660,
255
- 7777777770,
256
- 88888888880,
257
- 99999999990,
257
+ 11111111110, 22222222220, 33333333330, 44444444440, 55555555550,
258
+ 66666666660, 7777777770, 88888888880, 99999999990,
258
259
  ];
259
260
 
260
261
  if (tcknString.length !== 11) return false;