@ikas/storefront 4.2.0-beta.10 → 4.2.0-beta.12

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.
@@ -1,6 +1,6 @@
1
1
  import { IkasCustomerAddress } from ".";
2
2
  import { IkasCustomerAddress as ICustomerAddress } from "@ikas/storefront-models";
3
- import CountrySettingsModel from "../../checkout/country-settings-model";
3
+ import CountrySettingsModel, { AddressFormField, ErrorType } from "../../checkout/country-settings-model";
4
4
  declare type IkasLocalizeCustomerAddressConstructorData = {
5
5
  countrySettings?: CountrySettingsModel | null;
6
6
  } & ICustomerAddress;
@@ -8,37 +8,39 @@ export declare class IkasLocalizeCustomerAddress extends IkasCustomerAddress {
8
8
  countrySettings: CountrySettingsModel | null;
9
9
  constructor(data?: Partial<IkasLocalizeCustomerAddressConstructorData>);
10
10
  get fieldSettings(): {
11
- firstName: import("../../checkout/country-settings-model").AddressFormField;
12
- lastName: import("../../checkout/country-settings-model").AddressFormField;
13
- identityNumber: import("../../checkout/country-settings-model").AddressFormField;
14
- phone: import("../../checkout/country-settings-model").AddressFormField;
15
- addressLine1: import("../../checkout/country-settings-model").AddressFormField;
16
- addressLine2: import("../../checkout/country-settings-model").AddressFormField;
17
- postalCode: import("../../checkout/country-settings-model").AddressFormField;
18
- country: import("../../checkout/country-settings-model").AddressFormField;
19
- state: import("../../checkout/country-settings-model").AddressFormField;
20
- city: import("../../checkout/country-settings-model").AddressFormField;
21
- district: import("../../checkout/country-settings-model").AddressFormField;
22
- company?: import("../../checkout/country-settings-model").AddressFormField | undefined;
23
- taxOffice?: import("../../checkout/country-settings-model").AddressFormField | undefined;
24
- taxNumber?: import("../../checkout/country-settings-model").AddressFormField | undefined;
11
+ firstName: AddressFormField;
12
+ lastName: AddressFormField;
13
+ identityNumber: AddressFormField;
14
+ phone: AddressFormField;
15
+ addressLine1: AddressFormField;
16
+ addressLine2: AddressFormField;
17
+ postalCode: AddressFormField;
18
+ country: AddressFormField;
19
+ state: AddressFormField;
20
+ city: AddressFormField;
21
+ district: AddressFormField;
22
+ company?: AddressFormField | undefined;
23
+ taxOffice?: AddressFormField | undefined;
24
+ taxNumber?: AddressFormField | undefined;
25
+ title: AddressFormField;
25
26
  } | undefined;
26
27
  get addressFormat(): import("../../checkout/country-settings-model").AddressFormItem[][] | undefined;
27
28
  get addressFormatIgnoreCountry(): import("../../checkout/country-settings-model").AddressFormItem[][] | undefined;
28
29
  get billingFormat(): import("../../checkout/country-settings-model").AddressFormItem[][] | undefined;
29
30
  get countryCode(): string;
30
31
  get validationResults(): {
31
- firstName: import("../../checkout/country-settings-model").ErrorType;
32
- lastName: import("../../checkout/country-settings-model").ErrorType;
33
- addressLine1: import("../../checkout/country-settings-model").ErrorType;
34
- addressLine2: import("../../checkout/country-settings-model").ErrorType;
35
- country: import("../../checkout/country-settings-model").ErrorType;
36
- state: import("../../checkout/country-settings-model").ErrorType;
37
- city: import("../../checkout/country-settings-model").ErrorType;
38
- district: import("../../checkout/country-settings-model").ErrorType;
39
- phone: import("../../checkout/country-settings-model").ErrorType;
40
- postalCode: import("../../checkout/country-settings-model").ErrorType;
41
- identityNumber: import("../../checkout/country-settings-model").ErrorType;
32
+ firstName: ErrorType;
33
+ lastName: ErrorType;
34
+ addressLine1: ErrorType;
35
+ addressLine2: ErrorType;
36
+ country: ErrorType;
37
+ state: ErrorType;
38
+ city: ErrorType;
39
+ district: ErrorType;
40
+ phone: ErrorType;
41
+ postalCode: ErrorType;
42
+ identityNumber: ErrorType;
43
+ title: ErrorType;
42
44
  } | undefined;
43
45
  get isValidAddress(): boolean | undefined;
44
46
  get fieldLabels(): {
@@ -1 +1 @@
1
- import{__extends as t}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as e,observable as r}from"mobx";import{IkasCustomerAddress as n}from"./index.js";var i=function(n){function i(t){void 0===t&&(t={});var i=n.call(this,t)||this;return i.countrySettings=t.countrySettings||null,e(i,{countrySettings:r}),i}return t(i,n),Object.defineProperty(i.prototype,"fieldSettings",{get:function(){if(this.countrySettings)return this.countrySettings.getFieldSettings(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"addressFormat",{get:function(){if(this.countrySettings)return this.countrySettings.getAddressFormat(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"addressFormatIgnoreCountry",{get:function(){if(this.countrySettings)return this.countrySettings.getAddressFormatIgnoreCountry(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"billingFormat",{get:function(){if(this.countrySettings)return this.countrySettings.getBillingFormat(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"countryCode",{get:function(){var t;return(null===(t=this.country)||void 0===t?void 0:t.iso2)||"TR"},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"validationResults",{get:function(){if(this.countrySettings)return this.countrySettings.getValidationResult(this)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isValidAddress",{get:function(){if(this.countrySettings)return this.countrySettings.isValidAddress(this)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"fieldLabels",{get:function(){if(this.countrySettings)return this.countrySettings.getFieldLabels(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isFreeTextCity",{get:function(){if(this.countrySettings)return this.countrySettings.isFreeTextCity(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isFreeTextDistrict",{get:function(){if(this.countrySettings)return this.countrySettings.isFreeTextDistrict(this.countryCode)},enumerable:!1,configurable:!0}),i}(n);export{i as IkasLocalizeCustomerAddress};
1
+ import{__extends as t,__assign as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as i,observable as r}from"mobx";import{IkasCustomerAddress as n}from"./index.js";var o=function(n){function o(t){void 0===t&&(t={});var e=n.call(this,t)||this;return e.countrySettings=t.countrySettings||null,i(e,{countrySettings:r}),e}return t(o,n),Object.defineProperty(o.prototype,"fieldSettings",{get:function(){if(this.countrySettings){var t=this.countrySettings.getFieldSettings(this.countryCode);if(t)return e({title:{required:!0}},t)}},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"addressFormat",{get:function(){if(this.countrySettings)return this.countrySettings.getAddressFormat(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"addressFormatIgnoreCountry",{get:function(){if(this.countrySettings)return this.countrySettings.getAddressFormatIgnoreCountry(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"billingFormat",{get:function(){if(this.countrySettings)return this.countrySettings.getBillingFormat(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"countryCode",{get:function(){var t;return(null===(t=this.country)||void 0===t?void 0:t.iso2)||"TR"},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"validationResults",{get:function(){if(this.countrySettings){var t=this.countrySettings.getValidationResult(this);if(t)return e({title:{hasError:!this.title,isInvalid:!1,isEmpty:!this.title}},t)}},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isValidAddress",{get:function(){if(this.countrySettings)return!!this.title&&this.countrySettings.isValidAddress(this)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"fieldLabels",{get:function(){if(this.countrySettings)return this.countrySettings.getFieldLabels(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isFreeTextCity",{get:function(){if(this.countrySettings)return this.countrySettings.isFreeTextCity(this.countryCode)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isFreeTextDistrict",{get:function(){if(this.countrySettings)return this.countrySettings.isFreeTextDistrict(this.countryCode)},enumerable:!1,configurable:!0}),o}(n);export{o as IkasLocalizeCustomerAddress};
@@ -2,6 +2,7 @@ import { IkasCity, IkasCountry, IkasDistrict, IkasLocalizeCustomerAddress, IkasS
2
2
  import { AddressFormItem } from "../../../data/checkout/country-settings-model";
3
3
  declare type IkasAddressFormPropsValidatorMessage<T> = {
4
4
  requiredRule: ((model: T) => string) | string;
5
+ invalidRule: ((model: T) => string) | string;
5
6
  phoneRule?: ((model: T) => string) | string;
6
7
  };
7
8
  declare type IkasAddressFormProps<T> = {
@@ -26,6 +27,7 @@ export declare class IkasAddressForm {
26
27
  onTitleChange: (value: string) => void;
27
28
  onFirstNameChange: (value: string) => void;
28
29
  onLastNameChange: (value: string) => void;
30
+ onIdentityNumberChange: (value: string) => void;
29
31
  onPhoneChange: (value: string) => void;
30
32
  onAddressLine1Change: (value: string) => void;
31
33
  onAddressLine2Change: (value: string) => void;
@@ -40,8 +42,8 @@ export declare class IkasAddressForm {
40
42
  listStates: () => Promise<void>;
41
43
  listCities: () => Promise<void>;
42
44
  listDistricts: () => Promise<void>;
43
- get isFreeTextCity(): boolean;
44
- get isFreeTextDistrict(): boolean;
45
+ get isFreeTextCity(): boolean | undefined;
46
+ get isFreeTextDistrict(): boolean | undefined;
45
47
  get isEdit(): boolean;
46
48
  private get editingAddressIndex();
47
49
  get countryOptions(): {
@@ -80,6 +82,7 @@ export declare class IkasAddressForm {
80
82
  company?: import("../../../data").AddressFormField | undefined;
81
83
  taxOffice?: import("../../../data").AddressFormField | undefined;
82
84
  taxNumber?: import("../../../data").AddressFormField | undefined;
85
+ title: import("../../../data").AddressFormField;
83
86
  } | undefined;
84
87
  get addressFormat(): AddressFormItem[][] | undefined;
85
88
  get validationResult(): {
@@ -127,6 +130,10 @@ export declare class IkasAddressForm {
127
130
  hasError: boolean;
128
131
  message: string | ((model: IkasLocalizeCustomerAddress) => string) | undefined;
129
132
  };
133
+ title: {
134
+ hasError: boolean;
135
+ message: string | ((model: IkasLocalizeCustomerAddress) => string) | undefined;
136
+ };
130
137
  } | undefined;
131
138
  submit: () => Promise<{
132
139
  isFormError: boolean;
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as i,observable as s,computed as n,action as r}from"mobx";import d from"lodash/cloneDeep";import{listCheckoutSettings as a,listCountry as o,listState as u,listCity as c,listDistrict as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as h}from"@ikas/storefront-config";import{FREE_TEXT_CITY_COUNTRY_LIST as m}from"../../../../utils/constants.js";import{IkasBaseStore as p}from"../../../../store/base.js";import"../../../../store/customer/index.js";import"../../../../store/cart/index.js";import"../../../data/blog/category/index.js";import"../../../data/blog/content/index.js";import"../../../data/blog/meta-data/index.js";import"../../../data/blog/tag/index.js";import"../../../data/blog/index.js";import"../../../data/brand/index.js";import"@ikas/storefront-models";import"../../../data/campaign-offer/index.js";import"../../../data/cart/campaign-offer/index.js";import"../../../data/cart/index.js";import"../../../data/category/path-item/index.js";import"../../../data/category/index.js";import"../../../data/checkout/index.js";import f,{AddressFormItem as g}from"../../../data/checkout/country-settings-model.js";import"../../../data/checkout-settings/index.js";import"../../../data/city/index.js";import"../../../data/country/index.js";import"../../../data/customer/address/index.js";import{IkasLocalizeCustomerAddress as v}from"../../../data/customer/address/ikas-localize-customer-address.js";import"../../../data/customer/attribute/index.js";import"../../../data/customer/review/summary/index.js";import"../../../data/customer/review/index.js";import"../../../data/customer/index.js";import"../../../data/district/index.js";import"../../../data/favorite-product/index.js";import"../../../data/filter-category/index.js";import"../../../data/html-meta-data/index.js";import"../../../data/image/index.js";import"../../../data/order/address/index.js";import"../../../data/order/line-item/option/value/index.js";import"../../../data/order/line-item/variant/value/index.js";import"../../../data/order/line-item/variant/index.js";import"../../../data/order/line-item/index.js";import"../../../data/order/package/index.js";import"../../../data/order/transaction/index.js";import"../../../data/order/index.js";import"../../../data/payment-gateway/index.js";import"../../../data/product/attribute-value/index.js";import"../../../data/product/filter/index.js";import"../../../data/product/option-set/option/index.js";import"../../../data/product/option-set/index.js";import"../../../data/product/stock-location/index.js";import"../../../data/product/variant/price/index.js";import"../../../data/product/variant/index.js";import"../../../data/variant-type/index.js";import"../../../data/product/index.js";import"../../../data/raffle/index.js";import"../../../data/state/index.js";import"../../../data/theme-json/index.js";import"../../../data/theme-json/custom-data/index.js";import"../../../data/variant-type/variant-value/index.js";import y from"lodash/mapValues";var b=function(t){return t.sort((function(t,e){return t.label.localeCompare(e.label)}))},j=function(t){return{label:t.name,value:t.id+""}},x=function(){function x(m){var g=this;this.countries=[],this.states=[],this.cities=[],this.districts=[],this.isLoaded=!1,this._isCountriesPending=!0,this._isStatesPending=!1,this._isCitiesPending=!1,this._isDistrictsPending=!1,this.init=function(){return t(g,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,a({})];case 1:return(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this.countrySettings=new f({checkoutSettings:t.data[0]})),[4,this.countrySettings.waitUntilInitialized()];case 2:return e.sent(),this.address.countrySettings=this.countrySettings,this.isLoaded=!0,[2]}}))}))},this.onTitleChange=function(t){g.address.title=t},this.onFirstNameChange=function(t){g.address.firstName=t},this.onLastNameChange=function(t){g.address.lastName=t},this.onPhoneChange=function(t){g.address.phone=t},this.onAddressLine1Change=function(t){g.address.addressLine1=t},this.onAddressLine2Change=function(t){g.address.addressLine2=t},this.onAddressPostalCodeChange=function(t){g.address.postalCode=t},this.onCountryChange=function(t){var e;if((null===(e=g.address.country)||void 0===e?void 0:e.id)!==t){var i=g.countries.find((function(e){return e.id===t}));g.address.country={id:(null==i?void 0:i.id)||null,name:(null==i?void 0:i.name)||"",code:(null==i?void 0:i.iso3)||null,iso2:(null==i?void 0:i.iso2)||null,iso3:(null==i?void 0:i.iso3)||null},g.address.state=null,g.address.city=null,g.address.district=null,g.states=[],g.cities=[],g.districts=[],g.listStates()}},this.onStateChange=function(t){var e;if((null===(e=g.address.state)||void 0===e?void 0:e.id)!==t){var i=g.states.find((function(e){return e.id===t}));g.address.state={id:i.id,name:null==i?void 0:i.name,code:null==i?void 0:i.stateCode},g.address.isFreeTextCity||(g.address.city=null,g.cities=[],g.listCities()),g.address.isFreeTextDistrict||(g.address.district=null,g.districts=[])}},this.onCityChange=function(t){var e;if((null===(e=g.address.city)||void 0===e?void 0:e.id)!==t){var i=g.cities.find((function(e){return e.id===t}));g.address.city={id:i.id,name:i.name,code:null},g.address.isFreeTextDistrict||(g.address.district=null,g.districts=[],g.listDistricts())}},this.onCityInputChange=function(t){g.districts=[],g.address.city={id:null,name:t,code:null}},this.onDistrictChange=function(t){var e;if((null===(e=g.address.district)||void 0===e?void 0:e.id)!==t){var i=g.districts.find((function(e){return e.id===t}));g.address.district={id:i.id,name:i.name,code:null}}},this.onDistrictInputChange=function(t){g.address.district={id:null,name:t,code:null}},this.listCountries=function(){return t(g,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,3,4]),this._isCountriesPending=!0,[4,o({})];case 1:return t=e.sent(),i=h.getCurrentRouting(),s=t.data||[],(null===(n=null==i?void 0:i.countryCodes)||void 0===n?void 0:n.length)&&(s=s.filter((function(t){var e;return t.iso2&&(null===(e=i.countryCodes)||void 0===e?void 0:e.includes(t.iso2))}))),this.countries=s,1!==this.countries.length||this.address.country||this.onCountryChange(this.countries[0].id),this.countries=s,[3,4];case 2:return e.sent(),[3,4];case 3:return this._isCountriesPending=!1,[7];case 4:return[2]}}))}))},this.listStates=function(){return t(g,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.country)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isStatesPending=!0,[4,u({countryId:{eq:this.address.country.id}})];case 2:return t=e.sent(),this.states=t.data||[],this.hasState||this.onStateChange(this.states[0].id),[3,5];case 3:return e.sent(),[3,5];case 4:return this._isStatesPending=!1,[7];case 5:return[2]}}))}))},this.listCities=function(){return t(g,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.state)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isCitiesPending=!0,[4,c({stateId:{eq:this.address.state.id},countryId:(null===(s=this.address.country)||void 0===s?void 0:s.id)?{eq:null===(n=this.address.country)||void 0===n?void 0:n.id}:void 0})];case 2:return t=e.sent(),this.cities=t.data||[],[3,5];case 3:return e.sent(),[3,5];case 4:return this._isCitiesPending=!1,[7];case 5:return[2]}}))}))},this.listDistricts=function(){return t(g,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.city)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isDistrictsPending=!0,[4,l({cityId:{eq:this.address.city.id},stateId:(null===(s=this.address.state)||void 0===s?void 0:s.id)?{eq:null===(n=this.address.state)||void 0===n?void 0:n.id}:void 0})];case 2:return t=e.sent(),this.districts=t.data||[],[3,5];case 3:return e.sent(),[3,5];case 4:return this._isDistrictsPending=!1,[7];case 5:return[2]}}))}))},this.submit=function(){return t(g,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(t={isFormError:!1,isSuccess:!1},!this.address.isValidAddress)return t.isFormError=!0,[2,t];if(!(i=d(p.getInstance().customerStore.customer))||!this.address)return[2,t];(null==i?void 0:i.addresses)||(i.addresses=[]),this.isEdit?i.addresses[this.editingAddressIndex]=this.address:i.addresses.push(this.address),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,p.getInstance().customerStore.saveCustomer(i)];case 2:return e.sent()&&(t.isSuccess=!0),[2,t];case 3:return e.sent(),[2,t];case 4:return[2]}}))}))},i(this,{isLoaded:s,isEdit:n,editingAddressIndex:n,isFreeTextCity:n,isFreeTextDistrict:n,countries:s,states:s,cities:s,districts:s,_isCountriesPending:s,_isStatesPending:s,_isCitiesPending:s,_isDistrictsPending:s,isCountriesPending:n,isStatesPending:n,isCitiesPending:n,isDistrictsPending:n,onCountryChange:r,submit:r}),this.address=m.address||new v({addressLine1:"",addressLine2:null,attributes:null,company:null,firstName:"",identityNumber:null,isDefault:null,lastName:"",phone:null,postalCode:null,taxNumber:null,taxOffice:null,title:"",country:null,state:null,city:null,district:null,id:"",createdAt:0,updatedAt:0}),this.message=m.message,this.listCountries(),this.address.state&&this.listStates(),this.address.country&&this.listCities(),this.address.city&&this.listDistricts(),this.countrySettings=new f,this.init()}return Object.defineProperty(x.prototype,"isFreeTextCity",{get:function(){var t=this;return m.some((function(e){var i,s;return(null===(s=null===(i=t.address.country)||void 0===i?void 0:i.iso2)||void 0===s?void 0:s.toLowerCase())===e.toLowerCase()}))},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isFreeTextDistrict",{get:function(){return!this.districtOptions.length},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isEdit",{get:function(){return-1!==this.editingAddressIndex},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"editingAddressIndex",{get:function(){var t,e,i,s=this;return null!==(i=null===(e=null===(t=p.getInstance().customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===e?void 0:e.findIndex((function(t){return t.id===s.address.id})))&&void 0!==i?i:-1},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"countryOptions",{get:function(){var t=this.countries.map(j);return b(t)},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"stateOptions",{get:function(){var t=this.states.map(j);return b(t)},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"cityOptions",{get:function(){var t=this.cities.map(j);return b(t)},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"districtOptions",{get:function(){var t=this.districts.map(j);return b(t)},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"hasState",{get:function(){return this.states.length>1},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isCountriesPending",{get:function(){return this._isCountriesPending},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isStatesPending",{get:function(){return this.isCountriesPending||this._isStatesPending},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isCitiesPending",{get:function(){return this.isStatesPending||this._isCitiesPending},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"isDistrictsPending",{get:function(){return this.isCitiesPending||this._isDistrictsPending},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"fieldSettings",{get:function(){return this.address.fieldSettings},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"addressFormat",{get:function(){return this.countryOptions.length<=1?this.address.addressFormatIgnoreCountry:this.address.addressFormat},enumerable:!1,configurable:!0}),Object.defineProperty(x.prototype,"validationResult",{get:function(){var t=this;if(this.address.validationResults)return y(this.address.validationResults,(function(e,i){return{hasError:e.hasError,message:e.hasError?i===g.PHONE?t.message.phoneRule:t.message.requiredRule:""}}))},enumerable:!1,configurable:!0}),x}();export{x as IkasAddressForm};
1
+ import{__awaiter as t,__generator as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as i,observable as s,computed as n,action as r}from"mobx";import d from"lodash/cloneDeep";import{listCheckoutSettings as a,listCountry as o,listState as u,listCity as c,listDistrict as l}from"@ikas/storefront-api";import{IkasStorefrontConfig as h}from"@ikas/storefront-config";import{IkasBaseStore as m}from"../../../../store/base.js";import"../../../../store/customer/index.js";import"../../../../store/cart/index.js";import"../../../data/blog/category/index.js";import"../../../data/blog/content/index.js";import"../../../data/blog/meta-data/index.js";import"../../../data/blog/tag/index.js";import"../../../data/blog/index.js";import"../../../data/brand/index.js";import"@ikas/storefront-models";import"../../../data/campaign-offer/index.js";import"../../../data/cart/campaign-offer/index.js";import"../../../data/cart/index.js";import"../../../data/category/path-item/index.js";import"../../../data/category/index.js";import"../../../data/checkout/index.js";import p,{AddressFormItem as f}from"../../../data/checkout/country-settings-model.js";import"../../../data/checkout-settings/index.js";import"../../../data/city/index.js";import"../../../data/country/index.js";import"../../../data/customer/address/index.js";import{IkasLocalizeCustomerAddress as g}from"../../../data/customer/address/ikas-localize-customer-address.js";import"../../../data/customer/attribute/index.js";import"../../../data/customer/review/summary/index.js";import"../../../data/customer/review/index.js";import"../../../data/customer/index.js";import"../../../data/district/index.js";import"../../../data/favorite-product/index.js";import"../../../data/filter-category/index.js";import"../../../data/html-meta-data/index.js";import"../../../data/image/index.js";import"../../../data/order/address/index.js";import"../../../data/order/line-item/option/value/index.js";import"../../../data/order/line-item/variant/value/index.js";import"../../../data/order/line-item/variant/index.js";import"../../../data/order/line-item/index.js";import"../../../data/order/package/index.js";import"../../../data/order/transaction/index.js";import"../../../data/order/index.js";import"../../../data/payment-gateway/index.js";import"../../../data/product/attribute-value/index.js";import"../../../data/product/filter/index.js";import"../../../data/product/option-set/option/index.js";import"../../../data/product/option-set/index.js";import"../../../data/product/stock-location/index.js";import"../../../data/product/variant/price/index.js";import"../../../data/product/variant/index.js";import"../../../data/variant-type/index.js";import"../../../data/product/index.js";import"../../../data/raffle/index.js";import"../../../data/state/index.js";import"../../../data/theme-json/index.js";import"../../../data/theme-json/custom-data/index.js";import"../../../data/variant-type/variant-value/index.js";import v from"lodash/mapValues";var y=function(t){return t.sort((function(t,e){return t.label.localeCompare(e.label)}))},b=function(t){return{label:t.name,value:t.id+""}},j=function(){function j(f){var v=this;this.countries=[],this.states=[],this.cities=[],this.districts=[],this.isLoaded=!1,this._isCountriesPending=!0,this._isStatesPending=!1,this._isCitiesPending=!1,this._isDistrictsPending=!1,this.init=function(){return t(v,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return[4,a({})];case 1:return(t=e.sent()).isSuccess&&(null===(i=t.data)||void 0===i?void 0:i.length)&&(this.countrySettings=new p({checkoutSettings:t.data[0]})),[4,this.countrySettings.waitUntilInitialized()];case 2:return e.sent(),this.address.countrySettings=this.countrySettings,this.isLoaded=!0,[2]}}))}))},this.onTitleChange=function(t){v.address.title=t},this.onFirstNameChange=function(t){v.address.firstName=t},this.onLastNameChange=function(t){v.address.lastName=t},this.onIdentityNumberChange=function(t){v.address.identityNumber=t},this.onPhoneChange=function(t){v.address.phone=t},this.onAddressLine1Change=function(t){v.address.addressLine1=t},this.onAddressLine2Change=function(t){v.address.addressLine2=t},this.onAddressPostalCodeChange=function(t){v.address.postalCode=t},this.onCountryChange=function(t){var e;if((null===(e=v.address.country)||void 0===e?void 0:e.id)!==t){var i=v.countries.find((function(e){return e.id===t}));v.address.country={id:(null==i?void 0:i.id)||null,name:(null==i?void 0:i.name)||"",code:(null==i?void 0:i.iso3)||null,iso2:(null==i?void 0:i.iso2)||null,iso3:(null==i?void 0:i.iso3)||null},v.address.state=null,v.address.city=null,v.address.district=null,v.states=[],v.cities=[],v.districts=[],v.listStates()}},this.onStateChange=function(t){var e;if((null===(e=v.address.state)||void 0===e?void 0:e.id)!==t){var i=v.states.find((function(e){return e.id===t}));v.address.state={id:i.id,name:null==i?void 0:i.name,code:null==i?void 0:i.stateCode},v.address.isFreeTextCity||(v.address.city=null,v.cities=[],v.listCities()),v.address.isFreeTextDistrict||(v.address.district=null,v.districts=[])}},this.onCityChange=function(t){var e;if((null===(e=v.address.city)||void 0===e?void 0:e.id)!==t){var i=v.cities.find((function(e){return e.id===t}));v.address.city={id:i.id,name:i.name,code:null},v.address.isFreeTextDistrict||(v.address.district=null,v.districts=[],v.listDistricts())}},this.onCityInputChange=function(t){v.districts=[],v.address.city={id:null,name:t,code:null}},this.onDistrictChange=function(t){var e;if((null===(e=v.address.district)||void 0===e?void 0:e.id)!==t){var i=v.districts.find((function(e){return e.id===t}));v.address.district={id:i.id,name:i.name,code:null}}},this.onDistrictInputChange=function(t){v.address.district={id:null,name:t,code:null}},this.listCountries=function(){return t(v,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,3,4]),this._isCountriesPending=!0,[4,o({})];case 1:return t=e.sent(),i=h.getCurrentRouting(),s=t.data||[],(null===(n=null==i?void 0:i.countryCodes)||void 0===n?void 0:n.length)&&(s=s.filter((function(t){var e;return t.iso2&&(null===(e=i.countryCodes)||void 0===e?void 0:e.includes(t.iso2))}))),this.countries=s,1!==this.countries.length||this.address.country||this.onCountryChange(this.countries[0].id),this.countries=s,[3,4];case 2:return e.sent(),[3,4];case 3:return this._isCountriesPending=!1,[7];case 4:return[2]}}))}))},this.listStates=function(){return t(v,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.country)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isStatesPending=!0,[4,u({countryId:{eq:this.address.country.id}})];case 2:return t=e.sent(),this.states=t.data||[],this.hasState||this.onStateChange(this.states[0].id),[3,5];case 3:return e.sent(),[3,5];case 4:return this._isStatesPending=!1,[7];case 5:return[2]}}))}))},this.listCities=function(){return t(v,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.state)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isCitiesPending=!0,[4,c({stateId:{eq:this.address.state.id},countryId:(null===(s=this.address.country)||void 0===s?void 0:s.id)?{eq:null===(n=this.address.country)||void 0===n?void 0:n.id}:void 0})];case 2:return t=e.sent(),this.cities=t.data||[],[3,5];case 3:return e.sent(),[3,5];case 4:return this._isCitiesPending=!1,[7];case 5:return[2]}}))}))},this.listDistricts=function(){return t(v,void 0,void 0,(function(){var t,i,s,n;return e(this,(function(e){switch(e.label){case 0:if(!(null===(i=this.address.city)||void 0===i?void 0:i.id))return[2];e.label=1;case 1:return e.trys.push([1,3,4,5]),this._isDistrictsPending=!0,[4,l({cityId:{eq:this.address.city.id},stateId:(null===(s=this.address.state)||void 0===s?void 0:s.id)?{eq:null===(n=this.address.state)||void 0===n?void 0:n.id}:void 0})];case 2:return t=e.sent(),this.districts=t.data||[],[3,5];case 3:return e.sent(),[3,5];case 4:return this._isDistrictsPending=!1,[7];case 5:return[2]}}))}))},this.submit=function(){return t(v,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:if(t={isFormError:!1,isSuccess:!1},!this.address.isValidAddress)return t.isFormError=!0,[2,t];if(!(i=d(m.getInstance().customerStore.customer))||!this.address)return[2,t];(null==i?void 0:i.addresses)||(i.addresses=[]),this.isEdit?i.addresses[this.editingAddressIndex]=this.address:i.addresses.push(this.address),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,m.getInstance().customerStore.saveCustomer(i)];case 2:return e.sent()&&(t.isSuccess=!0),[2,t];case 3:return e.sent(),[2,t];case 4:return[2]}}))}))},i(this,{isLoaded:s,isEdit:n,editingAddressIndex:n,isFreeTextCity:n,isFreeTextDistrict:n,countries:s,states:s,cities:s,districts:s,_isCountriesPending:s,_isStatesPending:s,_isCitiesPending:s,_isDistrictsPending:s,isCountriesPending:n,isStatesPending:n,isCitiesPending:n,isDistrictsPending:n,onCountryChange:r,submit:r}),this.address=f.address||new g({addressLine1:"",addressLine2:null,attributes:null,company:null,firstName:"",identityNumber:null,isDefault:null,lastName:"",phone:null,postalCode:null,taxNumber:null,taxOffice:null,title:"",country:null,state:null,city:null,district:null,id:"",createdAt:0,updatedAt:0}),this.message=f.message,this.listCountries(),this.address.state&&this.listStates(),this.address.country&&this.listCities(),this.address.city&&this.listDistricts(),this.countrySettings=new p,this.init()}return Object.defineProperty(j.prototype,"isFreeTextCity",{get:function(){return this.address.isFreeTextCity},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isFreeTextDistrict",{get:function(){return this.address.isFreeTextDistrict},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isEdit",{get:function(){return-1!==this.editingAddressIndex},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"editingAddressIndex",{get:function(){var t,e,i,s=this;return null!==(i=null===(e=null===(t=m.getInstance().customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===e?void 0:e.findIndex((function(t){return t.id===s.address.id})))&&void 0!==i?i:-1},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"countryOptions",{get:function(){var t=this.countries.map(b);return y(t)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"stateOptions",{get:function(){var t=this.states.map(b);return y(t)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"cityOptions",{get:function(){var t=this.cities.map(b);return y(t)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"districtOptions",{get:function(){var t=this.districts.map(b);return y(t)},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"hasState",{get:function(){return this.states.length>1},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isCountriesPending",{get:function(){return this._isCountriesPending},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isStatesPending",{get:function(){return this.isCountriesPending||this._isStatesPending},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isCitiesPending",{get:function(){return this.isStatesPending||this._isCitiesPending},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"isDistrictsPending",{get:function(){return this.isCitiesPending||this._isDistrictsPending},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"fieldSettings",{get:function(){return this.address.fieldSettings},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"addressFormat",{get:function(){return this.countryOptions.length<=1?this.address.addressFormatIgnoreCountry:this.address.addressFormat},enumerable:!1,configurable:!0}),Object.defineProperty(j.prototype,"validationResult",{get:function(){var t=this;if(this.address.validationResults)return v(this.address.validationResults,(function(e,i){return{hasError:e.hasError,message:e.hasError?i===f.PHONE?t.message.phoneRule:e.isInvalid?t.message.invalidRule:t.message.requiredRule:""}}))},enumerable:!1,configurable:!0}),j}();export{j as IkasAddressForm};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.2.0-beta.10",
3
+ "version": "4.2.0-beta.12",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {},
20
20
  "devDependencies": {
21
- "@ikas/storefront-api": "^4.2.0-beta.10",
22
- "@ikas/storefront-config": "^4.2.0-beta.10",
23
- "@ikas/storefront-model-functions": "^4.2.0-beta.10",
24
- "@ikas/storefront-models": "^4.2.0-beta.10",
25
- "@ikas/storefront-providers": "^4.2.0-beta.10",
21
+ "@ikas/storefront-api": "^4.2.0-beta.12",
22
+ "@ikas/storefront-config": "^4.2.0-beta.12",
23
+ "@ikas/storefront-model-functions": "^4.2.0-beta.12",
24
+ "@ikas/storefront-models": "^4.2.0-beta.12",
25
+ "@ikas/storefront-providers": "^4.2.0-beta.12",
26
26
  "@rollup/plugin-commonjs": "^22.0.0",
27
27
  "@rollup/plugin-json": "^4.1.0",
28
28
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -52,11 +52,11 @@
52
52
  "libphonenumber-js": "^1.10.6"
53
53
  },
54
54
  "peerDependencies": {
55
- "@ikas/storefront-api": "^4.2.0-beta.10",
56
- "@ikas/storefront-config": "^4.2.0-beta.10",
57
- "@ikas/storefront-model-functions": "^4.2.0-beta.10",
58
- "@ikas/storefront-models": "^4.2.0-beta.10",
59
- "@ikas/storefront-providers": "^4.2.0-beta.10",
55
+ "@ikas/storefront-api": "^4.2.0-beta.12",
56
+ "@ikas/storefront-config": "^4.2.0-beta.12",
57
+ "@ikas/storefront-model-functions": "^4.2.0-beta.12",
58
+ "@ikas/storefront-models": "^4.2.0-beta.12",
59
+ "@ikas/storefront-providers": "^4.2.0-beta.12",
60
60
  "mobx": "^6.1.3",
61
61
  "mobx-react-lite": "^3.1.5",
62
62
  "next": "12.2.0",