@ikas/storefront 4.0.0-alpha.3 → 4.0.0-alpha.31

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 (43) 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 +8 -0
  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/index.tsx +41 -17
  9. package/src/components/checkout/components/form-item/index.tsx +9 -11
  10. package/src/components/checkout/components/offer-product/index.tsx +4 -3
  11. package/src/components/checkout/components/phone-number-input/get-countries.ts +37 -5
  12. package/src/components/checkout/components/phone-number-input/index.tsx +15 -10
  13. package/src/components/checkout/index.tsx +4 -3
  14. package/src/components/checkout/model.ts +8 -11
  15. package/src/components/checkout/modelMasterPass.ts +2 -2
  16. package/src/components/checkout/steps/step-payment/payment-gateways/index.tsx +6 -2
  17. package/src/components/checkout/steps/step-payment/payment-gateways/installments/index.tsx +5 -3
  18. package/src/components/checkout/steps/step-shipping/index.tsx +9 -4
  19. package/src/components/checkout/steps/step-success/index.tsx +4 -3
  20. package/src/components/page/head.tsx +12 -0
  21. package/src/components/page/index.tsx +4 -2
  22. package/src/components/page-editor/model.ts +15 -2
  23. package/src/models/data/checkout/index.ts +6 -2
  24. package/src/models/data/checkout-settings/price/index.ts +2 -0
  25. package/src/models/data/merchant-settings/index.ts +6 -0
  26. package/src/models/data/order/index.ts +24 -10
  27. package/src/models/data/order/line-item/index.ts +32 -13
  28. package/src/models/data/order/transaction/index.ts +2 -5
  29. package/src/models/data/product/variant/price/index.ts +23 -9
  30. package/src/models/data/product/variant-type/index.ts +2 -0
  31. package/src/models/data/raffle/index.ts +9 -7
  32. package/src/models/data/storefront/index.ts +2 -0
  33. package/src/models/ui/product-list/index.ts +0 -6
  34. package/src/models/ui/raffle-list/index.ts +1 -1
  35. package/src/models/ui/validator/form/raffle-form.ts +16 -3
  36. package/src/models/ui/validator/rules/index.ts +14 -13
  37. package/src/pages/checkout.tsx +2 -1
  38. package/src/pages/editor.tsx +5 -2
  39. package/src/store/cart/index.ts +2 -2
  40. package/src/store/customer/index.ts +6 -16
  41. package/src/store/raffle/index.ts +7 -10
  42. package/src/utils/currency.ts +9 -183
  43. 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;
@@ -9,7 +9,7 @@ import IkasCheckoutPage, {
9
9
  import { useRouter } from "next/router.js";
10
10
  import { FullscreenLoading } from "../components/checkout/components/fullscreen-loading";
11
11
  import { CheckoutStep } from "../components/checkout/model";
12
- import { getCartById } from "@ikas/storefront-api";
12
+ import { getCartById, setAPIClientConfig } from "@ikas/storefront-api";
13
13
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
14
14
  import { IkasBaseStore } from "..";
15
15
  import { IkasCheckout, IkasCheckoutSettings } from "../models/data";
@@ -35,6 +35,7 @@ const CheckoutPage: React.FC<Props> = ({
35
35
  const [checkout, setCheckout] = React.useState<IkasCheckout | undefined>();
36
36
 
37
37
  IkasStorefrontConfig.init(configJson);
38
+ setAPIClientConfig();
38
39
 
39
40
  React.useEffect(() => {
40
41
  setCustomizationProps(customizationProps);
@@ -8,7 +8,7 @@ const IkasPageEditor = dynamic(
8
8
  );
9
9
 
10
10
  type Props = {
11
- configJson: Record<string, any>;
11
+ configJson?: Record<string, any>; // local only
12
12
  components?: Record<string, any>;
13
13
  };
14
14
 
@@ -19,9 +19,12 @@ export default class Page extends React.Component<Props> {
19
19
  if (configJson) {
20
20
  IkasStorefrontConfig.init({
21
21
  ...configJson,
22
- currentPageComponents: components || {},
23
22
  });
24
23
  }
24
+
25
+ IkasStorefrontConfig.init({
26
+ currentPageComponents: components || {},
27
+ });
25
28
  }
26
29
 
27
30
  render() {
@@ -100,7 +100,7 @@ export class IkasCartStore {
100
100
 
101
101
  product.productOptionSet?.initOptionValues();
102
102
 
103
- return true;
103
+ return response;
104
104
  } catch (err) {
105
105
  console.log(err);
106
106
  return false;
@@ -145,7 +145,7 @@ export class IkasCartStore {
145
145
  Analytics.addToCart(item, quantity - oldQuantity, eventId, this.cart);
146
146
  }
147
147
  }
148
- return true;
148
+ return response;
149
149
  } catch (err) {
150
150
  console.log(err);
151
151
  return false;
@@ -24,6 +24,7 @@ import { IkasStorefrontConfig } from "@ikas/storefront-config";
24
24
  import { SaveMyCustomerInput } from "@ikas/storefront-api";
25
25
  import { populateRaffleProducts } from "@ikas/storefront-providers";
26
26
  import { IkasBaseStore } from "../base";
27
+ import { IkasRaffle } from "@ikas/storefront-models";
27
28
 
28
29
  const isServer = typeof localStorage === "undefined";
29
30
  const LS_TOKEN_KEY = "customerToken";
@@ -403,22 +404,11 @@ export class IkasCustomerStore {
403
404
  };
404
405
 
405
406
  getRaffles = async () => {
406
- const rafflesResponse = await RaffleStore.getRafflesByCustomerId({
407
- winnerFilter: false,
408
- });
409
- const wonRafflesResponse = await RaffleStore.getRafflesByCustomerId({
410
- winnerFilter: true,
411
- });
412
-
413
- const raffles = rafflesResponse.data;
414
- const wonRaffles = wonRafflesResponse.data;
415
-
416
- raffles?.forEach((raffle) => {
417
- if (wonRaffles?.find((wonRaffle) => wonRaffle.id === raffle.id))
418
- raffle.isCustomerWinner = true;
419
- });
420
-
421
- if (raffles) await populateRaffleProducts(raffles);
407
+ const rafflesResponse = await RaffleStore.listRaffleParticipants();
408
+ let raffles: IkasRaffle[] = [];
409
+ if (!rafflesResponse.data?.length) return raffles;
410
+ raffles = rafflesResponse.data;
411
+ if (raffles.length) await populateRaffleProducts(raffles);
422
412
  return raffles || [];
423
413
  };
424
414
 
@@ -1,11 +1,10 @@
1
1
  import { APIResponse } from "@ikas/fe-api-client";
2
2
  import {
3
- getRafflesByCustomerId,
4
- GetRafflesByCustomerIdQueryParams,
5
- listRaffle,
3
+ listRaffleParticipants,
4
+ listStorefrontRaffle,
6
5
  listRaffleMetaData,
7
6
  ListRaffleMetadataQueryParams,
8
- ListRaffleQueryParams,
7
+ ListStorefrontRaffleParams,
9
8
  saveRaffleParticipant,
10
9
  SaveRaffleParticipantQueryParams,
11
10
  } from "@ikas/storefront-api";
@@ -16,8 +15,8 @@ import {
16
15
  } from "../../models/data/raffle";
17
16
 
18
17
  export default class RaffleStore {
19
- static async listRaffle(params: ListRaffleQueryParams) {
20
- const response = await listRaffle(params);
18
+ static async listStorefrontRaffle(params: ListStorefrontRaffleParams) {
19
+ const response = await listStorefrontRaffle(params);
21
20
  return new APIResponse({
22
21
  ...response.data,
23
22
  data: response.data?.data?.map(
@@ -46,10 +45,8 @@ export default class RaffleStore {
46
45
  );
47
46
  }
48
47
 
49
- static async getRafflesByCustomerId(
50
- params: GetRafflesByCustomerIdQueryParams
51
- ) {
52
- const response = await getRafflesByCustomerId(params);
48
+ static async listRaffleParticipants() {
49
+ const response = await listRaffleParticipants();
53
50
  return new APIResponse(
54
51
  response.data?.map((d) => new IkasRaffle(d as unknown as IkasRaffle)),
55
52
  response.graphQLErrors
@@ -13,14 +13,19 @@ const format = (p: number, n: number, x: number, s: string, c: string) => {
13
13
  /**
14
14
  *
15
15
  * @param price Price to format
16
- * @param currencyCode Code for the currency, USD, EUR, TRY, etc..
16
+ * @param currencyCode Currency code
17
+ * @param currencySymbol Symbol for the currency
17
18
  */
18
- export const formatMoney = (price: number, currencyCode: string) => {
19
+ export const formatCurrency = (
20
+ price: number,
21
+ currencyCode: string,
22
+ currencySymbol: string | null
23
+ ) => {
19
24
  const formatSettings =
20
25
  IkasStorefrontConfig.getMerchantSettings()?.currencyFormats?.find(
21
26
  (s) => s.currencyCode === currencyCode
22
27
  );
23
- const symbol = formatSettings?.symbol || getCurrencySymbol(currencyCode);
28
+ const symbol = formatSettings?.symbol || currencySymbol || "";
24
29
  const decimalSeparator = formatSettings?.decimalSeparator || ".";
25
30
  const thousandSeparator = formatSettings?.thousandSeparator || ",";
26
31
  const symbolPosition = formatSettings?.symbolPosition || "LEFT";
@@ -62,189 +67,10 @@ export const formatMoney = (price: number, currencyCode: string) => {
62
67
  IkasStorefrontConfig.getCurrentLocale(),
63
68
  {
64
69
  style: "currency",
65
- currency: currencyCode || "TRY",
70
+ currency: currencySymbol || "TRY",
66
71
  }
67
72
  );
68
73
 
69
74
  return formatter.format(price);
70
75
  }
71
76
  };
72
-
73
- export function getCurrencySymbol(currencyCode: string) {
74
- return CURRENCIES[currencyCode] || currencyCode;
75
- }
76
-
77
- const CURRENCIES: Record<string, string> = {
78
- TRY: "₺",
79
- USD: "$",
80
- EUR: "€",
81
- AZN: "₼",
82
- AED: "د.إ.",
83
- AFN: "؋",
84
- ALL: "L",
85
- AMD: "դր",
86
- ANG: "ƒ",
87
- AOA: "Kz",
88
- ARS: "$",
89
- AUD: "$",
90
- AWG: "ƒ",
91
- BAM: "КМ",
92
- BBD: "$",
93
- BDT: "৳",
94
- BGN: "лв.",
95
- BHD: "د.ب.",
96
- BIF: "FBu",
97
- BMD: "$",
98
- BND: "$",
99
- BOB: "Bs.",
100
- BRL: "R$",
101
- BSD: "$",
102
- BTN: "Nu.",
103
- BWP: "P",
104
- BYN: "руб.",
105
- BZD: "$",
106
- CAD: "$",
107
- CDF: "₣",
108
- CHF: "₣",
109
- CKD: "$",
110
- CLP: "$",
111
- CNY: "¥元",
112
- COP: "$",
113
- CRC: "₡",
114
- CUC: "$",
115
- CUP: "₱",
116
- CVE: "$",
117
- CZK: "Kč",
118
- DJF: "ف.ج.",
119
- DKK: "kr.",
120
- DOP: "$",
121
- DZD: "د.ج.",
122
- EGP: "ج.م.",
123
- EHP: "Ptas.",
124
- ERN: "ناكفا",
125
- ETB: "ብር",
126
- FJD: "$",
127
- FKP: "£",
128
- FOK: "kr",
129
- GBP: "£",
130
- GEL: "₾",
131
- GGP: "£",
132
- GHS: "₵",
133
- GIP: "£",
134
- GMD: "D",
135
- GNF: "FG",
136
- GTQ: "$",
137
- GYD: "$",
138
- HKD: "$",
139
- HNL: "L",
140
- HRK: "kn",
141
- HTG: "G",
142
- HUF: "Ft",
143
- IDR: "Rp",
144
- ILS: "₪",
145
- IMP: "£",
146
- INR: "₹",
147
- IQD: "د.ع.",
148
- IRR: "﷼",
149
- ISK: "kr",
150
- JEP: "£",
151
- JMD: "$",
152
- JOD: "د.أ.",
153
- JPY: "¥",
154
- KES: "KSh",
155
- KGS: "с",
156
- KHR: "៛",
157
- KID: "$",
158
- KMF: "CF",
159
- KPW: "₩",
160
- KRW: "₩",
161
- KWD: "د.ك.",
162
- KYD: "$",
163
- KZT: "₸",
164
- LAK: "₭",
165
- LBP: "ل.ل.",
166
- LKR: "රු or ரூ",
167
- LRD: "$",
168
- LSL: "L",
169
- LYD: "ل.د.",
170
- MAD: "د.م.",
171
- MDL: "L",
172
- MGA: "Ar",
173
- MKD: "ден",
174
- MMK: "Ks",
175
- MNT: "₮",
176
- MOP: "MOP$",
177
- MRU: "أ.م.",
178
- MUR: "रु ",
179
- MVR: ".ރ",
180
- MWK: "MK",
181
- MXN: "$",
182
- MYR: "RM",
183
- MZN: "MT",
184
- NAD: "$",
185
- NGN: "₦",
186
- NIO: "C$",
187
- NOK: "kr",
188
- NPR: "रू",
189
- NZD: "$",
190
- OMR: "ر.ع.",
191
- PAB: "B/.",
192
- PEN: "S/.",
193
- PGK: "K",
194
- PHP: "₱",
195
- PKR: "Rs",
196
- PLN: "zł",
197
- PND: "$",
198
- PRB: "р.",
199
- PYG: "₲",
200
- QAR: "ر.ق.",
201
- RON: "L",
202
- RSD: "дин",
203
- RUB: "₽",
204
- RWF: "R₣",
205
- SAR: "ر.س.",
206
- SBD: "$",
207
- SCR: "Rs",
208
- SDG: "ج.س.",
209
- SEK: "kr",
210
- SGD: "$",
211
- SHP: "£",
212
- SLL: "Le",
213
- SLS: "Sl",
214
- SOS: "Ssh",
215
- SRD: "$",
216
- SSP: "SS£",
217
- STN: "Db",
218
- SVC: "₡",
219
- SYP: "ل.س.",
220
- SZL: "L",
221
- THB: "฿",
222
- TJS: "SM",
223
- TMT: "T",
224
- TND: "د.ت.",
225
- TOP: "PT",
226
- TTD: "$",
227
- TVD: "$",
228
- TWD: "圓",
229
- TZS: "TSh",
230
- UAH: "грн",
231
- UGX: "Sh",
232
- UYU: "$",
233
- UZS: "сум",
234
- VED: "Bs.",
235
- VES: "Bs.F",
236
- VND: "₫",
237
- VUV: "VT",
238
- WST: "ST",
239
- XAF: "Fr.",
240
- XCD: "$",
241
- XOF: "₣",
242
- XPF: "₣",
243
- YER: "ر.ي.",
244
- ZAR: "R",
245
- ZMW: "ZK",
246
- ZWB: "",
247
- ZWL: "$",
248
- Abkhazia: "",
249
- Artsakh: "դր.",
250
- };