@ikas/bp-storefront 0.103.0 → 0.105.0
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 e,__generator as i,__assign as t}from'./../../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../../packages/storefront-config/src/index.js";import'./../../../../ext/uuid/dist/esm-browser/stringify.js';import'./../../../../ext/uuid/dist/esm-browser/v3.js';import n from'./../../../../ext/uuid/dist/esm-browser/v4.js';import'./../../../../ext/uuid/dist/esm-browser/v5.js';import{I18n as s}from"../../../../i18n/index.js";import{customerStore as o}from"../../../../stores/customer/index.js";import{cloneDeep as a}from"../../../../utils/helper.js";import{validateValue as d,FORM_ITEM_DEFAULT_VALUE as l}from"../index.js";function u(r,n){return e(this,void 0,void 0,function(){var e,s,o,a,d;return i(this,function(i){switch(i.label){case 0:return r.id=null==n?void 0:n.id,r.title=n?t(t({},l),{value:n.title||""}):l,r.firstName=n?t(t({},l),{value:n.firstName||""}):l,r.lastName=n?t(t({},l),{value:n.lastName||""}):l,r.identityNumber=n?t(t({},l),{value:n.identityNumber||""}):l,r.addressLine1=n?t(t({},l),{value:n.addressLine1||""}):l,r.addressLine2=n?t(t({},l),{value:n.addressLine2||""}):l,r.postalCode=n?t(t({},l),{value:n.postalCode||""}):l,r.country=n?t(t({},Q),{value:(null===(e=n.country)||void 0===e?void 0:e.id)||""}):Q,r.state=n?t(t({},Q),{value:(null===(s=n.state)||void 0===s?void 0:s.id)||""}):Q,r.city=n?t(t({},Q),{value:(null===(o=n.city)||void 0===o?void 0:o.id)||""}):Q,r.district=n?t(t({},Q),{value:(null===(a=n.district)||void 0===a?void 0:a.id)||""}):Q,r.region=n?t(t({},l),{value:(null===(d=n.region)||void 0===d?void 0:d.id)||""}):l,r.phone=n?t(t({},l),{value:n.phone||""}):l,r.company=n?t(t({},l),{value:n.company||""}):l,r.taxOffice=n?t(t({},l),{value:n.taxOffice||""}):l,r.taxNumber=n?t(t({},l),{value:n.taxNumber||""}):l,r.isSubmitted=!1,r.isInitialized=!1,r.isSubmitting=!1,r.isFailure=void 0,r.isSuccess=void 0,r.responseMessage=void 0,r.countryOptions=[],r.stateOptions=[],r.cityOptions=[],r.districtOptions=[],r.regionOptions=[],[4,k(r)];case 1:return i.sent(),r.state.value?[4,M(r)]:[3,3];case 2:i.sent(),i.label=3;case 3:return r.country.value?[4,D(r)]:[3,5];case 4:i.sent(),i.label=5;case 5:return r.city.value?[4,Y(r)]:[3,7];case 6:i.sent(),i.label=7;case 7:return[4,F(r)];case 8:return i.sent(),[4,I(r)];case 9:return i.sent(),[4,A(r)];case 10:return i.sent(),_(r),r.isInitialized=!0,[2]}})})}function c(e,i){e.title&&(e.title.value=i),e.isSubmitted&&j(e)}function v(e,i){e.firstName&&(e.firstName.value=i),e.isSubmitted&&j(e)}function m(e,i){e.lastName&&(e.lastName.value=i),e.isSubmitted&&j(e)}function f(e,i){e.identityNumber&&(e.identityNumber.value=i),e.isSubmitted&&j(e)}function p(e,i){e.addressLine1&&(e.addressLine1.value=i),e.isSubmitted&&j(e)}function h(e,i){e.addressLine2&&(e.addressLine2.value=i),e.isSubmitted&&j(e)}function y(e,i){e.postalCode&&(e.postalCode.value=i),e.isSubmitted&&j(e)}function b(e,i){e.country&&e.country.value!==i&&(e.country.value=i,e.state&&(e.state.value=""),e.city&&(e.city.value=""),e.district&&(e.district.value=""),e.states=[],e.stateOptions=[],e.cities=[],e.cityOptions=[],e.districts=[],e.districtOptions=[],_(e),M(e),e.isSubmitted&&j(e))}function g(e,i){var t,r;e.state&&e.state.value!==i&&(e.state.value=i,(null===(t=e.city)||void 0===t?void 0:t.isFreeText)||(e.city&&(e.city.value=""),e.cities=[],e.cityOptions=[],D(e)),(null===(r=e.district)||void 0===r?void 0:r.isFreeText)||(e.district&&(e.district.value=""),e.districts=[],e.districtOptions=[]),e.isSubmitted&&j(e))}function N(e,i){var t;e.city&&(e.city.value=i,e.districts=[],e.districtOptions=[],(null===(t=e.district)||void 0===t?void 0:t.isFreeText)||(e.district&&(e.district.value=""),Y(e)),e.isSubmitted&&j(e))}function x(e,i){e.district&&e.district.value!==i&&(e.district.value=i,e.region&&(e.region.value=""),e.regionOptions=[],e.isSubmitted&&j(e))}function q(e,i){e.region&&e.region.value!==i&&(e.region.value=i,e.isSubmitted&&j(e))}function L(e,i){e.phone&&(e.phone.value=i),e.isSubmitted&&j(e)}function S(e,i){e.company&&(e.company.value=i),e.isSubmitted&&j(e)}function O(e,i){e.taxOffice&&(e.taxOffice.value=i),e.isSubmitted&&j(e)}function C(e,i){e.taxNumber&&(e.taxNumber.value=i),e.isSubmitted&&j(e)}function E(t){return e(this,void 0,void 0,function(){var e,r,n,d,l,u,c;return i(this,function(i){switch(i.label){case 0:if(t.isSubmitted=!0,t.isSuccess=void 0,t.isFailure=void 0,t.responseMessage=void 0,j(t))return[2,!1];t.isSubmitting=!0,i.label=1;case 1:return i.trys.push([1,4,5,6]),(e=a(o.customer))?(r=!!t.id,n=null===(c=e.addresses)||void 0===c?void 0:c.findIndex(function(e){return e.id===t.id}),r&&e.addresses&&void 0!==n?(d=H(t))&&(e.addresses[n]=d):(e.addresses||(e.addresses=[]),(d=H(t))&&e.addresses.push(d)),[4,import("../../../stores/customer/index.js")]):(t.isSubmitting=!1,[2,!1]);case 2:return[4,(0,i.sent().saveCustomer)(o,e)];case 3:return l=i.sent(),t.isSubmitting=!1,l?(t.isSuccess=!0,t.responseMessage=s.translate("notification.success.address"),[2,!0]):(t.isFailure=!0,t.responseMessage=s.translate("notification.failure.address"),[2,!1]);case 4:return u=i.sent(),console.error(u),[3,6];case 5:return t.isSubmitting=!1,[7];case 6:return[2,!1]}})})}function j(e){if(!(e.title&&e.firstName&&e.lastName&&e.addressLine1&&e.country&&e.city&&e.district))return!1;var i=d(e.title.value,{required:!0});i.hasError?(e.title.hasError=!0,e.title.message=i.message):(e.title.hasError=!1,e.title.message=void 0);var t=d(e.firstName.value,R(e,"firstName"));t.hasError?(e.firstName.hasError=!0,e.firstName.message=t.message):(e.firstName.hasError=!1,e.firstName.message=void 0);var r=d(e.lastName.value,R(e,"lastName"));r.hasError?(e.lastName.hasError=!0,e.lastName.message=r.message):(e.lastName.hasError=!1,e.lastName.message=void 0);var n=d(e.addressLine1.value,R(e,"addressLine1"));n.hasError?(e.addressLine1.hasError=!0,e.addressLine1.message=n.message):(e.addressLine1.hasError=!1,e.addressLine1.message=void 0);var s=d(e.country.value,R(e,"country"));s.hasError?(e.country.hasError=!0,e.country.message=s.message):(e.country.hasError=!1,e.country.message=void 0);var o=d(e.city.value,R(e,"city"));o.hasError?(e.city.hasError=!0,e.city.message=o.message):(e.city.hasError=!1,e.city.message=void 0);var a=d(e.district.value,R(e,"district"));return a.hasError?(e.district.hasError=!0,e.district.message=a.message):(e.district.hasError=!1,e.district.message=void 0),i.hasError||t.hasError||r.hasError||n.hasError||s.hasError||o.hasError||a.hasError}function R(e,i){var t,r,n,s,o,a,d,l,u,c,v,m,f,p,h,y,b,g,N=null===(t=P[i])||void 0===t?void 0:t.required,x=null===(r=P[i])||void 0===r?void 0:r.regex,q=null===(n=P[i])||void 0===n?void 0:n.isFreeText;void 0!==(null===(o=null===(s=e.countrySettings)||void 0===s?void 0:s[i])||void 0===o?void 0:o.required)&&(N=!1!==(null===(d=null===(a=e.countrySettings)||void 0===a?void 0:a[i])||void 0===d?void 0:d.required)),void 0!==(null===(u=null===(l=e.countrySettings)||void 0===l?void 0:l[i])||void 0===u?void 0:u.regex)&&(x=null===(v=null===(c=e.countrySettings)||void 0===c?void 0:c[i])||void 0===v?void 0:v.regex),void 0!==(null===(f=null===(m=e.countrySettings)||void 0===m?void 0:m[i])||void 0===f?void 0:f.type)&&(q="text"===(null===(h=null===(p=e.countrySettings)||void 0===p?void 0:p[i])||void 0===h?void 0:h.type));var L=null===(y=e.checkoutSettings)||void 0===y?void 0:y.identityNumberRequirement;"identityNumber"===i&&L&&(N="MANDATORY"===L);var S=null===(b=e.checkoutSettings)||void 0===b?void 0:b.postalCodeRequirement;"postalCode"===i&&S&&(N="MANDATORY"===S);var O=null===(g=e.checkoutSettings)||void 0===g?void 0:g.phoneRequirement;return"phone"===i&&O&&(N="MANDATORY"===O),"region"!==i||function(e){var i,t,r;return!!(null===(i=e.district)||void 0===i?void 0:i.value)&&(null===(r=null===(t=B(e))||void 0===t?void 0:t.regions)||void 0===r?void 0:r.length)}(e)||(N=!1),{required:N,regex:x,isFreeText:q}}function F(t){return e(this,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:return[4,T(t)];case 1:return e.sent(),[4,w(t)];case 2:return e.sent(),[2]}})})}function w(t){return e(this,void 0,void 0,function(){var e;return i(this,function(i){switch(i.label){case 0:return[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,i.sent().json()];case 2:return e=i.sent(),t.locationSettings=e,[2]}})})}function T(t){return e(this,void 0,void 0,function(){var e,n,o,a,d,l,u,c,v,m,f,p,h,y,b,g,N,x,q,L,S,O,C,E,j,R,F,w,T,_,I,A,k,M,D;return i(this,function(i){switch(i.label){case 0:return t.title&&t.firstName&&t.lastName&&t.identityNumber&&t.addressLine1&&t.addressLine2&&t.postalCode&&t.country&&t.state&&t.city&&t.district&&t.region&&t.phone&&t.company&&t.taxOffice&&t.taxNumber?(e=r.getCurrentLocale(),n="https://eu.myikas.com/sf/static/location/".concat(e,".json"),[4,fetch(n)]):[2];case 1:return[4,i.sent().json()];case 2:return o=i.sent(),a=Z(t),d=o.countryLabels[a].fields||{},t.title.label=s.translate("label.address_title"),t.title.placeholder="",t.firstName.label=(null===(l=d.firstName)||void 0===l?void 0:l.label)||s.translate("label.first_name"),t.firstName.placeholder=(null===(u=d.firstName)||void 0===u?void 0:u.placeholder)||"",t.lastName.label=(null===(c=d.lastName)||void 0===c?void 0:c.label)||s.translate("label.last_name"),t.lastName.placeholder=(null===(v=d.lastName)||void 0===v?void 0:v.placeholder)||"",t.identityNumber.label=(null===(m=d.identityNumber)||void 0===m?void 0:m.label)||s.translate("label.identity_number"),t.identityNumber.placeholder=(null===(f=d.identityNumber)||void 0===f?void 0:f.placeholder)||"",t.addressLine1.label=(null===(p=d.addressLine1)||void 0===p?void 0:p.label)||s.translate("label.address_line"),t.addressLine1.placeholder=(null===(h=d.addressLine1)||void 0===h?void 0:h.placeholder)||"",t.addressLine2.label=(null===(y=d.addressLine2)||void 0===y?void 0:y.label)||s.translate("label.address_line_2"),t.addressLine2.placeholder=(null===(b=d.addressLine2)||void 0===b?void 0:b.placeholder)||"",t.postalCode.label=(null===(g=d.postalCode)||void 0===g?void 0:g.label)||s.translate("label.postal_code"),t.postalCode.placeholder=(null===(N=d.postalCode)||void 0===N?void 0:N.placeholder)||"",t.country.label=(null===(x=d.country)||void 0===x?void 0:x.label)||s.translate("label.country"),t.country.placeholder=(null===(q=d.country)||void 0===q?void 0:q.placeholder)||"",t.state.label=(null===(L=d.state)||void 0===L?void 0:L.label)||s.translate("label.state"),t.state.placeholder=(null===(S=d.state)||void 0===S?void 0:S.placeholder)||"",t.city.label=(null===(O=d.city)||void 0===O?void 0:O.label)||s.translate("label.city"),t.city.placeholder=(null===(C=d.city)||void 0===C?void 0:C.placeholder)||"",t.district.label=(null===(E=d.district)||void 0===E?void 0:E.label)||s.translate("label.district"),t.district.placeholder=(null===(j=d.district)||void 0===j?void 0:j.placeholder)||"",t.region.label=(null===(R=d.region)||void 0===R?void 0:R.label)||s.translate("label.region"),t.region.placeholder=(null===(F=d.region)||void 0===F?void 0:F.placeholder)||"",t.phone.label=(null===(w=d.phone)||void 0===w?void 0:w.label)||s.translate("label.phone"),t.phone.placeholder=(null===(T=d.phone)||void 0===T?void 0:T.placeholder)||"",t.company.label=(null===(_=d.company)||void 0===_?void 0:_.label)||s.translate("label.company"),t.company.placeholder=(null===(I=d.company)||void 0===I?void 0:I.placeholder)||"",t.taxOffice.label=(null===(A=d.taxOffice)||void 0===A?void 0:A.label)||s.translate("label.tax_office"),t.taxOffice.placeholder=(null===(k=d.taxOffice)||void 0===k?void 0:k.placeholder)||"",t.taxNumber.label=(null===(M=d.taxNumber)||void 0===M?void 0:M.label)||s.translate("label.tax_number"),t.taxNumber.placeholder=(null===(D=d.taxNumber)||void 0===D?void 0:D.placeholder)||"",[2]}})})}function _(t){t.firstName&&t.lastName&&t.identityNumber&&t.addressLine1&&t.postalCode&&t.country&&t.city&&t.district&&t.region&&t.phone&&t.company&&t.taxOffice&&t.taxNumber&&(!function(t){e(this,void 0,void 0,function(){var e,r,n,s,o,a,d;return i(this,function(i){if(e=Z(t),r=null===(o=t.locationSettings)||void 0===o?void 0:o.addressFormats,n=null===(d=null===(a=t.locationSettings)||void 0===a?void 0:a.countrySettings)||void 0===d?void 0:d[e],!(s=null==n?void 0:n.fields))return[2];t.countrySettings=s;try{t.addressFormat=r[n.addressFormat]}catch(e){t.addressFormat=[]}return[2]})})}(t),t.firstName.isRequired=R(t,"firstName").required,t.lastName.isRequired=R(t,"lastName").required,t.identityNumber.isRequired=R(t,"identityNumber").required,t.addressLine1.isRequired=R(t,"addressLine1").required,t.postalCode.isRequired=R(t,"postalCode").required,t.country.isRequired=R(t,"country").required,t.city.isRequired=R(t,"city").required,t.city.isFreeText=R(t,"city").isFreeText,t.district.isRequired=R(t,"district").required,t.district.isFreeText=R(t,"district").isFreeText,t.region.isRequired=R(t,"region").required,t.phone.isRequired=R(t,"phone").required,t.company.isRequired=R(t,"company").required,t.taxOffice.isRequired=R(t,"taxOffice").required,t.taxNumber.isRequired=R(t,"taxNumber").required)}function I(t){return e(this,void 0,void 0,function(){var e,r;return i(this,function(i){switch(i.label){case 0:return[4,import("../../../api/checkout/index.js")];case 1:return[4,(0,i.sent().apiListCheckoutSettings)({})];case 2:return(e=i.sent()).isSuccess&&(null===(r=e.data)||void 0===r?void 0:r.length)?(t.checkoutSettings=e.data[0],[2]):[2]}})})}function A(t){return e(this,void 0,void 0,function(){var e,n,s,o;return i(this,function(i){switch(i.label){case 0:return[4,import("../../../api/location/index.js")];case 1:return[4,(0,i.sent().apiGetAvailableShippingZones)({salesChannelId:r.salesChannelId})];case 2:return(e=i.sent()).isSuccess&&(null===(o=e.data)||void 0===o?void 0:o.length)?(t.shippingZones=e.data,n=B(t),s=(null==n?void 0:n.regions)||[],t.regions=s,t.regionOptions=K(s.map(J)),[2]):[2]}})})}function k(t){return e(this,void 0,void 0,function(){var e,n,s,o,a,d,l,u,c;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,7,8,9]),t.country&&(t.country.isLoading=!0),[4,import("../../../api/location/index.js")];case 1:return[4,(0,i.sent().apiListCountry)({locale:r.getCurrentLocale()})];case 2:return e=i.sent(),n=r.getCurrentRouting(),s=e.data||[],(null===(l=null==n?void 0:n.countryCodes)||void 0===l?void 0:l.length)&&(s=s.filter(function(e){var i;return e.iso2&&(null===(i=n.countryCodes)||void 0===i?void 0:i.includes(e.iso2))})),t.countries=s,1!==t.countries.length||(null===(u=t.country)||void 0===u?void 0:u.value)?[3,3]:(b(t,t.countries[0].id),[3,6]);case 3:return!t.countries.length||(null===(c=t.country)||void 0===c?void 0:c.value)?[3,6]:[4,import("../../../api/location/index.js")];case 4:return[4,(0,i.sent().apiGetMyCountry)()];case 5:(o=i.sent()).isSuccess&&o.data&&(a=o.data,d=t.countries.find(function(e){return e.iso2===a}),b(t,d?d.id:t.countries[0].id)),i.label=6;case 6:return t.countries=s,t.countryOptions=K(t.countries.map(J)),[3,9];case 7:return i.sent(),[3,9];case 8:return t.country&&(t.country.isLoading=!1),[7];case 9:return[2]}})})}function M(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a;return i(this,function(i){switch(i.label){case 0:if(!(e=null===(o=t.country)||void 0===o?void 0:o.value))return[2];i.label=1;case 1:return i.trys.push([1,4,5,6]),t.state&&(t.state.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListState)({countryId:{eq:e}})];case 3:return r=i.sent(),n=r.data||[],(s=z(t))&&!s.showAllStates&&(null===(a=s.states)||void 0===a?void 0:a.length)&&(n=n.filter(function(e){var i;return null===(i=s.states)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.states=n,n.length<=1?(g(t,n[0].id),[2]):(t.stateOptions=K(n.map(J)),[3,6]);case 4:return i.sent(),[3,6];case 5:return t.state&&(t.state.isLoading=!1),[7];case 6:return[2]}})})}function D(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a;return i(this,function(i){switch(i.label){case 0:if(!(null===(s=t.state)||void 0===s?void 0:s.value))return[2];i.label=1;case 1:return i.trys.push([1,4,5,6]),t.city&&(t.city.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListCity)({stateId:{eq:t.state.value},countryId:(null===(o=t.country)||void 0===o?void 0:o.value)?{eq:t.country.value}:void 0})];case 3:return e=i.sent(),r=e.data||[],(n=G(t))&&!n.showAllCities&&(null===(a=n.cities)||void 0===a?void 0:a.length)&&(r=r.filter(function(e){var i;return null===(i=n.cities)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.cities=r,t.cityOptions=K(r.map(J)),[3,6];case 4:return i.sent(),[3,6];case 5:return t.city&&(t.city.isLoading=!1),[7];case 6:return[2]}})})}function Y(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a,d,l;return i(this,function(i){switch(i.label){case 0:if(!(e=null===(a=t.city)||void 0===a?void 0:a.value))return[2];r=null===(d=t.state)||void 0===d?void 0:d.value,i.label=1;case 1:return i.trys.push([1,4,5,6]),t.district&&(t.district.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListDistrict)({cityId:{eq:e},stateId:r?{eq:r}:void 0})];case 3:return n=i.sent(),s=n.data||[],(o=$(t))&&!o.showAllDistricts&&(null===(l=o.districts)||void 0===l?void 0:l.length)&&(s=s.filter(function(e){var i;return null===(i=o.districts)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.districts=s,t.districtOptions=K(s.map(J)),[3,6];case 4:return i.sent(),[3,6];case 5:return t.district&&(t.district.isLoading=!1),[7];case 6:return[2]}})})}function Z(e){var i,t=null===(i=e.countries)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.country)||void 0===t?void 0:t.value)});return(null==t?void 0:t.iso2)||"TR"}function z(e){var i;return null===(i=e.shippingZones)||void 0===i?void 0:i.find(function(i){var t;return i.countryId===(null===(t=e.country)||void 0===t?void 0:t.value)})}function G(e){var i,t=z(e);return null===(i=null==t?void 0:t.states)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.state)||void 0===t?void 0:t.value)})}function $(e){var i,t=G(e);return null===(i=null==t?void 0:t.cities)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.city)||void 0===t?void 0:t.value)})}function B(e){var i,t=$(e);return null===(i=null==t?void 0:t.districts)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.district)||void 0===t?void 0:t.value)})}function H(e){var i,t,r,s,o,a,d,l,u,c,v,m,f,p,h;if(e.countries&&e.states&&e.cities&&e.districts&&e.regions){var y=e.countries.find(function(i){var t;return i.id===(null===(t=e.country)||void 0===t?void 0:t.value)}),b=e.states.find(function(i){var t;return i.id===(null===(t=e.state)||void 0===t?void 0:t.value)}),g=e.cities.find(function(i){var t;return i.id===(null===(t=e.city)||void 0===t?void 0:t.value)}),N=e.districts.find(function(i){var t;return i.id===(null===(t=e.district)||void 0===t?void 0:t.value)}),x=e.regions.find(function(i){var t;return i.id===(null===(t=e.region)||void 0===t?void 0:t.value)});return{id:e.id||n(),title:null===(i=e.title)||void 0===i?void 0:i.value,firstName:null===(t=e.firstName)||void 0===t?void 0:t.value,lastName:null===(r=e.lastName)||void 0===r?void 0:r.value,identityNumber:null===(s=e.identityNumber)||void 0===s?void 0:s.value,addressLine1:null===(o=e.addressLine1)||void 0===o?void 0:o.value,addressLine2:null===(a=e.addressLine2)||void 0===a?void 0:a.value,postalCode:null===(d=e.postalCode)||void 0===d?void 0:d.value,country:y?{id:y.id,name:y.name,code:y.iso3,iso2:y.iso2,iso3:y.iso3}:null,state:b?{id:b.id,name:b.name,code:b.stateCode}:null,city:!(null===(l=e.city)||void 0===l?void 0:l.isFreeText)&&g?{id:g.id,name:g.name,code:null}:{id:null,name:null===(u=e.city)||void 0===u?void 0:u.value,code:null},district:!(null===(c=e.district)||void 0===c?void 0:c.isFreeText)&&N?{id:N.id,name:N.name,code:null}:{id:null,name:null===(v=e.district)||void 0===v?void 0:v.value,code:null},region:x?{id:x.id,name:x.name}:null,phone:null===(m=e.phone)||void 0===m?void 0:m.value,company:null===(f=e.company)||void 0===f?void 0:f.value,taxOffice:null===(p=e.taxOffice)||void 0===p?void 0:p.value,taxNumber:null===(h=e.taxNumber)||void 0===h?void 0:h.value}}}function J(e){return{label:e.name,value:e.id+""}}function K(e){return e.sort(function(e,i){return e.label.localeCompare(i.label)})}var P={firstName:{required:!0},lastName:{required:!0},identityNumber:{required:!0},addressLine1:{required:!0},addressLine2:{required:!1},postalCode:{required:!0},country:{required:!0},city:{required:!0,isFreeText:!1},district:{required:!0,isFreeText:!1},region:{required:!1},phone:{required:!1,regex:/^\+?\d{10,}$/},company:{required:!1},taxOffice:{required:!1},taxNumber:{required:!1}},Q={value:"",hasError:!1,message:void 0,isLoading:!0};export{u as initAddressForm,p as setAddressFormAddressLine1,h as setAddressFormAddressLine2,N as setAddressFormCity,S as setAddressFormCompany,b as setAddressFormCountry,x as setAddressFormDistrict,v as setAddressFormFirstName,f as setAddressFormIdentityNumber,m as setAddressFormLastName,L as setAddressFormPhone,y as setAddressFormPostalCode,q as setAddressFormRegion,g as setAddressFormState,C as setAddressFormTaxNumber,O as setAddressFormTaxOffice,c as setAddressFormTitle,E as submitAddressForm};
|
|
1
|
+
import{__awaiter as e,__generator as i,__assign as t}from'./../../../../ext/tslib/tslib.es6.mjs.js';import{IkasStorefrontConfig as r}from"../../../../packages/storefront-config/src/index.js";import'./../../../../ext/uuid/dist/esm-browser/stringify.js';import'./../../../../ext/uuid/dist/esm-browser/v3.js';import n from'./../../../../ext/uuid/dist/esm-browser/v4.js';import'./../../../../ext/uuid/dist/esm-browser/v5.js';import{I18n as s}from"../../../../i18n/index.js";import{customerStore as o}from"../../../../stores/customer/index.js";import{cloneDeep as a}from"../../../../utils/helper.js";import{validateValue as d,FORM_ITEM_DEFAULT_VALUE as l}from"../index.js";function u(r,n){return e(this,void 0,void 0,function(){var e,s,o,a,d,u;return i(this,function(i){switch(i.label){case 0:return r.id=null==n?void 0:n.id,r.title=n?t(t({},l),{value:n.title||""}):l,r.firstName=n?t(t({},l),{value:n.firstName||""}):l,r.lastName=n?t(t({},l),{value:n.lastName||""}):l,r.identityNumber=n?t(t({},l),{value:n.identityNumber||""}):l,r.addressLine1=n?t(t({},l),{value:n.addressLine1||""}):l,r.addressLine2=n?t(t({},l),{value:n.addressLine2||""}):l,r.postalCode=n?t(t({},l),{value:n.postalCode||""}):l,r.country=n?t(t({},U),{value:(null===(e=n.country)||void 0===e?void 0:e.id)||""}):U,r.state=n?t(t({},U),{value:(null===(s=n.state)||void 0===s?void 0:s.id)||""}):U,r.city=n?t(t({},U),{value:(null===(o=n.city)||void 0===o?void 0:o.id)||(null===(a=n.city)||void 0===a?void 0:a.name)||""}):U,r.district=n?t(t({},U),{value:(null===(d=n.district)||void 0===d?void 0:d.id)||""}):U,r.region=n?t(t({},l),{value:(null===(u=n.region)||void 0===u?void 0:u.id)||""}):l,r.phone=n?t(t({},l),{value:n.phone||""}):l,r.company=n?t(t({},l),{value:n.company||""}):l,r.taxOffice=n?t(t({},l),{value:n.taxOffice||""}):l,r.taxNumber=n?t(t({},l),{value:n.taxNumber||""}):l,r.isSubmitted=!1,r.isInitialized=!1,r.isSubmitting=!1,r.isFailure=void 0,r.isSuccess=void 0,r.responseMessage=void 0,r.countryOptions=[],r.stateOptions=[],r.cityOptions=[],r.districtOptions=[],r.regionOptions=[],[4,M(r)];case 1:return i.sent(),r.state.value?[4,D(r)]:[3,3];case 2:i.sent(),i.label=3;case 3:return r.country.value?[4,Y(r)]:[3,5];case 4:i.sent(),i.label=5;case 5:return r.city.value?[4,Z(r)]:[3,7];case 6:i.sent(),i.label=7;case 7:return[4,R(r)];case 8:return i.sent(),[4,A(r)];case 9:return i.sent(),[4,k(r)];case 10:return i.sent(),I(r),r.isInitialized=!0,[2]}})})}function c(e,i){e.title&&(e.title.value=i),e.isSubmitted&&j(e)}function v(e,i){e.firstName&&(e.firstName.value=i),e.isSubmitted&&j(e)}function m(e,i){e.lastName&&(e.lastName.value=i),e.isSubmitted&&j(e)}function f(e,i){e.identityNumber&&(e.identityNumber.value=i),e.isSubmitted&&j(e)}function p(e,i){e.addressLine1&&(e.addressLine1.value=i),e.isSubmitted&&j(e)}function h(e,i){e.addressLine2&&(e.addressLine2.value=i),e.isSubmitted&&j(e)}function y(e,i){e.postalCode&&(e.postalCode.value=i),e.isSubmitted&&j(e)}function b(e,i){e.country&&e.country.value!==i&&(e.country.value=i,e.state&&(e.state.value=""),e.city&&(e.city.value=""),e.district&&(e.district.value=""),e.states=[],e.stateOptions=[],e.cities=[],e.cityOptions=[],e.districts=[],e.districtOptions=[],_(e),I(e),D(e),e.isSubmitted&&j(e))}function g(e,i){var t,r;e.state&&e.state.value!==i&&(e.state.value=i,(null===(t=e.city)||void 0===t?void 0:t.isFreeText)||(e.city&&(e.city.value=""),e.cities=[],e.cityOptions=[],Y(e)),(null===(r=e.district)||void 0===r?void 0:r.isFreeText)||(e.district&&(e.district.value=""),e.districts=[],e.districtOptions=[]),e.isSubmitted&&j(e))}function N(e,i){var t;e.city&&(e.city.value=i,e.districts=[],e.districtOptions=[],(null===(t=e.district)||void 0===t?void 0:t.isFreeText)||(e.district&&(e.district.value=""),Z(e)),e.isSubmitted&&j(e))}function x(e,i){e.district&&e.district.value!==i&&(e.district.value=i,e.region&&(e.region.value=""),e.regionOptions=[],e.isSubmitted&&j(e))}function q(e,i){e.region&&e.region.value!==i&&(e.region.value=i,e.isSubmitted&&j(e))}function L(e,i){e.phone&&(e.phone.value=i),e.isSubmitted&&j(e)}function S(e,i){e.company&&(e.company.value=i),e.isSubmitted&&j(e)}function O(e,i){e.taxOffice&&(e.taxOffice.value=i),e.isSubmitted&&j(e)}function C(e,i){e.taxNumber&&(e.taxNumber.value=i),e.isSubmitted&&j(e)}function E(t){return e(this,void 0,void 0,function(){var e,r,n,d,l,u,c;return i(this,function(i){switch(i.label){case 0:if(t.isSubmitted=!0,t.isSuccess=void 0,t.isFailure=void 0,t.responseMessage=void 0,j(t))return[2,!1];t.isSubmitting=!0,i.label=1;case 1:return i.trys.push([1,4,5,6]),(e=a(o.customer))?(r=!!t.id,n=null===(c=e.addresses)||void 0===c?void 0:c.findIndex(function(e){return e.id===t.id}),r&&e.addresses&&void 0!==n?(d=J(t))&&(e.addresses[n]=d):(e.addresses||(e.addresses=[]),(d=J(t))&&e.addresses.push(d)),[4,import("../../../stores/customer/index.js")]):(t.isSubmitting=!1,[2,!1]);case 2:return[4,(0,i.sent().saveCustomer)(o,e)];case 3:return l=i.sent(),t.isSubmitting=!1,l?(t.isSuccess=!0,t.responseMessage=s.translate("notification.success.address"),[2,!0]):(t.isFailure=!0,t.responseMessage=s.translate("notification.failure.address"),[2,!1]);case 4:return u=i.sent(),console.error(u),[3,6];case 5:return t.isSubmitting=!1,[7];case 6:return[2,!1]}})})}function j(e){if(!(e.title&&e.firstName&&e.lastName&&e.addressLine1&&e.country&&e.city&&e.district&&e.state))return!1;var i=d(e.title.value,{required:!0});i.hasError?(e.title.hasError=!0,e.title.message=i.message):(e.title.hasError=!1,e.title.message=void 0);var t=d(e.firstName.value,F(e,"firstName"));t.hasError?(e.firstName.hasError=!0,e.firstName.message=t.message):(e.firstName.hasError=!1,e.firstName.message=void 0);var r=d(e.lastName.value,F(e,"lastName"));r.hasError?(e.lastName.hasError=!0,e.lastName.message=r.message):(e.lastName.hasError=!1,e.lastName.message=void 0);var n=d(e.addressLine1.value,F(e,"addressLine1"));n.hasError?(e.addressLine1.hasError=!0,e.addressLine1.message=n.message):(e.addressLine1.hasError=!1,e.addressLine1.message=void 0);var s=d(e.country.value,F(e,"country"));s.hasError?(e.country.hasError=!0,e.country.message=s.message):(e.country.hasError=!1,e.country.message=void 0);var o=d(e.state.value,F(e,"state"));o.hasError?(e.state.hasError=!0,e.state.message=o.message):(e.state.hasError=!1,e.state.message=void 0);var a=d(e.city.value,F(e,"city"));a.hasError?(e.city.hasError=!0,e.city.message=a.message):(e.city.hasError=!1,e.city.message=void 0);var l=d(e.district.value,F(e,"district"));return l.hasError?(e.district.hasError=!0,e.district.message=l.message):(e.district.hasError=!1,e.district.message=void 0),i.hasError||t.hasError||r.hasError||n.hasError||s.hasError||a.hasError||l.hasError||o.hasError}function F(e,i){var t,r,n,s,o,a,d,l,u,c,v,m,f,p,h,y,b,g,N=null===(t=Q[i])||void 0===t?void 0:t.required,x=null===(r=Q[i])||void 0===r?void 0:r.regex,q=null===(n=Q[i])||void 0===n?void 0:n.isFreeText;e.addressFormat&&!e.addressFormat.some(function(e){return e.some(function(e){return e===i})})&&(N=!1),void 0!==(null===(o=null===(s=e.countrySettings)||void 0===s?void 0:s[i])||void 0===o?void 0:o.required)&&(N=!1!==(null===(d=null===(a=e.countrySettings)||void 0===a?void 0:a[i])||void 0===d?void 0:d.required)),void 0!==(null===(u=null===(l=e.countrySettings)||void 0===l?void 0:l[i])||void 0===u?void 0:u.regex)&&(x=null===(v=null===(c=e.countrySettings)||void 0===c?void 0:c[i])||void 0===v?void 0:v.regex),void 0!==(null===(f=null===(m=e.countrySettings)||void 0===m?void 0:m[i])||void 0===f?void 0:f.type)&&(q="text"===(null===(h=null===(p=e.countrySettings)||void 0===p?void 0:p[i])||void 0===h?void 0:h.type));var L=null===(y=e.checkoutSettings)||void 0===y?void 0:y.identityNumberRequirement;"identityNumber"===i&&L&&(N="MANDATORY"===L);var S=null===(b=e.checkoutSettings)||void 0===b?void 0:b.postalCodeRequirement;"postalCode"===i&&S&&(N="MANDATORY"===S);var O=null===(g=e.checkoutSettings)||void 0===g?void 0:g.phoneRequirement;return"phone"===i&&O&&(N="MANDATORY"===O),"region"!==i||function(e){var i,t,r;return!!(null===(i=e.district)||void 0===i?void 0:i.value)&&(null===(r=null===(t=H(e))||void 0===t?void 0:t.regions)||void 0===r?void 0:r.length)}(e)||(N=!1),{required:N,regex:x,isFreeText:q}}function R(t){return e(this,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:return[4,T(t)];case 1:return e.sent(),[4,w(t)];case 2:return e.sent(),[2]}})})}function w(t){return e(this,void 0,void 0,function(){var e;return i(this,function(i){switch(i.label){case 0:return[4,fetch("https://cdn.myikas.com/sf/static/location/settings.json")];case 1:return[4,i.sent().json()];case 2:return e=i.sent(),t.locationSettings=e,[2]}})})}function T(t){return e(this,void 0,void 0,function(){var e,n,s;return i(this,function(i){switch(i.label){case 0:return t.title&&t.firstName&&t.lastName&&t.identityNumber&&t.addressLine1&&t.addressLine2&&t.postalCode&&t.country&&t.state&&t.city&&t.district&&t.region&&t.phone&&t.company&&t.taxOffice&&t.taxNumber?(e=r.getCurrentLocale(),n="https://eu.myikas.com/sf/static/location/".concat(e,".json"),[4,fetch(n)]):[2];case 1:return[4,i.sent().json()];case 2:return s=i.sent(),t.countryLabels=s.countryLabels,_(t),[2]}})})}function _(e){var i,t,r,n,o,a,d,l,u,c,v,m,f,p,h,y,b,g,N,x,q,L,S,O,C,E,j,F,R,w;if(e.title&&e.firstName&&e.lastName&&e.identityNumber&&e.addressLine1&&e.addressLine2&&e.postalCode&&e.country&&e.state&&e.city&&e.district&&e.region&&e.phone&&e.company&&e.taxOffice&&e.taxNumber){var T=z(e),_=e.countryLabels[T].fields||{};e.title.label=s.translate("label.address_title"),e.title.placeholder="",e.firstName.label=(null===(i=_.firstName)||void 0===i?void 0:i.label)||s.translate("label.first_name"),e.firstName.placeholder=(null===(t=_.firstName)||void 0===t?void 0:t.placeholder)||"",e.lastName.label=(null===(r=_.lastName)||void 0===r?void 0:r.label)||s.translate("label.last_name"),e.lastName.placeholder=(null===(n=_.lastName)||void 0===n?void 0:n.placeholder)||"",e.identityNumber.label=(null===(o=_.identityNumber)||void 0===o?void 0:o.label)||s.translate("label.identity_number"),e.identityNumber.placeholder=(null===(a=_.identityNumber)||void 0===a?void 0:a.placeholder)||"",e.addressLine1.label=(null===(d=_.addressLine1)||void 0===d?void 0:d.label)||s.translate("label.address_line"),e.addressLine1.placeholder=(null===(l=_.addressLine1)||void 0===l?void 0:l.placeholder)||"",e.addressLine2.label=(null===(u=_.addressLine2)||void 0===u?void 0:u.label)||s.translate("label.address_line_2"),e.addressLine2.placeholder=(null===(c=_.addressLine2)||void 0===c?void 0:c.placeholder)||"",e.postalCode.label=(null===(v=_.postalCode)||void 0===v?void 0:v.label)||s.translate("label.postal_code"),e.postalCode.placeholder=(null===(m=_.postalCode)||void 0===m?void 0:m.placeholder)||"",e.country.label=(null===(f=_.country)||void 0===f?void 0:f.label)||s.translate("label.country"),e.country.placeholder=(null===(p=_.country)||void 0===p?void 0:p.placeholder)||"",e.state.label=(null===(h=_.state)||void 0===h?void 0:h.label)||s.translate("label.state"),e.state.placeholder=(null===(y=_.state)||void 0===y?void 0:y.placeholder)||"",e.city.label=(null===(b=_.city)||void 0===b?void 0:b.label)||s.translate("label.city"),e.city.placeholder=(null===(g=_.city)||void 0===g?void 0:g.placeholder)||"",e.district.label=(null===(N=_.district)||void 0===N?void 0:N.label)||s.translate("label.district"),e.district.placeholder=(null===(x=_.district)||void 0===x?void 0:x.placeholder)||"",e.region.label=(null===(q=_.region)||void 0===q?void 0:q.label)||s.translate("label.region"),e.region.placeholder=(null===(L=_.region)||void 0===L?void 0:L.placeholder)||"",e.phone.label=(null===(S=_.phone)||void 0===S?void 0:S.label)||s.translate("label.phone"),e.phone.placeholder=(null===(O=_.phone)||void 0===O?void 0:O.placeholder)||"",e.company.label=(null===(C=_.company)||void 0===C?void 0:C.label)||s.translate("label.company"),e.company.placeholder=(null===(E=_.company)||void 0===E?void 0:E.placeholder)||"",e.taxOffice.label=(null===(j=_.taxOffice)||void 0===j?void 0:j.label)||s.translate("label.tax_office"),e.taxOffice.placeholder=(null===(F=_.taxOffice)||void 0===F?void 0:F.placeholder)||"",e.taxNumber.label=(null===(R=_.taxNumber)||void 0===R?void 0:R.label)||s.translate("label.tax_number"),e.taxNumber.placeholder=(null===(w=_.taxNumber)||void 0===w?void 0:w.placeholder)||""}}function I(t){t.firstName&&t.lastName&&t.identityNumber&&t.addressLine1&&t.postalCode&&t.country&&t.city&&t.district&&t.region&&t.phone&&t.company&&t.taxOffice&&t.taxNumber&&t.state&&(!function(t){e(this,void 0,void 0,function(){var e,r,n,s,o,a,d;return i(this,function(i){if(e=z(t),r=null===(o=t.locationSettings)||void 0===o?void 0:o.addressFormats,n=null===(d=null===(a=t.locationSettings)||void 0===a?void 0:a.countrySettings)||void 0===d?void 0:d[e],!(s=null==n?void 0:n.fields))return[2];t.countrySettings=s;try{t.addressFormat=r[n.addressFormat]}catch(e){t.addressFormat=[]}return[2]})})}(t),t.firstName.isRequired=F(t,"firstName").required,t.lastName.isRequired=F(t,"lastName").required,t.identityNumber.isRequired=F(t,"identityNumber").required,t.addressLine1.isRequired=F(t,"addressLine1").required,t.postalCode.isRequired=F(t,"postalCode").required,t.country.isRequired=F(t,"country").required,t.state.isRequired=F(t,"state").required,t.city.isRequired=F(t,"city").required,t.city.isFreeText=F(t,"city").isFreeText,t.district.isRequired=F(t,"district").required,t.district.isFreeText=F(t,"district").isFreeText,t.region.isRequired=F(t,"region").required,t.phone.isRequired=F(t,"phone").required,t.company.isRequired=F(t,"company").required,t.taxOffice.isRequired=F(t,"taxOffice").required,t.taxNumber.isRequired=F(t,"taxNumber").required)}function A(t){return e(this,void 0,void 0,function(){var e,r;return i(this,function(i){switch(i.label){case 0:return[4,import("../../../api/checkout/index.js")];case 1:return[4,(0,i.sent().apiListCheckoutSettings)({})];case 2:return(e=i.sent()).isSuccess&&(null===(r=e.data)||void 0===r?void 0:r.length)?(t.checkoutSettings=e.data[0],[2]):[2]}})})}function k(t){return e(this,void 0,void 0,function(){var e,n,s,o;return i(this,function(i){switch(i.label){case 0:return[4,import("../../../api/location/index.js")];case 1:return[4,(0,i.sent().apiGetAvailableShippingZones)({salesChannelId:r.salesChannelId})];case 2:return(e=i.sent()).isSuccess&&(null===(o=e.data)||void 0===o?void 0:o.length)?(t.shippingZones=e.data,n=H(t),s=(null==n?void 0:n.regions)||[],t.regions=s,t.regionOptions=P(s.map(K)),[2]):[2]}})})}function M(t){return e(this,void 0,void 0,function(){var e,n,s,o,a,d,l,u,c;return i(this,function(i){switch(i.label){case 0:return i.trys.push([0,7,8,9]),t.country&&(t.country.isLoading=!0),[4,import("../../../api/location/index.js")];case 1:return[4,(0,i.sent().apiListCountry)({locale:r.getCurrentLocale()})];case 2:return e=i.sent(),n=r.getCurrentRouting(),s=e.data||[],(null===(l=null==n?void 0:n.countryCodes)||void 0===l?void 0:l.length)&&(s=s.filter(function(e){var i;return e.iso2&&(null===(i=n.countryCodes)||void 0===i?void 0:i.includes(e.iso2))})),t.countries=s,1!==t.countries.length||(null===(u=t.country)||void 0===u?void 0:u.value)?[3,3]:(b(t,t.countries[0].id),[3,6]);case 3:return!t.countries.length||(null===(c=t.country)||void 0===c?void 0:c.value)?[3,6]:[4,import("../../../api/location/index.js")];case 4:return[4,(0,i.sent().apiGetMyCountry)()];case 5:(o=i.sent()).isSuccess&&o.data&&(a=o.data,d=t.countries.find(function(e){return e.iso2===a}),b(t,d?d.id:t.countries[0].id)),i.label=6;case 6:return t.countries=s,t.countryOptions=P(t.countries.map(K)),[3,9];case 7:return i.sent(),[3,9];case 8:return t.country&&(t.country.isLoading=!1),[7];case 9:return[2]}})})}function D(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a;return i(this,function(i){switch(i.label){case 0:if(!(e=null===(o=t.country)||void 0===o?void 0:o.value))return[2];i.label=1;case 1:return i.trys.push([1,4,5,6]),t.state&&(t.state.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListState)({countryId:{eq:e}})];case 3:return r=i.sent(),n=r.data||[],(s=G(t))&&!s.showAllStates&&(null===(a=s.states)||void 0===a?void 0:a.length)&&(n=n.filter(function(e){var i;return null===(i=s.states)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.states=n,n.length<=1?(g(t,n[0].id),[2]):(t.stateOptions=P(n.map(K)),[3,6]);case 4:return i.sent(),[3,6];case 5:return t.state&&(t.state.isLoading=!1),[7];case 6:return[2]}})})}function Y(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a;return i(this,function(i){switch(i.label){case 0:if(!(null===(s=t.state)||void 0===s?void 0:s.value))return[2];i.label=1;case 1:return i.trys.push([1,4,5,6]),t.city&&(t.city.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListCity)({stateId:{eq:t.state.value},countryId:(null===(o=t.country)||void 0===o?void 0:o.value)?{eq:t.country.value}:void 0})];case 3:return e=i.sent(),r=e.data||[],(n=$(t))&&!n.showAllCities&&(null===(a=n.cities)||void 0===a?void 0:a.length)&&(r=r.filter(function(e){var i;return null===(i=n.cities)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.cities=r,t.cityOptions=P(r.map(K)),[3,6];case 4:return i.sent(),[3,6];case 5:return t.city&&(t.city.isLoading=!1),[7];case 6:return[2]}})})}function Z(t){return e(this,void 0,void 0,function(){var e,r,n,s,o,a,d,l;return i(this,function(i){switch(i.label){case 0:if(!(e=null===(a=t.city)||void 0===a?void 0:a.value))return[2];r=null===(d=t.state)||void 0===d?void 0:d.value,i.label=1;case 1:return i.trys.push([1,4,5,6]),t.district&&(t.district.isLoading=!0),[4,import("../../../api/location/index.js")];case 2:return[4,(0,i.sent().apiListDistrict)({cityId:{eq:e},stateId:r?{eq:r}:void 0})];case 3:return n=i.sent(),s=n.data||[],(o=B(t))&&!o.showAllDistricts&&(null===(l=o.districts)||void 0===l?void 0:l.length)&&(s=s.filter(function(e){var i;return null===(i=o.districts)||void 0===i?void 0:i.some(function(i){return i.id===e.id})})),t.districts=s,t.districtOptions=P(s.map(K)),[3,6];case 4:return i.sent(),[3,6];case 5:return t.district&&(t.district.isLoading=!1),[7];case 6:return[2]}})})}function z(e){var i,t=null===(i=e.countries)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.country)||void 0===t?void 0:t.value)});return(null==t?void 0:t.iso2)||"TR"}function G(e){var i;return null===(i=e.shippingZones)||void 0===i?void 0:i.find(function(i){var t;return i.countryId===(null===(t=e.country)||void 0===t?void 0:t.value)})}function $(e){var i,t=G(e);return null===(i=null==t?void 0:t.states)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.state)||void 0===t?void 0:t.value)})}function B(e){var i,t=$(e);return null===(i=null==t?void 0:t.cities)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.city)||void 0===t?void 0:t.value)})}function H(e){var i,t=B(e);return null===(i=null==t?void 0:t.districts)||void 0===i?void 0:i.find(function(i){var t;return i.id===(null===(t=e.district)||void 0===t?void 0:t.value)})}function J(e){var i,t,r,s,o,a,d,l,u,c,v,m,f,p,h;if(e.countries&&e.states&&e.cities&&e.districts&&e.regions){var y=e.countries.find(function(i){var t;return i.id===(null===(t=e.country)||void 0===t?void 0:t.value)}),b=e.states.find(function(i){var t;return i.id===(null===(t=e.state)||void 0===t?void 0:t.value)}),g=e.cities.find(function(i){var t;return i.id===(null===(t=e.city)||void 0===t?void 0:t.value)}),N=e.districts.find(function(i){var t;return i.id===(null===(t=e.district)||void 0===t?void 0:t.value)}),x=e.regions.find(function(i){var t;return i.id===(null===(t=e.region)||void 0===t?void 0:t.value)});return{id:e.id||n(),title:null===(i=e.title)||void 0===i?void 0:i.value,firstName:null===(t=e.firstName)||void 0===t?void 0:t.value,lastName:null===(r=e.lastName)||void 0===r?void 0:r.value,identityNumber:null===(s=e.identityNumber)||void 0===s?void 0:s.value,addressLine1:null===(o=e.addressLine1)||void 0===o?void 0:o.value,addressLine2:null===(a=e.addressLine2)||void 0===a?void 0:a.value,postalCode:null===(d=e.postalCode)||void 0===d?void 0:d.value,country:y?{id:y.id,name:y.name,code:y.iso3,iso2:y.iso2,iso3:y.iso3}:null,state:b?{id:b.id,name:b.name,code:b.stateCode}:null,city:!(null===(l=e.city)||void 0===l?void 0:l.isFreeText)&&g?{id:g.id,name:g.name,code:null}:{id:null,name:null===(u=e.city)||void 0===u?void 0:u.value,code:null},district:!(null===(c=e.district)||void 0===c?void 0:c.isFreeText)&&N?{id:N.id,name:N.name,code:null}:{id:null,name:null===(v=e.district)||void 0===v?void 0:v.value,code:null},region:x?{id:x.id,name:x.name}:null,phone:null===(m=e.phone)||void 0===m?void 0:m.value,company:null===(f=e.company)||void 0===f?void 0:f.value,taxOffice:null===(p=e.taxOffice)||void 0===p?void 0:p.value,taxNumber:null===(h=e.taxNumber)||void 0===h?void 0:h.value}}}function K(e){return{label:e.name,value:e.id+""}}function P(e){return e.sort(function(e,i){return e.label.localeCompare(i.label)})}var Q={firstName:{required:!0},lastName:{required:!0},identityNumber:{required:!0},addressLine1:{required:!0},addressLine2:{required:!1},postalCode:{required:!0},country:{required:!0},city:{required:!0,isFreeText:!1},district:{required:!0,isFreeText:!1},region:{required:!1},phone:{required:!1,regex:/^\+?\d{10,}$/},company:{required:!1},taxOffice:{required:!1},taxNumber:{required:!1}},U={value:"",hasError:!1,message:void 0,isLoading:!0};export{u as initAddressForm,p as setAddressFormAddressLine1,h as setAddressFormAddressLine2,N as setAddressFormCity,S as setAddressFormCompany,b as setAddressFormCountry,x as setAddressFormDistrict,v as setAddressFormFirstName,f as setAddressFormIdentityNumber,m as setAddressFormLastName,L as setAddressFormPhone,y as setAddressFormPostalCode,q as setAddressFormRegion,g as setAddressFormState,C as setAddressFormTaxNumber,O as setAddressFormTaxOffice,c as setAddressFormTitle,E as submitAddressForm};
|