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

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 (61) hide show
  1. package/package.json +13 -13
  2. package/src/analytics/analytics.ts +1 -2
  3. package/src/analytics/googleUniversal.ts +2 -12
  4. package/src/analytics/head/index.tsx +2 -1
  5. package/src/analytics/ikas.ts +6 -24
  6. package/src/components/checkout/components/address-form/index.tsx +1 -1
  7. package/src/components/checkout/components/cart-summary/cart-item/index.tsx +9 -11
  8. package/src/components/checkout/components/cart-summary/cart-item/style.module.scss +10 -7
  9. package/src/components/checkout/components/cart-summary/index.tsx +17 -41
  10. package/src/components/checkout/components/customer-addresses/index.tsx +2 -6
  11. package/src/components/checkout/components/form-item/index.tsx +11 -9
  12. package/src/components/checkout/components/master-pass/credit-card-form/index.tsx +0 -2
  13. package/src/components/checkout/components/offer-product/index.tsx +19 -16
  14. package/src/components/checkout/components/offer-product/style.module.scss +3 -1
  15. package/src/components/checkout/components/phone-number-input/get-countries.ts +5 -37
  16. package/src/components/checkout/components/phone-number-input/index.tsx +10 -15
  17. package/src/components/checkout/components/phone-number-input/locale/en.ts +257 -0
  18. package/src/components/checkout/index.tsx +12 -14
  19. package/src/components/checkout/model.ts +61 -95
  20. package/src/components/checkout/modelMasterPass.ts +2 -2
  21. package/src/components/checkout/steps/step-payment/index.tsx +1 -6
  22. package/src/components/checkout/steps/step-payment/payment-gateways/index.tsx +3 -12
  23. package/src/components/checkout/steps/step-payment/payment-gateways/installments/index.tsx +3 -5
  24. package/src/components/checkout/steps/step-payment/style.module.scss +0 -5
  25. package/src/components/checkout/steps/step-shipping/index.tsx +4 -9
  26. package/src/components/checkout/steps/step-success/index.tsx +3 -4
  27. package/src/components/page/head.tsx +0 -12
  28. package/src/components/page/index.tsx +8 -9
  29. package/src/components/page-editor/ThemeComponentEditor.tsx +8 -15
  30. package/src/components/page-editor/model.ts +107 -44
  31. package/src/models/data/cart/campaign-offer/index.ts +2 -13
  32. package/src/models/data/cart/index.ts +1 -1
  33. package/src/models/data/category/path-item/index.ts +0 -4
  34. package/src/models/data/checkout/index.ts +3 -11
  35. package/src/models/data/checkout-settings/price/index.ts +0 -2
  36. package/src/models/data/merchant-settings/index.ts +0 -9
  37. package/src/models/data/order/index.ts +18 -37
  38. package/src/models/data/order/line-item/index.ts +13 -34
  39. package/src/models/data/order/line-item/variant/value/index.ts +1 -1
  40. package/src/models/data/order/transaction/index.ts +5 -2
  41. package/src/models/data/product/filter/index.ts +13 -4
  42. package/src/models/data/product/index.ts +0 -20
  43. package/src/models/data/product/option-set/option/index.ts +6 -25
  44. package/src/models/data/product/variant/index.ts +1 -23
  45. package/src/models/data/product/variant/price/index.ts +9 -23
  46. package/src/models/data/product/variant-type/index.ts +0 -2
  47. package/src/models/data/raffle/index.ts +7 -9
  48. package/src/models/data/state/index.ts +2 -6
  49. package/src/models/data/storefront/index.ts +0 -2
  50. package/src/models/ui/product-list/index.ts +17 -26
  51. package/src/models/ui/raffle-list/index.ts +1 -1
  52. package/src/models/ui/validator/form/raffle-form.ts +3 -16
  53. package/src/models/ui/validator/rules/index.ts +13 -14
  54. package/src/page-data-init/index.ts +404 -159
  55. package/src/pages/checkout.tsx +1 -2
  56. package/src/pages/editor.tsx +2 -5
  57. package/src/store/cart/index.ts +2 -2
  58. package/src/store/customer/index.ts +17 -7
  59. package/src/store/raffle/index.ts +10 -7
  60. package/src/utils/constants.ts +1 -1
  61. package/src/utils/currency.ts +183 -9
@@ -56,45 +56,31 @@ export class IkasProductList {
56
56
  private _fetchRequestTime = 0;
57
57
  private router?: NextRouter | null = null;
58
58
 
59
- constructor(
60
- data: IkasProductListParams | IkasProductList,
61
- router?: NextRouter
62
- ) {
63
- const _params = data as IkasProductListParams;
64
- const _list = data as IkasProductList;
65
-
59
+ constructor(data: IkasProductListParams, router?: NextRouter) {
66
60
  this.data = data.data ? data.data.map((d) => new IkasProduct(d)) : [];
67
61
  this._type =
68
- _params.type ||
69
- _list._type ||
70
- _params.productListPropValue.productListType ||
71
- _list._productListPropValue.productListType ||
62
+ data.type ||
63
+ data.productListPropValue.productListType ||
72
64
  IkasProductListType.ALL;
73
65
  this._pageType = data.pageType;
74
66
  this._sort =
75
67
  data.sort ||
76
68
  data.productListPropValue.initialSort ||
77
69
  IkasProductListSortType.LAST_ADDED;
78
- this._limit =
79
- data.limit ||
80
- _params.productListPropValue.initialLimit ||
81
- _list._productListPropValue.initialLimit ||
82
- 20;
70
+
71
+ this._limit = data.limit || data.productListPropValue.initialLimit || 20;
83
72
  this._page = data.page || 1;
84
73
  this._minPage = data.minPage || null;
85
74
  this._count = data.count || 0;
86
75
  this._searchKeyword = data.searchKeyword || "";
87
- this._productListPropValue =
88
- _params.productListPropValue || _list._productListPropValue;
76
+ this._productListPropValue = data.productListPropValue;
89
77
 
90
- this._filterBrandId = _params.filterBrandId || _list._filterBrandId || null;
91
- this._filterCategoryId =
92
- _params.filterCategoryId || _list._filterCategoryId || null;
78
+ this._filterBrandId = data.filterBrandId || null;
79
+ this._filterCategoryId = data.filterCategoryId || null;
93
80
 
94
- this._relatedProductData =
95
- _params.relatedProductData || _list._relatedProductData || null;
81
+ this._relatedProductData = data.relatedProductData || null;
96
82
 
97
- this._recommendFor = _params.recommendFor || _list._recommendFor;
83
+ this._recommendFor = data.recommendFor;
98
84
 
99
85
  this.filters = data.filters
100
86
  ? data.filters.map((f) => new IkasProductFilter(f, this))
@@ -102,8 +88,7 @@ export class IkasProductList {
102
88
  this._filterCategories = data.filterCategories
103
89
  ? data.filterCategories.map((c) => new IkasFilterCategory(c))
104
90
  : null;
105
- this.pageSpecificData =
106
- _params.pageSpecificData || _list.pageSpecificData || null;
91
+ this.pageSpecificData = data.pageSpecificData || null;
107
92
 
108
93
  this.router = router;
109
94
 
@@ -236,6 +221,12 @@ export class IkasProductList {
236
221
 
237
222
  get filterQueryParams() {
238
223
  const queryParams: Record<string, any> = {};
224
+ const _getQueryParams = this.getQueryParams();
225
+ if (_getQueryParams) {
226
+ _getQueryParams.forEach((value, key) => {
227
+ queryParams[key] = value;
228
+ });
229
+ }
239
230
 
240
231
  this.filters?.forEach((f) => {
241
232
  if (f.keyList.length) queryParams[f.key] = f.keyList;
@@ -75,7 +75,7 @@ export class IkasRaffleList {
75
75
  }
76
76
 
77
77
  private async getRaffleList(page: number, limit: number) {
78
- const response = await RaffleStore.listStorefrontRaffle({
78
+ const response = await RaffleStore.listRaffle({
79
79
  start: this._start ? { eq: this._start } : undefined,
80
80
  end: this._end ? { eq: this._end } : undefined,
81
81
  includeDeleted: this._includeDeleted || false,
@@ -1,6 +1,5 @@
1
1
  import { saveRaffleParticipant } from "@ikas/storefront-api";
2
2
  import { action, computed, makeObservable, observable } from "mobx";
3
- import { GraphQLError } from "graphql";
4
3
 
5
4
  import { Validator } from "..";
6
5
  import { IkasBaseStore } from "../../../../store";
@@ -238,11 +237,7 @@ export class RaffleForm {
238
237
  }
239
238
 
240
239
  async submit() {
241
- const response: {
242
- isFormError: boolean;
243
- isSuccess: boolean;
244
- errors?: readonly GraphQLError[];
245
- } = { isFormError: false, isSuccess: false };
240
+ const response = { isFormError: false, isSuccess: false };
246
241
  const hasFormError = await this.validateAll();
247
242
  if (hasFormError) {
248
243
  response.isFormError = true;
@@ -251,7 +246,7 @@ export class RaffleForm {
251
246
 
252
247
  try {
253
248
  const selectedVariant = this.raffle.products[0].selectedVariant;
254
- const saveRaffleParticipantResponse = await saveRaffleParticipant({
249
+ const isRaffleFormSuccess = await saveRaffleParticipant({
255
250
  input: {
256
251
  appliedProduct: {
257
252
  productId: selectedVariant.productId,
@@ -269,20 +264,12 @@ export class RaffleForm {
269
264
  },
270
265
  });
271
266
 
272
- if (saveRaffleParticipantResponse?.graphQLErrors) {
273
- response.errors = saveRaffleParticipantResponse.graphQLErrors;
274
- response.isSuccess = false;
275
- }
276
-
277
- if (saveRaffleParticipantResponse.data) {
267
+ if (isRaffleFormSuccess) {
278
268
  response.isSuccess = true;
279
269
  }
280
270
 
281
271
  return response;
282
272
  } catch (error) {
283
- if (error) {
284
- response.errors = error;
285
- }
286
273
  return response;
287
274
  }
288
275
  }
@@ -183,16 +183,6 @@ 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
- */
196
186
  export class PhoneRule<T> extends ValidationRule<T> {
197
187
  get errorMessage() {
198
188
  if (!this.message) return "";
@@ -203,8 +193,10 @@ export class PhoneRule<T> extends ValidationRule<T> {
203
193
  async run(): Promise<boolean> {
204
194
  if (!this.value) return true;
205
195
 
206
- const result = this.value.match(/^[\+\d](\d+\s)*\d+$/g);
207
- return !!result;
196
+ const result = this.value.match(/\d/g);
197
+ return (
198
+ (!!result && result.length <= 11) || !!/^\+(\d{12})$/gm.test(this.value)
199
+ );
208
200
  }
209
201
  }
210
202
 
@@ -254,8 +246,15 @@ export class IdentityNumberRule<T> extends ValidationRule<T> {
254
246
  TCSum = 0;
255
247
 
256
248
  const incorrect = [
257
- 11111111110, 22222222220, 33333333330, 44444444440, 55555555550,
258
- 66666666660, 7777777770, 88888888880, 99999999990,
249
+ 11111111110,
250
+ 22222222220,
251
+ 33333333330,
252
+ 44444444440,
253
+ 55555555550,
254
+ 66666666660,
255
+ 7777777770,
256
+ 88888888880,
257
+ 99999999990,
259
258
  ];
260
259
 
261
260
  if (tcknString.length !== 11) return false;