@ikas/storefront 6.1.0-beta.73 → 6.1.0-beta.74

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 +1 @@
1
- import{__awaiter as t,__generator as i,__assign as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import s from"lodash/sortBy";import"../../../../models/data/blog/category/index.js";import"../../../../models/data/blog/content/index.js";import"../../../../models/data/blog/meta-data/index.js";import"../../../../models/data/blog/tag/index.js";import"../../../../models/data/blog/index.js";import"../../../../models/data/brand/index.js";import"@ikas/storefront-models";import"../../../../models/data/campaign-offer/index.js";import"../../../../models/data/cart/campaign-offer/index.js";import"../../../../models/data/cart/index.js";import"../../../../models/data/category/path-item/index.js";import"../../../../models/data/category/index.js";import"../../../../models/data/checkout/index.js";import"../../../../models/data/checkout-settings/index.js";import"../../../../models/data/city/index.js";import"../../../../models/data/country/index.js";import"../../../../models/data/customer/address/region/index.js";import"../../../../models/data/customer/address/index.js";import"../../../../models/data/customer/address/ikas-localized-customer-address.js";import"../../../../models/data/customer/attribute/index.js";import"../../../../models/data/customer/review/summary/index.js";import"../../../../models/data/customer/review/index.js";import"../../../../models/data/customer/index.js";import"../../../../models/data/customer-form-data-input/index.js";import"../../../../models/data/district/index.js";import"../../../../models/data/favorite-product/index.js";import"../../../../models/data/filter-category/index.js";import"../../../../models/data/html-meta-data/index.js";import"../../../../models/data/image/index.js";import{IkasOrderAddressCity as r}from"../../../../models/data/order/address/city/index.js";import{IkasOrderAddressCountry as n}from"../../../../models/data/order/address/country/index.js";import{IkasOrderAddressDistrict as d}from"../../../../models/data/order/address/district/index.js";import{IkasOrderAddressRegion as a}from"../../../../models/data/order/address/region/index.js";import"../../../../models/data/order/address/index.js";import"../../../../models/data/order/line-item/option/value/index.js";import"../../../../models/data/order/line-item/variant/value/index.js";import"../../../../models/data/order/line-item/variant/index.js";import"../../../../models/data/order/line-item/index.js";import"../../../../models/data/order/order-transaction-with-prices/index.js";import"../../../../models/data/order/package/index.js";import"../../../../models/data/order/transaction/index.js";import"../../../../models/data/order/index.js";import"../../../../models/data/payment-gateway/index.js";import"../../../../models/data/product/attribute-value/index.js";import"../../../../models/data/product/filter/index.js";import"../../../../models/data/product/campaign-offer/index.js";import"../../../../models/data/product/option-set/option/index.js";import"../../../../models/data/product/option-set/index.js";import"../../../../models/data/product/stock-location/index.js";import"../../../../models/data/product/variant/price/index.js";import"../../../../models/data/product/variant/index.js";import"../../../../models/data/variant-type/index.js";import"../../../../models/data/product/index.js";import"../../../../models/data/raffle/index.js";import"../../../../models/data/shipping-zone/state/city/district/region/index.js";import"../../../../models/data/state/index.js";import"../../../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../../../models/data/storefront-popup/index.js";import"../../../../models/data/theme-json/index.js";import"../../../../models/data/theme-json/component/index.js";import"../../../../models/data/theme-json/custom-data/index.js";import"../../../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../../../models/ui/blog-list/index.js";import"../../../../models/ui/blog-category-list/index.js";import"../../../../models/ui/brand-list/index.js";import"../../../../models/ui/category-list/index.js";import"../../../../models/ui/product-list/index.js";import"../../../../models/ui/product-attribute-detail/index.js";import"../../../../models/ui/product-attribute-list/index.js";import"../../../../models/ui/customer-review-list/index.js";import"../../../../models/ui/customer-review-summary-list/index.js";import"../../../../models/ui/validator/index.js";import"../../../../models/ui/validator/rules/index.js";import"../../../../models/ui/validator/form/login.js";import"../../../../models/ui/validator/form/address.js";import"../../../../models/ui/validator/form/ikas-address.js";import"../../../../models/ui/validator/form/register.js";import"../../../../models/ui/validator/form/contact-form.js";import"../../../../models/ui/validator/form/forgot-password.js";import"../../../../models/ui/validator/form/recover-password.js";import"../../../../models/ui/validator/form/account-info.js";import"../../../../models/ui/validator/form/raffle-form.js";import"../../../../models/ui/validator/form/customer-review.js";import"../../../../models/ui/raffle-list/index.js";import{stringSorter as l,capitalize as u}from"../../../../utils/helper.js";import{FREE_TEXT_CITY_COUNTRY_LIST as c,DISTRICT_HIDDEN_COUNTRY_LIST as m}from"../../../../utils/constants.js";import p from"../../../../store/location/index.js";import{IkasStorefrontConfig as h}from"@ikas/storefront-config";var f=function(){function f(e){var s=this;this.isCorporate=!1,this.isErrorsVisible=!1,this.allowedCountryIds=null,this.allowCorporateInfo=!1,this.allowTitleChange=!1,this.firstNameChangeCallback=null,this.lastNameChangeCallback=null,this.countries=[],this.states=[],this.cities=[],this.districts=[],this.isLoadingCities=!1,this.isLoadingDistricts=!1,this.myCountryCode=null,this.fillDropdownOptions=function(){return t(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.listCountries()];case 1:return t.sent(),[4,this.listStates()];case 2:return t.sent(),[4,this.listCities()];case 3:return t.sent(),[4,this.listDistricts()];case 4:return t.sent(),[2]}}))}))},this.checkIsCorporate=function(){return t(s,void 0,void 0,(function(){return i(this,(function(t){return(this.address.company||this.address.taxNumber||this.address.taxOffice)&&(this.isCorporate=!0),[2]}))}))},this.listCountries=function(){return t(s,void 0,void 0,(function(){var t,e,o,s,r,n,d,a,l=this;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),this.myCountryCode?[3,2]:[4,p.getMyCountry()];case 1:t=i.sent(),this.myCountryCode=t.data,i.label=2;case 2:return[4,p.listCountry({id:(null===(d=this.allowedCountryIds)||void 0===d?void 0:d.length)?{in:this.allowedCountryIds}:void 0,locale:h.getCurrentLocale()})];case 3:return e=i.sent(),o=e.data||[],s=h.getCurrentRouting(),(null===(a=null==s?void 0:s.countryCodes)||void 0===a?void 0:a.length)?o=o.filter((function(t){var i;return t.iso2&&(null===(i=s.countryCodes)||void 0===i?void 0:i.includes(t.iso2))})):(r=h.getRoutings().filter((function(t){return t.id!==h.getStorefrontRoutingId()})),o=o.filter((function(t){return t.iso2&&!r.some((function(i){var e;return null===(e=i.countryCodes)||void 0===e?void 0:e.includes(t.iso2)}))}))),this.countries=o,1!==this.countries.length||this.country?this.countries.length&&this.myCountryCode&&!this.country&&((n=this.countries.find((function(t){return t.iso2===l.myCountryCode})))?this.onCountryChange(n.id):this.onCountryChange(this.countries[0].id)):this.onCountryChange(this.countries[0].id),[3,5];case 4:return i.sent(),[3,5];case 5:return[2]}}))}))},this.listStates=function(){return t(s,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.country)||void 0===e?void 0:e.id))return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,p.listState({countryId:{eq:this.country.id},locale:h.getCurrentLocale()})];case 2:return t=i.sent(),this.states=t.data||[],this.hasState||this.onStateChange(this.states[0].id),[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.listCities=function(){return t(s,void 0,void 0,(function(){var t,e,o;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.state)||void 0===e?void 0:e.id)||!(null===(o=this.country)||void 0===o?void 0:o.id))return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),this.isLoadingCities=!0,[4,p.listCity({stateId:{eq:this.state.id},countryId:{eq:this.country.id}})];case 2:return t=i.sent(),this.cities=t.data||[],this.isLoadingCities=!1,[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.listDistricts=function(){return t(s,void 0,void 0,(function(){var t,e,o,s;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.city)||void 0===e?void 0:e.id)||this.isDistrictHidden)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),this.isLoadingDistricts=!0,[4,p.listDistrict({cityId:{eq:this.city.id},stateId:(null===(o=this.state)||void 0===o?void 0:o.id)?{eq:null===(s=this.state)||void 0===s?void 0:s.id}:void 0})];case 2:return t=i.sent(),this.districts=t.data||[],this.districts.length?this.address.isDistrictRequired=!0:this.address.isDistrictRequired=!1,this.isLoadingDistricts=!1,[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.modelToOption=function(t){return{label:t.name,value:t.id+""}},this.onFirstNameChange=function(t){s.firstNameChangeCallback&&s.firstNameChangeCallback(t),s.address.firstName=t},this.onLastNameChange=function(t){s.lastNameChangeCallback&&s.lastNameChangeCallback(t),s.address.lastName=t},this.onPhoneChange=function(t){s.address.phone=t},this.onIdentityNumberChange=function(t){t?t.length<=11&&(s.address.identityNumber=t):s.address.identityNumber=""},this.onAddressTitleChange=function(t){s.address.title=t},this.onAddressLine1Change=function(t){s.address.addressLine1=t},this.onAddressLine2Change=function(t){s.address.addressLine2=t},this.onAddressPostalCodeChange=function(t){s.address.postalCode=t},this.onCountryChange=function(t){var i;if((null===(i=s.country)||void 0===i?void 0:i.id)!==t){var e=s.countries.find((function(i){return i.id===t}));s.address.country=new n({id:(null==e?void 0:e.id)||null,name:(null==e?void 0:e.name)||"",code:(null==e?void 0:e.iso3)||null,iso2:(null==e?void 0:e.iso2)||null,iso3:(null==e?void 0:e.iso3)||null}),s.address.state=null,s.address.city=null,s.address.district=null,s.address.phone=null,s.states=[],s.cities=[],s.districts=[],s.listStates()}},this.onStateChange=function(t){var i;if((null===(i=s.state)||void 0===i?void 0:i.id)!==t){var e=s.states.find((function(i){return i.id===t}));s.address.state={id:e.id,name:null==e?void 0:e.name,code:null==e?void 0:e.stateCode},s.address.isFreeTextCity||(s.address.city=null,s.cities=[],s.listCities()),s.address.isFreeTextDistrict||(s.address.district=null,s.districts=[])}},this.onCityChange=function(t){var i;if((null===(i=s.city)||void 0===i?void 0:i.id)!==t){var e=s.cities.find((function(i){return i.id===t}));s.address.city=new r({id:e.id,name:e.name,code:e.cityCode}),s.address.isFreeTextDistrict||(s.address.district=null,s.districts=[],s.listDistricts())}},this.onCityInputChange=function(t){s.districts=[],s.address.city=new r({id:void 0,name:t})},this.onDistrictChange=function(t){var i;if((null===(i=s.district)||void 0===i?void 0:i.id)!==t){var e=s.districts.find((function(i){return i.id===t}));s.address.district=new d({id:e.id,name:e.name}),s.address.region=null}},this.onDistrictInputChange=function(t){s.address.district=new d({id:void 0,name:t})},this.onRegionChange=function(t){var i,e,o;if((null===(i=s.region)||void 0===i?void 0:i.id)!==t){var r=null===(o=null===(e=s.shippingZoneDistrict)||void 0===e?void 0:e.regions)||void 0===o?void 0:o.find((function(i){return i.id===t}));s.address.region=new a({id:r.id,name:r.name})}},this.onCorporateChange=function(t){s.isCorporate=t,t||(s.address.company=null,s.address.taxNumber=null,s.address.taxOffice=null)},this.onCompanyChange=function(t){s.address.company=t},this.onTaxNumberChange=function(t){s.address.taxNumber=t},this.onTaxOfficeChange=function(t){s.address.taxOffice=t},this.address=e.address,this.isCorporate=e.isCorporate||!1,this.isErrorsVisible=e.isErrorsVisible||!1,this.isCustomerAddress=e.isCustomerAddress||!1,this.allowedCountryIds=e.allowedCountryIds,this.allowCorporateInfo=e.allowCorporateInfo||!1,this.allowTitleChange=e.allowTitleChange||!1,this.firstNameChangeCallback=e.firstNameChangeCallback||null,this.lastNameChangeCallback=e.lastNameChangeCallback||null,o(this,{firstNameChangeCallback:!1,lastNameChangeCallback:!1}),this.fillDropdownOptions(),this.checkIsCorporate()}return Object.defineProperty(f.prototype,"firstName",{get:function(){return this.address.firstName},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"lastName",{get:function(){return this.address.lastName},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"phone",{get:function(){return this.address.phone},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"identityNumber",{get:function(){return this.address.identityNumber},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZone",{get:function(){var t,i=this;return null===(t=this.address.shippingZones)||void 0===t?void 0:t.find((function(t){var e;return t.countryId===(null===(e=i.address.country)||void 0===e?void 0:e.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneState",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZone)||void 0===t?void 0:t.states)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.state)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneCity",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneState)||void 0===t?void 0:t.cities)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.city)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneDistrict",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneCity)||void 0===t?void 0:t.districts)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.district)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneRegions",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneDistrict)||void 0===t?void 0:t.regions)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.region)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"country",{get:function(){return this.address.country},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"state",{get:function(){return this.address.state},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"city",{get:function(){return this.address.city},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"district",{get:function(){return this.address.district},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"region",{get:function(){return this.address.region},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"countryOptions",{get:function(){var t=this.countries.map(this.modelToOption);return t.sort((function(t,i){return l(t.label,i.label)})),t},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"stateOptions",{get:function(){var t,i,e=this,o=this.states.map(this.modelToOption);return this.shippingZone&&!this.shippingZone.showAllStates&&(null===(i=null===(t=this.shippingZone)||void 0===t?void 0:t.states)||void 0===i?void 0:i.length)&&(o=o.filter((function(t){var i,o;return null===(o=null===(i=e.shippingZone)||void 0===i?void 0:i.states)||void 0===o?void 0:o.some((function(i){return i.id===t.value}))}))),o.sort((function(t,i){return l(t.label,i.label)})),o},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"cityOptions",{get:function(){var t,i,e,o=this,r=s(this.cities,"order").map(this.modelToOption);return this.shippingZone&&!(null===(t=this.shippingZoneState)||void 0===t?void 0:t.showAllCities)&&(null===(e=null===(i=this.shippingZoneState)||void 0===i?void 0:i.cities)||void 0===e?void 0:e.length)&&(r=r.filter((function(t){var i,e;return null===(e=null===(i=o.shippingZoneState)||void 0===i?void 0:i.cities)||void 0===e?void 0:e.some((function(i){return i.id===t.value}))}))),r},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"districtOptions",{get:function(){var t,i,o,s=this,r=this.districts.map((function(t){return e(e({},t),{name:u(t.name)})})).map(this.modelToOption);return this.shippingZone&&!(null===(t=this.shippingZoneCity)||void 0===t?void 0:t.showAllDistricts)&&(null===(o=null===(i=this.shippingZoneCity)||void 0===i?void 0:i.districts)||void 0===o?void 0:o.length)&&(r=r.filter((function(t){var i,e;return null===(e=null===(i=s.shippingZoneCity)||void 0===i?void 0:i.districts)||void 0===e?void 0:e.some((function(i){return i.id===t.value}))}))),r.sort((function(t,i){return l(t.label,i.label)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"regionOptions",{get:function(){var t,i,e=(null===(i=null===(t=this.shippingZoneDistrict)||void 0===t?void 0:t.regions)||void 0===i?void 0:i.map(this.modelToOption))||[];return e.sort((function(t,i){return l(t.label,i.label)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"hasState",{get:function(){return this.states.length>1},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"isFreeTextCity",{get:function(){var t=this;return c.some((function(i){var e,o;return(null===(o=null===(e=t.address.country)||void 0===e?void 0:e.iso2)||void 0===o?void 0:o.toLowerCase())===i.toLowerCase()}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"isDistrictHidden",{get:function(){var t=this;return m.some((function(i){var e,o;return(null===(o=null===(e=t.address.country)||void 0===e?void 0:e.iso2)||void 0===o?void 0:o.toLowerCase())===i.toLowerCase()}))},enumerable:!1,configurable:!0}),f}();export{f as default};
1
+ import{__awaiter as t,__generator as i,__assign as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as o}from"mobx";import s from"lodash/sortBy";import"../../../../models/data/blog/category/index.js";import"../../../../models/data/blog/content/index.js";import"../../../../models/data/blog/meta-data/index.js";import"../../../../models/data/blog/tag/index.js";import"../../../../models/data/blog/index.js";import"../../../../models/data/brand/index.js";import"@ikas/storefront-models";import"../../../../models/data/campaign-offer/index.js";import"../../../../models/data/cart/campaign-offer/index.js";import"../../../../models/data/cart/index.js";import"../../../../models/data/category/path-item/index.js";import"../../../../models/data/category/index.js";import"../../../../models/data/checkout/index.js";import"../../../../models/data/checkout-settings/index.js";import"../../../../models/data/city/index.js";import"../../../../models/data/country/index.js";import"../../../../models/data/customer/address/region/index.js";import"../../../../models/data/customer/address/index.js";import"../../../../models/data/customer/address/ikas-localized-customer-address.js";import"../../../../models/data/customer/attribute/index.js";import"../../../../models/data/customer/review/summary/index.js";import"../../../../models/data/customer/review/index.js";import"../../../../models/data/customer/index.js";import"../../../../models/data/customer-form-data-input/index.js";import"../../../../models/data/district/index.js";import"../../../../models/data/favorite-product/index.js";import"../../../../models/data/filter-category/index.js";import"../../../../models/data/html-meta-data/index.js";import"../../../../models/data/image/index.js";import{IkasOrderAddressCity as r}from"../../../../models/data/order/address/city/index.js";import{IkasOrderAddressCountry as n}from"../../../../models/data/order/address/country/index.js";import{IkasOrderAddressDistrict as d}from"../../../../models/data/order/address/district/index.js";import{IkasOrderAddressRegion as a}from"../../../../models/data/order/address/region/index.js";import"../../../../models/data/order/address/index.js";import"../../../../models/data/order/line-item/option/value/index.js";import"../../../../models/data/order/line-item/variant/value/index.js";import"../../../../models/data/order/line-item/variant/index.js";import"../../../../models/data/order/line-item/index.js";import"../../../../models/data/order/order-transaction-with-prices/index.js";import"../../../../models/data/order/package/index.js";import"../../../../models/data/order/transaction/index.js";import"../../../../models/data/order/index.js";import"../../../../models/data/payment-gateway/index.js";import"../../../../models/data/product/attribute-value/index.js";import"../../../../models/data/product/filter/index.js";import"../../../../models/data/product/campaign-offer/index.js";import"../../../../models/data/product/option-set/option/index.js";import"../../../../models/data/product/option-set/index.js";import"../../../../models/data/product/stock-location/index.js";import"../../../../models/data/product/variant/price/index.js";import"../../../../models/data/product/variant/index.js";import"../../../../models/data/variant-type/index.js";import"../../../../models/data/product/index.js";import"../../../../models/data/raffle/index.js";import"../../../../models/data/shipping-zone/state/city/district/region/index.js";import"../../../../models/data/state/index.js";import"../../../../models/data/storefront-popup/storefront-popup-display-filter/index.js";import"../../../../models/data/storefront-popup/storefront-popup-display-settings/index.js";import"../../../../models/data/storefront-popup/storefront-popup-page-filter/index.js";import"../../../../models/data/storefront-popup/index.js";import"../../../../models/data/theme-json/index.js";import"../../../../models/data/theme-json/component/index.js";import"../../../../models/data/theme-json/custom-data/index.js";import"../../../../models/data/variant-type/variant-value/index.js";import"@ikas/localized-address";import"../../../../models/ui/blog-list/index.js";import"../../../../models/ui/blog-category-list/index.js";import"../../../../models/ui/brand-list/index.js";import"../../../../models/ui/category-list/index.js";import"../../../../models/ui/product-list/index.js";import"../../../../models/ui/product-attribute-detail/index.js";import"../../../../models/ui/product-attribute-list/index.js";import"../../../../models/ui/customer-review-list/index.js";import"../../../../models/ui/customer-review-summary-list/index.js";import"../../../../models/ui/validator/index.js";import"../../../../models/ui/validator/rules/index.js";import"../../../../models/ui/validator/form/login.js";import"../../../../models/ui/validator/form/address.js";import"../../../../models/ui/validator/form/ikas-address.js";import"../../../../models/ui/validator/form/register.js";import"../../../../models/ui/validator/form/contact-form.js";import"../../../../models/ui/validator/form/forgot-password.js";import"../../../../models/ui/validator/form/recover-password.js";import"../../../../models/ui/validator/form/account-info.js";import"../../../../models/ui/validator/form/raffle-form.js";import"../../../../models/ui/validator/form/customer-review.js";import"../../../../models/ui/raffle-list/index.js";import{stringSorter as l,capitalize as u}from"../../../../utils/helper.js";import{FREE_TEXT_CITY_COUNTRY_LIST as c,DISTRICT_HIDDEN_COUNTRY_LIST as m}from"../../../../utils/constants.js";import p from"../../../../store/location/index.js";import{IkasStorefrontConfig as h}from"@ikas/storefront-config";var f=function(){function f(e){var s=this;this.isCorporate=!1,this.isErrorsVisible=!1,this.allowedCountryIds=null,this.allowCorporateInfo=!1,this.allowTitleChange=!1,this.firstNameChangeCallback=null,this.lastNameChangeCallback=null,this.countries=[],this.states=[],this.cities=[],this.districts=[],this.isLoadingCities=!1,this.isLoadingDistricts=!1,this.myCountryCode=null,this.fillDropdownOptions=function(){return t(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.listCountries()];case 1:return t.sent(),[4,this.listStates()];case 2:return t.sent(),[4,this.listCities()];case 3:return t.sent(),[4,this.listDistricts()];case 4:return t.sent(),[2]}}))}))},this.checkIsCorporate=function(){return t(s,void 0,void 0,(function(){return i(this,(function(t){return(this.address.company||this.address.taxNumber||this.address.taxOffice)&&this.allowCorporateInfo&&(this.isCorporate=!0),[2]}))}))},this.listCountries=function(){return t(s,void 0,void 0,(function(){var t,e,o,s,r,n,d,a,l=this;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),this.myCountryCode?[3,2]:[4,p.getMyCountry()];case 1:t=i.sent(),this.myCountryCode=t.data,i.label=2;case 2:return[4,p.listCountry({id:(null===(d=this.allowedCountryIds)||void 0===d?void 0:d.length)?{in:this.allowedCountryIds}:void 0,locale:h.getCurrentLocale()})];case 3:return e=i.sent(),o=e.data||[],s=h.getCurrentRouting(),(null===(a=null==s?void 0:s.countryCodes)||void 0===a?void 0:a.length)?o=o.filter((function(t){var i;return t.iso2&&(null===(i=s.countryCodes)||void 0===i?void 0:i.includes(t.iso2))})):(r=h.getRoutings().filter((function(t){return t.id!==h.getStorefrontRoutingId()})),o=o.filter((function(t){return t.iso2&&!r.some((function(i){var e;return null===(e=i.countryCodes)||void 0===e?void 0:e.includes(t.iso2)}))}))),this.countries=o,1!==this.countries.length||this.country?this.countries.length&&this.myCountryCode&&!this.country&&((n=this.countries.find((function(t){return t.iso2===l.myCountryCode})))?this.onCountryChange(n.id):this.onCountryChange(this.countries[0].id)):this.onCountryChange(this.countries[0].id),[3,5];case 4:return i.sent(),[3,5];case 5:return[2]}}))}))},this.listStates=function(){return t(s,void 0,void 0,(function(){var t,e;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.country)||void 0===e?void 0:e.id))return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),[4,p.listState({countryId:{eq:this.country.id},locale:h.getCurrentLocale()})];case 2:return t=i.sent(),this.states=t.data||[],this.hasState||this.onStateChange(this.states[0].id),[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.listCities=function(){return t(s,void 0,void 0,(function(){var t,e,o;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.state)||void 0===e?void 0:e.id)||!(null===(o=this.country)||void 0===o?void 0:o.id))return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),this.isLoadingCities=!0,[4,p.listCity({stateId:{eq:this.state.id},countryId:{eq:this.country.id}})];case 2:return t=i.sent(),this.cities=t.data||[],this.isLoadingCities=!1,[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.listDistricts=function(){return t(s,void 0,void 0,(function(){var t,e,o,s;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.city)||void 0===e?void 0:e.id)||this.isDistrictHidden)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),this.isLoadingDistricts=!0,[4,p.listDistrict({cityId:{eq:this.city.id},stateId:(null===(o=this.state)||void 0===o?void 0:o.id)?{eq:null===(s=this.state)||void 0===s?void 0:s.id}:void 0})];case 2:return t=i.sent(),this.districts=t.data||[],this.districts.length?this.address.isDistrictRequired=!0:this.address.isDistrictRequired=!1,this.isLoadingDistricts=!1,[3,4];case 3:return i.sent(),[3,4];case 4:return[2]}}))}))},this.modelToOption=function(t){return{label:t.name,value:t.id+""}},this.onFirstNameChange=function(t){s.firstNameChangeCallback&&s.firstNameChangeCallback(t),s.address.firstName=t},this.onLastNameChange=function(t){s.lastNameChangeCallback&&s.lastNameChangeCallback(t),s.address.lastName=t},this.onPhoneChange=function(t){s.address.phone=t},this.onIdentityNumberChange=function(t){t?t.length<=11&&(s.address.identityNumber=t):s.address.identityNumber=""},this.onAddressTitleChange=function(t){s.address.title=t},this.onAddressLine1Change=function(t){s.address.addressLine1=t},this.onAddressLine2Change=function(t){s.address.addressLine2=t},this.onAddressPostalCodeChange=function(t){s.address.postalCode=t},this.onCountryChange=function(t){var i;if((null===(i=s.country)||void 0===i?void 0:i.id)!==t){var e=s.countries.find((function(i){return i.id===t}));s.address.country=new n({id:(null==e?void 0:e.id)||null,name:(null==e?void 0:e.name)||"",code:(null==e?void 0:e.iso3)||null,iso2:(null==e?void 0:e.iso2)||null,iso3:(null==e?void 0:e.iso3)||null}),s.address.state=null,s.address.city=null,s.address.district=null,s.address.phone=null,s.states=[],s.cities=[],s.districts=[],s.listStates()}},this.onStateChange=function(t){var i;if((null===(i=s.state)||void 0===i?void 0:i.id)!==t){var e=s.states.find((function(i){return i.id===t}));s.address.state={id:e.id,name:null==e?void 0:e.name,code:null==e?void 0:e.stateCode},s.address.isFreeTextCity||(s.address.city=null,s.cities=[],s.listCities()),s.address.isFreeTextDistrict||(s.address.district=null,s.districts=[])}},this.onCityChange=function(t){var i;if((null===(i=s.city)||void 0===i?void 0:i.id)!==t){var e=s.cities.find((function(i){return i.id===t}));s.address.city=new r({id:e.id,name:e.name,code:e.cityCode}),s.address.isFreeTextDistrict||(s.address.district=null,s.districts=[],s.listDistricts())}},this.onCityInputChange=function(t){s.districts=[],s.address.city=new r({id:void 0,name:t})},this.onDistrictChange=function(t){var i;if((null===(i=s.district)||void 0===i?void 0:i.id)!==t){var e=s.districts.find((function(i){return i.id===t}));s.address.district=new d({id:e.id,name:e.name}),s.address.region=null}},this.onDistrictInputChange=function(t){s.address.district=new d({id:void 0,name:t})},this.onRegionChange=function(t){var i,e,o;if((null===(i=s.region)||void 0===i?void 0:i.id)!==t){var r=null===(o=null===(e=s.shippingZoneDistrict)||void 0===e?void 0:e.regions)||void 0===o?void 0:o.find((function(i){return i.id===t}));s.address.region=new a({id:r.id,name:r.name})}},this.onCorporateChange=function(t){s.isCorporate=t,t||(s.address.company=null,s.address.taxNumber=null,s.address.taxOffice=null)},this.onCompanyChange=function(t){s.address.company=t},this.onTaxNumberChange=function(t){s.address.taxNumber=t},this.onTaxOfficeChange=function(t){s.address.taxOffice=t},this.address=e.address,this.isCorporate=e.isCorporate||!1,this.isErrorsVisible=e.isErrorsVisible||!1,this.isCustomerAddress=e.isCustomerAddress||!1,this.allowedCountryIds=e.allowedCountryIds,this.allowCorporateInfo=e.allowCorporateInfo||!1,this.allowTitleChange=e.allowTitleChange||!1,this.firstNameChangeCallback=e.firstNameChangeCallback||null,this.lastNameChangeCallback=e.lastNameChangeCallback||null,o(this,{firstNameChangeCallback:!1,lastNameChangeCallback:!1}),this.fillDropdownOptions(),this.checkIsCorporate()}return Object.defineProperty(f.prototype,"firstName",{get:function(){return this.address.firstName},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"lastName",{get:function(){return this.address.lastName},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"phone",{get:function(){return this.address.phone},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"identityNumber",{get:function(){return this.address.identityNumber},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZone",{get:function(){var t,i=this;return null===(t=this.address.shippingZones)||void 0===t?void 0:t.find((function(t){var e;return t.countryId===(null===(e=i.address.country)||void 0===e?void 0:e.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneState",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZone)||void 0===t?void 0:t.states)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.state)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneCity",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneState)||void 0===t?void 0:t.cities)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.city)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneDistrict",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneCity)||void 0===t?void 0:t.districts)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.district)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"shippingZoneRegions",{get:function(){var t,i,e=this;return null===(i=null===(t=this.shippingZoneDistrict)||void 0===t?void 0:t.regions)||void 0===i?void 0:i.find((function(t){var i;return t.id===(null===(i=e.address.region)||void 0===i?void 0:i.id)}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"country",{get:function(){return this.address.country},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"state",{get:function(){return this.address.state},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"city",{get:function(){return this.address.city},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"district",{get:function(){return this.address.district},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"region",{get:function(){return this.address.region},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"countryOptions",{get:function(){var t=this.countries.map(this.modelToOption);return t.sort((function(t,i){return l(t.label,i.label)})),t},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"stateOptions",{get:function(){var t,i,e=this,o=this.states.map(this.modelToOption);return this.shippingZone&&!this.shippingZone.showAllStates&&(null===(i=null===(t=this.shippingZone)||void 0===t?void 0:t.states)||void 0===i?void 0:i.length)&&(o=o.filter((function(t){var i,o;return null===(o=null===(i=e.shippingZone)||void 0===i?void 0:i.states)||void 0===o?void 0:o.some((function(i){return i.id===t.value}))}))),o.sort((function(t,i){return l(t.label,i.label)})),o},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"cityOptions",{get:function(){var t,i,e,o=this,r=s(this.cities,"order").map(this.modelToOption);return this.shippingZone&&!(null===(t=this.shippingZoneState)||void 0===t?void 0:t.showAllCities)&&(null===(e=null===(i=this.shippingZoneState)||void 0===i?void 0:i.cities)||void 0===e?void 0:e.length)&&(r=r.filter((function(t){var i,e;return null===(e=null===(i=o.shippingZoneState)||void 0===i?void 0:i.cities)||void 0===e?void 0:e.some((function(i){return i.id===t.value}))}))),r},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"districtOptions",{get:function(){var t,i,o,s=this,r=this.districts.map((function(t){return e(e({},t),{name:u(t.name)})})).map(this.modelToOption);return this.shippingZone&&!(null===(t=this.shippingZoneCity)||void 0===t?void 0:t.showAllDistricts)&&(null===(o=null===(i=this.shippingZoneCity)||void 0===i?void 0:i.districts)||void 0===o?void 0:o.length)&&(r=r.filter((function(t){var i,e;return null===(e=null===(i=s.shippingZoneCity)||void 0===i?void 0:i.districts)||void 0===e?void 0:e.some((function(i){return i.id===t.value}))}))),r.sort((function(t,i){return l(t.label,i.label)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"regionOptions",{get:function(){var t,i,e=(null===(i=null===(t=this.shippingZoneDistrict)||void 0===t?void 0:t.regions)||void 0===i?void 0:i.map(this.modelToOption))||[];return e.sort((function(t,i){return l(t.label,i.label)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"hasState",{get:function(){return this.states.length>1},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"isFreeTextCity",{get:function(){var t=this;return c.some((function(i){var e,o;return(null===(o=null===(e=t.address.country)||void 0===e?void 0:e.iso2)||void 0===o?void 0:o.toLowerCase())===i.toLowerCase()}))},enumerable:!1,configurable:!0}),Object.defineProperty(f.prototype,"isDistrictHidden",{get:function(){var t=this;return m.some((function(i){var e,o;return(null===(o=null===(e=t.address.country)||void 0===e?void 0:e.iso2)||void 0===o?void 0:o.toLowerCase())===i.toLowerCase()}))},enumerable:!1,configurable:!0}),f}();export{f as default};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t}from'./../../../../ext/tslib/tslib.es6.js';import*as n from"react";import{observer as o}from"mobx-react-lite";import a from"lodash/sortBy";import c from"../input-with-button/index.js";import r from"../notification-box/index.js";import{CheckoutStep as l}from"../../model.js";import{IkasStorefrontConfig as i}from"@ikas/storefront-config";import{formatCurrency as u}from"../../../../utils/currency.js";import{useTranslation as s}from"../../../../utils/i18n.js";import{CartItem as m}from"./cart-item/index.js";import{FormItem as d}from"../form-item/index.js";import{FormItemType as p}from"../form-item/model.js";import C from"../tooltip/index.js";import E from"../svg/arrow-down.js";import h from"../svg/cross.js";import f from"../svg/gift.js";import v from"../../styles/common.module.scss.js";import g from"./style.module.scss.js";import k from"../svg/ikas.js";import{Button as N}from"../button/index.js";import y from"../../../../hooks/useDimension.js";var S;!function(e){e.COUPON_CODE_NOT_EXIST="COUPON_CODE_NOT_EXIST",e.COUPON_CODE_NOT_EXIST_FOR_GUESS="COUPON_CODE_NOT_EXIST_FOR_GUESS"}(S||(S={}));var T=o((function(e){var t,o,a=e.vm,c=e.allowExpand,d=e.isSuccessPageSummary,p=a.checkout,C=s().t,h=n.useState(!c),f=h[0],v=h[1],N=n.useState(!1),T=N[0],P=N[1],w=n.useState(null),_=w[0],L=w[1],R=n.useState(0),D=R[0],A=R[1],M=n.useState(null),B=M[0],U=M[1],F=n.useState(!1),G=F[0],V=F[1],X=n.useState(!1),H=X[0],q=X[1],z=n.useState(!1),$=z[0],K=z[1];y().isMobile,n.useEffect((function(){c&&(f?B&&A(B.getBoundingClientRect().height):A(0))}),[f,B,c,G,H,T,$]);var Q=n.useMemo((function(){switch(_){case S.COUPON_CODE_NOT_EXIST:return C("checkout-page:giftCodeErrorDescription");case S.COUPON_CODE_NOT_EXIST_FOR_GUESS:return C("checkout-page:mustBeSignInToApplyCampaign");default:return""}}),[_]),W=[g.CartSummary,c?g.HideOnDesktop:"",d?g.SuccessPageCartSummary:""].join(" "),J=c?{height:D+"px"}:void 0,Y=[g.ArrowDown,f?g.Rotated:""].join(" ");return p?n.createElement(n.Fragment,null,!!c&&n.createElement(n.Fragment,null,n.createElement("div",{id:"checkout-mobile-summary-header"}),n.createElement("div",{className:g.ExpandHeader,onClick:function(){if(!f){var e=document.getElementById("Checkout"),t=document.getElementById("checkout-mobile-summary-header");e&&t&&e.scrollTo({top:t.offsetTop,behavior:"smooth"})}v(!f)}},n.createElement("div",{className:g.Left},C("checkout-page:summary")),n.createElement("div",{className:g.Price},n.createElement("span",{className:g.PriceText},"".concat(u(a.finalPrice||0,p.currencyCode,p.currencySymbol)," (").concat(p.itemQuantity," ").concat(C("checkout-page:cartItemProduct"),")")),n.createElement("span",{className:Y},n.createElement(E,null))))),n.createElement("div",{className:W},n.createElement("div",{className:[g.DetailsContainer,d?g.SuccessPageDetailContainer:""].join(" "),style:J},n.createElement("div",{className:g.Details,ref:U},n.createElement("div",{className:g.ItemsContainer},n.createElement("div",null,p.items.map((function(e,t){return n.createElement(m,{key:t,vm:a,cartItem:e,currencyCode:p.currencyCode,onChange:K,isSuccessPageSummary:d})})))),n.createElement("div",{className:g.Divider}),n.createElement("div",{className:g.SubTotalInfo},T&&n.createElement("div",{className:g.NotificationContainer},n.createElement(r,{type:"warning",title:C("checkout-page:giftCodeErrorTitle"),content:Q,onClose:function(){P(!1),L(null)}})),n.createElement(b,{label:C("checkout-page:subtotal"),value:p.formattedTotalPrice,tooltipText:C("checkout-page:subtotalTooltip"),hideMarginBottom:!a.isCouponCodeVisible}),!!(null===(t=p.shippingLines)||void 0===t?void 0:t.length)&&(a.step===l.SUCCESS?n.createElement(b,{label:C("checkout-page:cartShippingTitle"),value:p.shippingTotal?p.formattedShippingTotal:C("checkout-page:free")}):p.shippingLines.map((function(e,t){return n.createElement(b,{key:t,label:e.paymentMethod?e.title:C("checkout-page:cartShippingTitle"),value:e.finalPrice?u(e.finalPrice,p.currencyCode,p.currencySymbol):C("checkout-page:free")})}))),n.createElement(x,{vm:a}),n.createElement(O,{vm:a}),(a.step===l.SUCCESS&&(!!a.checkout.note||!!a.checkout.appliedCouponCode)||a.step!==l.SUCCESS)&&a.isCouponCodeVisible&&n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement(j,{vm:a,isAddingCoupon:H,setAddingCoupon:q,setCouponError:P,setCouponErrorCode:L}),n.createElement(I,{vm:a,isAddingNote:G,setAddingNote:V}),!!a.installmentExtraPrice&&n.createElement(n.Fragment,null,n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement(b,{label:C("checkout-page:cartInterest"),value:u(a.installmentExtraPrice,p.currencyCode,p.currencySymbol)}))),n.createElement("div",{className:[g.TotalContainer,d?g.SuccessPageTotalContainer:""].join(" ")},n.createElement("div",{className:g.TitleContainer},n.createElement("div",{className:g.Title},C("checkout-page:total"))),n.createElement("div",null,n.createElement("div",{className:g.TotalPricesContainer},n.createElement("div",{className:g.TotalPrice},u(a.finalPrice||0,p.currencyCode,p.currencySymbol)),!!p.$totalTax&&!!(null===(o=a.customizationProps)||void 0===o?void 0:o.showTax)&&n.createElement("div",{className:[g.TotalTax].join(" ")},C("checkout-page:cartTaxTitle")+" "+p.$formattedTotalTax)))),!d&&!a.isPoweredByHidden&&n.createElement("div",{className:g.PoweredBy},n.createElement("span",null,"powered by"),n.createElement("a",{href:"https://ikas.com"+("tr"===i.getCurrentLocale()?"/tr":""),target:"_blank"},n.createElement(k,null))))))):null})),b=o((function(e){var t=e.label,o=e.value,a=e.tooltipText,c=e.hideMarginBottom;return n.createElement("div",{className:[g.InfoRow,c?g.hideMb:""].join(" ")},n.createElement("div",{className:g.Label},n.createElement("span",null,t),!!a&&n.createElement(C,{text:a,style:{marginLeft:"8px"}})),n.createElement("div",{className:g.Value},o))})),x=o((function(e){var t=e.vm,o=s().t;return t.checkout?n.createElement(n.Fragment,null,a(t.checkout.nonCouponAdjustments||[],"order").map((function(e,a){return n.createElement("div",{className:g.InfoRow,key:a},n.createElement("div",{className:g.Label},"INTEREST"===e.name?o("checkout-page:cartInterest"):e.name),n.createElement("div",{className:g.Value},n.createElement("span",null,"DECREMENT"===e.type?"- ":"")," ",n.createElement("span",null,u(e.amount,t.checkout.currencyCode,t.checkout.currencySymbol))))}))):null})),O=o((function(e){var t,o=e.vm,a=s().t;return o.checkout?n.createElement(n.Fragment,null,null===(t=o.checkout.giftPackageLines)||void 0===t?void 0:t.map((function(e,t){return n.createElement("div",{className:g.InfoRow,key:t},n.createElement("div",{className:g.Label},n.createElement("div",{className:g.GiftLabel},n.createElement(f,{style:{position:"relative",top:"-1px"}}),n.createElement("span",null,a("checkout-page:giftPackage")))),n.createElement("div",{className:g.Value},n.createElement("span",null,u(e.price,o.checkout.currencyCode,o.checkout.currencySymbol))))}))):null})),j=o((function(o){var a=o.vm,r=o.isAddingCoupon,i=o.setAddingCoupon,u=o.setCouponError,m=o.setCouponErrorCode,C=o.isOpenCouponCode,E=o.isMobile,h=o.showOnlyMobile,f=s().t,k=n.useState(""),y=k[0],S=k[1],T=n.useState(!1),b=T[0],x=T[1],O=n.useRef(null);n.useEffect((function(){r&&O.current&&O.current.focus()}),[r]);var j=function(){return e(void 0,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return a.checkout.couponCode=y,x(!0),[4,a.onCouponCodeApply()];case 1:return t.sent(),x(!1),S(""),e=a.checkout.giftCardLines&&!!a.checkout.giftCardLines.length,a.couponError?[3,4]:a.checkout.appliedCouponCode||e?(u(!1),m(null),[4,a.reInitPaymentMethod()]):[3,3];case 2:t.sent(),t.label=3;case 3:return[3,5];case 4:a.checkout.couponCode=null,u(!0),m(a.couponError),t.label=5;case 5:return[2]}}))}))},I=function(n){return e(void 0,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return x(!0),[4,a.removeGiftCardLine(n)];case 1:return e.sent(),[4,a.reInitPaymentMethod()];case 2:return e.sent(),x(!1),[2]}}))}))};a.step,l.SUCCESS;var w=a.step===l.SHIPPING,_=!!a.checkout.appliedCouponCode||!!(a.checkout.giftCardLines&&a.checkout.giftCardLines.length>0),L=!!a.checkout.appliedCouponCode&&C,R=!r&&a.isCouponCodeVisible&&!a.isCouponCodeRequirementOpen&&a.step!==l.SUCCESS,D=_&&(!C||E);return n.createElement(n.Fragment,null,!!C&&n.createElement(n.Fragment,null,n.createElement("div",{className:[g.CartSummary,g.OpenCouponCodeSummary].join(" ")},n.createElement("div",{className:v.FormSectionTitle},n.createElement("div",{style:{paddingBottom:L?0:6},className:v.Title},f("checkout-page:couponCode"))))),_&&!w&&!a.isCouponCodeRequirementDefult&&n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement("div",{className:R?g.InfoRow:""},R&&n.createElement("div",{className:g.ActionTextBtn,onClick:function(){return i(!0)}},f("checkout-page:addCouponCode")),r&&!C&&n.createElement("div",{style:{marginBottom:"10px"}},n.createElement(c,{value:y,placeholder:f("checkout-page:couponCode"),buttonLabel:f("checkout-page:actions.apply"),inputRef:O,onClick:j,isLoading:b,onChange:S})),C&&n.createElement("div",{tabIndex:0,onKeyDown:function(e){"Enter"===e.key&&j()},className:[g.OpenCouponCodeMain,D?g.OpenCouponCodeMainWithMb:""].join(" ")},n.createElement(d,{label:f("checkout-page:couponCode"),type:p.TEXT,value:y,onChange:S}),n.createElement(N,{style:{width:"33%"},text:f("checkout-page:actions.apply"),isLoading:b,onClick:j}))),D&&n.createElement(n.Fragment,null,!!a.checkout.appliedCouponCode&&n.createElement("div",{className:[g.InfoRow,h?g.InfoRowGiftCardMobile:""].join(" ")},n.createElement(P,{vm:a,onClearCouponCode:function(){return e(void 0,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return a.checkout.couponCode=null,x(!0),[4,a.onCouponCodeApply()];case 1:return e.sent(),[4,a.reInitPaymentMethod()];case 2:return e.sent(),x(!1),[2]}}))}))},couponCode:a.checkout.appliedCouponCode})),!!a.checkout.giftCardLines&&!!a.checkout.giftCardLines.length&&a.checkout.giftCardLines.map((function(e){return n.createElement("div",{className:[g.InfoRow,h?g.InfoRowGiftCardMobile:""].join(" ")},n.createElement(P,{vm:a,onClearGiftCode:I,couponCode:e.code,giftCardLine:e}))}))))})),P=o((function(e){var t=e.vm,o=e.onClearCouponCode,a=e.couponCode,c=e.giftCardLine,r=e.onClearGiftCode,i=t.checkout.couponAdjustment,m=s().t;return n.createElement(n.Fragment,null,n.createElement("div",{className:[g.ActionTextBtn,g.NoUnderline,g.Light].join(" ")},m(c?"checkout-page:giftCode":"checkout-page:couponCode"),n.createElement("span",{className:[g.AppliedCoupon,t.isCouponCodeRequirementDefult?"":g.NotClosed].join(" ")},n.createElement("span",{className:g.CouponCode},a),t.step!==l.SUCCESS&&n.createElement("span",{className:g.ClearCoupon,onClick:function(){return c?r&&r(c.giftCardId):o&&o()}},n.createElement(h,null)))),n.createElement("div",null,c?n.createElement("div",{className:g.Value},n.createElement("span",null,"-")," ",n.createElement("span",null,u((null==c?void 0:c.amount)||0,t.checkout.currencyCode,t.checkout.currencySymbol))):n.createElement("div",{className:g.Value},n.createElement("span",null,"DECREMENT"===(null==i?void 0:i.type)?"- ":"")," ",n.createElement("span",null,u((null==i?void 0:i.amount)||0,t.checkout.currencyCode,t.checkout.currencySymbol)))))})),I=o((function(e){var t=e.vm,o=e.isAddingNote,a=e.setAddingNote,c=s().t,r=n.useState(t.checkout.note?c("checkout-page:editOrderNote"):c("checkout-page:addOrderNote"))[0],i=n.useCallback((function(){a(!0)}),[]),u=n.useCallback((function(e){t.checkout.note=e}),[t,t.checkout]);if(!t.checkoutSettings.showCheckoutNote)return null;var m=t.step===l.SUCCESS;return m&&!t.checkout.note?null:n.createElement("div",{className:g.InfoRow},!o&&!m&&n.createElement("div",{className:g.ActionTextBtn,onClick:i},r),(o||m)&&n.createElement("div",{className:[g.CheckoutNoteContainer,m?g.Success:""].join(" ")},n.createElement("div",{className:g.Title},c("checkout-page:orderNote")),m?n.createElement("div",{className:g.CheckoutNoteDisplay},t.checkout.note):n.createElement(d,{style:{width:"100%"},type:p.TEXT_AREA,disableResize:!0,label:"",value:t.checkout.note||"",onChange:u,maxLength:320})))}));export{T as CartSummary,j as Coupon,S as CouponErrorCode};
1
+ import{__awaiter as e,__generator as t}from'./../../../../ext/tslib/tslib.es6.js';import*as n from"react";import{observer as o}from"mobx-react-lite";import a from"lodash/sortBy";import c from"../input-with-button/index.js";import r from"../notification-box/index.js";import{CheckoutStep as l}from"../../model.js";import{IkasStorefrontConfig as i}from"@ikas/storefront-config";import{formatCurrency as u}from"../../../../utils/currency.js";import{useTranslation as s}from"../../../../utils/i18n.js";import{CartItem as m}from"./cart-item/index.js";import{FormItem as d}from"../form-item/index.js";import{FormItemType as p}from"../form-item/model.js";import C from"../tooltip/index.js";import E from"../svg/arrow-down.js";import h from"../svg/cross.js";import f from"../svg/gift.js";import v from"../../styles/common.module.scss.js";import g from"./style.module.scss.js";import k from"../svg/ikas.js";import{Button as N}from"../button/index.js";import y from"../../../../hooks/useDimension.js";var S;!function(e){e.COUPON_CODE_NOT_EXIST="COUPON_CODE_NOT_EXIST",e.COUPON_CODE_NOT_EXIST_FOR_GUESS="COUPON_CODE_NOT_EXIST_FOR_GUESS"}(S||(S={}));var T=o((function(e){var t,o,a=e.vm,c=e.allowExpand,d=e.isSuccessPageSummary,p=a.checkout,C=s().t,h=n.useState(!c),f=h[0],v=h[1],N=n.useState(!1),T=N[0],P=N[1],w=n.useState(null),_=w[0],L=w[1],R=n.useState(0),D=R[0],A=R[1],M=n.useState(null),B=M[0],U=M[1],F=n.useState(!1),G=F[0],V=F[1],X=n.useState(!1),H=X[0],q=X[1],z=n.useState(!1),$=z[0],K=z[1];y().isMobile,n.useEffect((function(){c&&(f?B&&A(B.getBoundingClientRect().height):A(0))}),[f,B,c,G,H,T,$]);var Q=n.useMemo((function(){switch(_){case S.COUPON_CODE_NOT_EXIST:return C("checkout-page:giftCodeErrorDescription");case S.COUPON_CODE_NOT_EXIST_FOR_GUESS:return C("checkout-page:mustBeSignInToApplyCampaign");default:return""}}),[_]),W=[g.CartSummary,c?g.HideOnDesktop:"",d?g.SuccessPageCartSummary:""].join(" "),J=c?{height:D+"px"}:void 0,Y=[g.ArrowDown,f?g.Rotated:""].join(" ");return p?n.createElement(n.Fragment,null,!!c&&n.createElement(n.Fragment,null,n.createElement("div",{id:"checkout-mobile-summary-header"}),n.createElement("div",{className:g.ExpandHeader,onClick:function(){if(!f){var e=document.getElementById("Checkout"),t=document.getElementById("checkout-mobile-summary-header");e&&t&&e.scrollTo({top:t.offsetTop,behavior:"smooth"})}v(!f)}},n.createElement("div",{className:g.Left},C("checkout-page:summary")),n.createElement("div",{className:g.Price},n.createElement("span",{className:g.PriceText},"".concat(u(a.finalPrice||0,p.currencyCode,p.currencySymbol)," (").concat(p.itemQuantity," ").concat(C("checkout-page:cartItemProduct"),")")),n.createElement("span",{className:Y},n.createElement(E,null))))),n.createElement("div",{className:W},n.createElement("div",{className:[g.DetailsContainer,d?g.SuccessPageDetailContainer:""].join(" "),style:J},n.createElement("div",{className:g.Details,ref:U},n.createElement("div",{className:g.ItemsContainer},n.createElement("div",null,p.items.map((function(e,t){return n.createElement(m,{key:t,vm:a,cartItem:e,currencyCode:p.currencyCode,onChange:K,isSuccessPageSummary:d})})))),n.createElement("div",{className:g.Divider}),n.createElement("div",{className:g.SubTotalInfo},T&&n.createElement("div",{className:g.NotificationContainer},n.createElement(r,{type:"warning",title:C("checkout-page:giftCodeErrorTitle"),content:Q,onClose:function(){P(!1),L(null)}})),n.createElement(b,{label:C("checkout-page:subtotal"),value:p.formattedTotalPrice,tooltipText:C("checkout-page:subtotalTooltip"),hideMarginBottom:!a.isCouponCodeVisible}),!!(null===(t=p.shippingLines)||void 0===t?void 0:t.length)&&(a.step===l.SUCCESS?n.createElement(b,{label:C("checkout-page:cartShippingTitle"),value:p.shippingTotal?p.formattedShippingTotal:C("checkout-page:free")}):p.shippingLines.map((function(e,t){return n.createElement(b,{key:t,label:e.paymentMethod?e.title:C("checkout-page:cartShippingTitle"),value:e.finalPrice?u(e.finalPrice,p.currencyCode,p.currencySymbol):C("checkout-page:free")})}))),n.createElement(x,{vm:a}),n.createElement(O,{vm:a}),(a.step===l.SUCCESS&&(!!a.checkout.note||!!a.checkout.appliedCouponCode)||a.step!==l.SUCCESS)&&a.isCouponCodeVisible&&n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement(j,{vm:a,isAddingCoupon:H,setAddingCoupon:q,setCouponError:P,setCouponErrorCode:L}),n.createElement(I,{vm:a,isAddingNote:G,setAddingNote:V}),!!a.installmentExtraPrice&&n.createElement(n.Fragment,null,n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement(b,{label:C("checkout-page:cartInterest"),value:u(a.installmentExtraPrice,p.currencyCode,p.currencySymbol)}))),n.createElement("div",{className:[g.TotalContainer,d?g.SuccessPageTotalContainer:""].join(" ")},n.createElement("div",{className:g.TitleContainer},n.createElement("div",{className:g.Title},C("checkout-page:total"))),n.createElement("div",null,n.createElement("div",{className:g.TotalPricesContainer},n.createElement("div",{className:g.TotalPrice},u(a.finalPrice||0,p.currencyCode,p.currencySymbol)),!!p.$totalTax&&!!(null===(o=a.customizationProps)||void 0===o?void 0:o.showTax)&&n.createElement("div",{className:[g.TotalTax].join(" ")},C("checkout-page:cartTaxTitle")+" "+p.$formattedTotalTax)))),!d&&!a.isPoweredByHidden&&n.createElement("div",{className:g.PoweredBy},n.createElement("span",null,"powered by"),n.createElement("a",{href:"https://ikas.com"+("tr"===i.getCurrentLocale()?"/tr":""),target:"_blank"},n.createElement(k,null))))))):null})),b=o((function(e){var t=e.label,o=e.value,a=e.tooltipText,c=e.hideMarginBottom;return n.createElement("div",{className:[g.InfoRow,c?g.hideMb:""].join(" ")},n.createElement("div",{className:g.Label},n.createElement("span",null,t),!!a&&n.createElement(C,{text:a,style:{marginLeft:"8px"}})),n.createElement("div",{className:g.Value},o))})),x=o((function(e){var t=e.vm,o=s().t;return t.checkout?n.createElement(n.Fragment,null,a(t.checkout.nonCouponAdjustments||[],"order").map((function(e,a){return n.createElement("div",{className:g.InfoRow,key:a},n.createElement("div",{className:g.Label},"INTEREST"===e.name?o("checkout-page:cartInterest"):e.name),n.createElement("div",{className:g.Value},n.createElement("span",null,"DECREMENT"===e.type?"- ":"")," ",n.createElement("span",null,u(e.amount,t.checkout.currencyCode,t.checkout.currencySymbol))))}))):null})),O=o((function(e){var t,o=e.vm,a=s().t;return o.checkout?n.createElement(n.Fragment,null,null===(t=o.checkout.giftPackageLines)||void 0===t?void 0:t.map((function(e,t){return n.createElement("div",{className:g.InfoRow,key:t},n.createElement("div",{className:g.Label},n.createElement("div",{className:g.GiftLabel},n.createElement(f,{style:{position:"relative",top:"-1px"}}),n.createElement("span",null,a("checkout-page:giftPackage")))),n.createElement("div",{className:g.Value},n.createElement("span",null,u(e.price,o.checkout.currencyCode,o.checkout.currencySymbol))))}))):null})),j=o((function(o){var a=o.vm,r=o.isAddingCoupon,i=o.setAddingCoupon,u=o.setCouponError,m=o.setCouponErrorCode,C=o.isOpenCouponCode,E=o.isMobile,h=o.showOnlyMobile,f=s().t,k=n.useState(""),y=k[0],S=k[1],T=n.useState(!1),b=T[0],x=T[1],O=n.useRef(null);n.useEffect((function(){r&&O.current&&O.current.focus()}),[r]);var j=function(){return e(void 0,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return a.checkout.couponCode=y,x(!0),[4,a.onCouponCodeApply()];case 1:return t.sent(),x(!1),S(""),e=a.checkout.giftCardLines&&!!a.checkout.giftCardLines.length,a.couponError?[3,4]:a.checkout.appliedCouponCode||e?(u(!1),m(null),[4,a.reInitPaymentMethod()]):[3,3];case 2:t.sent(),t.label=3;case 3:return[3,5];case 4:a.checkout.couponCode=null,u(!0),m(a.couponError),t.label=5;case 5:return[2]}}))}))},I=function(n){return e(void 0,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return x(!0),[4,a.removeGiftCardLine(n)];case 1:return e.sent(),[4,a.reInitPaymentMethod()];case 2:return e.sent(),x(!1),[2]}}))}))};a.step,l.SUCCESS;var w=a.step===l.SHIPPING,_=!!a.checkout.appliedCouponCode||!!(a.checkout.giftCardLines&&a.checkout.giftCardLines.length>0),L=!!a.checkout.appliedCouponCode&&C,R=!r&&a.isCouponCodeVisible&&!a.isCouponCodeRequirementOpen&&a.step!==l.SUCCESS,D=_&&(!C||E);return n.createElement(n.Fragment,null,!!C&&n.createElement(n.Fragment,null,n.createElement("div",{className:[g.CartSummary,g.OpenCouponCodeSummary].join(" ")},n.createElement("div",{className:v.FormSectionTitle},n.createElement("div",{style:{paddingBottom:L?0:6},className:v.Title},f("checkout-page:couponCode"))))),_&&!w&&!a.isCouponCodeRequirementDefult&&n.createElement("div",{className:g.Divider,style:{marginTop:"24px",marginBottom:"24px"}}),n.createElement("div",{className:R?g.InfoRow:""},R&&n.createElement("div",{className:g.ActionTextBtn,onClick:function(){return i(!0)}},f("checkout-page:addCouponCode")),r&&!C&&n.createElement("div",{style:{marginBottom:"10px"}},n.createElement(c,{value:y,placeholder:f("checkout-page:couponCode"),buttonLabel:f("checkout-page:actions.apply"),inputRef:O,onClick:j,isLoading:b,onChange:S})),C&&n.createElement("div",{tabIndex:0,onKeyDown:function(e){"Enter"===e.key&&j()},className:[g.OpenCouponCodeMain,D?g.OpenCouponCodeMainWithMb:""].join(" ")},n.createElement(d,{label:f("checkout-page:addCouponCode"),type:p.TEXT,value:y,onChange:S}),n.createElement(N,{style:{width:"33%"},text:f("checkout-page:actions.apply"),isLoading:b,onClick:j}))),D&&n.createElement(n.Fragment,null,!!a.checkout.appliedCouponCode&&n.createElement("div",{className:[g.InfoRow,h?g.InfoRowGiftCardMobile:""].join(" ")},n.createElement(P,{vm:a,onClearCouponCode:function(){return e(void 0,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return a.checkout.couponCode=null,x(!0),[4,a.onCouponCodeApply()];case 1:return e.sent(),[4,a.reInitPaymentMethod()];case 2:return e.sent(),x(!1),[2]}}))}))},couponCode:a.checkout.appliedCouponCode})),!!a.checkout.giftCardLines&&!!a.checkout.giftCardLines.length&&a.checkout.giftCardLines.map((function(e){return n.createElement("div",{className:[g.InfoRow,h?g.InfoRowGiftCardMobile:""].join(" ")},n.createElement(P,{vm:a,onClearGiftCode:I,couponCode:e.code,giftCardLine:e}))}))))})),P=o((function(e){var t=e.vm,o=e.onClearCouponCode,a=e.couponCode,c=e.giftCardLine,r=e.onClearGiftCode,i=t.checkout.couponAdjustment,m=s().t;return n.createElement(n.Fragment,null,n.createElement("div",{className:[g.ActionTextBtn,g.NoUnderline,g.Light].join(" ")},m(c?"checkout-page:giftCode":"checkout-page:couponCode"),n.createElement("span",{className:[g.AppliedCoupon,t.isCouponCodeRequirementDefult?"":g.NotClosed].join(" ")},n.createElement("span",{className:g.CouponCode},a),t.step!==l.SUCCESS&&n.createElement("span",{className:g.ClearCoupon,onClick:function(){return c?r&&r(c.giftCardId):o&&o()}},n.createElement(h,null)))),n.createElement("div",null,c?n.createElement("div",{className:g.Value},n.createElement("span",null,"-")," ",n.createElement("span",null,u((null==c?void 0:c.amount)||0,t.checkout.currencyCode,t.checkout.currencySymbol))):n.createElement("div",{className:g.Value},n.createElement("span",null,"DECREMENT"===(null==i?void 0:i.type)?"- ":"")," ",n.createElement("span",null,u((null==i?void 0:i.amount)||0,t.checkout.currencyCode,t.checkout.currencySymbol)))))})),I=o((function(e){var t=e.vm,o=e.isAddingNote,a=e.setAddingNote,c=s().t,r=n.useState(t.checkout.note?c("checkout-page:editOrderNote"):c("checkout-page:addOrderNote"))[0],i=n.useCallback((function(){a(!0)}),[]),u=n.useCallback((function(e){t.checkout.note=e}),[t,t.checkout]);if(!t.checkoutSettings.showCheckoutNote)return null;var m=t.step===l.SUCCESS;return m&&!t.checkout.note?null:n.createElement("div",{className:g.InfoRow},!o&&!m&&n.createElement("div",{className:g.ActionTextBtn,onClick:i},r),(o||m)&&n.createElement("div",{className:[g.CheckoutNoteContainer,m?g.Success:""].join(" ")},n.createElement("div",{className:g.Title},c("checkout-page:orderNote")),m?n.createElement("div",{className:g.CheckoutNoteDisplay},t.checkout.note):n.createElement(d,{style:{width:"100%"},type:p.TEXT_AREA,disableResize:!0,label:"",value:t.checkout.note||"",onChange:u,maxLength:320})))}));export{T as CartSummary,j as Coupon,S as CouponErrorCode};
@@ -1 +1 @@
1
- import{__awaiter as t,__generator as e,__assign as r}from'./../../ext/tslib/tslib.es6.js';import*as n from"react";import{observer as o}from"mobx-react-lite";import{IkasBaseStore as i}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import a from"../../store/checkout/index.js";import{IkasStorefrontConfig as u}from"@ikas/storefront-config";import{getStorefrontSettings as s}from"@ikas/storefront-api";var c=o((function(o){var c=o.product,l=o.errorMessage,d=o.quantity,p=void 0===d?1:d,f=i.getInstance(),v=f.customerStore.customer,h=n.useState(""),m=h[0],g=h[1],y=n.useState(!1),w=y[0],b=y[1],S=n.useState(null),I=S[0],P=S[1],C=n.useRef(null),E=n.useRef(null),U=n.useRef(null),j=n.useRef(null),R=function(t){U.current=t};n.useEffect((function(){t(void 0,void 0,void 0,(function(){var t,r,n;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,a.getPayPalClientId({})];case 1:return t=e.sent(),g((null===(n=t.data)||void 0===n?void 0:n.clientId)||""),[3,3];case 2:return r=e.sent(),console.error("Error fetching Client ID:",r),[3,3];case 3:return[2]}}))}))}),[c]),n.useEffect((function(){t(void 0,void 0,void 0,(function(){var t,r,n,o;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,s()];case 1:return t=e.sent(),(null===(n=t.data)||void 0===n?void 0:n.paypalSettings)&&P(null===(o=t.data)||void 0===o?void 0:o.paypalSettings),[3,3];case 2:return r=e.sent(),console.error("getStorefrontSettings error",r),[3,3];case 3:return[2]}}))}))}),[]);var A=function(n){return t(void 0,void 0,void 0,(function(){var t,o,i;return e(this,(function(e){switch(e.label){case 0:return t=C.current,o=U.current,t&&o?(i=E.current,[4,a.updatePaypalOrder({input:r(r({cartId:o,transactionId:t,customer:v?{email:v.email,firstName:v.firstName,id:v.id,lastName:v.lastName}:null,address:i?{city:i.city,country:i.countryCode,postalCode:i.postalCode,state:i.state}:null},n.shippingSettingsId?{shippingSettingsId:n.shippingSettingsId}:{}),n.shippingZoneRateId?{shippingZoneRateId:n.shippingZoneRateId}:{})})]):[2,!1];case 1:return[2,!!e.sent().data]}}))}))},k=function(t){if(I)return I.find((function(e){return e.label===t}))};return n.useEffect((function(){if(m&&I){var n=k("productPageBuyButton");if(!n||"disabled"!==n.value){var o=document.querySelector("#paypal-button-container");o&&(o.innerHTML="");var i=document.querySelector('script[src^="https://www.paypal.com/sdk/js"]');i&&document.body.removeChild(i);var s=k("productColor"),l=k("productShape"),d=k("productLabel"),v=k("productTagline"),h=document.createElement("script");return h.src="https://www.paypal.com/sdk/js?client-id=".concat(m,"&currency=").concat(c.selectedVariant.price.currency,"&disable-funding=credit,card"),h.setAttribute("data-page-type","product-details"),h.addEventListener("load",(function(){window.paypal&&window.paypal.Buttons({style:r(r(r(r({},s?{color:null==s?void 0:s.value}:{}),l?{shape:null==l?void 0:l.value}:{}),d?{label:null==d?void 0:d.value}:{}),v?{tagline:"true"===(null==v?void 0:v.value)}:{}),onClick:function(r,n){return t(void 0,void 0,void 0,(function(){return e(this,(function(r){switch(r.label){case 0:return[4,t(void 0,void 0,void 0,(function(){return e(this,(function(t){if(f.cartStore.cart)try{f.cartStore.removeCart()}catch(t){console.error("Error removing items:",t)}return[2]}))}))];case 1:return r.sent(),[2,n.resolve()]}}))}))},createOrder:function(){return t(void 0,void 0,void 0,(function(){var r,n,o,i,s;return e(this,(function(l){switch(l.label){case 0:return[4,t(void 0,void 0,void 0,(function(){var t,r,n,o,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,f.cartStore.addItem(c.selectedVariant,c,p)];case 1:return t=e.sent(),(null===(i=null===(o=t.response)||void 0===o?void 0:o.data)||void 0===i?void 0:i.id)?(r=t.response.data,R(r.id),[2,r.id]):[2,null];case 2:return n=e.sent(),console.log("err",n),[2,null];case 3:return[2]}}))}))];case 1:return l.sent(),[4,t(void 0,void 0,void 0,(function(){var t,r,n,o,i,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=u.getPaymentGateways().map((function(t){return t.id})),(r=U.current)?[4,a.listPaymentGateway({cartId:r,id:{in:t},locale:u.getCurrentLocale(),transactionAmount:c.selectedVariant.finalPrice})]:[2,null];case 1:return n=e.sent(),[2,(null===(s=null===(i=n.data)||void 0===i?void 0:i.find((function(t){return"PAYPAL"===t.code})))||void 0===s?void 0:s.id)||null];case 2:return o=e.sent(),console.error("Error fetching PayPal ID:",o),[2,null];case 3:return[2]}}))}))];case 2:return r=l.sent(),(n=U.current)&&r?[4,a.createPayPalOrder({input:{cartId:n,paymentGatewayId:r},isPayNow:!0})]:[3,4];case 3:return o=l.sent(),b(!1),R(n),(null===(i=o.data)||void 0===i?void 0:i.transactionId)&&(v=o.data.transactionId,C.current=v,d={failUrl:o.data.failUrl,returnUrl:o.data.returnUrl},j.current={failUrl:d.failUrl,returnUrl:d.returnUrl}),[2,null===(s=o.data)||void 0===s?void 0:s.sessionToken];case 4:console.log("err"),l.label=5;case 5:return[2]}var d,v}))}))},onShippingOptionsChange:function(r,n){return t(this,void 0,void 0,(function(){var t,o,i;return e(this,(function(e){switch(e.label){case 0:return console.log("selectedShippingOption",r),t=r.selectedShippingOption.id.split(":"),o=t[0],i=t[1],[4,A({shippingSettingsId:o,shippingZoneRateId:i})];case 1:return e.sent()?[2]:[2,n.reject()]}}))}))},onShippingAddressChange:function(r,n){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return console.log("SHIPPING_ADDRESS",r),function(t){E.current=t}(r.shippingAddress),[4,A({})];case 1:return t.sent()?[2]:[2,n.reject()]}}))}))},onApprove:function(r,n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,n.order.capture().then((function(t){console.log("data",r),console.log("details",t),console.log("urls",j),j.current&&(console.log("burda"),"COMPLETED"===t.status?window.location.href=j.current.returnUrl:window.location.href=window.location.href=j.current.failUrl)})).catch((function(t){return b(!0)}))]}))}))},onError:function(t){console.error("PayPal button error:",t)}}).render("#paypal-button-container")})),document.body.appendChild(h),function(){document.body.removeChild(h)}}}}),[m,c.id,I]),n.createElement("div",null,n.createElement("div",{id:"paypal-button-container"}),!!w&&!!l&&n.createElement("div",{className:"paypal__error__message"},l))}));export{c as PaypalExpressCheckout};
1
+ import{__awaiter as t,__generator as e,__assign as r}from'./../../ext/tslib/tslib.es6.js';import*as n from"react";import{observer as o}from"mobx-react-lite";import{IkasBaseStore as i}from"../../store/base.js";import"../../store/customer/index.js";import"../../store/cart/index.js";import a from"../../store/checkout/index.js";import{IkasStorefrontConfig as u}from"@ikas/storefront-config";import{getStorefrontSettings as s}from"@ikas/storefront-api";var c=o((function(o){var c=o.product,l=o.errorMessage,d=o.quantity,p=void 0===d?1:d,f=i.getInstance(),v=f.customerStore.customer,h=n.useState(""),m=h[0],g=h[1],y=n.useState(!1),w=y[0],b=y[1],S=n.useState(null),I=S[0],P=S[1],C=n.useRef(null),E=n.useRef(null),U=n.useRef(null),j=n.useRef(null),R=function(t){U.current=t};n.useEffect((function(){t(void 0,void 0,void 0,(function(){var t,r,n;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,a.getPayPalClientId({})];case 1:return t=e.sent(),g((null===(n=t.data)||void 0===n?void 0:n.clientId)||""),[3,3];case 2:return r=e.sent(),console.error("Error fetching Client ID:",r),[3,3];case 3:return[2]}}))}))}),[c]),n.useEffect((function(){t(void 0,void 0,void 0,(function(){var t,r,n,o;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,s()];case 1:return t=e.sent(),(null===(n=t.data)||void 0===n?void 0:n.paypalSettings)&&P(null===(o=t.data)||void 0===o?void 0:o.paypalSettings),[3,3];case 2:return r=e.sent(),console.error("getStorefrontSettings error",r),[3,3];case 3:return[2]}}))}))}),[]);var A=function(n){return t(void 0,void 0,void 0,(function(){var t,o,i;return e(this,(function(e){switch(e.label){case 0:return t=C.current,o=U.current,t&&o?(i=E.current,[4,a.updatePaypalOrder({input:r(r({cartId:o,transactionId:t,customer:v?{email:v.email,firstName:v.firstName,id:v.id,lastName:v.lastName}:null,address:i?{city:i.city,country:i.countryCode,postalCode:i.postalCode,state:i.state}:null},n.shippingSettingsId?{shippingSettingsId:n.shippingSettingsId}:{}),n.shippingZoneRateId?{shippingZoneRateId:n.shippingZoneRateId}:{})})]):[2,!1];case 1:return[2,!!e.sent().data]}}))}))},k=function(t){if(I)return I.find((function(e){return e.label===t}))};return n.useEffect((function(){if(m&&I){var n=k("productPageBuyButton");if(!n||"disabled"!==n.value){var o=document.querySelector("#paypal-button-container");o&&(o.innerHTML="");var i=document.querySelector('script[src^="https://www.paypal.com/sdk/js"]');i&&document.body.removeChild(i);var s=k("productColor"),l=k("productShape"),d=k("productLabel"),v=k("productTagline"),h=document.createElement("script");return h.src="https://www.paypal.com/sdk/js?client-id=".concat(m,"&currency=").concat(c.selectedVariant.price.currency,"&disable-funding=credit,card"),h.setAttribute("data-page-type","product-details"),h.addEventListener("load",(function(){window.paypal&&window.paypal.Buttons({style:r(r(r(r({layout:"horizontal"},s?{color:null==s?void 0:s.value}:{}),l?{shape:null==l?void 0:l.value}:{}),d?{label:null==d?void 0:d.value}:{}),v?{tagline:"true"===(null==v?void 0:v.value)}:{}),onClick:function(r,n){return t(void 0,void 0,void 0,(function(){return e(this,(function(r){switch(r.label){case 0:return[4,t(void 0,void 0,void 0,(function(){return e(this,(function(t){if(f.cartStore.cart)try{f.cartStore.removeCart()}catch(t){console.error("Error removing items:",t)}return[2]}))}))];case 1:return r.sent(),[2,n.resolve()]}}))}))},createOrder:function(){return t(void 0,void 0,void 0,(function(){var r,n,o,i,s;return e(this,(function(l){switch(l.label){case 0:return[4,t(void 0,void 0,void 0,(function(){var t,r,n,o,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,f.cartStore.addItem(c.selectedVariant,c,p)];case 1:return t=e.sent(),(null===(i=null===(o=t.response)||void 0===o?void 0:o.data)||void 0===i?void 0:i.id)?(r=t.response.data,R(r.id),[2,r.id]):[2,null];case 2:return n=e.sent(),console.log("err",n),[2,null];case 3:return[2]}}))}))];case 1:return l.sent(),[4,t(void 0,void 0,void 0,(function(){var t,r,n,o,i,s;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),t=u.getPaymentGateways().map((function(t){return t.id})),(r=U.current)?[4,a.listPaymentGateway({cartId:r,id:{in:t},locale:u.getCurrentLocale(),transactionAmount:c.selectedVariant.finalPrice})]:[2,null];case 1:return n=e.sent(),[2,(null===(s=null===(i=n.data)||void 0===i?void 0:i.find((function(t){return"PAYPAL"===t.code})))||void 0===s?void 0:s.id)||null];case 2:return o=e.sent(),console.error("Error fetching PayPal ID:",o),[2,null];case 3:return[2]}}))}))];case 2:return r=l.sent(),(n=U.current)&&r?[4,a.createPayPalOrder({input:{cartId:n,paymentGatewayId:r},isPayNow:!0})]:[3,4];case 3:return o=l.sent(),b(!1),R(n),(null===(i=o.data)||void 0===i?void 0:i.transactionId)&&(v=o.data.transactionId,C.current=v,d={failUrl:o.data.failUrl,returnUrl:o.data.returnUrl},j.current={failUrl:d.failUrl,returnUrl:d.returnUrl}),[2,null===(s=o.data)||void 0===s?void 0:s.sessionToken];case 4:console.log("err"),l.label=5;case 5:return[2]}var d,v}))}))},onShippingOptionsChange:function(r,n){return t(this,void 0,void 0,(function(){var t,o,i;return e(this,(function(e){switch(e.label){case 0:return console.log("selectedShippingOption",r),t=r.selectedShippingOption.id.split(":"),o=t[0],i=t[1],[4,A({shippingSettingsId:o,shippingZoneRateId:i})];case 1:return e.sent()?[2]:[2,n.reject()]}}))}))},onShippingAddressChange:function(r,n){return t(this,void 0,void 0,(function(){return e(this,(function(t){switch(t.label){case 0:return console.log("SHIPPING_ADDRESS",r),function(t){E.current=t}(r.shippingAddress),[4,A({})];case 1:return t.sent()?[2]:[2,n.reject()]}}))}))},onApprove:function(r,n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,n.order.capture().then((function(t){console.log("data",r),console.log("details",t),console.log("urls",j),j.current&&(console.log("burda"),"COMPLETED"===t.status?window.location.href=j.current.returnUrl:window.location.href=window.location.href=j.current.failUrl)})).catch((function(t){return b(!0)}))]}))}))},onError:function(t){console.error("PayPal button error:",t)}}).render("#paypal-button-container")})),document.body.appendChild(h),function(){document.body.removeChild(h)}}}}),[m,c.id,I]),n.createElement("div",null,n.createElement("div",{id:"paypal-button-container"}),!!w&&!!l&&n.createElement("div",{className:"paypal__error__message"},l))}));export{c as PaypalExpressCheckout};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "6.1.0-beta.73",
3
+ "version": "6.1.0-beta.74",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -21,11 +21,11 @@
21
21
  "swiper": "11.0.6"
22
22
  },
23
23
  "devDependencies": {
24
- "@ikas/storefront-api": "^6.1.0-beta.73",
25
- "@ikas/storefront-config": "^6.1.0-beta.73",
26
- "@ikas/storefront-model-functions": "^6.1.0-beta.73",
27
- "@ikas/storefront-models": "^6.1.0-beta.73",
28
- "@ikas/storefront-providers": "^6.1.0-beta.73",
24
+ "@ikas/storefront-api": "^6.1.0-beta.74",
25
+ "@ikas/storefront-config": "^6.1.0-beta.74",
26
+ "@ikas/storefront-model-functions": "^6.1.0-beta.74",
27
+ "@ikas/storefront-models": "^6.1.0-beta.74",
28
+ "@ikas/storefront-providers": "^6.1.0-beta.74",
29
29
  "@ikas/localized-address": "1.0.0-beta.6",
30
30
  "@adyen/adyen-web": "^5.57.0",
31
31
  "@rollup/plugin-commonjs": "^22.0.0",
@@ -60,11 +60,11 @@
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@ikas/localized-address": "1.0.0-beta.6",
63
- "@ikas/storefront-api": "^6.1.0-beta.73",
64
- "@ikas/storefront-config": "^6.1.0-beta.73",
65
- "@ikas/storefront-model-functions": "^6.1.0-beta.73",
66
- "@ikas/storefront-models": "^6.1.0-beta.73",
67
- "@ikas/storefront-providers": "^6.1.0-beta.73",
63
+ "@ikas/storefront-api": "^6.1.0-beta.74",
64
+ "@ikas/storefront-config": "^6.1.0-beta.74",
65
+ "@ikas/storefront-model-functions": "^6.1.0-beta.74",
66
+ "@ikas/storefront-models": "^6.1.0-beta.74",
67
+ "@ikas/storefront-providers": "^6.1.0-beta.74",
68
68
  "mobx": "^6.1.3",
69
69
  "mobx-react-lite": "^3.1.5",
70
70
  "next": "12.2.0",