@ikas/storefront 4.2.0-beta.11 → 4.2.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/checkout/components/address-form/index.js +1 -1
- package/build/models/data/checkout/country-settings-model.d.ts +14 -14
- package/build/models/data/checkout/country-settings-model.js +1 -1
- package/build/models/ui/validator/form/ikas-address.d.ts +2 -0
- package/build/models/ui/validator/form/ikas-address.js +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__assign as e}from'./../../../../ext/tslib/tslib.es6.js';import*as r from"react";import{observer as t}from"mobx-react-lite";import{IkasCheckoutRequirement as a}from"@ikas/storefront-models";import{FormItem as o}from"../form-item/index.js";import{FormItemType as n,FormItemInputMode as s}from"../form-item/model.js";import l from"./model.js";import{Checkbox as i}from"../checkbox/index.js";import"@ikas/storefront-config";import{useTranslation as d}from"../../../../utils/i18n.js";import{AddressFormItem as c}from"../../../../models/data/checkout/country-settings-model.js";import u from"../../styles/common.module.scss.js";import m from"../../style.module.scss.js";var v=t((function(t){var a=r.useMemo((function(){return new l(e({},t))}),[]);return r.useEffect((function(){Object.entries(t).forEach((function(e){a[e[0]]=e[1]}))}),Object.values(t)),"in-store"===t.deliveryMethod?r.createElement(E,{props:t,vm:a}):r.createElement(p,{props:t,vm:a})})),E=t((function(t){var o=t.props,n=t.vm;return d().t,r.createElement("div",null,r.createElement("div",{className:[u.Grid,u.Grid2].join(" ")},r.createElement(h,e({},o,{vm:n})),r.createElement(f,e({},o,{vm:n})),r.createElement("div",null)," "),!!n.address.checkoutSettings&&n.address.checkoutSettings.phoneRequirement!==a.INVISIBLE&&r.createElement("div",{className:m.RowPB},r.createElement(O,e({},o,{vm:n})),r.createElement("div",null)," "))})),p=t((function(t){var a,o,n,s=t.props,l=t.vm,v=d().t,E=function(t){switch(t){case c.FIRSTNAME:return r.createElement(h,e({},s,{vm:l}));case c.LASTNAME:return r.createElement(f,e({},s,{vm:l}));case c.IDENTITY_NUMBER:return r.createElement(g,e({},s,{vm:l}));case c.ADDRESS_LINE_1:return r.createElement(T,e({},s,{vm:l}));case c.ADDRESS_LINE_2:return r.createElement(b,e({},s,{vm:l}));case c.POSTAL_CODE:return r.createElement(y,e({},s,{vm:l}));case c.COUNTRY:return r.createElement(N,e({},s,{vm:l}));case c.STATE:return r.createElement(L,e({},s,{vm:l}));case c.CITY:return l.address.isFreeTextCity?r.createElement(x,e({},s,{vm:l})):r.createElement(k,e({},s,{vm:l}));case c.DISTRICT:return l.address.isFreeTextDistrict?r.createElement(I,e({},s,{vm:l})):r.createElement(R,e({},s,{vm:l}));case c.PHONE:return r.createElement(O,e({},s,{vm:l}));case c.COMPANY:return r.createElement(S,e({},s,{vm:l}));case c.TAX_NUMBER:return r.createElement(A,e({},s,{vm:l}));case c.TAX_OFFICE:return r.createElement(j,e({},s,{vm:l}));default:return null}},p=function(e){return r.createElement(r.Fragment,null,1===e.length&&r.createElement("div",{className:m.RowPB},e.map((function(e){return E(e)}))),2===e.length&&r.createElement("div",{className:[u.Grid,u.Grid2].join(" ")},e.map((function(e){return E(e)})),r.createElement("div",null)," "),3===e.length&&r.createElement("div",{className:[u.Grid,u.Grid2,u.Grid3].join(" ")},e.map((function(e){return E(e)})),r.createElement("div",null)," "))};return r.createElement("div",null,l.allowTitleChange&&r.createElement("div",{className:m.RowPB},r.createElement(C,e({},s,{vm:l}))),l.countryOptions.length<=1?null===(a=l.address.addressFormatIgnoreCountry)||void 0===a?void 0:a.map((function(e){return p(e)})):null===(o=l.address.addressFormat)||void 0===o?void 0:o.map((function(e){return p(e)})),!!l.allowCorporateInfo&&r.createElement("div",{style:{marginTop:"12px"}},r.createElement(i,{value:l.isCorporate,label:v("checkout-page:corporateInvoice"),onChange:l.onCorporateChange})),!!l.isCorporate&&(null===(n=l.address.billingFormat)||void 0===n?void 0:n.map((function(e){return p(e)}))))})),h=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.firstName)||l("checkout-page:firstName"),autocomplete:"given-name",value:s.firstName||"",onChange:s.onFirstNameChange,hasError:s.isErrorsVisible&&(null===(a=s.address.validationResults)||void 0===a?void 0:a.firstName.hasError),errorText:l("checkout-page:firstNameError")})})),f=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.lastName)||l("checkout-page:lastName"),autocomplete:"family-name",value:s.lastName||"",onChange:s.onLastNameChange,hasError:s.isErrorsVisible&&(null===(a=s.address.validationResults)||void 0===a?void 0:a.lastName.hasError),errorText:l("checkout-page:lastNameError")})})),g=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.identityNumber)||l("checkout-page:identityNumber"),value:s.identityNumber||"",onChange:s.onIdentityNumberChange,hasError:s.isErrorsVisible&&(null===(a=s.address.validationResults)||void 0===a?void 0:a.identityNumber.hasError),errorText:l("checkout-page:identityNumberError")})})),C=t((function(e){var t=e.vm,a=d().t,s=t.address;return r.createElement(o,{type:n.TEXT,label:a("checkout-page:addressTitle"),value:s.title||"",onChange:t.onAddressTitleChange,hasError:t.isErrorsVisible&&!s.title,errorText:a("checkout-page:addressTitleError")})})),T=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.addressLine1)||l("checkout-page:addressLine1"),autocomplete:"address-line1",value:s.address.addressLine1||"",onChange:s.onAddressLine1Change,hasError:s.isErrorsVisible&&(null===(a=s.address.validationResults)||void 0===a?void 0:a.addressLine1.hasError),errorText:l("checkout-page:addressError")})})),b=t((function(e){var t,a=e.vm,s=d().t;return r.createElement(o,{type:n.TEXT,autocomplete:"address-line2",label:(null===(t=a.address.fieldLabels)||void 0===t?void 0:t.addressLine2)||s("checkout-page:addressLine2"),value:a.address.addressLine2||"",onChange:a.onAddressLine2Change})})),y=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.postalCode)||l("checkout-page:postalCode"),autocomplete:"postal-code",value:s.address.postalCode||"",onChange:s.onAddressPostalCodeChange,hasError:s.isErrorsVisible&&(null===(a=s.address.validationResults)||void 0===a?void 0:a.postalCode.hasError),errorText:l("checkout-page:postalCodeError")})})),N=t((function(e){var t,a,s,l=e.vm,i=d().t;return l.countryOptions.length<=1?null:r.createElement(o,{type:n.SELECT,label:(null===(t=l.address.fieldLabels)||void 0===t?void 0:t.country)||i("checkout-page:country"),autocomplete:"country-name",value:(null===(a=l.country)||void 0===a?void 0:a.id)||"",onChange:l.onCountryChange,options:l.countryOptions,hasError:l.isErrorsVisible&&(null===(s=l.address.validationResults)||void 0===s?void 0:s.country.hasError),errorText:i("checkout-page:countryError")})})),L=t((function(e){var t,a,s,l=e.vm,i=d().t;return r.createElement(o,{type:n.SELECT,label:(null===(t=l.address.fieldLabels)||void 0===t?void 0:t.state)||i("checkout-page:state"),value:(null===(a=l.state)||void 0===a?void 0:a.id)||"",onChange:l.onStateChange,options:l.stateOptions,hasError:l.isErrorsVisible&&(null===(s=l.address.validationResults)||void 0===s?void 0:s.state.hasError),errorText:i("checkout-page:stateError")})})),k=t((function(e){var t,a,s,l=e.vm,i=d().t;return r.createElement(o,{type:n.SELECT,label:(null===(t=l.address.fieldLabels)||void 0===t?void 0:t.city)||i("checkout-page:city"),autocomplete:"off",value:(null===(a=l.city)||void 0===a?void 0:a.id)||"",onChange:l.onCityChange,options:l.cityOptions,hasError:l.isErrorsVisible&&(null===(s=l.address.validationResults)||void 0===s?void 0:s.city.hasError),errorText:i("checkout-page:cityError")})})),x=t((function(e){var t,a,s,l=e.vm,i=d().t;return r.createElement(o,{type:n.TEXT,autocomplete:"address-level2",label:(null===(t=l.address.fieldLabels)||void 0===t?void 0:t.city)||i("checkout-page:city"),value:(null===(a=l.city)||void 0===a?void 0:a.name)||"",hasError:l.isErrorsVisible&&(null===(s=l.address.validationResults)||void 0===s?void 0:s.city.hasError),onChange:l.onCityInputChange,errorText:i("checkout-page:cityError")})})),R=t((function(e){var t,a,s,l=e.vm,i=d().t;return r.createElement(o,{type:n.SELECT,label:(null===(t=l.address.fieldLabels)||void 0===t?void 0:t.district)||i("checkout-page:district"),autocomplete:"off",value:(null===(a=l.district)||void 0===a?void 0:a.id)||"",onChange:l.onDistrictChange,options:l.districtOptions,hasError:l.isErrorsVisible&&(null===(s=l.address.validationResults)||void 0===s?void 0:s.district.hasError),errorText:i("checkout-page:districtError")})})),I=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,autocomplete:"address-level3",label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.district)||l("checkout-page:district"),value:(null===(a=s.district)||void 0===a?void 0:a.name)||"",onChange:s.onDistrictInputChange})})),O=t((function(e){var t,a,l,i=e.vm,c=d().t;return r.createElement(o,{type:n.TEL,inputMode:s.TEL,label:(null===(t=i.address.fieldLabels)||void 0===t?void 0:t.phone)||c("checkout-page:phone"),autocomplete:"tel",value:i.phone||"",onChange:i.onPhoneChange,hasError:i.isErrorsVisible&&(null===(a=i.address.validationResults)||void 0===a?void 0:a.phone.hasError),currentCountryCode:(null===(l=i.address.country)||void 0===l?void 0:l.iso2)||i.myCountryCode,errorText:c("checkout-page:phoneError")})})),S=t((function(e){var t,a=e.vm,s=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=a.address.fieldLabels)||void 0===t?void 0:t.company)||s("checkout-page:companyName"),value:a.address.company||"",onChange:a.onCompanyChange})})),j=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.taxOffice)||l("checkout-page:taxOffice"),value:(null===(a=s.address)||void 0===a?void 0:a.taxOffice)||"",onChange:s.onTaxOfficeChange})})),A=t((function(e){var t,a,s=e.vm,l=d().t;return r.createElement(o,{type:n.TEXT,label:(null===(t=s.address.fieldLabels)||void 0===t?void 0:t.taxNumber)||l("checkout-page:taxNumber"),value:(null===(a=s.address)||void 0===a?void 0:a.taxNumber)||"",onChange:s.onTaxNumberChange})}));export{v as AddressForm};
|
|
1
|
+
import{__assign as e}from'./../../../../ext/tslib/tslib.es6.js';import*as r from"react";import{observer as t}from"mobx-react-lite";import{IkasCheckoutRequirement as o}from"@ikas/storefront-models";import{FormItem as a}from"../form-item/index.js";import{FormItemType as l,FormItemInputMode as n}from"../form-item/model.js";import i from"./model.js";import{Checkbox as s}from"../checkbox/index.js";import"@ikas/storefront-config";import{useTranslation as d}from"../../../../utils/i18n.js";import{AddressFormItem as u}from"../../../../models/data/checkout/country-settings-model.js";import c from"../../styles/common.module.scss.js";import v from"../../style.module.scss.js";var m=t((function(t){var o=r.useMemo((function(){return new i(e({},t))}),[]);return r.useEffect((function(){Object.entries(t).forEach((function(e){o[e[0]]=e[1]}))}),Object.values(t)),"in-store"===t.deliveryMethod?r.createElement(E,{props:t,vm:o}):r.createElement(p,{props:t,vm:o})})),E=t((function(t){var a=t.props,l=t.vm;return d().t,r.createElement("div",null,r.createElement("div",{className:[c.Grid,c.Grid2].join(" ")},r.createElement(h,e({},a,{vm:l})),r.createElement(f,e({},a,{vm:l})),r.createElement("div",null)," "),!!l.address.checkoutSettings&&l.address.checkoutSettings.phoneRequirement!==o.INVISIBLE&&r.createElement("div",{className:v.RowPB},r.createElement(O,e({},a,{vm:l})),r.createElement("div",null)," "))})),p=t((function(t){var o,a,l,n=t.props,i=t.vm,m=d().t,E=function(t){switch(t){case u.FIRSTNAME:return r.createElement(h,e({},n,{vm:i}));case u.LASTNAME:return r.createElement(f,e({},n,{vm:i}));case u.IDENTITY_NUMBER:return r.createElement(g,e({},n,{vm:i}));case u.ADDRESS_LINE_1:return r.createElement(C,e({},n,{vm:i}));case u.ADDRESS_LINE_2:return r.createElement(T,e({},n,{vm:i}));case u.POSTAL_CODE:return r.createElement(y,e({},n,{vm:i}));case u.COUNTRY:return r.createElement(N,e({},n,{vm:i}));case u.STATE:return r.createElement(L,e({},n,{vm:i}));case u.CITY:return i.address.isFreeTextCity?r.createElement(x,e({},n,{vm:i})):r.createElement(k,e({},n,{vm:i}));case u.DISTRICT:return i.address.isFreeTextDistrict?r.createElement(I,e({},n,{vm:i})):r.createElement(R,e({},n,{vm:i}));case u.PHONE:return r.createElement(O,e({},n,{vm:i}));case u.COMPANY:return r.createElement(S,e({},n,{vm:i}));case u.TAX_NUMBER:return r.createElement(A,e({},n,{vm:i}));case u.TAX_OFFICE:return r.createElement(j,e({},n,{vm:i}));default:return null}},p=function(e){return r.createElement(r.Fragment,null,1===e.length&&r.createElement("div",{className:v.RowPB},e.map((function(e){return E(e)}))),2===e.length&&r.createElement("div",{className:[c.Grid,c.Grid2].join(" ")},e.map((function(e){return E(e)})),r.createElement("div",null)," "),3===e.length&&r.createElement("div",{className:[c.Grid,c.Grid2,c.Grid3].join(" ")},e.map((function(e){return E(e)})),r.createElement("div",null)," "))};return r.createElement("div",null,i.allowTitleChange&&r.createElement("div",{className:v.RowPB},r.createElement(b,e({},n,{vm:i}))),i.countryOptions.length<=1?null===(o=i.address.addressFormatIgnoreCountry)||void 0===o?void 0:o.map((function(e){return p(e)})):null===(a=i.address.addressFormat)||void 0===a?void 0:a.map((function(e){return p(e)})),!!i.allowCorporateInfo&&r.createElement("div",{style:{marginTop:"12px"}},r.createElement(s,{value:i.isCorporate,label:m("checkout-page:corporateInvoice"),onChange:i.onCorporateChange})),!!i.isCorporate&&(null===(l=i.address.billingFormat)||void 0===l?void 0:l.map((function(e){return p(e)}))))})),h=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.firstName)||void 0===o?void 0:o.label)||s("checkout-page:firstName"),autocomplete:"given-name",value:i.firstName||"",onChange:i.onFirstNameChange,hasError:i.isErrorsVisible&&(null===(n=i.address.validationResults)||void 0===n?void 0:n.firstName.hasError),errorText:s("checkout-page:firstNameError")})})),f=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.lastName)||void 0===o?void 0:o.label)||s("checkout-page:lastName"),autocomplete:"family-name",value:i.lastName||"",onChange:i.onLastNameChange,hasError:i.isErrorsVisible&&(null===(n=i.address.validationResults)||void 0===n?void 0:n.lastName.hasError),errorText:s("checkout-page:lastNameError")})})),g=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.identityNumber)||void 0===o?void 0:o.label)||s("checkout-page:identityNumber"),value:i.identityNumber||"",onChange:i.onIdentityNumberChange,hasError:i.isErrorsVisible&&(null===(n=i.address.validationResults)||void 0===n?void 0:n.identityNumber.hasError),errorText:s("checkout-page:identityNumberError")})})),b=t((function(e){var t=e.vm,o=d().t,n=t.address;return r.createElement(a,{type:l.TEXT,label:o("checkout-page:addressTitle"),value:n.title||"",onChange:t.onAddressTitleChange,hasError:t.isErrorsVisible&&!n.title,errorText:o("checkout-page:addressTitleError")})})),C=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.addressLine1)||void 0===o?void 0:o.label)||s("checkout-page:addressLine1"),autocomplete:"address-line1",value:i.address.addressLine1||"",onChange:i.onAddressLine1Change,hasError:i.isErrorsVisible&&(null===(n=i.address.validationResults)||void 0===n?void 0:n.addressLine1.hasError),errorText:s("checkout-page:addressError")})})),T=t((function(e){var t,o,n=e.vm,i=d().t;return r.createElement(a,{type:l.TEXT,autocomplete:"address-line2",label:(null===(o=null===(t=n.address.fieldLabels)||void 0===t?void 0:t.addressLine2)||void 0===o?void 0:o.label)||i("checkout-page:addressLine2"),value:n.address.addressLine2||"",onChange:n.onAddressLine2Change})})),y=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.postalCode)||void 0===o?void 0:o.label)||s("checkout-page:postalCode"),autocomplete:"postal-code",value:i.address.postalCode||"",onChange:i.onAddressPostalCodeChange,hasError:i.isErrorsVisible&&(null===(n=i.address.validationResults)||void 0===n?void 0:n.postalCode.hasError),errorText:s("checkout-page:postalCodeError")})})),N=t((function(e){var t,o,n,i,s=e.vm,u=d().t;return s.countryOptions.length<=1?null:r.createElement(a,{type:l.SELECT,label:(null===(o=null===(t=s.address.fieldLabels)||void 0===t?void 0:t.country)||void 0===o?void 0:o.label)||u("checkout-page:country"),autocomplete:"country-name",value:(null===(n=s.country)||void 0===n?void 0:n.id)||"",onChange:s.onCountryChange,options:s.countryOptions,hasError:s.isErrorsVisible&&(null===(i=s.address.validationResults)||void 0===i?void 0:i.country.hasError),errorText:u("checkout-page:countryError")})})),L=t((function(e){var t,o,n,i,s=e.vm,u=d().t;return r.createElement(a,{type:l.SELECT,label:(null===(o=null===(t=s.address.fieldLabels)||void 0===t?void 0:t.state)||void 0===o?void 0:o.label)||u("checkout-page:state"),value:(null===(n=s.state)||void 0===n?void 0:n.id)||"",onChange:s.onStateChange,options:s.stateOptions,hasError:s.isErrorsVisible&&(null===(i=s.address.validationResults)||void 0===i?void 0:i.state.hasError),errorText:u("checkout-page:stateError")})})),k=t((function(e){var t,o,n,i,s=e.vm,u=d().t;return r.createElement(a,{type:l.SELECT,label:(null===(o=null===(t=s.address.fieldLabels)||void 0===t?void 0:t.city)||void 0===o?void 0:o.label)||u("checkout-page:city"),autocomplete:"off",value:(null===(n=s.city)||void 0===n?void 0:n.id)||"",onChange:s.onCityChange,options:s.cityOptions,hasError:s.isErrorsVisible&&(null===(i=s.address.validationResults)||void 0===i?void 0:i.city.hasError),errorText:u("checkout-page:cityError")})})),x=t((function(e){var t,o,n,i,s=e.vm,u=d().t;return r.createElement(a,{type:l.TEXT,autocomplete:"address-level2",label:(null===(o=null===(t=s.address.fieldLabels)||void 0===t?void 0:t.city)||void 0===o?void 0:o.label)||u("checkout-page:city"),value:(null===(n=s.city)||void 0===n?void 0:n.name)||"",hasError:s.isErrorsVisible&&(null===(i=s.address.validationResults)||void 0===i?void 0:i.city.hasError),onChange:s.onCityInputChange,errorText:u("checkout-page:cityError")})})),R=t((function(e){var t,o,n,i,s=e.vm,u=d().t;return r.createElement(a,{type:l.SELECT,label:(null===(o=null===(t=s.address.fieldLabels)||void 0===t?void 0:t.district)||void 0===o?void 0:o.label)||u("checkout-page:district"),autocomplete:"off",value:(null===(n=s.district)||void 0===n?void 0:n.id)||"",onChange:s.onDistrictChange,options:s.districtOptions,hasError:s.isErrorsVisible&&(null===(i=s.address.validationResults)||void 0===i?void 0:i.district.hasError),errorText:u("checkout-page:districtError")})})),I=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,autocomplete:"address-level3",label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.district)||void 0===o?void 0:o.label)||s("checkout-page:district"),value:(null===(n=i.district)||void 0===n?void 0:n.name)||"",onChange:i.onDistrictInputChange})})),O=t((function(e){var t,o,i,s,u=e.vm,c=d().t;return r.createElement(a,{type:l.TEL,inputMode:n.TEL,label:(null===(o=null===(t=u.address.fieldLabels)||void 0===t?void 0:t.phone)||void 0===o?void 0:o.label)||c("checkout-page:phone"),autocomplete:"tel",value:u.phone||"",onChange:u.onPhoneChange,hasError:u.isErrorsVisible&&(null===(i=u.address.validationResults)||void 0===i?void 0:i.phone.hasError),currentCountryCode:(null===(s=u.address.country)||void 0===s?void 0:s.iso2)||u.myCountryCode,errorText:c("checkout-page:phoneError")})})),S=t((function(e){var t,o,n=e.vm,i=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=n.address.fieldLabels)||void 0===t?void 0:t.company)||void 0===o?void 0:o.label)||i("checkout-page:companyName"),value:n.address.company||"",onChange:n.onCompanyChange})})),j=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.taxOffice)||void 0===o?void 0:o.label)||s("checkout-page:taxOffice"),value:(null===(n=i.address)||void 0===n?void 0:n.taxOffice)||"",onChange:i.onTaxOfficeChange})})),A=t((function(e){var t,o,n,i=e.vm,s=d().t;return r.createElement(a,{type:l.TEXT,label:(null===(o=null===(t=i.address.fieldLabels)||void 0===t?void 0:t.taxNumber)||void 0===o?void 0:o.label)||s("checkout-page:taxNumber"),value:(null===(n=i.address)||void 0===n?void 0:n.taxNumber)||"",onChange:i.onTaxNumberChange})}));export{m as AddressForm};
|
|
@@ -30,20 +30,20 @@ export default class CountrySettingsModel {
|
|
|
30
30
|
taxNumber?: AddressFormField | undefined;
|
|
31
31
|
};
|
|
32
32
|
getFieldLabels(country: string): {
|
|
33
|
-
firstName?:
|
|
34
|
-
lastName?:
|
|
35
|
-
identityNumber?:
|
|
36
|
-
addressLine1?:
|
|
37
|
-
addressLine2?:
|
|
38
|
-
postalCode?:
|
|
39
|
-
country?:
|
|
40
|
-
state?:
|
|
41
|
-
city?:
|
|
42
|
-
district?:
|
|
43
|
-
phone?:
|
|
44
|
-
company?:
|
|
45
|
-
taxOffice?:
|
|
46
|
-
taxNumber?:
|
|
33
|
+
firstName?: AddressFormLabel | undefined;
|
|
34
|
+
lastName?: AddressFormLabel | undefined;
|
|
35
|
+
identityNumber?: AddressFormLabel | undefined;
|
|
36
|
+
addressLine1?: AddressFormLabel | undefined;
|
|
37
|
+
addressLine2?: AddressFormLabel | undefined;
|
|
38
|
+
postalCode?: AddressFormLabel | undefined;
|
|
39
|
+
country?: AddressFormLabel | undefined;
|
|
40
|
+
state?: AddressFormLabel | undefined;
|
|
41
|
+
city?: AddressFormLabel | undefined;
|
|
42
|
+
district?: AddressFormLabel | undefined;
|
|
43
|
+
phone?: AddressFormLabel | undefined;
|
|
44
|
+
company?: AddressFormLabel | undefined;
|
|
45
|
+
taxOffice?: AddressFormLabel | undefined;
|
|
46
|
+
taxNumber?: AddressFormLabel | undefined;
|
|
47
47
|
} | undefined;
|
|
48
48
|
getAddressFormatView(addressFormat: string): AddressFormItem[][];
|
|
49
49
|
getBillingFormatView(billingFormat: string): AddressFormItem[][];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as t,__assign as e,__generator as i}from'./../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";import{IkasCheckoutRequirement as s}from"@ikas/storefront-models";import o from"lodash/difference";import d from"lodash/mapValues";import{COUNTRY_FORMS_LOCALES as u}from"../../../utils/constants.js";var a,l,c=function(){function c(t){void 0===t&&(t={}),this._initialized=!1,this.checkoutSettings=t.checkoutSettings,this.init(),r(this)}return c.prototype.init=function(){return t(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return t.sent(),[4,this.getAddressFormCountryLabels()];case 2:return t.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(c.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),c.prototype.waitUntilInitialized=function(){var t=this;return new Promise((function(e){var i=setInterval((function(){t.initialized&&(clearInterval(i),e(null))}),100)}))},c.prototype.getCountrySettings=function(t){return this._addressFormCountrySettings.countrySettings[t]},c.prototype.getCountryLabels=function(t){return this._addressFormCountryLabels.countryLabels[t]},c.prototype.getFieldSettings=function(t){var i,r,n,o,d,u,a,l,c=this.getCountrySettings(t),h=e(e({},c.fields),{firstName:{required:!0},lastName:{required:!0},identityNumber:e(e({},c.fields.identityNumber),{required:(null===(i=c.fields.identityNumber)||void 0===i?void 0:i.required)||!1}),phone:e(e({},c.fields.phone),{required:(null===(r=c.fields.phone)||void 0===r?void 0:r.required)||!1}),addressLine1:{required:!0},addressLine2:e(e({},c.fields.addressLine2),{required:(null===(n=c.fields.addressLine2)||void 0===n?void 0:n.required)||!1}),postalCode:e(e({},c.fields.postalCode),{required:(null===(o=c.fields.postalCode)||void 0===o?void 0:o.required)||!1}),country:e(e({},c.fields.country),{required:(null===(d=c.fields.country)||void 0===d?void 0:d.required)||!1}),state:e(e({},c.fields.state),{required:(null===(u=c.fields.state)||void 0===u?void 0:u.required)||!1}),city:e(e({},c.fields.city),{required:(null===(a=c.fields.city)||void 0===a?void 0:a.required)||!1}),district:e(e({},c.fields.district),{required:(null===(l=c.fields.district)||void 0===l?void 0:l.required)||!1})});return this.checkoutSettings&&(this.checkoutSettings.phoneRequirement&&(h.phone.required=this.checkoutSettings.phoneRequirement===s.MANDATORY),this.checkoutSettings.postalCodeRequirement&&(h.postalCode.required=this.checkoutSettings.postalCodeRequirement===s.MANDATORY),this.checkoutSettings.identityNumberRequirement&&(h.identityNumber.required=this.checkoutSettings.identityNumberRequirement===s.MANDATORY)),h},c.prototype.getFieldLabels=function(t){var e=this.getCountryLabels(t);if(e)return d(e.fields,(function(t){return
|
|
1
|
+
import{__awaiter as t,__assign as e,__generator as i}from'./../../../ext/tslib/tslib.es6.js';import{makeAutoObservable as r}from"mobx";import{IkasStorefrontConfig as n}from"@ikas/storefront-config";import{IkasCheckoutRequirement as s}from"@ikas/storefront-models";import o from"lodash/difference";import d from"lodash/mapValues";import{COUNTRY_FORMS_LOCALES as u}from"../../../utils/constants.js";var a,l,c=function(){function c(t){void 0===t&&(t={}),this._initialized=!1,this.checkoutSettings=t.checkoutSettings,this.init(),r(this)}return c.prototype.init=function(){return t(this,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return t.sent(),[4,this.getAddressFormCountryLabels()];case 2:return t.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(c.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),c.prototype.waitUntilInitialized=function(){var t=this;return new Promise((function(e){var i=setInterval((function(){t.initialized&&(clearInterval(i),e(null))}),100)}))},c.prototype.getCountrySettings=function(t){return this._addressFormCountrySettings.countrySettings[t]},c.prototype.getCountryLabels=function(t){return this._addressFormCountryLabels.countryLabels[t]},c.prototype.getFieldSettings=function(t){var i,r,n,o,d,u,a,l,c=this.getCountrySettings(t),h=e(e({},c.fields),{firstName:{required:!0},lastName:{required:!0},identityNumber:e(e({},c.fields.identityNumber),{required:(null===(i=c.fields.identityNumber)||void 0===i?void 0:i.required)||!1}),phone:e(e({},c.fields.phone),{required:(null===(r=c.fields.phone)||void 0===r?void 0:r.required)||!1}),addressLine1:{required:!0},addressLine2:e(e({},c.fields.addressLine2),{required:(null===(n=c.fields.addressLine2)||void 0===n?void 0:n.required)||!1}),postalCode:e(e({},c.fields.postalCode),{required:(null===(o=c.fields.postalCode)||void 0===o?void 0:o.required)||!1}),country:e(e({},c.fields.country),{required:(null===(d=c.fields.country)||void 0===d?void 0:d.required)||!1}),state:e(e({},c.fields.state),{required:(null===(u=c.fields.state)||void 0===u?void 0:u.required)||!1}),city:e(e({},c.fields.city),{required:(null===(a=c.fields.city)||void 0===a?void 0:a.required)||!1}),district:e(e({},c.fields.district),{required:(null===(l=c.fields.district)||void 0===l?void 0:l.required)||!1})});return this.checkoutSettings&&(this.checkoutSettings.phoneRequirement&&(h.phone.required=this.checkoutSettings.phoneRequirement===s.MANDATORY),this.checkoutSettings.postalCodeRequirement&&(h.postalCode.required=this.checkoutSettings.postalCodeRequirement===s.MANDATORY),this.checkoutSettings.identityNumberRequirement&&(h.identityNumber.required=this.checkoutSettings.identityNumberRequirement===s.MANDATORY)),h},c.prototype.getFieldLabels=function(t){var e=this.getCountryLabels(t);if(e)return d(e.fields,(function(t){return t}))},c.prototype.getAddressFormatView=function(t){return this._addressFormCountrySettings.addressFormats[t]},c.prototype.getBillingFormatView=function(t){return this._addressFormCountrySettings.billingFormats[t]},c.prototype.getAddressFormat=function(t){var e=this.getCountrySettings(t),i=this.getAddressFormatView(e.addressFormat);if(this.checkoutSettings&&i){var r=[];return this.checkoutSettings.identityNumberRequirement===s.INVISIBLE&&r.push(l.IDENTITY_NUMBER),this.checkoutSettings.postalCodeRequirement===s.INVISIBLE&&r.push(l.POSTAL_CODE),this.checkoutSettings.phoneRequirement===s.INVISIBLE&&r.push(l.PHONE),i.map((function(t){return o(t,r)}))||[]}return i},c.prototype.getBillingFormat=function(t){var e=this.getCountrySettings(t);return this.getBillingFormatView(e.billingFormat)},c.prototype.getAddressFormatIgnoreCountry=function(t){return this.getAddressFormat(t).map((function(t){return o(t,[l.COUNTRY])}))},c.prototype.getValidationResult=function(t){var e,i,r,n,o,d,u,a,l=this.getFieldSettings((null===(e=t.country)||void 0===e?void 0:e.iso2)||"TR");if(l){var c=!!t.phone&&t.phone.length>=10&&this.validatePhoneNumber(t.phone);return{firstName:this.isValidField(t.firstName,l.firstName),lastName:this.isValidField(t.lastName,l.lastName),addressLine1:this.isValidField(t.addressLine1,l.addressLine1),addressLine2:this.isValidField(t.addressLine2||"",l.addressLine2),country:this.isValidField((null===(i=t.country)||void 0===i?void 0:i.name)||"",l.country),state:this.isValidField((null===(r=t.state)||void 0===r?void 0:r.name)||"",l.state),city:this.isValidField((null===(n=t.city)||void 0===n?void 0:n.name)||"",l.city),district:this.isValidField((null===(o=t.district)||void 0===o?void 0:o.name)||"",l.district),phone:(null===(d=l.phone)||void 0===d?void 0:d.regex)?this.isValidField(t.phone||"",l.phone,this.checkoutSettings?this.checkoutSettings.phoneRequirement:void 0):(null===(u=this.checkoutSettings)||void 0===u?void 0:u.phoneRequirement)===s.MANDATORY||(null===(a=this.checkoutSettings)||void 0===a?void 0:a.phoneRequirement)===s.OPTIONAL&&t.phone?{hasError:!c,isInvalid:!c,isEmpty:!t.phone}:{hasError:!1,isInvalid:!1,isEmpty:!1},postalCode:this.isValidField(t.postalCode||"",l.postalCode,this.checkoutSettings?this.checkoutSettings.postalCodeRequirement:void 0),identityNumber:this.isValidField(t.identityNumber||"",l.identityNumber,this.checkoutSettings?this.checkoutSettings.identityNumberRequirement:void 0)}}},c.prototype.isValidAddress=function(t){var e=this.getValidationResult(t);return!!e&&Object.values(e).every((function(t){return!t.hasError}))},c.prototype.isValidField=function(t,e,i){var r=!1,n=!1,o=i?i===s.MANDATORY:(null==e?void 0:e.required)||!1,d=!!(null==e?void 0:e.regex)||!1;return o&&!d&&(n=!t),o&&d&&(n=!t,r=!this.validateByRegexString(t,e.regex)),!o&&d&&t&&(r=!this.validateByRegexString(t,e.regex)),{hasError:r||n,isInvalid:r,isEmpty:n}},c.prototype.isFreeTextCity=function(t){var e=this.getFieldSettings(t);return e&&e.city&&e.city.type===a.TEXT},c.prototype.isFreeTextDistrict=function(t){var e=this.getFieldSettings(t);return e&&e.district&&e.district.type===a.TEXT},c.prototype.getAddressFormCountrySettings=function(){return t(this,void 0,void 0,(function(){var t;return i(this,(function(e){switch(e.label){case 0:return"https://cdn.myikas.com/sf/static/location/settings.json",[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,e.sent().json()];case 2:return t=e.sent(),this._addressFormCountrySettings=t,[2]}}))}))},c.prototype.getAddressFormCountryLabels=function(){return t(this,void 0,void 0,(function(){var t,e,r;return i(this,(function(i){switch(i.label){case 0:return t=n.getCurrentLocale(),u.find((function(e){return e===t}))||(t="en"),e="https://cdn.myikas.com/sf/static/location/".concat(t,".json"),[4,fetch(e)];case 1:return[4,i.sent().json()];case 2:return r=i.sent(),this._addressFormCountryLabels=r,[2]}}))}))},c.prototype.validatePhoneNumber=function(t){return/^\+?\d+$/.test(t)},c.prototype.validateByRegexString=function(t,e){return new RegExp(e).test(t)},c}();!function(t){t.TEXT="text",t.DROPDOWN="dropdown"}(a||(a={})),function(t){t.FIRSTNAME="firstName",t.LASTNAME="lastName",t.IDENTITY_NUMBER="identityNumber",t.ADDRESS_LINE_1="addressLine1",t.ADDRESS_LINE_2="addressLine2",t.POSTAL_CODE="postalCode",t.COUNTRY="country",t.STATE="state",t.CITY="city",t.DISTRICT="district",t.PHONE="phone",t.COMPANY="company",t.TAX_OFFICE="taxOffice",t.TAX_NUMBER="taxNumber"}(l||(l={}));export{l as AddressFormItem,a as IkasAddressFormInputType,c as default};
|
|
@@ -16,6 +16,7 @@ export declare class IkasAddressForm {
|
|
|
16
16
|
cities: IkasCity[];
|
|
17
17
|
districts: IkasDistrict[];
|
|
18
18
|
isLoaded: boolean;
|
|
19
|
+
private isFormSubmit;
|
|
19
20
|
private _isCountriesPending;
|
|
20
21
|
private _isStatesPending;
|
|
21
22
|
private _isCitiesPending;
|
|
@@ -27,6 +28,7 @@ export declare class IkasAddressForm {
|
|
|
27
28
|
onTitleChange: (value: string) => void;
|
|
28
29
|
onFirstNameChange: (value: string) => void;
|
|
29
30
|
onLastNameChange: (value: string) => void;
|
|
31
|
+
onIdentityNumberChange: (value: string) => void;
|
|
30
32
|
onPhoneChange: (value: string) => void;
|
|
31
33
|
onAddressLine1Change: (value: string) => void;
|
|
32
34
|
onAddressLine2Change: (value: string) => void;
|
|
@@ -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{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.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};
|
|
1
|
+
import{__awaiter as t,__generator as i}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as e,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 m}from"@ikas/storefront-config";import{IkasBaseStore as h}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,i){return t.label.localeCompare(i.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.isFormSubmit=!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,e;return i(this,(function(i){switch(i.label){case 0:return[4,a({})];case 1:return(t=i.sent()).isSuccess&&(null===(e=t.data)||void 0===e?void 0:e.length)&&(this.countrySettings=new p({checkoutSettings:t.data[0]})),[4,this.countrySettings.waitUntilInitialized()];case 2:return i.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 i;if((null===(i=v.address.country)||void 0===i?void 0:i.id)!==t){var e=v.countries.find((function(i){return i.id===t}));v.address.country={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},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 i;if((null===(i=v.address.state)||void 0===i?void 0:i.id)!==t){var e=v.states.find((function(i){return i.id===t}));v.address.state={id:e.id,name:null==e?void 0:e.name,code:null==e?void 0:e.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 i;if((null===(i=v.address.city)||void 0===i?void 0:i.id)!==t){var e=v.cities.find((function(i){return i.id===t}));v.address.city={id:e.id,name:e.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 i;if((null===(i=v.address.district)||void 0===i?void 0:i.id)!==t){var e=v.districts.find((function(i){return i.id===t}));v.address.district={id:e.id,name:e.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,e,s,n;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,3,4]),this._isCountriesPending=!0,[4,o({})];case 1:return t=i.sent(),e=m.getCurrentRouting(),s=t.data||[],(null===(n=null==e?void 0:e.countryCodes)||void 0===n?void 0:n.length)&&(s=s.filter((function(t){var i;return t.iso2&&(null===(i=e.countryCodes)||void 0===i?void 0:i.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 i.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,e;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.address.country)||void 0===e?void 0:e.id))return[2];i.label=1;case 1:return i.trys.push([1,3,4,5]),this._isStatesPending=!0,[4,u({countryId:{eq:this.address.country.id}})];case 2:return t=i.sent(),this.states=t.data||[],this.hasState||this.onStateChange(this.states[0].id),[3,5];case 3:return i.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,e,s,n;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.address.state)||void 0===e?void 0:e.id))return[2];i.label=1;case 1:return i.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=i.sent(),this.cities=t.data||[],[3,5];case 3:return i.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,e,s,n;return i(this,(function(i){switch(i.label){case 0:if(!(null===(e=this.address.city)||void 0===e?void 0:e.id))return[2];i.label=1;case 1:return i.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=i.sent(),this.districts=t.data||[],[3,5];case 3:return i.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,e;return i(this,(function(i){switch(i.label){case 0:if(t={isFormError:!1,isSuccess:!1},this.isFormSubmit=!0,!this.address.isValidAddress)return t.isFormError=!0,[2,t];if(!(e=d(h.getInstance().customerStore.customer))||!this.address)return[2,t];(null==e?void 0:e.addresses)||(e.addresses=[]),this.isEdit?e.addresses[this.editingAddressIndex]=this.address:e.addresses.push(this.address),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,h.getInstance().customerStore.saveCustomer(e)];case 2:return i.sent()&&(t.isSuccess=!0),[2,t];case 3:return i.sent(),[2,t];case 4:return[2]}}))}))},e(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,i,e,s=this;return null!==(e=null===(i=null===(t=h.getInstance().customerStore.customer)||void 0===t?void 0:t.addresses)||void 0===i?void 0:i.findIndex((function(t){return t.id===s.address.id})))&&void 0!==e?e:-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(i,e){return{hasError:t.isFormSubmit&&i.hasError,message:t.isFormSubmit&&i.hasError?e===f.PHONE?t.message.phoneRule:i.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.
|
|
3
|
+
"version": "4.2.0-beta.13",
|
|
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.
|
|
22
|
-
"@ikas/storefront-config": "^4.2.0-beta.
|
|
23
|
-
"@ikas/storefront-model-functions": "^4.2.0-beta.
|
|
24
|
-
"@ikas/storefront-models": "^4.2.0-beta.
|
|
25
|
-
"@ikas/storefront-providers": "^4.2.0-beta.
|
|
21
|
+
"@ikas/storefront-api": "^4.2.0-beta.13",
|
|
22
|
+
"@ikas/storefront-config": "^4.2.0-beta.13",
|
|
23
|
+
"@ikas/storefront-model-functions": "^4.2.0-beta.13",
|
|
24
|
+
"@ikas/storefront-models": "^4.2.0-beta.13",
|
|
25
|
+
"@ikas/storefront-providers": "^4.2.0-beta.13",
|
|
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.
|
|
56
|
-
"@ikas/storefront-config": "^4.2.0-beta.
|
|
57
|
-
"@ikas/storefront-model-functions": "^4.2.0-beta.
|
|
58
|
-
"@ikas/storefront-models": "^4.2.0-beta.
|
|
59
|
-
"@ikas/storefront-providers": "^4.2.0-beta.
|
|
55
|
+
"@ikas/storefront-api": "^4.2.0-beta.13",
|
|
56
|
+
"@ikas/storefront-config": "^4.2.0-beta.13",
|
|
57
|
+
"@ikas/storefront-model-functions": "^4.2.0-beta.13",
|
|
58
|
+
"@ikas/storefront-models": "^4.2.0-beta.13",
|
|
59
|
+
"@ikas/storefront-providers": "^4.2.0-beta.13",
|
|
60
60
|
"mobx": "^6.1.3",
|
|
61
61
|
"mobx-react-lite": "^3.1.5",
|
|
62
62
|
"next": "12.2.0",
|