@dropins/storefront-account 0.1.0-alpha4 → 0.1.0-alpha5
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/api/createCustomerAddress/createCustomerAddress.d.ts +4 -0
- package/api/createCustomerAddress/graphql/createCustomerAddress.graphql.d.ts +2 -0
- package/api/createCustomerAddress/index.d.ts +2 -0
- package/api/getAttributesForm/getAttributesForm.d.ts +4 -0
- package/api/getAttributesForm/graphql/getAttributesForm.graphql.d.ts +3 -0
- package/api/getAttributesForm/index.d.ts +2 -0
- package/api/getCountries/getCountries.d.ts +5 -0
- package/api/getCountries/graphql/getCountries.graphql.d.ts +2 -0
- package/api/getCountries/index.d.ts +2 -0
- package/api/getCustomer/getCustomer.d.ts +4 -0
- package/api/getCustomer/graphql/getCustomer.graphql.d.ts +2 -0
- package/api/getCustomer/index.d.ts +2 -0
- package/api/getCustomerAddress/getCustomerAddress.d.ts +4 -0
- package/api/getCustomerAddress/graphql/getCustomerAddress.graphql.d.ts +2 -0
- package/api/getCustomerAddress/index.d.ts +2 -0
- package/api/getRegions/getRegions.d.ts +2 -0
- package/api/getRegions/graphql/getRegions.graphql.d.ts +2 -0
- package/api/getRegions/index.d.ts +2 -0
- package/api/index.d.ts +8 -0
- package/api/initialize/initialize.d.ts +4 -0
- package/api/removeCustomerAddress/graphql/removeCustomerAddress.graphql.d.ts +2 -0
- package/api/removeCustomerAddress/index.d.ts +2 -0
- package/api/removeCustomerAddress/removeCustomerAddress.d.ts +2 -0
- package/api/updateCustomerAddress/graphql/updateCustomerAddress.graphql.d.ts +2 -0
- package/api/updateCustomerAddress/index.d.ts +2 -0
- package/api/updateCustomerAddress/updateCustomerAddress.d.ts +8 -0
- package/api.js +9 -1
- package/chunks/AddressFormWrapper.js +1 -0
- package/chunks/removeCustomerAddress.js +35 -0
- package/chunks/updateCustomerAddress.js +78 -0
- package/components/AccountLoaders/AccountLoaders.d.ts +7 -0
- package/components/AccountLoaders/index.d.ts +3 -0
- package/components/AddressActions/AddressActions.d.ts +5 -0
- package/components/AddressActions/index.d.ts +3 -0
- package/components/AddressCard/AddressCard.d.ts +5 -0
- package/components/AddressCard/index.d.ts +3 -0
- package/components/AddressFormWrapper/AddressFormWrapper.d.ts +5 -0
- package/components/AddressFormWrapper/index.d.ts +3 -0
- package/components/AddressModal/AddressModal.d.ts +5 -0
- package/components/AddressModal/index.d.ts +3 -0
- package/components/AddressesWrapper/AddressesWrapper.d.ts +5 -0
- package/components/AddressesWrapper/index.d.ts +3 -0
- package/components/EmptyList/EmptyList.d.ts +9 -0
- package/components/EmptyList/index.d.ts +3 -0
- package/components/Form/Form.d.ts +5 -0
- package/components/Form/FormInputs/FormInputs.d.ts +5 -0
- package/components/Form/FormInputs/index.d.ts +3 -0
- package/components/Form/index.d.ts +3 -0
- package/components/index.d.ts +11 -0
- package/configs/addressField.config.d.ts +39 -0
- package/configs/defaultAttributePreset.config.d.ts +2 -0
- package/configs/mockDefaultAddress.config.d.ts +182 -0
- package/containers/AddressForm/AddressForm.d.ts +5 -0
- package/containers/AddressForm/index.d.ts +3 -0
- package/containers/AddressForm.d.ts +3 -0
- package/containers/AddressForm.js +1 -0
- package/containers/Addresses/Addresses.d.ts +5 -0
- package/containers/Addresses/index.d.ts +3 -0
- package/containers/Addresses.d.ts +3 -0
- package/containers/Addresses.js +1 -0
- package/containers/index.d.ts +3 -0
- package/data/models/attributes-form.d.ts +45 -0
- package/data/models/country.d.ts +5 -0
- package/data/models/customer-address.d.ts +21 -0
- package/data/models/customer.d.ts +6 -0
- package/data/models/index.d.ts +4 -1
- package/data/models/region.d.ts +10 -0
- package/data/transforms/index.d.ts +5 -1
- package/data/transforms/transform-attributes-form.d.ts +6 -0
- package/data/transforms/transform-countries.d.ts +6 -0
- package/data/transforms/transform-customer-address.d.ts +7 -0
- package/data/transforms/transform-customer.d.ts +5 -0
- package/data/transforms/transform-regions.d.ts +6 -0
- package/hooks/api/useCountryRegionOptions.d.ts +7 -0
- package/hooks/components/useForm.d.ts +12 -0
- package/hooks/containers/useAddressForm.d.ts +20 -0
- package/hooks/containers/useAddresses.d.ts +22 -0
- package/hooks/useDebounce.d.ts +3 -0
- package/i18n/en_US.json.d.ts +42 -1
- package/lib/checkIsFunction.d.ts +2 -0
- package/lib/convertCase.d.ts +4 -0
- package/lib/convertToBoolean.d.ts +2 -0
- package/lib/convertToInputDateFormat.d.ts +2 -0
- package/lib/fetch-error.d.ts +5 -0
- package/lib/getFieldsConfig.d.ts +24 -0
- package/lib/getFormValues.d.ts +2 -0
- package/lib/manageAddressDeletion.d.ts +9 -0
- package/lib/network-error.d.ts +6 -0
- package/lib/normalizeAttributes.d.ts +2 -0
- package/lib/serializeAddressForm.d.ts +4 -0
- package/package.json +1 -1
- package/render.js +2 -1
- package/types/addressForm.types.d.ts +41 -0
- package/types/addresses.types.d.ts +54 -0
- package/types/api/createCustomerAddress.types.d.ts +47 -0
- package/types/api/getAttributesForm.types.d.ts +31 -0
- package/types/api/getCountries.types.d.ts +15 -0
- package/types/api/getCustomer.types.d.ts +13 -0
- package/types/api/getCustomerAddress.type.d.ts +36 -0
- package/types/api/getRegions.types.d.ts +16 -0
- package/types/api/removeCustomerAddress.types.d.ts +9 -0
- package/types/api/updateCustomerAddress.types.d.ts +11 -0
- package/types/form.types.d.ts +40 -0
- package/types/index.d.ts +12 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const GET_ATTRIBUTES_FORM = "\n query GET_ATTRIBUTES_FORM($formCode: String!) {\n attributesForm(formCode: $formCode) {\n items {\n code\n default_value\n entity_type\n frontend_class\n frontend_input\n is_required\n is_unique\n label\n options {\n is_default\n label\n value\n }\n ... on CustomerAttributeMetadata {\n multiline_count\n sort_order\n validate_rules {\n name\n value\n }\n }\n }\n errors {\n type\n message\n }\n }\n }\n";
|
|
2
|
+
export declare const GET_ATTRIBUTES_FORM_SHORT = "\n query GET_ATTRIBUTES_FORM_SHORT {\n attributesForm(formCode: customer_register_address) {\n items {\n frontend_input\n label\n code\n ... on CustomerAttributeMetadata {\n multiline_count\n sort_order\n }\n }\n }\n }\n";
|
|
3
|
+
//# sourceMappingURL=getAttributesForm.graphql.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const GET_CUSTOMER_ADDRESS = "\n query GET_CUSTOMER_ADDRESS {\n customer {\n addresses {\n firstname\n lastname\n city\n company\n country_code\n region {\n region\n region_code\n region_id\n }\n custom_attributesV2 {\n ... on AttributeValue {\n code\n value\n }\n }\n telephone\n id\n vat_id\n postcode\n street\n default_shipping\n default_billing\n }\n }\n }\n";
|
|
2
|
+
//# sourceMappingURL=getCustomerAddress.graphql.d.ts.map
|
package/api/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export * from './initialize';
|
|
2
2
|
export * from './fetch-graphql';
|
|
3
|
+
export * from './getAttributesForm';
|
|
4
|
+
export * from './createCustomerAddress';
|
|
5
|
+
export * from './getCustomerAddress';
|
|
6
|
+
export * from './getCountries';
|
|
7
|
+
export * from './getRegions';
|
|
8
|
+
export * from './updateCustomerAddress';
|
|
9
|
+
export * from './getCustomer';
|
|
10
|
+
export * from './removeCustomerAddress';
|
|
3
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,6 +3,10 @@ import { Lang } from '@dropins/tools/types/elsie/src/i18n';
|
|
|
3
3
|
|
|
4
4
|
type ConfigProps = {
|
|
5
5
|
langDefinitions?: Lang;
|
|
6
|
+
authHeaderConfig?: {
|
|
7
|
+
header?: string;
|
|
8
|
+
tokenPrefix?: string;
|
|
9
|
+
};
|
|
6
10
|
};
|
|
7
11
|
export declare const initialize: Initializer<ConfigProps>;
|
|
8
12
|
export declare const config: import('@dropins/tools/types/elsie/src/lib').Config<ConfigProps>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CustomerAddressesModel } from '../../data/models';
|
|
2
|
+
|
|
3
|
+
type ExtendedAddressFormProps = CustomerAddressesModel & {
|
|
4
|
+
addressId: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const updateCustomerAddress: (forms: ExtendedAddressFormProps) => Promise<string>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=updateCustomerAddress.d.ts.map
|
package/api.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
import{Initializer as
|
|
1
|
+
import{Initializer as s}from"@dropins/tools/lib.js";import{f as n,h as d,a as u}from"./chunks/updateCustomerAddress.js";import{e as x,d as H,g as Q,i as w,j as y,r as z,s as R,b,c as k,u as v}from"./chunks/updateCustomerAddress.js";import{g as O,r as S}from"./chunks/removeCustomerAddress.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/fetch-graphql.js";const c=new s({init:async t=>{const a={authHeaderConfig:{header:"Authorization",tokenPrefix:"Bearer"}};c.config.setConfig({...a,...t})},listeners:()=>[]}),G=c.config,f=t=>{var a,r,e,i,o,m;return{email:((r=(a=t==null?void 0:t.data)==null?void 0:a.customer)==null?void 0:r.email)||"",firstname:((i=(e=t==null?void 0:t.data)==null?void 0:e.customer)==null?void 0:i.firstname)||"",lastname:((m=(o=t==null?void 0:t.data)==null?void 0:o.customer)==null?void 0:m.lastname)||""}},h=`
|
|
2
|
+
query GET_CUSTOMER {
|
|
3
|
+
customer {
|
|
4
|
+
firstname
|
|
5
|
+
lastname
|
|
6
|
+
email
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
`,A=async()=>await n(h,{method:"GET",cache:"force-cache"}).then(t=>{var a;return(a=t.errors)!=null&&a.length?d(t.errors):f(t)}).catch(u);export{G as config,x as createCustomerAddress,n as fetchGraphQl,H as getAttributesForm,Q as getConfig,w as getCountries,A as getCustomer,O as getCustomerAddress,y as getRegions,c as initialize,S as removeCustomerAddress,z as removeFetchGraphQlHeader,R as setEndpoint,b as setFetchGraphQlHeader,k as setFetchGraphQlHeaders,v as updateCustomerAddress};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as n,Fragment as j,jsxs as U}from"@dropins/tools/preact-jsx-runtime.js";import{classes as F,Slot as G}from"@dropins/tools/lib.js";import{memo as C,useCallback as R}from"@dropins/tools/preact-compat.js";import{Field as O,Picker as Y,Input as J,InputDate as k,Checkbox as Q,TextArea as Z,Skeleton as P,SkeletonRow as $,Card as B,InLineAlert as ee,Button as H}from"@dropins/tools/components.js";import"@dropins/tools/preact.js";import{useRef as te,useState as N,useEffect as S,useCallback as L,useMemo as re}from"@dropins/tools/preact-hooks.js";import{useText as X}from"@dropins/tools/i18n.js";import{i as ae,j as se,k as de,d as ne,u as oe,e as le}from"./updateCustomerAddress.js";const ze=({slots:e,addressesFormTitle:a,className:i,addressFormId:s,inputsDefaultValueSet:r,billingCheckBoxValue:o,shippingCheckBoxValue:c,showBillingCheckBox:d,showShippingCheckBox:b,isOpen:g,onSubmit:E,onCloseBtnClick:T,onSuccess:I,onError:t,onChange:l})=>n("div",{className:F(["dropin-address-form"]),children:n(Te,{slots:e,addressesFormTitle:a,className:i,addressFormId:s,inputsDefaultValueSet:r,shippingCheckBoxValue:c,billingCheckBoxValue:o,showShippingCheckBox:b,showBillingCheckBox:d,isOpen:g,onSubmit:E,onCloseBtnClick:T,onSuccess:I,onError:t,onChange:l})}),ue=e=>e.reduce((a,{code:i,required:s,defaultValue:r})=>(s&&(a[i]=r),a),{}),ie=({fieldsConfig:e,onSubmit:a,handleSetCountryCode:i,onChange:s})=>{const{requiredFieldError:r}=X({requiredFieldError:"Account.FormText.requiredFieldError"}),o=te(null),[c,d]=N({}),[b,g]=N({}),[E,T]=N({previousCountryCode:null,previousRegionCode:null,initialLoad:!0});S(()=>{var A;const f=c.country_code,u=e==null?void 0:e.find(h=>h.code==="region");if(E.initialLoad)T(h=>({...h,previousCountryCode:f,initialLoad:!1}));else if(E.previousCountryCode!==f){T(m=>({...m,previousCountryCode:f}));const h=!((A=u==null?void 0:u.options)!=null&&A.length)&&!(u!=null&&u.defaultValue)||E.previousRegionCode?"":(u==null?void 0:u.defaultValue)??"";d(m=>({...m,region:h})),i(f)}u!=null&&u.defaultValue&&E.previousCountryCode===f&&T(h=>({...h,previousRegionCode:u.defaultValue}))},[e,c,E.previousCountryCode,E.initialLoad,E.previousRegionCode,i,d]),S(()=>{if(!(e!=null&&e.length))return;const f=ue(e);d(f)},[e==null?void 0:e.length]);const I=L((f,u)=>{const A=e.find(h=>h.code===f);return A!=null&&A.required&&!u?r:""},[e,r]),t=L(f=>{const{name:u,value:A,type:h,checked:m}=f==null?void 0:f.target,y=h==="checkbox"?m:A;d(_=>({..._,[u]:y}))},[]),l=L(f=>{const u=f.currentTarget,A=f.target,h=new FormData(u),m=Object.fromEntries(h.entries()),y={[A.name]:m[A.name]&&String(m[A.name])};s==null||s(m,y,f)},[s]),p=L(f=>{const{name:u,value:A,type:h,checked:m}=f==null?void 0:f.target,y=h==="checkbox"?m:A;g(_=>({..._,[u]:I(u,y)}))},[I]),M=L(f=>{f.preventDefault();let u=!0,A={},h=null;for(const[m,y]of Object.entries(c)){const _=I(m,y);_&&(A[m]=_,u=!1,h||(h=m))}if(g(A),h&&o.current){const m=o.current.elements.namedItem(h);m==null||m.focus()}a==null||a(f,u)},[c,I,a]);return{formData:c,errors:b,formRef:o,handleInputChange:t,handleFormChange:l,handleBlur:p,handleSubmit:M}};var z=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(z||{});const ce=C(({loading:e,values:a,fields:i=[],errors:s,className:r="",onChange:o,onBlur:c})=>{const d=`${r}__field`,b=R((t,l,p)=>n(O,{error:p,className:F([d,`${d}--${t.id}`,[`${d}--${t.id}-hidden`,t.isHidden],t.className]),"data-testid":`${r}--${t.id}`,disabled:e,children:n(Y,{name:t.id,floatingLabel:`${t.label} ${t.required?"*":""}`,placeholder:t.label,"aria-label":t.label,options:t.options,onBlur:c,handleSelect:o,value:l||t.defaultValue})},t.id),[r,e,d,c,o]),g=R((t,l,p)=>n(O,{error:p,className:F([d,`${d}--${t.id}`,[`${d}--${t.id}-hidden`,t.isHidden],t.className]),"data-testid":`${r}--${t.id}`,disabled:e,children:n(J,{type:"text",name:t.id,value:l??t.defaultValue,placeholder:t.label,floatingLabel:`${t.label} ${t.required?"*":""}`,onBlur:c,onChange:o})},t.id),[r,e,d,c,o]),E=R((t,l,p)=>n(O,{error:p,className:F([d,`${d}--${t.id}`,[`${d}--${t.id}-hidden`,t.isHidden],t.className]),"data-testid":`${r}--${t.id}`,disabled:e,children:n(k,{type:"text",name:t.id,value:l||t.defaultValue,placeholder:t.label,floatingLabel:`${t.label} ${t.required?"*":""}`,onBlur:c,onChange:o})},t.id),[r,e,d,c,o]),T=R((t,l,p)=>n(O,{error:p,className:F([d,`${d}--${t.id}`,[`${d}--${t.id}-hidden`,t.isHidden],t.className]),"data-testid":`${r}--${t.id}`,disabled:e,children:n(Q,{name:t.id,checked:l||t.defaultValue,placeholder:t.label,label:`${t.label} ${t.required?"*":""}`,onBlur:c,onChange:o})},t.id),[r,e,d,c,o]),I=R((t,l,p)=>n(O,{error:p,className:F([d,`${d}--${t.id}`,[`${d}--${t.id}-hidden`,t.isHidden],t.className]),"data-testid":`${r}--${t.id}`,disabled:e,children:n(Z,{type:"text",name:t.id,value:l??t.defaultValue,label:`${t.label} ${t.required?"*":""}`,onBlur:c,onChange:o})},t.id),[r,e,d,c,o]);return i.length?n(j,{children:i.map(t=>{const l=s==null?void 0:s[t.id],p=a==null?void 0:a[t.id];switch(t.fieldType){case z.TEXT:return t.options.length?b(t,p,l):g(t,p,l);case z.MULTILINE:return g(t,p,l);case z.SELECT:return b(t,p,l);case z.DATE:return E(t,p,l);case z.BOOLEAN:return T(t,p,l);case"TEXTAREA":return I(t,p,l);default:return null}})}):null}),pe=C(({slots:e,name:a,loading:i,children:s,className:r="defaultForm",fieldsConfig:o,onSubmit:c,handleSetCountryCode:d,onChange:b})=>{const{formData:g,errors:E,formRef:T,handleInputChange:I,handleFormChange:t,handleBlur:l,handleSubmit:p}=ie({fieldsConfig:o,onSubmit:c,handleSetCountryCode:d,onChange:b});return U("form",{className:F(["dropin-form",r]),onSubmit:p,onChange:t,name:a,ref:T,children:[n(ce,{className:r,loading:i,fields:o,onChange:I,onBlur:l,errors:E,values:g}),e!=null&&e.AddressFormInputs?n(G,{"data-testid":"addressFormInputs",name:"AddressFormInputs",slot:e.AddressFormInputs,context:{formActions:{handleChange:I}}}):null,s]})}),Ue=({testId:e,withCard:a=!0})=>{const i=U(P,{"data-testid":e||"skeletonLoader",children:[n($,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),n($,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),n($,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return a?i:n(B,{variant:"secondary",className:F(["dropin-account-loaders","dropin-account-loaders--card-loader"]),children:i})},fe=()=>U(P,{"data-testid":"addressFormLoader",children:[n($,{variant:"heading",size:"medium"}),n($,{variant:"empty",size:"medium"}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large",fullWidth:!0}),n($,{size:"large",fullWidth:!0,lines:3}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large"}),n($,{size:"large",fullWidth:!0})]}),he=()=>{const[e,a]=N(""),[i,s]=N({});S(()=>{ae().then(o=>{s(c=>({...c,country_code:o}))})},[]),S(()=>{e&&se(e).then(o=>{s(c=>({...c,region:o}))})},[e]);const r=L(o=>{o&&a(o)},[]);return{countryRegionOptions:i,handleSetCountryCode:r}},K={entityType:"CUSTOMER_ADDRESS",isUnique:!1,options:[],multilineCount:0,validateRules:[],defaultValue:!1,fieldType:z.BOOLEAN,className:"",required:!1,orderNumber:90,isHidden:!1},me={...K,label:"Set as default shipping address",name:"default_shipping",id:"default_shipping",code:"default_shipping",customUpperCode:"defaultShipping"},Ae={...K,label:"Set as default billing address",name:"default_billing",id:"default_billing",code:"default_billing",customUpperCode:"defaultBilling"},ye=(e,a)=>{const i=a.map(s=>({...s}));return i.forEach(s=>{if(Object.prototype.hasOwnProperty.call(e,s.customUpperCode)){const r=e[s.customUpperCode];if(s.customUpperCode==="region"&&typeof r=="object"){const o=r!=null&&r.regionCode&&(r!=null&&r.regionId)?`${r.regionCode},${r.regionId}`:r.region;s.defaultValue=o}else s.defaultValue=r}}),i},W=e=>{if(!e)return null;const a=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(s=>{a.has(s.name)||a.set(s.name,"false"),s.checked&&a.set(s.name,"true")}),a&&typeof a.entries=="function"){const s=a.entries();if(s&&typeof s[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(s)))||{}}return{}},be=e=>{switch(e){case"on":case"true":case 1:case"1":return!0;case"0":case"off":case"false":case 0:return!1;default:return!1}},ge=e=>{const a=["region","city","company","country_code","country_id","default_billing","default_shipping","fax","firstname","lastname","middlename","postcode","prefix","street","suffix","telephone","vat_id","addressId"],i={},s=[];return Object.keys(e).forEach(r=>{a.includes(r)?i[r]=e[r]:s.push({attribute_code:r,value:e[r]})}),s.length>0&&(i.custom_attributesV2=s),i},w=e=>{const a=["street","street_1","street_2"],i=["on","off","true","false"],s=[],r={};for(const l in e){const p=e[l];i.includes(p)&&(r[l]=be(p)),a.includes(l)&&s.push(p)}const{street:o,street_2:c,street_1:d,region:b,...g}=e,[E,T]=b?b.split(","):[void 0,void 0],I=T&&E?{region_id:+T,region_code:E}:{region:E},t=ge({...g,...r,region:{...I},street:s});return de(t,"camelCase",{})},Ee=(e,a)=>a!=null&&a.length?e.code==="region"?{...e,required:!!(a!=null&&a.length),options:a}:{...e,options:a}:e,Ie=({addressFormId:e,billingCheckBoxValue:a,shippingCheckBoxValue:i,showShippingCheckBox:s,showBillingCheckBox:r,countryRegionOptions:o,inputsDefaultValueSet:c,onCloseBtnClick:d,onSuccess:b,onError:g})=>{const[E,T]=N(!1),[I,t]=N(e||""),[l,p]=N([]),[M,f]=N({text:"",type:"success"});S(()=>{ne(I?"customer_address_edit":"customer_register_address").then(y=>{p(y)})},[I]);const u=L(()=>{f({text:"",type:"success"}),d==null||d()},[d]),A=L(async(y,_)=>{if(!_)return null;T(!0);const V=W(y.target),q=w(V);await oe(q).then(()=>{var x;b==null||b(),d==null||d(),(x=y==null?void 0:y.target)==null||x.reset()}).catch(x=>{f(D=>({...D,text:x.message,type:"error"})),g==null||g(x)}).finally(()=>{t(""),T(!1)})},[d,g,b]),h=L(async(y,_)=>{if(!_)return null;T(!0);const V=W(y.target),q=w(V);await le(q).then(()=>{var x;b==null||b(),d==null||d(),(x=y==null?void 0:y.target)==null||x.reset()}).catch(x=>{f(D=>({...D,text:x.message,type:"error"})),g==null||g(x)}).finally(()=>{t(""),T(!1)})},[d,g,b]),m=re(()=>{if(!l.length)return[];const y={...me,defaultValue:i,isHidden:!s},_={...Ae,defaultValue:a,isHidden:!r},V=[...l,y,_];return ye(c||{},V).filter(D=>!(I&&(D.customUpperCode==="defaultShipping"||D.customUpperCode==="defaultBilling")&&D.defaultValue)).map(D=>{const v=o[D.code];return Ee(D,v)})},[l,s,i,r,a,c,o,I]);return{inLineAlert:M,addressId:I,submitLoading:E,normalizeFieldsConfig:m,handleUpdateAddress:A,handleCreateAddress:h,handleOnCloseForm:u}},Te=({slots:e,addressesFormTitle:a,className:i,addressFormId:s,inputsDefaultValueSet:r,showShippingCheckBox:o=!0,showBillingCheckBox:c=!0,shippingCheckBoxValue:d=!0,billingCheckBoxValue:b=!0,isOpen:g,onSubmit:E,onCloseBtnClick:T,onSuccess:I,onError:t,onChange:l})=>{const p=X({secondaryButton:"Account.AddressForm.formText.secondaryButton",primaryButton:"Account.AddressForm.formText.primaryButton"}),{countryRegionOptions:M,handleSetCountryCode:f}=he(),{inLineAlert:u,addressId:A,submitLoading:h,normalizeFieldsConfig:m,handleUpdateAddress:y,handleCreateAddress:_,handleOnCloseForm:V}=Ie({addressFormId:s,inputsDefaultValueSet:r,countryRegionOptions:M,shippingCheckBoxValue:d,billingCheckBoxValue:b,showShippingCheckBox:o,showBillingCheckBox:c,onSuccess:I,onError:t,onCloseBtnClick:T});return g?m!=null&&m.length?U("div",{className:F(["dropin-address-form-wrapper",i]),children:[n("div",{className:"dropin-address-form-wrapper--title","data-testid":"addressesFormTitle",children:a}),u.text?n(ee,{"data-testid":"inLineAlert",className:"dropin-address-form-wrapper--notification",type:u.type,variant:"secondary",heading:u.text,icon:u.icon}):null,U(pe,{slots:e,className:"dropin-address-form",name:"addressesForm",loading:h,fieldsConfig:m,onSubmit:E||(A?y:_),handleSetCountryCode:f,onChange:l,children:[A?n("input",{type:"hidden",name:"addressId",value:A,"data-testid":"hidden_test_id"}):null,n("div",{className:"dropin-field dropin-address-form-wrapper--buttons",children:e!=null&&e.AddressFormActions?n(G,{"data-testid":"addressFormActions",name:"AddressFormActions",slot:e.AddressFormActions,context:{handleUpdateAddress:y,handleCreateAddress:_,addressId:A}}):U(j,{children:[n(H,{type:"button",onClick:V,variant:"secondary",disabled:h,children:p.secondaryButton}),n(H,{disabled:h,children:p.primaryButton})]})})]})]}):n("div",{children:n(fe,{})}):null};export{ze as A,Ue as C};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import{k as g,f as e,h as u,a as f}from"./updateCustomerAddress.js";const h=a=>{const t={};for(const o in a){const s=a[o];!Array.isArray(s)||s.length===0||(o==="custom_attributesV2"?s.forEach(n=>{typeof n=="object"&&"value"in n&&(t[n==null?void 0:n.code]=n==null?void 0:n.value)}):s.length>1?s.forEach((n,r)=>{r===0?t[o]=n:t[`${o}_${r+1}`]=n}):t[o]=s[0])}return t},_=a=>{var s,n;const t=((n=(s=a==null?void 0:a.data)==null?void 0:s.customer)==null?void 0:n.addresses)||[];return t.length?t.map(r=>{var i,d,c;return{firstname:(r==null?void 0:r.firstname)||"",lastname:(r==null?void 0:r.lastname)||"",city:(r==null?void 0:r.city)||"",company:(r==null?void 0:r.company)||"",country_code:(r==null?void 0:r.country_code)||"",region:{region:((i=r==null?void 0:r.region)==null?void 0:i.region)||"",region_code:((d=r==null?void 0:r.region)==null?void 0:d.region_code)||"",region_id:((c=r==null?void 0:r.region)==null?void 0:c.region_id)||""},telephone:(r==null?void 0:r.telephone)||"",id:(r==null?void 0:r.id)||"",vat_id:(r==null?void 0:r.vat_id)||"",postcode:(r==null?void 0:r.postcode)||"",default_shipping:(r==null?void 0:r.default_shipping)||!1,default_billing:(r==null?void 0:r.default_billing)||!1,...h(r)}}).map(r=>g(r,"camelCase",{})).sort((r,i)=>(Number(i.defaultBilling)||Number(i.defaultShipping))-(Number(r.defaultBilling)||Number(r.defaultShipping))):[]},m=`
|
|
2
|
+
query GET_CUSTOMER_ADDRESS {
|
|
3
|
+
customer {
|
|
4
|
+
addresses {
|
|
5
|
+
firstname
|
|
6
|
+
lastname
|
|
7
|
+
city
|
|
8
|
+
company
|
|
9
|
+
country_code
|
|
10
|
+
region {
|
|
11
|
+
region
|
|
12
|
+
region_code
|
|
13
|
+
region_id
|
|
14
|
+
}
|
|
15
|
+
custom_attributesV2 {
|
|
16
|
+
... on AttributeValue {
|
|
17
|
+
code
|
|
18
|
+
value
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
telephone
|
|
22
|
+
id
|
|
23
|
+
vat_id
|
|
24
|
+
postcode
|
|
25
|
+
street
|
|
26
|
+
default_shipping
|
|
27
|
+
default_billing
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`,p=async()=>await e(m,{method:"GET",cache:"force-cache"}).then(a=>{var t;return(t=a.errors)!=null&&t.length?u(a.errors):_(a)}).catch(f),E=`
|
|
32
|
+
mutation REMOVE_CUSTOMER_ADDRESS($id: Int!) {
|
|
33
|
+
deleteCustomerAddress(id:$id)
|
|
34
|
+
}
|
|
35
|
+
`,S=async a=>await e(E,{method:"POST",variables:{id:a}}).then(t=>{var o;return(o=t.errors)!=null&&o.length?u(t.errors):t.data.deleteCustomerAddress}).catch(f);export{p as g,S as r};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import{events as E}from"@dropins/tools/event-bus.js";import{FetchGraphQL as b}from"@dropins/tools/fetch-graphql.js";const{setEndpoint:U,setFetchGraphQlHeader:w,removeFetchGraphQlHeader:D,setFetchGraphQlHeaders:F,fetchGraphQl:l,getConfig:M}=new b().getMethods(),C=`
|
|
2
|
+
query GET_ATTRIBUTES_FORM($formCode: String!) {
|
|
3
|
+
attributesForm(formCode: $formCode) {
|
|
4
|
+
items {
|
|
5
|
+
code
|
|
6
|
+
default_value
|
|
7
|
+
entity_type
|
|
8
|
+
frontend_class
|
|
9
|
+
frontend_input
|
|
10
|
+
is_required
|
|
11
|
+
is_unique
|
|
12
|
+
label
|
|
13
|
+
options {
|
|
14
|
+
is_default
|
|
15
|
+
label
|
|
16
|
+
value
|
|
17
|
+
}
|
|
18
|
+
... on CustomerAttributeMetadata {
|
|
19
|
+
multiline_count
|
|
20
|
+
sort_order
|
|
21
|
+
validate_rules {
|
|
22
|
+
name
|
|
23
|
+
value
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
errors {
|
|
28
|
+
type
|
|
29
|
+
message
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`,T=`
|
|
34
|
+
query GET_ATTRIBUTES_FORM_SHORT {
|
|
35
|
+
attributesForm(formCode: customer_register_address) {
|
|
36
|
+
items {
|
|
37
|
+
frontend_input
|
|
38
|
+
label
|
|
39
|
+
code
|
|
40
|
+
... on CustomerAttributeMetadata {
|
|
41
|
+
multiline_count
|
|
42
|
+
sort_order
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`,m=t=>{throw t instanceof DOMException&&t.name==="AbortError"||E.emit("error",{source:"auth",type:"network",error:t}),t},_=t=>{const e=t.map(r=>r.message).join(" ");throw Error(e)},h=t=>t.replace(/_([a-z])/g,(e,r)=>r.toUpperCase()),A=t=>t.replace(/([A-Z])/g,e=>`_${e.toLowerCase()}`),d=(t,e,r)=>{const n=["string","boolean","number"],o=e==="camelCase"?h:A;return Array.isArray(t)?t.map(a=>n.includes(typeof a)||a===null?a:typeof a=="object"?d(a,e,r):a):t!==null&&typeof t=="object"?Object.entries(t).reduce((a,[s,u])=>{const i=r&&r[s]?r[s]:o(s);return a[i]=n.includes(typeof u)||u===null?u:d(u,e,r),a},{}):t},R=t=>{let e=[];for(const r of t)if(!(r.frontend_input!=="MULTILINE"||r.multiline_count<2))for(let n=2;n<=r.multiline_count;n++){const o={...r,name:`${r.code}_${n}`,code:`${r.code}_${n}`,id:`${r.code}_${n}`};e.push(o)}return e},g=t=>{var a,s,u;const e=((s=(a=t==null?void 0:t.data)==null?void 0:a.attributesForm)==null?void 0:s.items)||[];if(!e.length)return[];const r=(u=e.filter(i=>{var c;return!((c=i.frontend_input)!=null&&c.includes("HIDDEN"))}))==null?void 0:u.map(({code:i,...c})=>{const f=i!=="country_id"?i:"country_code";return{...c,name:f,id:f,code:f}}),n=R(r);return r.concat(n).map(i=>{const c=h(i.code);return d({...i,customUpperCode:c},"camelCase",{frontend_input:"fieldType",frontend_class:"className",is_required:"required",sort_order:"orderNumber"})}).sort((i,c)=>i.orderNumber-c.orderNumber)},S=t=>{var n,o;if(!((o=(n=t==null?void 0:t.data)==null?void 0:n.countries)!=null&&o.length))return[];const{countries:e}=t.data;return e.filter(({two_letter_abbreviation:a,full_name_locale:s})=>!!(a&&s)).map(a=>{const{two_letter_abbreviation:s,full_name_locale:u}=a;return{value:s,text:u}})},y=t=>{var r,n;return(n=(r=t==null?void 0:t.data)==null?void 0:r.country)!=null&&n.available_regions?t.data.country.available_regions.filter(o=>{if(!o)return!1;const{id:a,code:s,name:u}=o;return!!(a&&s&&u)}).map(o=>{const{id:a}=o;return{id:a,text:o.name,value:`${o.code},${o.id}`}}):[]},N=async t=>await l(t!=="shortRequest"?C:T,{method:"GET",cache:"force-cache",variables:{formCode:t}}).then(e=>{var r;return(r=e.errors)!=null&&r.length?_(e.errors):g(e)}).catch(m),v=`
|
|
48
|
+
mutation CREATE_CUSTOMER_ADDRESS($input: CustomerAddressInput!) {
|
|
49
|
+
createCustomerAddress(input:$input) {
|
|
50
|
+
firstname
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`,q=async t=>await l(v,{method:"POST",variables:{input:d(t,"snakeCase",{customAttributesV2:"custom_attributesV2"})}}).then(e=>{var r,n,o;return(r=e.errors)!=null&&r.length?_(e.errors):((o=(n=e==null?void 0:e.data)==null?void 0:n.createCustomerAddress)==null?void 0:o.firstname)||""}).catch(m),I=`
|
|
54
|
+
query GET_COUNTRIES_QUERY {
|
|
55
|
+
countries {
|
|
56
|
+
two_letter_abbreviation
|
|
57
|
+
full_name_locale
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`,Q=async()=>await l(I,{method:"GET",cache:"no-cache"}).then(t=>{var e;return(e=t.errors)!=null&&e.length?_(t.errors):S(t)}).catch(m),$=`
|
|
61
|
+
query GET_REGIONS($countryCode: String!) {
|
|
62
|
+
country(id: $countryCode) {
|
|
63
|
+
id
|
|
64
|
+
available_regions {
|
|
65
|
+
id
|
|
66
|
+
code
|
|
67
|
+
name
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`,B=async t=>await l($,{method:"GET",cache:"no-cache",variables:{countryCode:t}}).then(e=>{var r;return(r=e.errors)!=null&&r.length?_(e.errors):y(e)}).catch(m),G=`
|
|
72
|
+
mutation UPDATE_CUSTOMER_ADDRESS($id: Int!,
|
|
73
|
+
$input: CustomerAddressInput) {
|
|
74
|
+
updateCustomerAddress(id:$id, input:$input) {
|
|
75
|
+
firstname
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`,H=async t=>{const{addressId:e,...r}=t;return e?await l(G,{method:"POST",variables:{id:e,input:d(r,"snakeCase",{customAttributesV2:"custom_attributesV2"})}}).then(n=>{var o,a,s;return(o=n.errors)!=null&&o.length?_(n.errors):((s=(a=n==null?void 0:n.data)==null?void 0:a.updateCustomerAddress)==null?void 0:s.firstname)||""}).catch(m):""};export{m as a,w as b,F as c,N as d,q as e,l as f,M as g,_ as h,Q as i,B as j,d as k,h as l,D as r,U as s,H as u};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
export declare const CardLoader: ({ testId, withCard, }: {
|
|
3
|
+
testId?: string | undefined;
|
|
4
|
+
withCard?: boolean | undefined;
|
|
5
|
+
}) => import("preact").JSX.Element;
|
|
6
|
+
export declare const AddressFormLoader: () => import("preact").JSX.Element;
|
|
7
|
+
//# sourceMappingURL=AccountLoaders.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FunctionComponent } from 'preact';
|
|
2
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
3
|
+
|
|
4
|
+
export interface EmptyListProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
isEmpty: boolean;
|
|
6
|
+
typeList: 'address' | 'orders';
|
|
7
|
+
}
|
|
8
|
+
export declare const EmptyList: FunctionComponent<EmptyListProps>;
|
|
9
|
+
//# sourceMappingURL=EmptyList.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from '../containers/AddressForm';
|
|
2
|
+
export * from './Form';
|
|
3
|
+
export * from './Form/FormInputs';
|
|
4
|
+
export * from './AddressCard';
|
|
5
|
+
export * from './AddressActions';
|
|
6
|
+
export * from './AddressModal';
|
|
7
|
+
export * from './EmptyList';
|
|
8
|
+
export * from './AccountLoaders';
|
|
9
|
+
export * from './AddressesWrapper';
|
|
10
|
+
export * from './AddressFormWrapper';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FieldEnumList } from '../data/models';
|
|
2
|
+
|
|
3
|
+
export declare const defaultShippingCheckBox: {
|
|
4
|
+
label: string;
|
|
5
|
+
name: string;
|
|
6
|
+
id: string;
|
|
7
|
+
code: string;
|
|
8
|
+
customUpperCode: string;
|
|
9
|
+
entityType: string;
|
|
10
|
+
isUnique: boolean;
|
|
11
|
+
options: never[];
|
|
12
|
+
multilineCount: number;
|
|
13
|
+
validateRules: never[];
|
|
14
|
+
defaultValue: boolean;
|
|
15
|
+
fieldType: FieldEnumList;
|
|
16
|
+
className: string;
|
|
17
|
+
required: boolean;
|
|
18
|
+
orderNumber: number;
|
|
19
|
+
isHidden: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare const defaultBillingCheckBox: {
|
|
22
|
+
label: string;
|
|
23
|
+
name: string;
|
|
24
|
+
id: string;
|
|
25
|
+
code: string;
|
|
26
|
+
customUpperCode: string;
|
|
27
|
+
entityType: string;
|
|
28
|
+
isUnique: boolean;
|
|
29
|
+
options: never[];
|
|
30
|
+
multilineCount: number;
|
|
31
|
+
validateRules: never[];
|
|
32
|
+
defaultValue: boolean;
|
|
33
|
+
fieldType: FieldEnumList;
|
|
34
|
+
className: string;
|
|
35
|
+
required: boolean;
|
|
36
|
+
orderNumber: number;
|
|
37
|
+
isHidden: boolean;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=addressField.config.d.ts.map
|