@ikas/storefront 4.0.0-alpha.49 → 4.0.0-alpha.5

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 (85) 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 +7 -25
  6. package/src/components/checkout/components/address-form/index.tsx +1 -1
  7. package/src/components/checkout/components/address-form/model.ts +0 -1
  8. package/src/components/checkout/components/button/style.module.scss +2 -2
  9. package/src/components/checkout/components/cart-summary/cart-item/index.tsx +29 -16
  10. package/src/components/checkout/components/cart-summary/cart-item/style.module.scss +23 -60
  11. package/src/components/checkout/components/cart-summary/index.tsx +27 -58
  12. package/src/components/checkout/components/cart-summary/style.module.scss +3 -48
  13. package/src/components/checkout/components/customer-addresses/index.tsx +2 -7
  14. package/src/components/checkout/components/customer-addresses/model.ts +8 -16
  15. package/src/components/checkout/components/error/index.tsx +1 -1
  16. package/src/components/checkout/components/error/unknown-error/index.tsx +2 -4
  17. package/src/components/checkout/components/form-item/index.tsx +11 -9
  18. package/src/components/checkout/components/master-pass/credit-card-form/index.tsx +0 -2
  19. package/src/components/checkout/components/offer-product/index.tsx +19 -16
  20. package/src/components/checkout/components/offer-product/style.module.scss +3 -1
  21. package/src/components/checkout/components/phone-number-input/get-countries.ts +5 -37
  22. package/src/components/checkout/components/phone-number-input/index.tsx +10 -15
  23. package/src/components/checkout/components/phone-number-input/locale/en.ts +257 -0
  24. package/src/components/checkout/index.tsx +19 -28
  25. package/src/components/checkout/model.ts +91 -214
  26. package/src/components/checkout/modelMasterPass.ts +2 -2
  27. package/src/components/checkout/steps/step-info/index.tsx +3 -9
  28. package/src/components/checkout/steps/step-payment/billing-address/index.tsx +1 -1
  29. package/src/components/checkout/steps/step-payment/index.tsx +2 -11
  30. package/src/components/checkout/steps/step-payment/payment-gateways/index.tsx +3 -12
  31. package/src/components/checkout/steps/step-payment/payment-gateways/installments/index.tsx +3 -5
  32. package/src/components/checkout/steps/step-payment/style.module.scss +0 -5
  33. package/src/components/checkout/steps/step-shipping/index.tsx +4 -9
  34. package/src/components/checkout/steps/step-success/index.tsx +7 -15
  35. package/src/components/page/head.tsx +0 -12
  36. package/src/components/page/index.tsx +9 -10
  37. package/src/components/page-editor/ThemeComponentEditor.tsx +8 -19
  38. package/src/components/page-editor/model.ts +107 -44
  39. package/src/models/data/cart/campaign-offer/index.ts +2 -13
  40. package/src/models/data/cart/index.ts +1 -1
  41. package/src/models/data/category/init.ts +33 -0
  42. package/src/models/data/category/path-item/index.ts +0 -4
  43. package/src/models/data/checkout/index.ts +4 -36
  44. package/src/models/data/checkout-settings/price/index.ts +0 -2
  45. package/src/models/data/country/index.ts +0 -4
  46. package/src/models/data/index.ts +0 -3
  47. package/src/models/data/merchant-settings/index.ts +0 -9
  48. package/src/models/data/order/index.ts +32 -51
  49. package/src/models/data/order/line-item/index.ts +18 -76
  50. package/src/models/data/order/line-item/variant/index.ts +0 -8
  51. package/src/models/data/order/line-item/variant/price/index.ts +0 -2
  52. package/src/models/data/order/line-item/variant/value/index.ts +1 -1
  53. package/src/models/data/order/transaction/index.ts +5 -2
  54. package/src/models/data/product/attribute-value/index.ts +0 -40
  55. package/src/models/data/product/filter/index.ts +13 -4
  56. package/src/models/data/product/index.ts +7 -45
  57. package/src/models/data/product/option-set/index.ts +3 -8
  58. package/src/models/data/product/option-set/option/index.ts +13 -36
  59. package/src/models/data/product/variant/index.ts +1 -26
  60. package/src/models/data/product/variant/price/index.ts +9 -25
  61. package/src/models/data/product/variant-type/index.ts +0 -2
  62. package/src/models/data/raffle/index.ts +7 -9
  63. package/src/models/data/state/index.ts +2 -6
  64. package/src/models/data/storefront/index.ts +0 -2
  65. package/src/models/data/storefront/routing/index.tsx +0 -4
  66. package/src/models/ui/product-list/index.ts +17 -26
  67. package/src/models/ui/raffle-list/index.ts +1 -1
  68. package/src/models/ui/validator/form/raffle-form.ts +3 -16
  69. package/src/models/ui/validator/rules/index.ts +13 -14
  70. package/src/page-data-init/index.ts +404 -159
  71. package/src/pages/checkout.tsx +1 -2
  72. package/src/pages/editor.tsx +2 -5
  73. package/src/store/base.ts +2 -2
  74. package/src/store/cart/index.ts +2 -2
  75. package/src/store/customer/index.ts +17 -7
  76. package/src/store/index.ts +0 -2
  77. package/src/store/raffle/index.ts +10 -7
  78. package/src/utils/constants.ts +1 -1
  79. package/src/utils/currency.ts +183 -9
  80. package/src/models/data/country/location-translations/index.ts +0 -15
  81. package/src/models/data/order/line-item/base-unit/index.ts +0 -22
  82. package/src/models/data/order/line-item/base-unit/unit-type/index.ts +0 -14
  83. package/src/models/data/order/line-item/variant/unit/index.ts +0 -17
  84. package/src/models/data/product/base-unit/index.ts +0 -32
  85. package/src/models/data/product/variant/unit/index.ts +0 -17
@@ -13,17 +13,16 @@ import {
13
13
  } from "@ikas/storefront-models";
14
14
  import { IkasProductOptionSet } from "./option-set";
15
15
  import { makeAutoObservable } from "mobx";
16
- import { IkasProductFunctions } from "@ikas/storefront-model-functions";
16
+ import {
17
+ IkasProductFunctions,
18
+ IkasProductOptionSetFunctions,
19
+ } from "@ikas/storefront-model-functions";
17
20
  import { IkasVariantValue } from "../variant-type/variant-value";
18
21
  import { IkasProductCampaign } from "./campaign";
19
22
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
20
23
  import { Analytics } from "../../../analytics";
21
24
  import { IkasVariantType } from "../variant-type";
22
25
  import { IkasBaseStore } from "../../../store/base";
23
- import { IkasProductAttributeMap } from "./attribute-value";
24
- import _groupBy from "lodash/groupBy";
25
- import { IkasProductBaseUnit } from "./base-unit";
26
- import { formatCurrency } from "../../../utils";
27
26
 
28
27
  export class IkasProduct implements IProduct {
29
28
  id: string;
@@ -39,7 +38,6 @@ export class IkasProduct implements IProduct {
39
38
  attributes: IkasProductAttributeValue[];
40
39
  variantTypes: IkasProductVariantType[];
41
40
  productOptionSetId: string | null = null;
42
- baseUnit: IkasProductBaseUnit | null;
43
41
 
44
42
  // Extra
45
43
  productOptionSet?: IkasProductOptionSet | null = null;
@@ -71,9 +69,6 @@ export class IkasProduct implements IProduct {
71
69
  ? data.variantTypes.map((v) => new IkasProductVariantType(v))
72
70
  : [];
73
71
  this.productOptionSetId = data.productOptionSetId || null;
74
- this.baseUnit = data.baseUnit
75
- ? new IkasProductBaseUnit(data.baseUnit)
76
- : null;
77
72
 
78
73
  this.productOptionSet = data.productOptionSet
79
74
  ? new IkasProductOptionSet(data.productOptionSet)
@@ -99,7 +94,9 @@ export class IkasProduct implements IProduct {
99
94
 
100
95
  get hasValidProductOptionValues() {
101
96
  if (this.productOptionSet) {
102
- return this.productOptionSet.hasValidValues;
97
+ return IkasProductOptionSetFunctions.hasValidValues(
98
+ this.productOptionSet
99
+ );
103
100
  } else {
104
101
  return true;
105
102
  }
@@ -164,28 +161,6 @@ export class IkasProduct implements IProduct {
164
161
  );
165
162
  }
166
163
 
167
- get groupedAttributeValues(): IkasProductAttributeMap[] {
168
- const groupedValues = _groupBy(this.attributes, "productAttributeId");
169
-
170
- return (this.attributes
171
- ?.map((attribute) => {
172
- const attributeId = attribute.productAttributeId;
173
- if (!attributeId) return;
174
-
175
- const values = groupedValues[attributeId];
176
- if (values?.length && values[0].productAttribute)
177
- return {
178
- attribute: values[0].productAttribute,
179
- values: values,
180
- };
181
- })
182
- .filter((v) => !!v) || []) as IkasProductAttributeMap[];
183
- }
184
-
185
- get selectedVariantUnitPriceText() {
186
- return this.getVariantUnitPriceText(this.selectedVariant);
187
- }
188
-
189
164
  selectVariantValue(variantValue: IkasVariantValue) {
190
165
  const metaData = this.metaData;
191
166
  const selectedVariantValues = this.selectedVariantValues.map((vv) => {
@@ -283,19 +258,6 @@ export class IkasProduct implements IProduct {
283
258
  Analytics.productView(this);
284
259
  }
285
260
 
286
- getVariantUnitPriceText(variant: IkasProductVariant) {
287
- const price = variant.price;
288
- if (!price.unitPrice || !this.baseUnit) {
289
- return;
290
- }
291
-
292
- return `${formatCurrency(
293
- price.unitPrice,
294
- price.currency || "",
295
- price.currencySymbol || ""
296
- )} / ${this.baseUnit?.unit?.name}`;
297
- }
298
-
299
261
  private setOptionPrices() {
300
262
  const variant = this.variants[0];
301
263
  if (!variant) return;
@@ -79,18 +79,13 @@ export class IkasProductOptionSet implements IProductOptionSet {
79
79
  ? data.translations?.map((o) => new IkasProductOptionSetTranslations(o))
80
80
  : null;
81
81
 
82
- this.initOptionValues();
83
82
  makeAutoObservable(this);
84
83
  }
85
84
 
86
85
  get displayedOptions() {
87
- return IkasProductOptionSetFunctions.getDisplayedOptions(
88
- this
89
- ) as IkasProductOption[];
90
- }
91
-
92
- get hasValidValues() {
93
- return this.displayedOptions.every((o) => o.hasValidValues);
86
+ return IkasProductOptionSetFunctions.getDisplayedOptions(this).map(
87
+ (o) => new IkasProductOption(o)
88
+ );
94
89
  }
95
90
 
96
91
  initOptionValues = async () => {
@@ -13,7 +13,7 @@ import { makeAutoObservable } from "mobx";
13
13
  import { IkasImage } from "../../../image";
14
14
  import _sortBy from "lodash/sortBy";
15
15
  import { IkasProductOptionFunctions } from "@ikas/storefront-model-functions";
16
- import { getProductOptionFileUrl, uploadFile } from "@ikas/storefront-api";
16
+ import { uploadProductOptionFile } from "@ikas/storefront-api";
17
17
 
18
18
  export class IkasProductOptionOtherPrice implements IProductOptionOtherPrice {
19
19
  currencyCode: string;
@@ -181,17 +181,16 @@ export class IkasProductOption implements IProductOption {
181
181
  this.requiredOptionValueIds = data.requiredOptionValueIds || null;
182
182
 
183
183
  this.values = data.values || [];
184
- this.childOptions = data.childOptions
185
- ? data.childOptions.map((co) => new IkasProductOption(co))
186
- : [];
184
+ //@ts-ignore
185
+ this.childOptions = data.childOptions || [];
187
186
 
188
187
  makeAutoObservable(this);
189
188
  }
190
189
 
191
190
  get displayedChildOptions() {
192
- return IkasProductOptionFunctions.getDisplayedChildOptions(
193
- this
194
- ) as IkasProductOption[];
191
+ return IkasProductOptionFunctions.getDisplayedChildOptions(this).map(
192
+ (o) => new IkasProductOption(o)
193
+ );
195
194
  }
196
195
 
197
196
  productOptionFileUpload = async (files: File[]) => {
@@ -203,37 +202,15 @@ export class IkasProductOption implements IProductOption {
203
202
  )
204
203
  return [];
205
204
 
206
- let tempUploadFiles = (
207
- await Promise.all(
208
- files.map((file) =>
209
- getProductOptionFileUrl(
210
- {
211
- fileName: file.name,
212
- productOptionSetId: this.productOptionSetId,
213
- productOptionId: this.id,
214
- },
215
- file
216
- )
217
- )
218
- )
219
- ).filter((file) => file.data);
220
-
221
- const uploadedFiles: string[] = [];
222
- for (const file of tempUploadFiles) {
223
- const isSuccess = await uploadFile(file.data!, file.data!.file);
224
- if (isSuccess) {
225
- uploadedFiles.push(file.data!.optionUrl);
226
- }
227
- }
228
-
229
- return uploadedFiles;
205
+ let fileIds = await Promise.all(
206
+ files.map((file) => uploadProductOptionFile(file, this))
207
+ );
208
+ fileIds = fileIds.filter((id) => id !== null);
209
+ return fileIds;
230
210
  };
231
211
 
232
- get hasValidValues(): boolean {
233
- return (
234
- IkasProductOptionFunctions.hasValidValues(this) &&
235
- this.displayedChildOptions.every((o) => o.hasValidValues)
236
- );
212
+ get hasValidValues() {
213
+ return IkasProductOptionFunctions.hasValidValues(this);
237
214
  }
238
215
 
239
216
  get values() {
@@ -1,9 +1,6 @@
1
1
  import { IkasProductPrice } from "./price";
2
2
  import { IkasVariantValue } from "../../variant-type/variant-value";
3
- import {
4
- IkasProductAttributeMap,
5
- IkasProductAttributeValue,
6
- } from "../attribute-value";
3
+ import { IkasProductAttributeValue } from "../attribute-value";
7
4
  import { IkasProductCampaign } from "../campaign";
8
5
  import { IkasProductImage } from "../image";
9
6
  import { IkasProductVariant as IProductVariant } from "@ikas/storefront-models";
@@ -14,8 +11,6 @@ import {
14
11
  listProductBackInStockRemind,
15
12
  saveProductBackInStockRemind,
16
13
  } from "@ikas/storefront-api";
17
- import _groupBy from "lodash/groupBy";
18
- import { IkasProductVariantUnit } from "./unit";
19
14
 
20
15
  export class IkasProductVariant implements IProductVariant {
21
16
  id: string;
@@ -30,7 +25,6 @@ export class IkasProductVariant implements IProductVariant {
30
25
  sellIfOutOfStock: boolean;
31
26
  images: IkasProductImage[] | null;
32
27
  campaigns?: IkasProductCampaign[];
33
- unit: IkasProductVariantUnit | null;
34
28
  private _backInStockReminderSaved = false;
35
29
 
36
30
  constructor(data: Partial<IProductVariant> = {}) {
@@ -53,7 +47,6 @@ export class IkasProductVariant implements IProductVariant {
53
47
  this.stock = data.stock || 0;
54
48
  this.isActive = data.isActive !== undefined ? data.isActive : true;
55
49
  this.campaigns = data.campaigns || [];
56
- this.unit = data.unit ? new IkasProductVariantUnit(data.unit) : null;
57
50
  this.sellIfOutOfStock = data.sellIfOutOfStock || false;
58
51
 
59
52
  makeAutoObservable(this);
@@ -80,24 +73,6 @@ export class IkasProductVariant implements IProductVariant {
80
73
  return this._backInStockReminderSaved;
81
74
  }
82
75
 
83
- get groupedAttributeValues(): IkasProductAttributeMap[] {
84
- const groupedValues = _groupBy(this.attributes, "productAttributeId");
85
-
86
- return (this.attributes
87
- ?.map((attribute) => {
88
- const attributeId = attribute.productAttributeId;
89
- if (!attributeId) return;
90
-
91
- const values = groupedValues[attributeId];
92
- if (values?.length && values[0].productAttribute)
93
- return {
94
- attribute: values[0].productAttribute,
95
- values: values,
96
- };
97
- })
98
- .filter((v) => !!v) || []) as IkasProductAttributeMap[];
99
- }
100
-
101
76
  async saveBackInStockReminder(email: string) {
102
77
  const listResponse = await listProductBackInStockRemind({
103
78
  email: { eq: email },
@@ -1,63 +1,47 @@
1
1
  import { IkasProductPriceFunctions } from "@ikas/storefront-model-functions";
2
2
  import { IkasProductPrice as IProductPrice } from "@ikas/storefront-models";
3
3
  import { makeAutoObservable } from "mobx";
4
- import { formatCurrency } from "../../../../../utils/currency";
4
+ import { getCurrencySymbol, formatMoney } from "../../../../../utils/currency";
5
5
 
6
6
  export class IkasProductPrice implements IProductPrice {
7
7
  buyPrice: number | null = null;
8
8
  currency: string | null = null;
9
- currencySymbol: string | null = null;
10
9
  discountPrice: number | null = null;
11
10
  priceListId: string | null = null;
12
11
  sellPrice: number;
13
- unitPrice: number | null = null;
14
12
 
15
13
  constructor(data?: IProductPrice) {
16
14
  this.buyPrice = data?.buyPrice ?? null;
17
15
  this.currency = data?.currency ?? null;
18
- this.currencySymbol = data?.currencySymbol ?? "";
19
16
  this.discountPrice = data?.discountPrice ?? null;
20
17
  this.priceListId = data?.priceListId ?? null;
21
18
  this.sellPrice = data?.sellPrice ?? 0;
22
- this.unitPrice = data?.unitPrice ?? null;
23
19
 
24
20
  makeAutoObservable(this);
25
21
  }
26
22
 
23
+ get currencySymbol() {
24
+ return getCurrencySymbol(this.currency || "");
25
+ }
26
+
27
27
  get finalPrice() {
28
28
  return IkasProductPriceFunctions.getFinalPrice(this);
29
29
  }
30
30
 
31
31
  get formattedFinalPrice() {
32
- return formatCurrency(
33
- this.finalPrice,
34
- this.currency || "",
35
- this.currencySymbol || ""
36
- );
32
+ return formatMoney(this.finalPrice, this.currencySymbol);
37
33
  }
38
34
 
39
35
  get formattedBuyPrice() {
40
- return formatCurrency(
41
- this.buyPrice || 0,
42
- this.currency || "",
43
- this.currencySymbol || ""
44
- );
36
+ return formatMoney(this.buyPrice || 0, this.currencySymbol);
45
37
  }
46
38
 
47
39
  get formattedDiscountPrice() {
48
- return formatCurrency(
49
- this.discountPrice || 0,
50
- this.currency || "",
51
- this.currencySymbol || ""
52
- );
40
+ return formatMoney(this.discountPrice || 0, this.currencySymbol);
53
41
  }
54
42
 
55
43
  get formattedSellPrice() {
56
- return formatCurrency(
57
- this.sellPrice || 0,
58
- this.currency || "",
59
- this.currencySymbol || ""
60
- );
44
+ return formatMoney(this.sellPrice || 0, this.currencySymbol);
61
45
  }
62
46
 
63
47
  get hasDiscount() {
@@ -3,12 +3,10 @@ import { IkasProductVariantType as IProductVariantType } from "@ikas/storefront-
3
3
  import { makeAutoObservable } from "mobx";
4
4
 
5
5
  export class IkasProductVariantType implements IProductVariantType {
6
- order: number;
7
6
  variantType: IkasVariantType;
8
7
  variantValueIds: string[];
9
8
 
10
9
  constructor(data: Partial<IkasProductVariantType>) {
11
- this.order = data.order || 0;
12
10
  this.variantType = data.variantType
13
11
  ? new IkasVariantType(data.variantType)
14
12
  : new IkasVariantType();
@@ -8,7 +8,6 @@ import {
8
8
  IkasRaffleAppliedProduct as IRaffleAppliedProduct,
9
9
  IkasRaffleVerificationType,
10
10
  IkasRaffleMetadataTargetType,
11
- IkasRaffleParticipantStatus,
12
11
  } from "@ikas/storefront-models";
13
12
  import { IkasRaffleFunctions } from "@ikas/storefront-model-functions";
14
13
 
@@ -34,12 +33,13 @@ export class IkasRaffle implements IRaffle {
34
33
  dateRange: IkasRaffleDateRangeField | null;
35
34
  metadata: IkasRaffleMetaData | null;
36
35
  name: string;
36
+ participantCount?: number | null;
37
37
  requiredCustomerAccount: boolean;
38
38
  status: boolean;
39
39
  variants: IkasRaffleAppliedProduct[] | null;
40
- verificationType: IkasRaffleVerificationType;
41
-
42
40
  products: IkasProduct[];
41
+ verificationType: IkasRaffleVerificationType;
42
+ isCustomerWinner: boolean | null;
43
43
 
44
44
  constructor(data: Partial<IkasRaffle> = {}) {
45
45
  this.id = data.id || Date.now() + "";
@@ -47,10 +47,12 @@ export class IkasRaffle implements IRaffle {
47
47
  this.updatedAt = data.updatedAt || Date.now();
48
48
  this.deleted = data.deleted || null;
49
49
  this.name = data.name || "";
50
+ this.participantCount = data.participantCount || 0;
50
51
  this.requiredCustomerAccount = data.requiredCustomerAccount || false;
51
52
  this.status = data.status || false;
52
53
  this.verificationType =
53
54
  data.verificationType || IkasRaffleVerificationType.EMAIL;
55
+ this.isCustomerWinner = data.isCustomerWinner || null;
54
56
 
55
57
  this.dateRange = data.dateRange
56
58
  ? new IkasRaffleDateRangeField(data.dateRange)
@@ -111,10 +113,8 @@ export class IkasRaffleParticipant implements IRaffleParticipant {
111
113
  email: string;
112
114
  applicationDate: number;
113
115
  phone: string | null = null;
114
- isDeliveredCargo: boolean | null;
116
+ isWinner: boolean | null = null;
115
117
 
116
- raffle: IkasRaffle | null;
117
- status: IkasRaffleParticipantStatus | null;
118
118
  extraData: Record<string, any> | null = null;
119
119
  appliedProduct: IkasRaffleAppliedProduct;
120
120
 
@@ -131,10 +131,8 @@ export class IkasRaffleParticipant implements IRaffleParticipant {
131
131
  this.email = data.email || "";
132
132
  this.applicationDate = data.applicationDate || 0;
133
133
  this.phone = data.phone || null;
134
- this.isDeliveredCargo = data.isDeliveredCargo || false;
134
+ this.isWinner = data.isWinner || null;
135
135
 
136
- this.raffle = data.raffle ? new IkasRaffle(data.raffle) : null;
137
- this.status = data.status || null;
138
136
  this.extraData = data.extraData || {};
139
137
  this.appliedProduct = new IkasRaffleAppliedProduct(
140
138
  data.appliedProduct || {}
@@ -1,6 +1,6 @@
1
1
  import { IkasBaseModel } from "../base";
2
2
  import { IkasState as IState } from "@ikas/storefront-models";
3
- import { makeObservable, observable } from "mobx";
3
+ import { makeAutoObservable } from "mobx";
4
4
 
5
5
  export class IkasState extends IkasBaseModel implements IState {
6
6
  countryId: string;
@@ -13,10 +13,6 @@ export class IkasState extends IkasBaseModel implements IState {
13
13
  this.name = data.name;
14
14
  this.stateCode = data.stateCode;
15
15
 
16
- makeObservable(this, {
17
- countryId: observable,
18
- name: observable,
19
- stateCode: observable,
20
- });
16
+ makeAutoObservable(this);
21
17
  }
22
18
  }
@@ -20,7 +20,6 @@ export class IkasStorefront implements IStorefront {
20
20
  analytics4Id: string | null;
21
21
  universalAnalyticsId: string | null;
22
22
  tiktokPixelId: string | null;
23
- token: string | null;
24
23
 
25
24
  localizations: IkasStorefrontLocalization[];
26
25
  routings: IkasStorefrontRouting[];
@@ -41,7 +40,6 @@ export class IkasStorefront implements IStorefront {
41
40
  this.analytics4Id = data.analytics4Id || null;
42
41
  this.universalAnalyticsId = data.universalAnalyticsId || null;
43
42
  this.tiktokPixelId = data.tiktokPixelId || null;
44
- this.token = data.token || null;
45
43
 
46
44
  // Sub Models
47
45
  this.localizations = data.localizations
@@ -10,8 +10,6 @@ export class IkasStorefrontRouting implements IStorefrontRouting {
10
10
  path: string | null;
11
11
  priceListId: string | null;
12
12
  dynamicCurrencySettings: IkasStorefrontDynamicCurrencySettings | null;
13
- currencyCode: string | null;
14
- currencySymbol: string | null;
15
13
 
16
14
  constructor(data: IStorefrontRouting) {
17
15
  this.id = data.id;
@@ -21,8 +19,6 @@ export class IkasStorefrontRouting implements IStorefrontRouting {
21
19
  this.path = data.path;
22
20
  this.priceListId = data.priceListId;
23
21
  this.dynamicCurrencySettings = data.dynamicCurrencySettings;
24
- this.currencyCode = data.currencyCode;
25
- this.currencySymbol = data.currencySymbol;
26
22
 
27
23
  makeAutoObservable(this);
28
24
  }
@@ -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;