From 0a0173cee629a7ca1f3c97bbe844a9bd11fdd20b Mon Sep 17 00:00:00 2001 From: Konstantin Fandelyuk Date: Fri, 20 Sep 2024 12:26:01 +0300 Subject: [PATCH] updated --- .../storefront-order/chunks/CustomerDetailsContent.js | 1 - scripts/__dropins__/storefront-order/chunks/OrderLoaders.js | 2 +- .../__dropins__/storefront-order/containers/CustomerDetails.js | 2 +- scripts/__dropins__/storefront-order/containers/OrderSearch.js | 2 +- scripts/__dropins__/storefront-order/containers/OrderStatus.js | 2 +- .../__dropins__/storefront-order/containers/ShippingStatus.js | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) delete mode 100644 scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js diff --git a/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js b/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js deleted file mode 100644 index 92be7fa587..0000000000 --- a/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js +++ /dev/null @@ -1 +0,0 @@ -import{jsx as h,Fragment as v,jsxs as M}from"@dropins/tools/preact-jsx-runtime.js";import{useRef as _,useState as D,useEffect as w,useCallback as T}from"@dropins/tools/preact-hooks.js";import{useText as y}from"@dropins/tools/i18n.js";import*as C from"@dropins/tools/preact-compat.js";import{memo as V,useCallback as L}from"@dropins/tools/preact-compat.js";import{classes as k}from"@dropins/tools/lib.js";import{Field as q,Picker as A,Input as I,InputDate as R,Checkbox as O,TextArea as N}from"@dropins/tools/components.js";const j=l=>C.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...l},C.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.8052 14.4968C10.8552 14.4968 9.9752 14.0268 9.4452 13.2368L9.4152 13.1868L9.3852 13.1268C8.1352 11.2268 7.5352 8.96681 7.6852 6.68681C7.7552 4.42681 9.6052 2.61681 11.8652 2.60681H12.0052C14.2752 2.47681 16.2152 4.21681 16.3452 6.47681C16.3452 6.55681 16.3452 6.62681 16.3452 6.70681C16.4852 8.94681 15.9052 11.1768 14.6852 13.0568L14.6052 13.1768C14.0552 13.9868 13.1352 14.4668 12.1652 14.4768H12.0052C11.9352 14.4768 11.8652 14.4868 11.7952 14.4868L11.8052 14.4968Z",stroke:"currentColor"}),C.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M4.3252 21.5469C4.3552 20.4169 4.4752 19.2869 4.6752 18.1769C4.8952 17.1669 6.4752 16.0269 8.9052 15.1569C9.2352 15.0369 9.4852 14.7869 9.5952 14.4569L9.8052 14.0269",stroke:"currentColor"}),C.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M14.425 14.4069L14.165 14.1569C14.375 14.5969 14.725 14.9569 15.155 15.1869C16.945 15.7969 19.125 16.9569 19.375 18.2069C19.585 19.3069 19.685 20.4269 19.675 21.5369",stroke:"currentColor"})),H=l=>l.reduce((u,{code:p,required:$,defaultValue:c})=>($&&(u[p]=c),u),{}),S=({fieldsConfig:l,onSubmit:u})=>{const{requiredFieldError:p}=y({requiredFieldError:"Order.Form.notifications.requiredFieldError"}),$=_(null),[c,s]=D({}),[o,t]=D({});w(()=>{if(s({}),!l||!l.length)return;const n=H(l);s(n)},[l==null?void 0:l.length]),w(()=>()=>{var n;console.log("unmount"),s({}),(n=$.current)==null||n.reset()},[]);const f=T((n,e)=>{const r=l.find(d=>d.code===n);return r!=null&&r.required&&!e?p:""},[l,p]),b=T(n=>{const{name:e,value:r,type:a,checked:d}=n==null?void 0:n.target,i=a==="checkbox"?d:r;s(E=>({...E,[e]:i}))},[]),x=T(n=>{const{name:e,value:r,type:a,checked:d}=n==null?void 0:n.target,i=a==="checkbox"?d:r;t(E=>({...E,[e]:f(e,i)}))},[f]),F=T(n=>{n.preventDefault();let e=!0,r={},a=null;for(const[d,i]of Object.entries(c)){const E=f(d,i);E&&(r[d]=E,e=!1,a||(a=d))}if(t(r),a&&$.current){const d=$.current.elements.namedItem(a);d==null||d.focus()}u==null||u(n,e)},[c,f,u]);return{formData:c,errors:o,formRef:$,handleChange:b,handleBlur:x,handleSubmit:F}},U=V(({loading:l,values:u,fields:p=[],errors:$,className:c="",onChange:s,onBlur:o})=>{const t=`${c}__item`,f=L((e,r,a)=>{const d=e.options.map(i=>({text:i.label,value:i.value}));return h(q,{error:a,className:k([t,`${t}--${e.id}`,[`${t}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:l,children:h(A,{name:e.id,floatingLabel:`${e.label} ${e.required?"*":""}`,placeholder:e.label,"aria-label":e.label,options:d,onBlur:o,handleSelect:s,value:r||e.defaultValue})},e.id)},[c,l,t,o,s]),b=L((e,r,a)=>{const d=e.id==="email",i=d?h(j,{}):void 0,E=d?"username":"";return h(q,{error:a,className:k([t,`${t}--${e.id}`,[`${t}--${e.id}-hidden`,e==null?void 0:e.is_hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:l,children:h(I,{"aria-label":e.label,"aria-required":e.required,autoComplete:E,icon:i,type:"text",name:e.id,value:r||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:o,onChange:s})},e.id)},[c,l,t,o,s]),x=L((e,r,a)=>h(q,{error:a,className:k([t,`${t}--${e.id}`,[`${t}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:l,children:h(R,{type:"text",name:e.id,value:r||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:o,onChange:s})},e.id),[c,l,t,o,s]),F=L((e,r,a)=>h(q,{error:a,className:k([t,`${t}--${e.id}`,[`${t}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:l,children:h(O,{name:e.id,checked:r||e.defaultValue,placeholder:e.label,label:`${e.label} ${e.required?"*":""}`,onBlur:o,onChange:s})},e.id),[c,l,t,o,s]),n=L((e,r,a)=>h(q,{error:a,className:k([t,`${t}--${e.id}`,[`${t}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${c}--${e.id}`,disabled:l,children:h(N,{type:"text",name:e.id,value:r===void 0?e.defaultValue:r,label:`${e.label} ${e.required?"*":""}`,onBlur:o,onChange:s})},e.id),[c,l,t,o,s]);return p.length?h(v,{children:p.map(e=>{var d;const r=($==null?void 0:$[e.id])??"",a=(u==null?void 0:u[e.id])??"";switch(e.fieldType){case"TEXT":return(d=e==null?void 0:e.options)!=null&&d.length?f(e,a,r):b(e,a,r);case"MULTILINE":return b(e,a,r);case"SELECT":return f(e,a,r);case"DATE":return x(e,a,r);case"BOOLEAN":return F(e,a,r);case"TEXTAREA":return n(e,a,r);default:return null}})}):null}),K=V(({name:l,loading:u,children:p,className:$="defaultForm",fieldsConfig:c,onSubmit:s})=>{const{formData:o,errors:t,formRef:f,handleChange:b,handleBlur:x,handleSubmit:F}=S({fieldsConfig:c,onSubmit:s});return M("form",{className:k(["dropin-form",$]),onSubmit:F,name:l,ref:f,children:[h(U,{className:$,loading:u,fields:c,onChange:b,onBlur:x,errors:t,values:o}),p]})});export{K as F}; diff --git a/scripts/__dropins__/storefront-order/chunks/OrderLoaders.js b/scripts/__dropins__/storefront-order/chunks/OrderLoaders.js index f526c2d187..be1abb5c9c 100644 --- a/scripts/__dropins__/storefront-order/chunks/OrderLoaders.js +++ b/scripts/__dropins__/storefront-order/chunks/OrderLoaders.js @@ -1 +1 @@ -import{jsx as e,jsxs as t}from"@dropins/tools/preact-jsx-runtime.js";import{Card as l,Skeleton as s,SkeletonRow as r}from"@dropins/tools/components.js";import"./CustomerDetailsContent.js";import{classes as n}from"@dropins/tools/lib.js";const h=({testId:a,withCard:d=!0})=>{const i=t(s,{"data-testid":a??"skeletonLoader",children:[e(r,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),e(r,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),e(r,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return d?i:e(l,{variant:"secondary",className:n(["dropin-order-loaders","dropin-order-loaders--card-loader"]),children:i})},g=a=>e(l,{variant:"secondary",...a,children:t(s,{"data-testid":"order-details-skeleton",children:[e(r,{variant:"heading",size:"medium",fullWidth:!0}),e(r,{size:"medium"}),e(r,{variant:"empty",size:"medium"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"})]})});export{h as C,g as D}; +import{jsx as e,jsxs as t}from"@dropins/tools/preact-jsx-runtime.js";import{Card as l,Skeleton as s,SkeletonRow as r}from"@dropins/tools/components.js";/* empty css */import{classes as n}from"@dropins/tools/lib.js";const h=({testId:a,withCard:d=!0})=>{const i=t(s,{"data-testid":a??"skeletonLoader",children:[e(r,{variant:"heading",size:"xlarge",fullWidth:!1,lines:1}),e(r,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1}),e(r,{variant:"heading",size:"xlarge",fullWidth:!0,lines:1})]});return d?i:e(l,{variant:"secondary",className:n(["dropin-order-loaders","dropin-order-loaders--card-loader"]),children:i})},g=a=>e(l,{variant:"secondary",...a,children:t(s,{"data-testid":"order-details-skeleton",children:[e(r,{variant:"heading",size:"medium",fullWidth:!0}),e(r,{size:"medium"}),e(r,{variant:"empty",size:"medium"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"}),e(r,{size:"xlarge"})]})});export{h as C,g as D}; diff --git a/scripts/__dropins__/storefront-order/containers/CustomerDetails.js b/scripts/__dropins__/storefront-order/containers/CustomerDetails.js index cf47b92bf8..2e18cc419d 100644 --- a/scripts/__dropins__/storefront-order/containers/CustomerDetails.js +++ b/scripts/__dropins__/storefront-order/containers/CustomerDetails.js @@ -1 +1 @@ -import{jsx as t,jsxs as p,Fragment as L}from"@dropins/tools/preact-jsx-runtime.js";import{classes as k}from"@dropins/tools/lib.js";import{useMemo as O,useState as v,useEffect as D,useCallback as V}from"@dropins/tools/preact-hooks.js";import{events as S}from"@dropins/tools/event-bus.js";import{e as W}from"../chunks/fetch-graphql.js";import{g as j}from"../chunks/getAttributesForm.js";import{Card as P,Header as Z,Price as x,Icon as z}from"@dropins/tools/components.js";import"../chunks/CustomerDetailsContent.js";import*as o from"@dropins/tools/preact-compat.js";import{D as B}from"../chunks/OrderLoaders.js";import{useText as q}from"@dropins/tools/i18n.js";import"@dropins/tools/fetch-graphql.js";const F=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),K=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.00718 5H22.1507C22.7047 5 23.1579 5.45323 23.1579 6.00718V7.51794C23.1579 7.51794 1.01007 7.58844 1 7.55823V6.00718C1 5.45323 1.45323 5 2.00718 5Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M23.1579 9.78409V18.3451C23.1579 18.899 22.7047 19.3523 22.1507 19.3523H2.00718C1.45323 19.3523 1 18.899 1 18.3451V9.78409H23.1579Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M3.01465 15.9682H8.40305",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.6192 17.5897C18.4535 17.5897 19.1299 16.9133 19.1299 16.0789C19.1299 15.2446 18.4535 14.5682 17.6192 14.5682C16.7848 14.5682 16.1084 15.2446 16.1084 16.0789C16.1084 16.9133 16.7848 17.5897 17.6192 17.5897Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8848 17.5897C20.7192 17.5897 21.3956 16.9133 21.3956 16.0789C21.3956 15.2446 20.7192 14.5682 19.8848 14.5682C19.0504 14.5682 18.374 15.2446 18.374 16.0789C18.374 16.9133 19.0504 17.5897 19.8848 17.5897Z",stroke:"currentColor",strokeWidth:1})),R=({loading:d,order:i,withHeader:f=!0,title:l,paymentIconsMap:u={},normalizeAddress:h})=>{var E,N,A,T,$,y,w;const a=q({emailTitle:"Order.CustomerDetails.email.title",shippingAddressTitle:"Order.CustomerDetails.shippingAddress.title",shippingMethodsTitle:"Order.CustomerDetails.shippingMethods.title",billingAddressTitle:"Order.CustomerDetails.billingAddress.title",billingMethodsTitle:"Order.CustomerDetails.billingMethods.title",headerText:"Order.CustomerDetails.headerText",freeShipping:"Order.CustomerDetails.freeShipping"}),g=O(()=>({checkmo:F,card:K,...u}),[u]);if(!i||d)return t(B,{});const C=(i==null?void 0:i.email)??"",n=(E=i==null?void 0:i.shipping)==null?void 0:E.code,c=(N=i==null?void 0:i.shipping)==null?void 0:N.amount,s=(A=i==null?void 0:i.shipping)==null?void 0:A.currency,m=i==null?void 0:i.payments,_=m&&m.length>0,b=_?(T=m[0])==null?void 0:T.name:"",M=_?($=m[0])==null?void 0:$.code:"",H=_&&b!=="";return p(P,{"data-testid":"order-details",variant:"secondary",className:k(["dropin-details"]),children:[f?t(Z,{title:l??a.headerText}):null,p("div",{className:"dropin-details__container",children:[p("div",{className:"dropin-details__container-email",children:[t("div",{className:"dropin-details__container-title",children:a.emailTitle}),t("p",{children:C})]}),p("div",{className:"dropin-details__container-shipping_address",children:[t("div",{className:"dropin-details__container-title",children:a.shippingAddressTitle}),t("div",{className:"dropin-details__container-description",children:(y=h.shippingAddress)==null?void 0:y.filter(({value:e})=>e).map((e,r)=>r===1?t("p",{"data-testid":`${e.name}_${r}`,children:t("span",{children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value})},r):t("p",{"data-testid":`${e.name}_${r}`,children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value},r))})]}),p("div",{className:"dropin-details__container-billing_address",children:[t("div",{className:"dropin-details__container-title",children:a.billingAddressTitle}),t("div",{className:"dropin-details__container-description",children:(w=h.billingAddress)==null?void 0:w.filter(({value:e})=>e).map((e,r)=>r===1||r===5?t("p",{"data-testid":`${e.name}_${r}`,children:t("span",{children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value})},r):t("p",{"data-testid":`${e.name}_${r}`,children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value},r))})]}),p("div",{className:"dropin-details__container-shipping_methods",children:[t("div",{className:"dropin-details__container-title",children:a.shippingMethodsTitle}),n?t(L,{children:c?p("p",{"data-testid":"shipping_methods_price",children:[t(x,{amount:c,currency:s})," ",n]}):t("p",{"data-testid":"shipping_methods_placeholder",children:a.freeShipping})}):null]}),p("div",{className:"dropin-details__container-billing_methods",children:[t("div",{className:"dropin-details__container-title",children:a.billingMethodsTitle}),H&&p("p",{"data-testid":"billing_methods_description",className:k([["dropin-details__container-billing_methods--icon",!!g[M]]]),children:[t(z,{source:g[M]}),b]})]})]})]})},G=["firstname","lastname","city","company","country_code","region","region_code","region_id","telephone","id","vat_id","postcode","street","street_2","default_shipping","default_billing"],I=({orderData:d})=>{const[i,f]=v(!0),[l,u]=v(d),[h,a]=v([]);D(()=>{const n=S.on("order/data",c=>{u(c)},{eager:!0});return()=>{n==null||n.off()}},[]),D(()=>{j("shortRequest").then(n=>{if(n){const c=n.map(({name:s,orderNumber:m,label:_})=>({name:W(s),orderNumber:m,label:G.includes(s)?null:_}));a(c)}}).finally(()=>{f(!1)})},[]);const g=V(n=>{if(!h.length||!l||!l[n])return[];const c=Object.fromEntries(Object.entries(l[n]).map(([s,m])=>[s.toLowerCase(),m]));return h.filter(({name:s})=>c[s.toLowerCase()]).map(s=>({name:s.name,orderNumber:s.orderNumber,value:c[s.name],label:s.label}))},[h,l]),C=O(()=>({billingAddress:g("billingAddress"),shippingAddress:g("shippingAddress")}),[g]);return{order:l,normalizeAddress:C,loading:i}},ae=({paymentIconsMap:d,orderData:i,title:f,className:l})=>{const{order:u,normalizeAddress:h,loading:a}=I({orderData:i});return t("div",{className:k(["dropin-customer-details",l]),children:t(R,{loading:a,order:u,title:f,paymentIconsMap:d,normalizeAddress:h})})};export{ae as CustomerDetails,ae as default}; +import{jsx as t,jsxs as p,Fragment as L}from"@dropins/tools/preact-jsx-runtime.js";import{classes as k}from"@dropins/tools/lib.js";import{useMemo as O,useState as v,useEffect as D,useCallback as V}from"@dropins/tools/preact-hooks.js";import{events as S}from"@dropins/tools/event-bus.js";import{e as W}from"../chunks/fetch-graphql.js";import{g as j}from"../chunks/getAttributesForm.js";import{Card as P,Header as Z,Price as x,Icon as z}from"@dropins/tools/components.js";/* empty css */import*as o from"@dropins/tools/preact-compat.js";import{D as B}from"../chunks/OrderLoaders.js";import{useText as q}from"@dropins/tools/i18n.js";import"@dropins/tools/fetch-graphql.js";const F=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),K=d=>o.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.00718 5H22.1507C22.7047 5 23.1579 5.45323 23.1579 6.00718V7.51794C23.1579 7.51794 1.01007 7.58844 1 7.55823V6.00718C1 5.45323 1.45323 5 2.00718 5Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M23.1579 9.78409V18.3451C23.1579 18.899 22.7047 19.3523 22.1507 19.3523H2.00718C1.45323 19.3523 1 18.899 1 18.3451V9.78409H23.1579Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M3.01465 15.9682H8.40305",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round"}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.6192 17.5897C18.4535 17.5897 19.1299 16.9133 19.1299 16.0789C19.1299 15.2446 18.4535 14.5682 17.6192 14.5682C16.7848 14.5682 16.1084 15.2446 16.1084 16.0789C16.1084 16.9133 16.7848 17.5897 17.6192 17.5897Z",stroke:"currentColor",strokeWidth:1}),o.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8848 17.5897C20.7192 17.5897 21.3956 16.9133 21.3956 16.0789C21.3956 15.2446 20.7192 14.5682 19.8848 14.5682C19.0504 14.5682 18.374 15.2446 18.374 16.0789C18.374 16.9133 19.0504 17.5897 19.8848 17.5897Z",stroke:"currentColor",strokeWidth:1})),R=({loading:d,order:i,withHeader:f=!0,title:l,paymentIconsMap:u={},normalizeAddress:h})=>{var E,N,A,T,$,y,w;const a=q({emailTitle:"Order.CustomerDetails.email.title",shippingAddressTitle:"Order.CustomerDetails.shippingAddress.title",shippingMethodsTitle:"Order.CustomerDetails.shippingMethods.title",billingAddressTitle:"Order.CustomerDetails.billingAddress.title",billingMethodsTitle:"Order.CustomerDetails.billingMethods.title",headerText:"Order.CustomerDetails.headerText",freeShipping:"Order.CustomerDetails.freeShipping"}),g=O(()=>({checkmo:F,card:K,...u}),[u]);if(!i||d)return t(B,{});const C=(i==null?void 0:i.email)??"",n=(E=i==null?void 0:i.shipping)==null?void 0:E.code,c=(N=i==null?void 0:i.shipping)==null?void 0:N.amount,s=(A=i==null?void 0:i.shipping)==null?void 0:A.currency,m=i==null?void 0:i.payments,_=m&&m.length>0,b=_?(T=m[0])==null?void 0:T.name:"",M=_?($=m[0])==null?void 0:$.code:"",H=_&&b!=="";return p(P,{"data-testid":"order-details",variant:"secondary",className:k(["dropin-details"]),children:[f?t(Z,{title:l??a.headerText}):null,p("div",{className:"dropin-details__container",children:[p("div",{className:"dropin-details__container-email",children:[t("div",{className:"dropin-details__container-title",children:a.emailTitle}),t("p",{children:C})]}),p("div",{className:"dropin-details__container-shipping_address",children:[t("div",{className:"dropin-details__container-title",children:a.shippingAddressTitle}),t("div",{className:"dropin-details__container-description",children:(y=h.shippingAddress)==null?void 0:y.filter(({value:e})=>e).map((e,r)=>r===1?t("p",{"data-testid":`${e.name}_${r}`,children:t("span",{children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value})},r):t("p",{"data-testid":`${e.name}_${r}`,children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value},r))})]}),p("div",{className:"dropin-details__container-billing_address",children:[t("div",{className:"dropin-details__container-title",children:a.billingAddressTitle}),t("div",{className:"dropin-details__container-description",children:(w=h.billingAddress)==null?void 0:w.filter(({value:e})=>e).map((e,r)=>r===1||r===5?t("p",{"data-testid":`${e.name}_${r}`,children:t("span",{children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value})},r):t("p",{"data-testid":`${e.name}_${r}`,children:e.label?`${e.label}: ${e==null?void 0:e.value}`:e==null?void 0:e.value},r))})]}),p("div",{className:"dropin-details__container-shipping_methods",children:[t("div",{className:"dropin-details__container-title",children:a.shippingMethodsTitle}),n?t(L,{children:c?p("p",{"data-testid":"shipping_methods_price",children:[t(x,{amount:c,currency:s})," ",n]}):t("p",{"data-testid":"shipping_methods_placeholder",children:a.freeShipping})}):null]}),p("div",{className:"dropin-details__container-billing_methods",children:[t("div",{className:"dropin-details__container-title",children:a.billingMethodsTitle}),H&&p("p",{"data-testid":"billing_methods_description",className:k([["dropin-details__container-billing_methods--icon",!!g[M]]]),children:[t(z,{source:g[M]}),b]})]})]})]})},G=["firstname","lastname","city","company","country_code","region","region_code","region_id","telephone","id","vat_id","postcode","street","street_2","default_shipping","default_billing"],I=({orderData:d})=>{const[i,f]=v(!0),[l,u]=v(d),[h,a]=v([]);D(()=>{const n=S.on("order/data",c=>{u(c)},{eager:!0});return()=>{n==null||n.off()}},[]),D(()=>{j("shortRequest").then(n=>{if(n){const c=n.map(({name:s,orderNumber:m,label:_})=>({name:W(s),orderNumber:m,label:G.includes(s)?null:_}));a(c)}}).finally(()=>{f(!1)})},[]);const g=V(n=>{if(!h.length||!l||!l[n])return[];const c=Object.fromEntries(Object.entries(l[n]).map(([s,m])=>[s.toLowerCase(),m]));return h.filter(({name:s})=>c[s.toLowerCase()]).map(s=>({name:s.name,orderNumber:s.orderNumber,value:c[s.name],label:s.label}))},[h,l]),C=O(()=>({billingAddress:g("billingAddress"),shippingAddress:g("shippingAddress")}),[g]);return{order:l,normalizeAddress:C,loading:i}},ae=({paymentIconsMap:d,orderData:i,title:f,className:l})=>{const{order:u,normalizeAddress:h,loading:a}=I({orderData:i});return t("div",{className:k(["dropin-customer-details",l]),children:t(R,{loading:a,order:u,title:f,paymentIconsMap:d,normalizeAddress:h})})};export{ae as CustomerDetails,ae as default}; diff --git a/scripts/__dropins__/storefront-order/containers/OrderSearch.js b/scripts/__dropins__/storefront-order/containers/OrderSearch.js index cdf7c05077..3604f88731 100644 --- a/scripts/__dropins__/storefront-order/containers/OrderSearch.js +++ b/scripts/__dropins__/storefront-order/containers/OrderSearch.js @@ -1 +1 @@ -import{jsxs as v,jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{classes as _}from"@dropins/tools/lib.js";import{Card as U,InLineAlert as C,Icon as x,Button as V}from"@dropins/tools/components.js";import{F as L}from"../chunks/CustomerDetailsContent.js";import{useState as R,useCallback as D,useEffect as O,useMemo as k}from"@dropins/tools/preact-hooks.js";import*as g from"@dropins/tools/preact-compat.js";import{Text as S,useText as H}from"@dropins/tools/i18n.js";import{events as w}from"@dropins/tools/event-bus.js";import{c as A,g as P}from"../chunks/getCustomer.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const X=e=>g.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},g.createElement("path",{vectorEffect:"non-scaling-stroke",fillRule:"evenodd",clipRule:"evenodd",d:"M1 20.8953L12.1922 1.5L23.395 20.8953H1ZM13.0278 13.9638L13.25 10.0377V9H11.25V10.0377L11.4722 13.9638H13.0278ZM11.2994 16V17.7509H13.2253V16H11.2994Z",fill:"currentColor"})),B=({onSubmit:e,loading:t,inLineAlert:o,fieldsConfig:r})=>v(U,{variant:"secondary",className:"dropin-order-search-form",children:[n("h2",{className:"dropin-order-search-form__title",children:n(S,{id:"Order.OrderSearchForm.title"})}),n("p",{children:n(S,{id:"Order.OrderSearchForm.description"})}),o.text?n(C,{"data-testid":"orderAlert",className:"dropin-order-search-form__alert",type:o.type,variant:"secondary",heading:o.text,icon:n(x,{source:X})}):null,n(L,{className:"dropin-order-search-form__wrapper",name:"orderSearchForm",loading:t,fieldsConfig:r,onSubmit:e,children:n("div",{className:"dropin-order-search-form__button-container",children:n(V,{className:"dropin-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:t,children:n(S,{id:"Order.OrderSearchForm.button"})},"logIn")})})]});var T=(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))(T||{});const j=e=>{if(!e)return null;const t=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(r=>{t.has(r.name)||t.set(r.name,"false"),r.checked&&t.set(r.name,"true")}),t&&typeof t.entries=="function"){const r=t.entries();if(r&&typeof r[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(r)))||{}}return{}},p=(e,t)=>{if(typeof e!="function")return;const o=e();if(!t||Object.keys(t).length===0){window.location.href=o;return}const r=new URLSearchParams;Object.entries(t).forEach(([u,d])=>{r.append(u,String(d))});const s=o.includes("?")?"&":"?";window.location.href=`${o}${s}${r.toString()}`},I=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},q=({onError:e,isAuth:t,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:s})=>{const[u,d]=R({text:"",type:"success"}),[E,h]=R(!1),l=H({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),b=D(async a=>{const f=I("orderRef"),c=f&&f.length>20;if(!a&&!f||!(a!=null&&a.number)&&!(a!=null&&a.token)&&!f)return null;if(t){const m=await A();(m==null?void 0:m.email)===a.email?p(r,{orderRef:a==null?void 0:a.number}):c||p(s,{orderRef:a.token})}else c||p(s,{orderRef:a==null?void 0:a.token})},[t,r,s]);O(()=>{w.on("order/data",a=>{b(a)},{eager:!0})},[b]),O(()=>{const a=I("orderRef"),f=a&&a.length>20?a:null;a&&(f?p(s,{orderRef:a}):t?p(r,{orderRef:a}):o==null||o({render:!0,formValues:{number:a}}))},[t,r,s,o]);const M=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:l.email,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:l.postcode,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:l.number,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[l]);return{onSubmit:D(async(a,f)=>{if(!f)return null;h(!0);const c=j(a.target);await P(c).then(i=>{i||d({text:l.invalidSearch,type:"warning"}),w.emit("order/data",i)}).catch(async i=>{var N;let m=!0;e==null||e({error:i.message});const y=t?await A():{email:""};(y==null?void 0:y.email)===(c==null?void 0:c.email)?(m=!1,p(r,{orderRef:c.number})):m=o==null?void 0:o({render:(N=i==null?void 0:i.message)==null?void 0:N.includes("Please login to view the order."),formValues:c}),m&&d({text:i.message,type:"warning"})}).finally(()=>{h(!1)})},[t,e,o,r,l.invalidSearch]),inLineAlert:u,loading:E,normalizeFieldsConfig:M}},te=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:s,onError:u})=>{const{onSubmit:d,loading:E,inLineAlert:h,normalizeFieldsConfig:l}=q({onError:u,isAuth:t,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:s});return n("div",{className:_(["dropin-order-search",e]),children:n(B,{onSubmit:d,loading:E,inLineAlert:h,fieldsConfig:l})})};export{te as OrderSearch,te as default}; +import{jsxs as L,jsx as i,Fragment as C}from"@dropins/tools/preact-jsx-runtime.js";import{classes as y}from"@dropins/tools/lib.js";import{Card as V,InLineAlert as q,Icon as U,Button as F,Field as w,Picker as H,Input as P,InputDate as X,Checkbox as j,TextArea as G}from"@dropins/tools/components.js";/* empty css */import{useRef as W,useState as A,useEffect as M,useCallback as R,useMemo as z}from"@dropins/tools/preact-hooks.js";import{Text as I,useText as g}from"@dropins/tools/i18n.js";import*as S from"@dropins/tools/preact-compat.js";import{useCallback as N}from"@dropins/tools/preact-compat.js";import{events as v}from"@dropins/tools/event-bus.js";import{c as _,g as Z}from"../chunks/getCustomer.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const B=r=>S.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.8052 14.4968C10.8552 14.4968 9.9752 14.0268 9.4452 13.2368L9.4152 13.1868L9.3852 13.1268C8.1352 11.2268 7.5352 8.96681 7.6852 6.68681C7.7552 4.42681 9.6052 2.61681 11.8652 2.60681H12.0052C14.2752 2.47681 16.2152 4.21681 16.3452 6.47681C16.3452 6.55681 16.3452 6.62681 16.3452 6.70681C16.4852 8.94681 15.9052 11.1768 14.6852 13.0568L14.6052 13.1768C14.0552 13.9868 13.1352 14.4668 12.1652 14.4768H12.0052C11.9352 14.4768 11.8652 14.4868 11.7952 14.4868L11.8052 14.4968Z",stroke:"currentColor"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M4.3252 21.5469C4.3552 20.4169 4.4752 19.2869 4.6752 18.1769C4.8952 17.1669 6.4752 16.0269 8.9052 15.1569C9.2352 15.0369 9.4852 14.7869 9.5952 14.4569L9.8052 14.0269",stroke:"currentColor"}),S.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M14.425 14.4069L14.165 14.1569C14.375 14.5969 14.725 14.9569 15.155 15.1869C16.945 15.7969 19.125 16.9569 19.375 18.2069C19.585 19.3069 19.685 20.4269 19.675 21.5369",stroke:"currentColor"})),Y=r=>S.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...r},S.createElement("path",{vectorEffect:"non-scaling-stroke",fillRule:"evenodd",clipRule:"evenodd",d:"M1 20.8953L12.1922 1.5L23.395 20.8953H1ZM13.0278 13.9638L13.25 10.0377V9H11.25V10.0377L11.4722 13.9638H13.0278ZM11.2994 16V17.7509H13.2253V16H11.2994Z",fill:"currentColor"})),J=({onSubmit:r,loading:a,inLineAlert:s,fieldsConfig:l})=>L(V,{variant:"secondary",className:"dropin-order-search-form",children:[i("h2",{className:"dropin-order-search-form__title",children:i(I,{id:"Order.OrderSearchForm.title"})}),i("p",{children:i(I,{id:"Order.OrderSearchForm.description"})}),s.text?i(q,{"data-testid":"orderAlert",className:"dropin-order-search-form__alert",type:s.type,variant:"secondary",heading:s.text,icon:i(U,{source:Y})}):null,i(re,{className:"dropin-order-search-form__wrapper",name:"orderSearchForm",loading:a,fieldsConfig:l,onSubmit:r,children:i("div",{className:"dropin-order-search-form__button-container",children:i(F,{className:"dropin-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:a,children:i(I,{id:"Order.OrderSearchForm.button"})},"logIn")})})]}),Q=r=>r.reduce((a,{code:s,required:l,defaultValue:o})=>(l&&(a[s]=o),a),{}),K=({fieldsConfig:r,onSubmit:a})=>{const{requiredFieldError:s}=g({requiredFieldError:"Order.Form.notifications.requiredFieldError"}),l=W(null),[o,u]=A({}),[f,d]=A({});M(()=>{if(u({}),!r||!r.length)return;const h=Q(r);u(h)},[r==null?void 0:r.length]),M(()=>()=>{var h;console.log("unmount"),u({}),(h=l.current)==null||h.reset()},[]);const b=R((h,e)=>{const t=r.find(c=>c.code===h);return t!=null&&t.required&&!e?s:""},[r,s]),E=R(h=>{const{name:e,value:t,type:n,checked:c}=h==null?void 0:h.target,p=n==="checkbox"?c:t;u(T=>({...T,[e]:p}))},[]),m=R(h=>{const{name:e,value:t,type:n,checked:c}=h==null?void 0:h.target,p=n==="checkbox"?c:t;d(T=>({...T,[e]:b(e,p)}))},[b]),$=R(h=>{h.preventDefault();let e=!0,t={},n=null;for(const[c,p]of Object.entries(o)){const T=b(c,p);T&&(t[c]=T,e=!1,n||(n=c))}if(d(t),n&&l.current){const c=l.current.elements.namedItem(n);c==null||c.focus()}a==null||a(h,e)},[o,b,a]);return{formData:o,errors:f,formRef:l,handleChange:E,handleBlur:m,handleSubmit:$}},ee=({loading:r,values:a,fields:s=[],errors:l,className:o="",onChange:u,onBlur:f})=>{const d=`${o}__item`,b=N((e,t,n)=>{const c=e.options.map(p=>({text:p.label,value:p.value}));return i(w,{error:n,className:y([d,`${d}--${e.id}`,[`${d}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:i(H,{name:e.id,floatingLabel:`${e.label} ${e.required?"*":""}`,placeholder:e.label,"aria-label":e.label,options:c,onBlur:f,handleSelect:u,value:t||e.defaultValue})},e.id)},[o,r,d,f,u]),E=N((e,t,n)=>{const c=e.id==="email",p=c?i(B,{}):void 0,T=c?"username":"";return i(w,{error:n,className:y([d,`${d}--${e.id}`,[`${d}--${e.id}-hidden`,e==null?void 0:e.is_hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:i(P,{"aria-label":e.label,"aria-required":e.required,autoComplete:T,icon:p,type:"text",name:e.id,value:t||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:f,onChange:u})},e.id)},[o,r,d,f,u]),m=N((e,t,n)=>i(w,{error:n,className:y([d,`${d}--${e.id}`,[`${d}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:i(X,{type:"text",name:e.id,value:t||e.defaultValue,placeholder:e.label,floatingLabel:`${e.label} ${e.required?"*":""}`,onBlur:f,onChange:u})},e.id),[o,r,d,f,u]),$=N((e,t,n)=>i(w,{error:n,className:y([d,`${d}--${e.id}`,[`${d}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:i(j,{name:e.id,checked:t||e.defaultValue,placeholder:e.label,label:`${e.label} ${e.required?"*":""}`,onBlur:f,onChange:u})},e.id),[o,r,d,f,u]),h=N((e,t,n)=>i(w,{error:n,className:y([d,`${d}--${e.id}`,[`${d}--${e.id}-hidden`,e.is_hidden],e.className]),"data-testid":`${o}--${e.id}`,disabled:r,children:i(G,{type:"text",name:e.id,value:t===void 0?e.defaultValue:t,label:`${e.label} ${e.required?"*":""}`,onBlur:f,onChange:u})},e.id),[o,r,d,f,u]);return s.length?i(C,{children:s.map(e=>{var c;const t=(l==null?void 0:l[e.id])??"",n=(a==null?void 0:a[e.id])??"";switch(e.fieldType){case"TEXT":return(c=e==null?void 0:e.options)!=null&&c.length?b(e,n,t):E(e,n,t);case"MULTILINE":return E(e,n,t);case"SELECT":return b(e,n,t);case"DATE":return m(e,n,t);case"BOOLEAN":return $(e,n,t);case"TEXTAREA":return h(e,n,t);default:return null}})}):null},re=({name:r,loading:a,children:s,className:l="defaultForm",fieldsConfig:o,onSubmit:u})=>{const{formData:f,errors:d,formRef:b,handleChange:E,handleBlur:m,handleSubmit:$}=K({fieldsConfig:o,onSubmit:u});return L("form",{className:y(["dropin-form",l]),onSubmit:$,name:r,ref:b,children:[i(ee,{className:l,loading:a,fields:o,onChange:E,onBlur:m,errors:d,values:f}),s]})};var O=(r=>(r.BOOLEAN="BOOLEAN",r.DATE="DATE",r.DATETIME="DATETIME",r.DROPDOWN="DROPDOWN",r.FILE="FILE",r.GALLERY="GALLERY",r.HIDDEN="HIDDEN",r.IMAGE="IMAGE",r.MEDIA_IMAGE="MEDIA_IMAGE",r.MULTILINE="MULTILINE",r.MULTISELECT="MULTISELECT",r.PRICE="PRICE",r.SELECT="SELECT",r.TEXT="TEXT",r.TEXTAREA="TEXTAREA",r.UNDEFINED="UNDEFINED",r.VISUAL="VISUAL",r.WEIGHT="WEIGHT",r.EMPTY="",r))(O||{});const ae=r=>{if(!r)return null;const a=new FormData(r);if(r.querySelectorAll('input[type="checkbox"]').forEach(l=>{a.has(l.name)||a.set(l.name,"false"),l.checked&&a.set(l.name,"true")}),a&&typeof a.entries=="function"){const l=a.entries();if(l&&typeof l[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(l)))||{}}return{}},D=(r,a)=>{if(typeof r!="function")return;const s=r();if(!a||Object.keys(a).length===0){window.location.href=s;return}const l=new URLSearchParams;Object.entries(a).forEach(([u,f])=>{l.append(u,String(f))});const o=s.includes("?")?"&":"?";window.location.href=`${s}${o}${l.toString()}`},x=r=>{try{return new URL(window.location.href).searchParams.get(r)}catch{return null}},te=({onError:r,isAuth:a,renderSignIn:s,routeCustomerOrder:l,routeGuestOrder:o})=>{const[u,f]=A({text:"",type:"success"}),[d,b]=A(!1),E=g({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),m=R(async e=>{const t=x("orderRef"),n=t&&t.length>20;if(!e&&!t||!(e!=null&&e.number)&&!(e!=null&&e.token)&&!t)return null;if(a){const p=await _();(p==null?void 0:p.email)===e.email?D(l,{orderRef:e==null?void 0:e.number}):n||D(o,{orderRef:e.token})}else n||D(o,{orderRef:e==null?void 0:e.token})},[a,l,o]);M(()=>{v.on("order/data",e=>{m(e)},{eager:!0})},[m]),M(()=>{const e=x("orderRef"),t=e&&e.length>20?e:null;e&&(t?D(o,{orderRef:e}):a?D(l,{orderRef:e}):s==null||s({render:!0,formValues:{number:e}}))},[a,l,o,s]);const $=z(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:E.email,options:[],defaultValue:"",fieldType:O.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:E.postcode,options:[],defaultValue:"",fieldType:O.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:E.number,options:[],defaultValue:"",fieldType:O.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[E]);return{onSubmit:R(async(e,t)=>{if(!t)return null;b(!0);const n=ae(e.target);await Z(n).then(c=>{c||f({text:E.invalidSearch,type:"warning"}),v.emit("order/data",c)}).catch(async c=>{var k;let p=!0;r==null||r({error:c.message});const T=a?await _():{email:""};(T==null?void 0:T.email)===(n==null?void 0:n.email)?(p=!1,D(l,{orderRef:n.number})):p=s==null?void 0:s({render:(k=c==null?void 0:c.message)==null?void 0:k.includes("Please login to view the order."),formValues:n}),p&&f({text:c.message,type:"warning"})}).finally(()=>{b(!1)})},[a,r,s,l,E.invalidSearch]),inLineAlert:u,loading:d,normalizeFieldsConfig:$}},be=({className:r,isAuth:a,renderSignIn:s,routeCustomerOrder:l,routeGuestOrder:o,onError:u})=>{const{onSubmit:f,loading:d,inLineAlert:b,normalizeFieldsConfig:E}=te({onError:u,isAuth:a,renderSignIn:s,routeCustomerOrder:l,routeGuestOrder:o});return i("div",{className:y(["dropin-order-search",r]),children:i(J,{onSubmit:f,loading:d,inLineAlert:b,fieldsConfig:E})})};export{be as OrderSearch,be as default}; diff --git a/scripts/__dropins__/storefront-order/containers/OrderStatus.js b/scripts/__dropins__/storefront-order/containers/OrderStatus.js index 2490a1ff1f..4943e09860 100644 --- a/scripts/__dropins__/storefront-order/containers/OrderStatus.js +++ b/scripts/__dropins__/storefront-order/containers/OrderStatus.js @@ -1 +1 @@ -import{jsx as t,jsxs as O,Fragment as f}from"@dropins/tools/preact-jsx-runtime.js";import{Card as E,Header as v,Button as p}from"@dropins/tools/components.js";import"../chunks/CustomerDetailsContent.js";import{Slot as g,classes as m}from"@dropins/tools/lib.js";import{useState as C,useEffect as N}from"@dropins/tools/preact-hooks.js";import{useMemo as w}from"@dropins/tools/preact-compat.js";import{useText as l}from"@dropins/tools/i18n.js";import{C as y}from"../chunks/OrderLoaders.js";import{events as A}from"@dropins/tools/event-bus.js";const h={pending:"orderPending",shiping:"orderShipped",complete:"orderComplete",processing:"orderProcessing","on hold":"orderOnHold",canceled:"orderCanceled","suspected fraud":"orderSuspectedFraud","payment Review":"orderPaymentReview","order received":"orderReceived"},_=({slots:r,title:a,status:n,orderData:e})=>{var s;const c=String(n).toLocaleLowerCase(),d=l(`Order.OrderStatusContent.${h[c]}.title`),o=l(`Order.OrderStatusContent.${h[c]}.message`);return n?O(E,{className:"dropin-order-status-content",variant:"secondary",children:[t(v,{title:a??d.title}),O("div",{className:"dropin-order-status-content__wrapper",children:[t("div",{className:"dropin-order-status-content__wrapper-description",children:t("p",{children:(s=o.message)==null?void 0:s.replace("{DATE}","01.01.1900")})}),t(T,{orderData:e,slots:r})]})]}):t("div",{})};var i=(r=>(r.CANCEL="CANCEL",r.RETURN="RETURN",r.REORDER="REORDER",r))(i||{});const T=({className:r,children:a,orderData:n,slots:e,...c})=>{const d=l({cancel:"Order.OrderStatusContent.actions.cancel",return:"Order.OrderStatusContent.actions.return",reorder:"Order.OrderStatusContent.actions.reorder"}),o=w(()=>{const s=n==null?void 0:n.availableActions,R=!!(s!=null&&s.length);return t(f,{children:e!=null&&e.OrderActions?t(g,{"data-testid":"OrderActionsSlot",name:"OrderCanceledActions",slot:e==null?void 0:e.OrderActions,context:n}):t("div",{"data-testid":"availableActionsList",className:m(["dropin-order-actions__wrapper",["dropin-order-actions__wrapper--empty",!R]]),children:s==null?void 0:s.map((S,u)=>{switch(S){case i.CANCEL:return t(p,{variant:"secondary",children:d.cancel},u);case i.RETURN:return t(p,{variant:"secondary",children:d.return},u);case i.REORDER:return t(p,{variant:"secondary",children:d.reorder},u)}})})})},[n,e==null?void 0:e.OrderActions,d]);return t("div",{...c,className:m(["dropin-order-actions",r]),children:o})},L=({orderData:r})=>{const[a,n]=C(r),[e,c]=C(r==null?void 0:r.status);return N(()=>{const d=A.on("order/data",o=>{n(o),c(o.status)},{eager:!0});return()=>{d==null||d.off()}},[]),{orderStatus:e,order:a}},k=({slots:r,orderData:a,className:n,statusTitle:e,status:c})=>{const{orderStatus:d,order:o}=L({orderData:a});return t("div",{className:m(["dropin-order-status",n]),children:o?t(_,{title:e,status:c||d,slots:r,orderData:o}):t(y,{withCard:!1})})};export{k as OrderStatus,k as default}; +import{jsx as t,jsxs as O,Fragment as f}from"@dropins/tools/preact-jsx-runtime.js";import{Card as E,Header as v,Button as p}from"@dropins/tools/components.js";/* empty css */import{useState as C,useEffect as g}from"@dropins/tools/preact-hooks.js";import{Slot as N,classes as m}from"@dropins/tools/lib.js";import{useMemo as w}from"@dropins/tools/preact-compat.js";import{useText as l}from"@dropins/tools/i18n.js";import{C as y}from"../chunks/OrderLoaders.js";import{events as A}from"@dropins/tools/event-bus.js";const h={pending:"orderPending",shiping:"orderShipped",complete:"orderComplete",processing:"orderProcessing","on hold":"orderOnHold",canceled:"orderCanceled","suspected fraud":"orderSuspectedFraud","payment Review":"orderPaymentReview","order received":"orderReceived"},_=({slots:r,title:a,status:n,orderData:e})=>{var s;const c=String(n).toLocaleLowerCase(),d=l(`Order.OrderStatusContent.${h[c]}.title`),o=l(`Order.OrderStatusContent.${h[c]}.message`);return n?O(E,{className:"dropin-order-status-content",variant:"secondary",children:[t(v,{title:a??d.title}),O("div",{className:"dropin-order-status-content__wrapper",children:[t("div",{className:"dropin-order-status-content__wrapper-description",children:t("p",{children:(s=o.message)==null?void 0:s.replace("{DATE}","01.01.1900")})}),t(T,{orderData:e,slots:r})]})]}):t("div",{})};var i=(r=>(r.CANCEL="CANCEL",r.RETURN="RETURN",r.REORDER="REORDER",r))(i||{});const T=({className:r,children:a,orderData:n,slots:e,...c})=>{const d=l({cancel:"Order.OrderStatusContent.actions.cancel",return:"Order.OrderStatusContent.actions.return",reorder:"Order.OrderStatusContent.actions.reorder"}),o=w(()=>{const s=n==null?void 0:n.availableActions,R=!!(s!=null&&s.length);return t(f,{children:e!=null&&e.OrderActions?t(N,{"data-testid":"OrderActionsSlot",name:"OrderCanceledActions",slot:e==null?void 0:e.OrderActions,context:n}):t("div",{"data-testid":"availableActionsList",className:m(["dropin-order-actions__wrapper",["dropin-order-actions__wrapper--empty",!R]]),children:s==null?void 0:s.map((S,u)=>{switch(S){case i.CANCEL:return t(p,{variant:"secondary",children:d.cancel},u);case i.RETURN:return t(p,{variant:"secondary",children:d.return},u);case i.REORDER:return t(p,{variant:"secondary",children:d.reorder},u)}})})})},[n,e==null?void 0:e.OrderActions,d]);return t("div",{...c,className:m(["dropin-order-actions",r]),children:o})},L=({orderData:r})=>{const[a,n]=C(r),[e,c]=C(r==null?void 0:r.status);return g(()=>{const d=A.on("order/data",o=>{n(o),c(o.status)},{eager:!0});return()=>{d==null||d.off()}},[]),{orderStatus:e,order:a}},k=({slots:r,orderData:a,className:n,statusTitle:e,status:c})=>{const{orderStatus:d,order:o}=L({orderData:a});return t("div",{className:m(["dropin-order-status",n]),children:o?t(_,{title:e,status:c||d,slots:r,orderData:o}):t(y,{withCard:!1})})};export{k as OrderStatus,k as default}; diff --git a/scripts/__dropins__/storefront-order/containers/ShippingStatus.js b/scripts/__dropins__/storefront-order/containers/ShippingStatus.js index a6ecc7c839..eeb1ee5068 100644 --- a/scripts/__dropins__/storefront-order/containers/ShippingStatus.js +++ b/scripts/__dropins__/storefront-order/containers/ShippingStatus.js @@ -1 +1 @@ -import{jsx as e,jsxs as h,Fragment as $}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as A,classes as G}from"@dropins/tools/lib.js";import{Image as E,Card as m,Header as C,Accordion as b,AccordionSection as w}from"@dropins/tools/components.js";import"../chunks/CustomerDetailsContent.js";import{useCallback as H,useState as M,useEffect as R}from"@dropins/tools/preact-hooks.js";import{useText as U}from"@dropins/tools/i18n.js";import{C as Y}from"../chunks/OrderLoaders.js";import"@dropins/tools/preact-compat.js";import{events as j}from"@dropins/tools/event-bus.js";var f=(i=>(i.PENDING="pending",i.SHIPPING="shipping",i.COMPLETE="complete",i.PROCESSING="processing",i.HOLD="on hold",i.CANCELED="Canceled",i.SUSPECTED_FRAUD="suspected fraud",i.PAYMENT_REVIEW="payment review",i))(f||{});const F=({slots:i,orderData:n,collapseThreshold:o=0})=>{var T,S,I,v,O;const s=U({carrier:"Order.ShippingStatusCard.carrier",prepositionOf:"Order.ShippingStatusCard.prepositionOf",shippingCardTitle:"Order.ShippingStatusCard.shippingCardTitle",shippingInfoTitle:"Order.ShippingStatusCard.shippingInfoTitle",notYetShippedTitle:"Order.ShippingStatusCard.notYetShippedTitle",notYetShippedImagesTitle:"Order.ShippingStatusCard.notYetShippedImagesTitle",noInfoTitle:"Order.OrderStatusContent.noInfoTitle"}),r=H(t=>t==null?void 0:t.map(p=>{var l,g,_,y,L,N;const a=(_=(g=(l=p==null?void 0:p.orderItem)==null?void 0:l.product)==null?void 0:g.thumbnail)==null?void 0:_.label,u=(N=(L=(y=p==null?void 0:p.orderItem)==null?void 0:y.product)==null?void 0:L.thumbnail)==null?void 0:N.url;return e(E,{alt:a,src:u,width:85,height:114},p.id)}),[]),d=(T=n==null?void 0:n.status)==null?void 0:T.toLocaleLowerCase(),x=((S=n==null?void 0:n.shipments)==null?void 0:S.length)===1&&(d==null?void 0:d.includes(f.COMPLETE)),c=(I=n==null?void 0:n.items)==null?void 0:I.filter(t=>(t==null?void 0:t.quantityShipped)===0);return!n||d!=null&&d.includes(f.CANCELED)?null:(v=n==null?void 0:n.shipments)!=null&&v.length?h($,{children:[(O=n==null?void 0:n.shipments)==null?void 0:O.map(({tracking:t,items:p,id:a},u)=>h(m,{variant:"secondary",className:"dropin-shipping-status-card",children:[e(C,{title:`${s.shippingCardTitle} ${u+1}`}),t==null?void 0:t.map(l=>{var g;return h("div",{className:"dropin-shipping-status-card__header",role:"status",children:[h("div",{className:"dropin-shipping-status-card__header--content",children:[h("p",{children:[s.carrier," ",(g=l==null?void 0:l.carrier)==null?void 0:g.toLocaleUpperCase()," | ",l==null?void 0:l.number]}),e("p",{children:l==null?void 0:l.title})]}),i!=null&&i.DeliveryTrackActions?e(A,{"data-testid":"deliverySlotActions",name:"DeliveryTrackActions",slot:i==null?void 0:i.DeliveryTrackActions,context:{trackInformation:l}}):null]},l.number)}),x?null:e(b,{actionIconPosition:"right","data-testid":"dropinAccordion",children:e(w,{"data-position":u+1,defaultOpen:o>=(p==null?void 0:p.length),title:`Package contents (${p==null?void 0:p.length} items)`,children:e("div",{className:"dropin-shipping-status-card__images",children:r(p)})})}),i!=null&&i.DeliveryTimeLine?e(A,{"data-testid":"deliverySlotTimeLine",name:"DeliveryTimeLine",slot:i==null?void 0:i.DeliveryTimeLine,context:{}}):null]},a)),c!=null&&c.length?h(m,{variant:"secondary",className:"dropin-shipping-status-card","data-testid":"dropinAccordionNotYetShipped2",children:[e(C,{title:s.notYetShippedTitle}),e(b,{actionIconPosition:"right",children:e(w,{title:`${s.notYetShippedImagesTitle} ${c==null?void 0:c.length}`,children:e("div",{className:"dropin-shipping-status-card__images",children:c==null?void 0:c.map(({id:t,thumbnail:{url:p,label:a}})=>e(E,{alt:a,src:p,width:85,height:114},t))})})})]}):null]}):h(m,{variant:"secondary",className:"dropin-shipping-status-card",children:[e(C,{title:s.shippingInfoTitle}),e("div",{className:"dropin-shipping-status-card__header",children:h("div",{className:"dropin-shipping-status-card__header--content",children:[n!=null&&n.carrier?e("p",{children:n==null?void 0:n.carrier}):null,e("p",{children:s.noInfoTitle})]})})]})},q=({orderData:i})=>{const[n,o]=M(i);return R(()=>{const s=j.on("order/data",r=>{o(r)},{eager:!0});return()=>{s==null||s.off()}},[]),{order:n}},k=({slots:i,className:n,collapseThreshold:o,orderData:s})=>{const{order:r}=q({orderData:s});return e("div",{className:G(["dropin-shipping-status",n]),children:r?e(F,{slots:i,orderData:r,collapseThreshold:o}):e(Y,{withCard:!1})})};export{k as ShippingStatus,k as default}; +import{jsx as e,jsxs as h,Fragment as $}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as A,classes as G}from"@dropins/tools/lib.js";import{Image as E,Card as m,Header as C,Accordion as b,AccordionSection as w}from"@dropins/tools/components.js";/* empty css */import{useCallback as H,useState as M,useEffect as R}from"@dropins/tools/preact-hooks.js";import{useText as U}from"@dropins/tools/i18n.js";import{C as Y}from"../chunks/OrderLoaders.js";import"@dropins/tools/preact-compat.js";import{events as j}from"@dropins/tools/event-bus.js";var f=(i=>(i.PENDING="pending",i.SHIPPING="shipping",i.COMPLETE="complete",i.PROCESSING="processing",i.HOLD="on hold",i.CANCELED="Canceled",i.SUSPECTED_FRAUD="suspected fraud",i.PAYMENT_REVIEW="payment review",i))(f||{});const F=({slots:i,orderData:n,collapseThreshold:o=0})=>{var T,S,I,v,O;const s=U({carrier:"Order.ShippingStatusCard.carrier",prepositionOf:"Order.ShippingStatusCard.prepositionOf",shippingCardTitle:"Order.ShippingStatusCard.shippingCardTitle",shippingInfoTitle:"Order.ShippingStatusCard.shippingInfoTitle",notYetShippedTitle:"Order.ShippingStatusCard.notYetShippedTitle",notYetShippedImagesTitle:"Order.ShippingStatusCard.notYetShippedImagesTitle",noInfoTitle:"Order.OrderStatusContent.noInfoTitle"}),r=H(t=>t==null?void 0:t.map(p=>{var l,g,_,y,L,N;const a=(_=(g=(l=p==null?void 0:p.orderItem)==null?void 0:l.product)==null?void 0:g.thumbnail)==null?void 0:_.label,u=(N=(L=(y=p==null?void 0:p.orderItem)==null?void 0:y.product)==null?void 0:L.thumbnail)==null?void 0:N.url;return e(E,{alt:a,src:u,width:85,height:114},p.id)}),[]),d=(T=n==null?void 0:n.status)==null?void 0:T.toLocaleLowerCase(),x=((S=n==null?void 0:n.shipments)==null?void 0:S.length)===1&&(d==null?void 0:d.includes(f.COMPLETE)),c=(I=n==null?void 0:n.items)==null?void 0:I.filter(t=>(t==null?void 0:t.quantityShipped)===0);return!n||d!=null&&d.includes(f.CANCELED)?null:(v=n==null?void 0:n.shipments)!=null&&v.length?h($,{children:[(O=n==null?void 0:n.shipments)==null?void 0:O.map(({tracking:t,items:p,id:a},u)=>h(m,{variant:"secondary",className:"dropin-shipping-status-card",children:[e(C,{title:`${s.shippingCardTitle} ${u+1}`}),t==null?void 0:t.map(l=>{var g;return h("div",{className:"dropin-shipping-status-card__header",role:"status",children:[h("div",{className:"dropin-shipping-status-card__header--content",children:[h("p",{children:[s.carrier," ",(g=l==null?void 0:l.carrier)==null?void 0:g.toLocaleUpperCase()," | ",l==null?void 0:l.number]}),e("p",{children:l==null?void 0:l.title})]}),i!=null&&i.DeliveryTrackActions?e(A,{"data-testid":"deliverySlotActions",name:"DeliveryTrackActions",slot:i==null?void 0:i.DeliveryTrackActions,context:{trackInformation:l}}):null]},l.number)}),x?null:e(b,{actionIconPosition:"right","data-testid":"dropinAccordion",children:e(w,{"data-position":u+1,defaultOpen:o>=(p==null?void 0:p.length),title:`Package contents (${p==null?void 0:p.length} items)`,children:e("div",{className:"dropin-shipping-status-card__images",children:r(p)})})}),i!=null&&i.DeliveryTimeLine?e(A,{"data-testid":"deliverySlotTimeLine",name:"DeliveryTimeLine",slot:i==null?void 0:i.DeliveryTimeLine,context:{}}):null]},a)),c!=null&&c.length?h(m,{variant:"secondary",className:"dropin-shipping-status-card","data-testid":"dropinAccordionNotYetShipped2",children:[e(C,{title:s.notYetShippedTitle}),e(b,{actionIconPosition:"right",children:e(w,{title:`${s.notYetShippedImagesTitle} ${c==null?void 0:c.length}`,children:e("div",{className:"dropin-shipping-status-card__images",children:c==null?void 0:c.map(({id:t,thumbnail:{url:p,label:a}})=>e(E,{alt:a,src:p,width:85,height:114},t))})})})]}):null]}):h(m,{variant:"secondary",className:"dropin-shipping-status-card",children:[e(C,{title:s.shippingInfoTitle}),e("div",{className:"dropin-shipping-status-card__header",children:h("div",{className:"dropin-shipping-status-card__header--content",children:[n!=null&&n.carrier?e("p",{children:n==null?void 0:n.carrier}):null,e("p",{children:s.noInfoTitle})]})})]})},q=({orderData:i})=>{const[n,o]=M(i);return R(()=>{const s=j.on("order/data",r=>{o(r)},{eager:!0});return()=>{s==null||s.off()}},[]),{order:n}},k=({slots:i,className:n,collapseThreshold:o,orderData:s})=>{const{order:r}=q({orderData:s});return e("div",{className:G(["dropin-shipping-status",n]),children:r?e(F,{slots:i,orderData:r,collapseThreshold:o}):e(Y,{withCard:!1})})};export{k as ShippingStatus,k as default};