Package not found. Please check the package name and try again.

@ikas/storefront 4.0.0-alpha.2 → 4.0.0-alpha.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.21",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "Umut Ozan Yıldırım",
6
6
  "license": "ISC",
@@ -20,21 +20,22 @@
20
20
  "@stripe/react-stripe-js": "^1.7.2",
21
21
  "@stripe/stripe-js": "^1.29.0",
22
22
  "query-string": "^6.13.8",
23
- "react-tooltip": "^4.2.21"
23
+ "react-tooltip": "^4.2.21",
24
+ "libphonenumber-js": "^1.10.6"
24
25
  },
25
26
  "devDependencies": {
26
- "@ikas/storefront-api": "^4.0.0-alpha.2",
27
- "@ikas/storefront-config": "^4.0.0-alpha.2",
28
- "@ikas/storefront-model-functions": "^4.0.0-alpha.2",
29
- "@ikas/storefront-models": "^4.0.0-alpha.2",
30
- "@ikas/storefront-providers": "^4.0.0-alpha.2",
27
+ "@ikas/storefront-api": "^4.0.0-alpha.21",
28
+ "@ikas/storefront-config": "^4.0.0-alpha.21",
29
+ "@ikas/storefront-model-functions": "^4.0.0-alpha.21",
30
+ "@ikas/storefront-models": "^4.0.0-alpha.21",
31
+ "@ikas/storefront-providers": "^4.0.0-alpha.21",
31
32
  "@rollup/plugin-commonjs": "^22.0.0",
32
33
  "@rollup/plugin-json": "^4.1.0",
33
34
  "@rollup/plugin-node-resolve": "^13.3.0",
34
35
  "@types/react-phone-number-input": "^3.0.10",
35
36
  "mobx": "^6.1.3",
36
37
  "mobx-react-lite": "^3.1.5",
37
- "next": "canary",
38
+ "next": "12.0.7",
38
39
  "prettier": "^2.2.1",
39
40
  "react": "17.0.2",
40
41
  "react-dom": "17.0.2",
@@ -51,14 +52,14 @@
51
52
  "html-react-parser": "^1.4.0"
52
53
  },
53
54
  "peerDependencies": {
54
- "@ikas/storefront-api": "^4.0.0-alpha.2",
55
- "@ikas/storefront-config": "^4.0.0-alpha.2",
56
- "@ikas/storefront-model-functions": "^4.0.0-alpha.2",
57
- "@ikas/storefront-models": "^4.0.0-alpha.2",
58
- "@ikas/storefront-providers": "^4.0.0-alpha.2",
55
+ "@ikas/storefront-api": "^4.0.0-alpha.21",
56
+ "@ikas/storefront-config": "^4.0.0-alpha.21",
57
+ "@ikas/storefront-model-functions": "^4.0.0-alpha.21",
58
+ "@ikas/storefront-models": "^4.0.0-alpha.21",
59
+ "@ikas/storefront-providers": "^4.0.0-alpha.21",
59
60
  "mobx": "^6.1.3",
60
61
  "mobx-react-lite": "^3.1.5",
61
- "next": "canary",
62
+ "next": "12.0.7",
62
63
  "react": "17.0.2",
63
64
  "react-dom": "17.0.2",
64
65
  "lodash": "^4.17.20",
@@ -54,6 +54,7 @@ export class Analytics {
54
54
  const customerInfo = await Analytics.getCustomerInfo();
55
55
 
56
56
  GoogleTagManager.pageView(url);
57
+ GoogleUniversal.pageView(window.location.pathname);
57
58
  IkasAnalytics.pageView(pageType);
58
59
 
59
60
  tryForEach(Analytics.subscribers, (s) => {
@@ -194,7 +195,7 @@ export class Analytics {
194
195
  try {
195
196
  localStorage.removeItem(LS_BEGIN_CHECKOUT_KEY);
196
197
 
197
- FacebookPixel.purchase(checkout, checkout.orderNumber || "");
198
+ FacebookPixel.purchase(checkout, transaction.id || "");
198
199
  GoogleTagManager.purchase(checkout, checkout.orderNumber || "");
199
200
  IkasAnalytics.orderSuccess(checkout);
200
201
  GoogleAnalytics.purchase(checkout, checkout.orderNumber || "");
@@ -8,12 +8,23 @@ export class GoogleUniversal {
8
8
  makeAutoObservable(this);
9
9
  }
10
10
 
11
+ static pageView(url: string) {
12
+ try {
13
+ if (!isServer && (window as any).ga) {
14
+ (window as any).ga("set", "page", url);
15
+ (window as any).ga("send", "pageview");
16
+ }
17
+ return;
18
+ } catch (err) {
19
+ console.error(err);
20
+ }
21
+ }
22
+
11
23
  static productView(productDetail: IkasProduct) {
12
24
  try {
13
25
  if (!isServer && (window as any).ga) {
14
26
  (window as any).ga("ec:addProduct", productToGUItem(productDetail));
15
27
  (window as any).ga("ec:setAction", "detail");
16
- (window as any).ga("send", "pageview");
17
28
  }
18
29
  return;
19
30
  } catch (err) {
@@ -79,7 +90,6 @@ export class GoogleUniversal {
79
90
  shipping: "" + checkout.shippingTotal,
80
91
  coupon: checkout.couponCode,
81
92
  });
82
- (window as any).ga("send", "pageview");
83
93
  }
84
94
  return;
85
95
  } catch (err) {
@@ -79,8 +79,7 @@ export const AnalyticsHead: React.FC<HeadProps> = observer(({ blockHTML }) => {
79
79
  dangerouslySetInnerHTML={{
80
80
  __html: `window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
81
81
  ga('create', '${universalAnalyticsId}', 'auto');
82
- ga('require', 'ec');
83
- ga('send', 'pageview');`,
82
+ ga('require', 'ec');`,
84
83
  }}
85
84
  />
86
85
  <script
@@ -181,6 +181,10 @@ export default class IkasAnalytics {
181
181
  } else {
182
182
  await this.createSessionId();
183
183
  }
184
+
185
+ IkasStorefrontConfig.init({
186
+ sessionId: this.sessionId || "",
187
+ });
184
188
  } catch (err) {
185
189
  console.error(err);
186
190
  }
@@ -196,6 +200,10 @@ export default class IkasAnalytics {
196
200
  this.visitorId = Date.now() + "";
197
201
  localStorage.setItem(this.VISITOR_ID_KEY, this.visitorId);
198
202
  }
203
+
204
+ IkasStorefrontConfig.init({
205
+ visitorId: this.visitorId,
206
+ });
199
207
  } catch (err) {
200
208
  console.error(err);
201
209
  }
@@ -315,7 +315,7 @@ const CityInput: React.FC<FormItemProps> = observer(({ vm }) => {
315
315
  return (
316
316
  <FormItem
317
317
  type={FormItemType.TEXT}
318
- autocomplete="address-level3"
318
+ autocomplete="address-level2"
319
319
  label={t("checkout-page:city")}
320
320
  value={vm.city?.name || ""}
321
321
  onChange={vm.onCityInputChange}
@@ -7,6 +7,7 @@ import styles from "./style.module.scss";
7
7
 
8
8
  import { useTranslation } from "../../../../utils";
9
9
  import ReactTooltip from "react-tooltip";
10
+ import { PhoneNumberInput } from "../phone-number-input";
10
11
 
11
12
  export const FormItem: React.FC<Props> = observer((props) => {
12
13
  const { t } = useTranslation();
@@ -108,17 +109,14 @@ export const FormItem: React.FC<Props> = observer((props) => {
108
109
  />
109
110
  )}
110
111
  {vm.type === FormItemType.TEL && (
111
- <div></div>
112
- // <PhoneInput
113
- // key={props.currentCountryCode || "1"}
114
- // disabled={vm.disabled}
115
- // defaultCountry={props.currentCountryCode}
116
- // placeholder={t("checkout-page:enterPhoneNumber")}
117
- // value={vm.value ? vm.value : ""}
118
- // onChange={vm.onPhoneChange}
119
- // international={true}
120
- // addInternationalOption={false}
121
- // />
112
+ <PhoneNumberInput
113
+ key={props.currentCountryCode || "1"}
114
+ disabled={vm.disabled}
115
+ defaultCountry={props.currentCountryCode}
116
+ placeholder={t("checkout-page:enterPhoneNumber")}
117
+ value={vm.value ? vm.value : ""}
118
+ onChange={vm.onPhoneChange}
119
+ />
122
120
  )}
123
121
  {vm.type === FormItemType.TEXT_AREA && <TextArea vm={vm} />}
124
122
  {vm.type === FormItemType.SELECT && (
@@ -0,0 +1,5 @@
1
+ const compareStrings = (a: string, b: string) => {
2
+ return a.localeCompare(b);
3
+ };
4
+
5
+ export default compareStrings;
@@ -0,0 +1,52 @@
1
+ import { IkasStorefrontConfig } from "@ikas/storefront-config";
2
+ import { CountryCode, getCountries as categories } from "libphonenumber-js";
3
+ import compareStrings from "./compare-strings";
4
+
5
+ export type CountryType = {
6
+ value: CountryCode;
7
+ label: string | undefined;
8
+ };
9
+
10
+ const getUrl = () => {
11
+ const languages = [
12
+ "de",
13
+ "el",
14
+ "en",
15
+ "es",
16
+ "fi",
17
+ "fr",
18
+ "it",
19
+ "nb",
20
+ "pl",
21
+ "pt-BR",
22
+ "pt",
23
+ "ru",
24
+ "sv",
25
+ "tr",
26
+ "ua",
27
+ "vi",
28
+ ];
29
+
30
+ let locale = IkasStorefrontConfig.getCurrentLocale();
31
+
32
+ if (!languages.some((language) => language === locale)) {
33
+ locale = "en";
34
+ }
35
+
36
+ return `https://cdn.myikas.com/sf/static/locale/country/${locale}.json`;
37
+ };
38
+
39
+ const getCountries = async (): Promise<CountryType[]> => {
40
+ const url = getUrl();
41
+ const response = await fetch(url);
42
+ const lang = await response.json();
43
+
44
+ return categories()
45
+ .map((country) => ({
46
+ value: country,
47
+ label: lang[country],
48
+ }))
49
+ .sort((a, b) => compareStrings(a.label, b.label));
50
+ };
51
+
52
+ export default getCountries;
@@ -0,0 +1,125 @@
1
+ import * as React from "react";
2
+ import { observer } from "mobx-react-lite";
3
+ import parsePhoneNumber, {
4
+ CountryCode,
5
+ formatIncompletePhoneNumber,
6
+ getCountryCallingCode,
7
+ parseIncompletePhoneNumber,
8
+ } from "libphonenumber-js";
9
+ import getCountries, { CountryType } from "./get-countries";
10
+
11
+ import styles from "./style.module.scss";
12
+
13
+ type Props = {
14
+ defaultCountry?: string | null;
15
+ disabled?: boolean;
16
+ placeholder: string | undefined;
17
+ value: string;
18
+ onChange: (value: string) => void;
19
+ };
20
+
21
+ const DEFAULT_COUNTRY = "TR";
22
+
23
+ export const PhoneNumberInput: React.FC<Props> = observer(
24
+ ({ defaultCountry, disabled = false, placeholder, value, onChange }) => {
25
+ const [countries, setCountries] = React.useState<CountryType[]>([]);
26
+ const [activeCountry, setActiveCountry] = React.useState(
27
+ (defaultCountry as CountryCode) || DEFAULT_COUNTRY
28
+ );
29
+ const [formatedValue, setFormatedValue] = React.useState("");
30
+
31
+ React.useEffect(() => {
32
+ fetchCountries();
33
+
34
+ let countryCode = activeCountry;
35
+
36
+ if (value) {
37
+ const parsedPhoneNumber = parsePhoneNumber(value);
38
+
39
+ if (parsedPhoneNumber && parsedPhoneNumber.country) {
40
+ countryCode = parsedPhoneNumber.country;
41
+ }
42
+
43
+ setFormatedValue(formatIncompletePhoneNumber(value, countryCode));
44
+ } else {
45
+ setDefaultValue(countryCode);
46
+ }
47
+
48
+ setActiveCountry(countryCode);
49
+ }, []);
50
+
51
+ const fetchCountries = async () => {
52
+ const categories = await getCountries();
53
+ setCountries(categories);
54
+ };
55
+
56
+ const onValueChange = (event: React.ChangeEvent<HTMLInputElement>) => {
57
+ const phoneNumber = formatPhoneNumber(event.target.value);
58
+ setFormatedValue(phoneNumber);
59
+ onChange(
60
+ !phoneNumber
61
+ ? event.target.value
62
+ : parseIncompletePhoneNumber(phoneNumber)
63
+ );
64
+ };
65
+
66
+ const onCountryChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
67
+ if (event.target.value) {
68
+ const country = event.target.value as CountryCode;
69
+
70
+ setActiveCountry(country);
71
+ setDefaultValue(country);
72
+ }
73
+ };
74
+
75
+ const setDefaultValue = (countyCode: CountryCode) => {
76
+ const countryCallingCode = getCountryCallingCode(countyCode);
77
+
78
+ setFormatedValue(`+${countryCallingCode}`);
79
+ };
80
+
81
+ const formatPhoneNumber = (phoneNumber: string) => {
82
+ return formatIncompletePhoneNumber(phoneNumber, activeCountry);
83
+ };
84
+
85
+ const getImageSrc = () => {
86
+ return `https://cdn.myikas.com/sf/assets/flags/3x2/${activeCountry}.svg`;
87
+ };
88
+
89
+ return (
90
+ <React.Fragment>
91
+ <div className={styles.SelectFlag}>
92
+ <div className={styles.FlagContainer}>
93
+ <div className={styles.Flag}>
94
+ <img
95
+ className={styles.FlagImage}
96
+ alt={activeCountry}
97
+ src={getImageSrc()}
98
+ ></img>
99
+ <div className={styles.Arrow}></div>
100
+ </div>
101
+ <select
102
+ className={styles.Select}
103
+ value={activeCountry}
104
+ onChange={onCountryChange}
105
+ disabled={disabled}
106
+ >
107
+ {countries.map((country) => (
108
+ <option key={country.value} value={country.value}>
109
+ {country.label}
110
+ </option>
111
+ ))}
112
+ </select>
113
+ </div>
114
+ </div>
115
+ <input
116
+ className={styles.Input}
117
+ value={formatedValue}
118
+ onChange={onValueChange}
119
+ placeholder={placeholder}
120
+ disabled={disabled}
121
+ ></input>
122
+ </React.Fragment>
123
+ );
124
+ }
125
+ );
@@ -0,0 +1,83 @@
1
+ .SelectFlag {
2
+ position: absolute;
3
+ top: 26px;
4
+ left: 16px;
5
+
6
+ .FlagContainer {
7
+ position: relative;
8
+ width: 35px;
9
+ height: 24px;
10
+
11
+ flex: 0 0 35px;
12
+
13
+ .Select {
14
+ position: absolute;
15
+ top: 0;
16
+ left: 0;
17
+ z-index: 1;
18
+ padding: 0;
19
+ opacity: 0;
20
+ border: 0;
21
+ width: 100%;
22
+ height: 100%;
23
+ cursor: pointer;
24
+ }
25
+ }
26
+
27
+ .Flag {
28
+ position: relative;
29
+ width: 35px;
30
+ height: 24px;
31
+
32
+ display: flex;
33
+ align-items: center;
34
+
35
+ &Image {
36
+ width: 24px;
37
+ flex: 0 0 24px;
38
+ }
39
+
40
+ .Arrow {
41
+ display: block;
42
+ content: "";
43
+ width: 0.3em;
44
+ height: 0.3em;
45
+ margin-left: 0.35em;
46
+ margin-top: -0.2em;
47
+ border-style: solid;
48
+ border-color: inherit;
49
+ border-top-width: 0;
50
+ border-bottom-width: 1px;
51
+ border-left-width: 0;
52
+ border-right-width: 1px;
53
+ transform: rotate(45deg);
54
+ opacity: 0.45;
55
+
56
+ flex: 0 0 0.3em;
57
+ }
58
+ }
59
+ }
60
+
61
+ .Input {
62
+ padding-left: 64px !important;
63
+
64
+ &:disabled {
65
+ color: #8A8B94 !important;
66
+ background-color: #F7F7F9 !important;
67
+ }
68
+
69
+ &::placeholder {
70
+ color: #8A8B94 !important;
71
+ font-size: 14px !important;
72
+ }
73
+
74
+ // &:disabled {
75
+ // color: $buttonDisabledTextColor !important;
76
+ // background-color: $buttonDisabledBgColor !important;
77
+ // }
78
+
79
+ // &::placeholder {
80
+ // color: $secondaryTextColor !important;
81
+ // font-size: 14px !important;
82
+ // }
83
+ }
@@ -32,7 +32,6 @@ import CreditCardData from "./components/credit-card-form/model";
32
32
  import { IkasCheckoutSettings } from "../../models/data/checkout-settings";
33
33
  import { TFunction } from "../../utils/i18n";
34
34
  import CustomerStoreAPI from "../../store/customer/api";
35
- import MerchantStore from "../../store/merchant";
36
35
  import CheckoutStore from "../../store/checkout";
37
36
  import CartStoreAPI from "../../store/cart/api";
38
37
  import { IkasCheckoutCustomizationProps } from ".";
@@ -45,7 +44,7 @@ import {
45
44
  RetrieveInstallmentInfoResponse,
46
45
  TransactionResponse,
47
46
  UpdateCartCampaignOfferInput,
48
- } from "@ikas/storefront-api/build/__api/types";
47
+ } from "@ikas/storefront-api";
49
48
  import { IkasBaseStore } from "../../store";
50
49
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
51
50
  import { Analytics } from "../../analytics";
@@ -54,11 +53,6 @@ import {
54
53
  RetrieveInstallmentInfoQueryParams,
55
54
  SaveCartInput,
56
55
  } from "@ikas/storefront-api";
57
- import { OrderAddressCountryInputData } from "@ikas/storefront-api/build/__api/models/OrderAddressCountryInput";
58
- import { OrderAddressCityInputData } from "@ikas/storefront-api/build/__api/models/OrderAddressCityInput";
59
- import { OrderAddressStateInputData } from "@ikas/storefront-api/build/__api/models/OrderAddressStateInput";
60
- import { OrderAddressDistrictInputData } from "@ikas/storefront-api/build/__api/models/OrderAddressDistrictInput";
61
- import { CampaignOfferTargetPageTypeEnum } from "@ikas/storefront-api/build/__api/types";
62
56
 
63
57
  const NUMBER_ONLY_REGEX = /^\d+$/;
64
58
  const MAX_CARD_NUMBER_LENGTH = 16;
@@ -446,7 +440,10 @@ export default class CheckoutViewModel {
446
440
  input = await this.inStockDeliveryInputData(input);
447
441
  }
448
442
 
449
- if (this.step === CheckoutStep.INFO) {
443
+ if (
444
+ this.step === CheckoutStep.INFO ||
445
+ this.step === CheckoutStep.SHIPPING
446
+ ) {
450
447
  input.billingAddress = null;
451
448
  }
452
449
 
@@ -482,13 +479,11 @@ export default class CheckoutViewModel {
482
479
  inStoreLocation.address
483
480
  ) {
484
481
  inputData.shippingAddress.country = inStoreLocation.address
485
- .country as OrderAddressCountryInputData;
486
- inputData.shippingAddress.city = inStoreLocation.address
487
- .city as OrderAddressCityInputData;
488
- inputData.shippingAddress.state = inStoreLocation.address
489
- .state as OrderAddressStateInputData;
482
+ .country as any;
483
+ inputData.shippingAddress.city = inStoreLocation.address.city as any;
484
+ inputData.shippingAddress.state = inStoreLocation.address.state as any;
490
485
  inputData.shippingAddress.district = inStoreLocation.address
491
- .district as OrderAddressDistrictInputData;
486
+ .district as any;
492
487
  inputData.shippingAddress.postalCode = inStoreLocation.address.postalCode;
493
488
  inputData.shippingAddress.addressLine1 =
494
489
  inStoreLocation.address.address || "";
@@ -5,8 +5,8 @@ import { SuccessModalType } from "./components/master-pass/modal-success";
5
5
  import { useTranslation } from "../../utils/i18n";
6
6
  import { IkasBaseStore } from "../../store";
7
7
  import { IkasCheckout, IkasPaymentGateway } from "../../models";
8
- import { MasterPassOperationTypeEnum } from "@ikas/storefront-api/build/__api/types";
9
- import { getMasterpassRequestToken } from "@ikas/storefront-api";
8
+ import { MasterPassOperationTypeEnum } from "@ikas/storefront-api";
9
+ import { getMasterPassRequestToken } from "@ikas/storefront-api";
10
10
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
11
11
 
12
12
  const isServer = typeof localStorage === "undefined";
@@ -437,7 +437,7 @@ export default class MasterPassModel {
437
437
  operationType: MasterPassOperationTypeEnum;
438
438
  phoneNumber: string;
439
439
  }) => {
440
- const response = await getMasterpassRequestToken({
440
+ const response = await getMasterPassRequestToken({
441
441
  cartId,
442
442
  paymentGatewayId,
443
443
  operationType,
@@ -251,6 +251,18 @@ function createStoreSchema(merchantSettings: IkasMerchantSettings) {
251
251
  logo: logo,
252
252
  image: logo,
253
253
  url: "https://" + IkasStorefrontConfig.getDomain(),
254
+ telephone: merchantSettings?.phone,
255
+ address: {
256
+ "@type": "PostalAddress",
257
+ streetAddress: merchantSettings.address?.addressLine1,
258
+ addressLocality: merchantSettings.address?.city?.name,
259
+ ...(merchantSettings.address &&
260
+ merchantSettings.address.state && {
261
+ addressRegion: merchantSettings.address.state.code,
262
+ }),
263
+ postalCode: merchantSettings.address?.postalCode,
264
+ addressCountry: merchantSettings.address?.country?.code,
265
+ },
254
266
  };
255
267
  }
256
268
 
@@ -23,6 +23,7 @@ import HtmlMetaDataStore from "../../store/html-meta-data";
23
23
  import BlogStore from "../../store/blog";
24
24
  import RaffleStore from "../../store/raffle";
25
25
  import ProductStore from "../../store/product";
26
+ import { IkasAPIClientConfig } from "@ikas/storefront-api";
26
27
 
27
28
  const PACKAGE_VERSION = "2.0.20";
28
29
  // import { version as PACKAGE_VERSION } from "../../../package.json";
@@ -535,6 +536,8 @@ export default class IkasPageEditorViewModel {
535
536
 
536
537
  // Message Handlers
537
538
 
539
+ static setAPIClientConfig() {}
540
+
538
541
  handleUpdateFrameData = async (data: any) => {
539
542
  this.theme = new IkasThemeJson(data.theme);
540
543
  this.page = this.theme?.pages.find((p) => p.id === data.selectedPage.id);
@@ -565,7 +568,22 @@ export default class IkasPageEditorViewModel {
565
568
  translations: this.translations || {},
566
569
  isEditor: true,
567
570
  apiKey: data.apiKey,
571
+ apiUrl: data.apiUrl,
572
+ adminApiUrl: data.adminApiUrl,
573
+ cdnUrl: data.cdnUrl,
568
574
  });
575
+
576
+ IkasAPIClientConfig.URL = IkasStorefrontConfig.getApiUrl() || "";
577
+ IkasAPIClientConfig.HEADERS = {
578
+ "x-api-key": IkasStorefrontConfig.getApiKey() || "",
579
+ "x-sfid": IkasStorefrontConfig.getStorefrontId() || "",
580
+ "x-sfrid": IkasStorefrontConfig.getStorefrontRoutingId() || "",
581
+ };
582
+
583
+ if (IkasStorefrontConfig.getCustomerToken()) {
584
+ IkasAPIClientConfig.TOKEN =
585
+ IkasStorefrontConfig.getCustomerToken() || "";
586
+ }
569
587
  }
570
588
 
571
589
  // (window as any).editorApiKey = data.apiKey;
@@ -1,15 +1,18 @@
1
1
  import {
2
2
  IkasMerchantSettingsCurrencyFormat,
3
3
  IkasMerchantSettings as IMerchantSettings,
4
+ IkasMerchantAddress,
4
5
  } from "@ikas/storefront-models";
5
6
  import { makeAutoObservable } from "mobx";
6
7
  import { IkasImage } from "../image";
7
8
 
8
9
  export class IkasMerchantSettings implements IMerchantSettings {
9
10
  currencyFormats: IkasMerchantSettingsCurrencyFormat[] | null;
11
+ address: IkasMerchantAddress | null;
10
12
  logoId: string | null;
11
13
  merchantId: string;
12
14
  merchantName: string;
15
+ phone: string | null;
13
16
 
14
17
  // Extra
15
18
  logo?: IkasImage | null;
@@ -19,6 +22,9 @@ export class IkasMerchantSettings implements IMerchantSettings {
19
22
  this.logoId = data.logoId;
20
23
  this.merchantId = data.merchantId;
21
24
  this.merchantName = data.merchantName;
25
+ this.phone = data.phone || null;
26
+ this.address = data.address || null;
27
+
22
28
  this.logo = data.logo ? new IkasImage(data.logo) : null;
23
29
 
24
30
  makeAutoObservable(this);
@@ -3,10 +3,12 @@ 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;
6
7
  variantType: IkasVariantType;
7
8
  variantValueIds: string[];
8
9
 
9
10
  constructor(data: Partial<IkasProductVariantType>) {
11
+ this.order = data.order || 0;
10
12
  this.variantType = data.variantType
11
13
  ? new IkasVariantType(data.variantType)
12
14
  : new IkasVariantType();
@@ -20,6 +20,7 @@ export class IkasStorefront implements IStorefront {
20
20
  analytics4Id: string | null;
21
21
  universalAnalyticsId: string | null;
22
22
  tiktokPixelId: string | null;
23
+ token: string | null;
23
24
 
24
25
  localizations: IkasStorefrontLocalization[];
25
26
  routings: IkasStorefrontRouting[];
@@ -40,6 +41,7 @@ export class IkasStorefront implements IStorefront {
40
41
  this.analytics4Id = data.analytics4Id || null;
41
42
  this.universalAnalyticsId = data.universalAnalyticsId || null;
42
43
  this.tiktokPixelId = data.tiktokPixelId || null;
44
+ this.token = data.token || null;
43
45
 
44
46
  // Sub Models
45
47
  this.localizations = data.localizations
@@ -25,7 +25,7 @@ import {
25
25
  SearchInputOrderByInput,
26
26
  SortByDirectionEnum,
27
27
  SortByTypeEnum,
28
- } from "@ikas/storefront-api/build/__api/types";
28
+ } from "@ikas/storefront-api";
29
29
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
30
30
  import { IkasBaseStore } from "../../..";
31
31
  import { Analytics } from "../../../analytics";
@@ -221,12 +221,6 @@ export class IkasProductList {
221
221
 
222
222
  get filterQueryParams() {
223
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
- }
230
224
 
231
225
  this.filters?.forEach((f) => {
232
226
  if (f.keyList.length) queryParams[f.key] = f.keyList;
@@ -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;
@@ -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() {
@@ -10,7 +10,7 @@ import {
10
10
  } from "../../models/data";
11
11
  import { IkasStorefrontConfig } from "@ikas/storefront-config";
12
12
  import { Analytics } from "../../analytics";
13
- import { CartLineOptionInput } from "@ikas/storefront-api/build/__api/types";
13
+ import { CartLineOptionInput } from "@ikas/storefront-api";
14
14
 
15
15
  export const CART_LS_KEY = "cartId";
16
16
 
@@ -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;