@ikas/storefront 4.0.0-alpha.39 → 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 (62) 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 +9 -10
  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 +32 -51
  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 +3 -21
  43. package/src/models/data/product/option-set/index.ts +0 -4
  44. package/src/models/data/product/option-set/option/index.ts +10 -33
  45. package/src/models/data/product/variant/index.ts +1 -23
  46. package/src/models/data/product/variant/price/index.ts +9 -23
  47. package/src/models/data/product/variant-type/index.ts +0 -2
  48. package/src/models/data/raffle/index.ts +7 -9
  49. package/src/models/data/state/index.ts +2 -6
  50. package/src/models/data/storefront/index.ts +0 -2
  51. package/src/models/ui/product-list/index.ts +17 -26
  52. package/src/models/ui/raffle-list/index.ts +1 -1
  53. package/src/models/ui/validator/form/raffle-form.ts +3 -16
  54. package/src/models/ui/validator/rules/index.ts +13 -14
  55. package/src/page-data-init/index.ts +404 -159
  56. package/src/pages/checkout.tsx +1 -2
  57. package/src/pages/editor.tsx +2 -5
  58. package/src/store/cart/index.ts +2 -2
  59. package/src/store/customer/index.ts +17 -7
  60. package/src/store/raffle/index.ts +10 -7
  61. package/src/utils/constants.ts +1 -1
  62. package/src/utils/currency.ts +183 -9
@@ -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, setAPIClientConfig } from "@ikas/storefront-api";
12
+ import { getCartById } 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,7 +35,6 @@ const CheckoutPage: React.FC<Props> = ({
35
35
  const [checkout, setCheckout] = React.useState<IkasCheckout | undefined>();
36
36
 
37
37
  IkasStorefrontConfig.init(configJson);
38
- setAPIClientConfig();
39
38
 
40
39
  React.useEffect(() => {
41
40
  setCustomizationProps(customizationProps);
@@ -8,7 +8,7 @@ const IkasPageEditor = dynamic(
8
8
  );
9
9
 
10
10
  type Props = {
11
- configJson?: Record<string, any>; // local only
11
+ configJson: Record<string, any>;
12
12
  components?: Record<string, any>;
13
13
  };
14
14
 
@@ -19,12 +19,9 @@ export default class Page extends React.Component<Props> {
19
19
  if (configJson) {
20
20
  IkasStorefrontConfig.init({
21
21
  ...configJson,
22
+ currentPageComponents: components || {},
22
23
  });
23
24
  }
24
-
25
- IkasStorefrontConfig.init({
26
- currentPageComponents: components || {},
27
- });
28
25
  }
29
26
 
30
27
  render() {
@@ -100,7 +100,7 @@ export class IkasCartStore {
100
100
 
101
101
  product.productOptionSet?.initOptionValues();
102
102
 
103
- return response;
103
+ return true;
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 response;
148
+ return true;
149
149
  } catch (err) {
150
150
  console.log(err);
151
151
  return false;
@@ -24,7 +24,6 @@ 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";
28
27
 
29
28
  const isServer = typeof localStorage === "undefined";
30
29
  const LS_TOKEN_KEY = "customerToken";
@@ -294,7 +293,7 @@ export class IkasCustomerStore {
294
293
  const favoriteProductsResponse =
295
294
  await CustomerStoreAPI.listFavoriteProducts();
296
295
  if (
297
- !favoriteProductsResponse.isSuccess ||
296
+ favoriteProductsResponse.isSuccess ||
298
297
  !favoriteProductsResponse.data?.length
299
298
  )
300
299
  return [];
@@ -404,11 +403,22 @@ export class IkasCustomerStore {
404
403
  };
405
404
 
406
405
  getRaffles = async () => {
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);
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);
412
422
  return raffles || [];
413
423
  };
414
424
 
@@ -1,10 +1,11 @@
1
1
  import { APIResponse } from "@ikas/fe-api-client";
2
2
  import {
3
- listRaffleParticipants,
4
- listStorefrontRaffle,
3
+ getRafflesByCustomerId,
4
+ GetRafflesByCustomerIdQueryParams,
5
+ listRaffle,
5
6
  listRaffleMetaData,
6
7
  ListRaffleMetadataQueryParams,
7
- ListStorefrontRaffleParams,
8
+ ListRaffleQueryParams,
8
9
  saveRaffleParticipant,
9
10
  SaveRaffleParticipantQueryParams,
10
11
  } from "@ikas/storefront-api";
@@ -15,8 +16,8 @@ import {
15
16
  } from "../../models/data/raffle";
16
17
 
17
18
  export default class RaffleStore {
18
- static async listStorefrontRaffle(params: ListStorefrontRaffleParams) {
19
- const response = await listStorefrontRaffle(params);
19
+ static async listRaffle(params: ListRaffleQueryParams) {
20
+ const response = await listRaffle(params);
20
21
  return new APIResponse({
21
22
  ...response.data,
22
23
  data: response.data?.data?.map(
@@ -45,8 +46,10 @@ export default class RaffleStore {
45
46
  );
46
47
  }
47
48
 
48
- static async listRaffleParticipants() {
49
- const response = await listRaffleParticipants();
49
+ static async getRafflesByCustomerId(
50
+ params: GetRafflesByCustomerIdQueryParams
51
+ ) {
52
+ const response = await getRafflesByCustomerId(params);
50
53
  return new APIResponse(
51
54
  response.data?.map((d) => new IkasRaffle(d as unknown as IkasRaffle)),
52
55
  response.graphQLErrors
@@ -1,2 +1,2 @@
1
- export const FREE_TEXT_CITY_COUNTRY_LIST = ["DE", "US", "AT"];
1
+ export const FREE_TEXT_CITY_COUNTRY_LIST = ["DE", "US"];
2
2
  export const DISTRICT_HIDDEN_COUNTRY_LIST = ["US"];
@@ -13,19 +13,14 @@ 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 Currency code
17
- * @param currencySymbol Symbol for the currency
16
+ * @param currencyCode Code for the currency, USD, EUR, TRY, etc..
18
17
  */
19
- export const formatCurrency = (
20
- price: number,
21
- currencyCode: string,
22
- currencySymbol: string | null
23
- ) => {
18
+ export const formatMoney = (price: number, currencyCode: string) => {
24
19
  const formatSettings =
25
20
  IkasStorefrontConfig.getMerchantSettings()?.currencyFormats?.find(
26
21
  (s) => s.currencyCode === currencyCode
27
22
  );
28
- const symbol = formatSettings?.symbol || currencySymbol || "";
23
+ const symbol = formatSettings?.symbol || getCurrencySymbol(currencyCode);
29
24
  const decimalSeparator = formatSettings?.decimalSeparator || ".";
30
25
  const thousandSeparator = formatSettings?.thousandSeparator || ",";
31
26
  const symbolPosition = formatSettings?.symbolPosition || "LEFT";
@@ -67,10 +62,189 @@ export const formatCurrency = (
67
62
  IkasStorefrontConfig.getCurrentLocale(),
68
63
  {
69
64
  style: "currency",
70
- currency: currencySymbol || "TRY",
65
+ currency: currencyCode || "TRY",
71
66
  }
72
67
  );
73
68
 
74
69
  return formatter.format(price);
75
70
  }
76
71
  };
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
+ };