diff --git a/scripts/__dropins__/storefront-order/containers/ShippingStatus.js b/scripts/__dropins__/storefront-order/containers/ShippingStatus.js index 147af8b17..0997ed9dc 100644 --- a/scripts/__dropins__/storefront-order/containers/ShippingStatus.js +++ b/scripts/__dropins__/storefront-order/containers/ShippingStatus.js @@ -1,3 +1,3 @@ /*! Copyright 2024 Adobe All Rights Reserved. */ -import{jsx as i,jsxs as S,Fragment as w}from"@dropins/tools/preact-jsx-runtime.js";import{classes as $,VComponent as E,Slot as q}from"@dropins/tools/lib.js";import{Card as A,Header as x,Accordion as G,AccordionSection as V,ContentGrid as B,Image as M}from"@dropins/tools/components.js";import{useState as R,useEffect as tn}from"@dropins/tools/preact-hooks.js";import"../chunks/ShippingStatusCard.js";import"@dropins/tools/preact-compat.js";import{u as sn}from"../chunks/useGetStoreConfig.js";import"@dropins/tools/preact.js";import{events as ln}from"@dropins/tools/event-bus.js";import{C as rn}from"../chunks/OrderLoaders.js";import{u as hn}from"../chunks/useIsMobile.js";import{Text as U,useText as un}from"@dropins/tools/i18n.js";import"../chunks/getStoreConfig.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";var H=(s=>(s.PENDING="pending",s.SHIPPING="shipping",s.COMPLETE="complete",s.PROCESSING="processing",s.HOLD="on hold",s.CANCELED="Canceled",s.SUSPECTED_FRAUD="suspected fraud",s.PAYMENT_REVIEW="payment review",s))(H||{});const dn=({orderData:s})=>{const[r,h]=R(!0),[n,u]=R(s),[l,m]=R(!1);return tn(()=>{const d=ln.on("order/data",o=>{u(o),m(o==null?void 0:o.isVirtual),h(!1)},{eager:!0});return s!=null&&s.id&&h(!1),()=>{d==null||d.off()}},[s]),{loading:r,order:n,isVirtualProduct:l}},en=({value:s,variant:r="primary",size:h="medium",icon:n,className:u,children:l,disabled:m=!1,active:d=!1,activeChildren:o,activeIcon:b,href:e,...C})=>{let c="dropin-button";(n&&!l||n&&d&&!o||!n&&d&&b)&&(c="dropin-iconButton"),d&&o&&(c="dropin-button"),u=$([c,`${c}--${h}`,`${c}--${r}`,[`${c}--${r}--disabled`,m],l&&n&&`${c}--with-icon`,!l&&o&&n&&`${c}--with-icon`,d&&b&&`${c}--with-icon`,u]);const I=$(["dropin-button-icon",`dropin-button-icon--${r}`,[`dropin-button-icon--${r}--disabled`,m],n==null?void 0:n.props.className]),g=e?{node:i("a",{}),role:"link",href:e,...C,disabled:m,active:d,onKeyDown:y=>{m&&y.preventDefault()},tabIndex:m?-1:0}:{node:i("button",{}),role:"button",...C,value:s,disabled:m,active:d};return S(E,{...g,className:u,children:[n&&!d&&i(E,{node:n,className:I}),b&&d&&i(E,{node:b,className:I}),l&&!d&&(typeof l=="string"?i("span",{children:l}):l),d&&o&&(typeof o=="string"?i("span",{children:o}):o)]})},cn=({placeholderImage:s,slots:r,collapseThreshold:h,translations:n,returnData:u,routeTracking:l,routeProductDetails:m})=>{var b;const d=hn(),o=m?"a":"span";return console.log("returnData.items",u),console.log("returnData.items",u.items),S(A,{variant:"secondary",className:$(["order-shipping-status-card","order-shipping-status-card--return-order"]),children:[i(x,{title:n.returnOrderCardTitle}),S("div",{children:[(b=u==null?void 0:u.tracking)==null?void 0:b.map((e,C)=>{var y,O;const c={title:"",number:(e==null?void 0:e.trackingNumber)??"",carrier:((y=e==null?void 0:e.carrier)==null?void 0:y.label)??""},I=l==null?void 0:l(c),g=I?()=>{window.open(I,"_blank","noreferrer")}:null;return S("div",{className:"order-shipping-status-card__header",children:[S("div",{children:[`${n.carrier} `,`${(O=c.carrier)==null?void 0:O.toLocaleUpperCase()} | `,c.number]}),g?i(en,{onClick:g,children:n.trackButton}):null]},`${c.number}_${C}`)}),r!=null&&r.ReturnItemsDetails?i(q,{"data-testid":"returnItemsDetails",name:"ReturnItemsDetails",slot:r==null?void 0:r.ReturnItemsDetails,context:{items:u.items}}):null,i(G,{actionIconPosition:"right","data-testid":"dropinAccordion",children:i(V,{defaultOpen:h>=u.items.length,title:i(U,{id:"Order.ShippingStatusCard.itemText",plural:u.items.reduce((e,C)=>e+C.requestQuantity,0),fields:{count:u.items.reduce((e,C)=>e+C.requestQuantity,0)}}),children:i(B,{maxColumns:d?3:9,emptyGridContent:i(w,{}),className:$(["order-shipping-status-card__images",["order-shipping-status-card__images-3",d]]),children:u.items.map((e,C)=>{var g,y,O,_;const c=(g=e.thumbnail)==null?void 0:g.label,I=(O=(y=e.thumbnail)==null?void 0:y.url)!=null&&O.length?(_=e.thumbnail)==null?void 0:_.url:s;return i(o,{href:(m==null?void 0:m(e))??"#","data-testid":`${C}${e.uid}`,children:i(M,{alt:c,src:I,width:85,height:114})},`${C}${e.uid}`)})})})})]})]})},mn=({placeholderImage:s,translations:r,slots:h,orderData:n,collapseThreshold:u=10,routeProductDetails:l,routeTracking:m})=>{var O,_,j,F,Q,K,W;const d=!!(n!=null&&n.returnNumber),o=n==null?void 0:n.returnNumber,b=l?"a":"span",e=(O=n==null?void 0:n.status)==null?void 0:O.toLocaleLowerCase(),c=((_=n==null?void 0:n.shipments)==null?void 0:_.length)===1&&(e==null?void 0:e.includes(H.COMPLETE)),I=(j=n==null?void 0:n.shipments)==null?void 0:j.every(p=>p.tracking.length===0),g=(F=n==null?void 0:n.items)==null?void 0:F.filter(p=>(p==null?void 0:p.quantityShipped)===0||(p==null?void 0:p.quantityShipped)<(p==null?void 0:p.quantityOrdered)),y=(Q=n==null?void 0:n.items)==null?void 0:Q.reduce((p,f)=>{const T=f.quantityOrdered-f.quantityShipped;return p+(T>0?T:0)},0);if(console.log("0",0),d&&(n!=null&&n.returns.length)){console.log("1",1);const p=n.returns.find(f=>f.returnNumber===o);return!p||p.tracking.length===0?null:(console.log("2",2),i(cn,{placeholderImage:s,slots:h,collapseThreshold:u,translations:r,returnData:p,routeTracking:m,routeProductDetails:l}))}return!n||e!=null&&e.includes(H.CANCELED)?null:(K=n==null?void 0:n.shipments)!=null&&K.length?I&&!(g!=null&&g.length)&&c?null:S(w,{children:[(W=n==null?void 0:n.shipments)==null?void 0:W.map(({tracking:p,items:f,id:T},pn)=>{const Y=f.reduce((t,N)=>t+((N==null?void 0:N.quantityShipped)??0),0);return S(A,{variant:"secondary",className:"order-shipping-status-card",children:[i(x,{title:r.shippingCardTitle}),p==null?void 0:p.map(t=>{var a;const N=m==null?void 0:m(t),L=N?()=>{window.open(N,"_blank","noreferrer")}:null;return S("div",{className:"order-shipping-status-card__header",role:"status",children:[S("div",{className:"order-shipping-status-card__header--content",children:[S("p",{children:[r.carrier," ",(a=t==null?void 0:t.carrier)==null?void 0:a.toLocaleUpperCase()," | ",t==null?void 0:t.number]}),i("p",{children:t==null?void 0:t.title})]}),h!=null&&h.DeliveryTrackActions?i(q,{"data-testid":"deliverySlotActions",name:"DeliveryTrackActions",slot:h==null?void 0:h.DeliveryTrackActions,context:{trackInformation:t}}):L?i(en,{onClick:L,children:r.trackButton}):null]},t.number)}),c?null:i(G,{actionIconPosition:"right","data-testid":"dropinAccordion",children:i(V,{"data-position":pn+1,defaultOpen:u>=(f==null?void 0:f.length),title:i(U,{id:"Order.ShippingStatusCard.notYetShippedImagesTitle",plural:Y,fields:{count:Y}}),children:i(B,{maxColumns:6,emptyGridContent:i(w,{}),className:"order-shipping-status-card__images",children:f==null?void 0:f.map(t=>{var a,z,J,X,Z,v,P,k,D,nn;const N=(J=(z=(a=t==null?void 0:t.orderItem)==null?void 0:a.product)==null?void 0:z.thumbnail)==null?void 0:J.label,L=(P=(v=(Z=(X=t==null?void 0:t.orderItem)==null?void 0:X.product)==null?void 0:Z.thumbnail)==null?void 0:v.url)!=null&&P.length?(nn=(D=(k=t==null?void 0:t.orderItem)==null?void 0:k.product)==null?void 0:D.thumbnail)==null?void 0:nn.url:s;return i(b,{href:(l==null?void 0:l(t))??"#",children:i(M,{alt:N,src:L,width:85,height:114})},t.id)})})})}),h!=null&&h.DeliveryTimeLine?i(q,{"data-testid":"deliverySlotTimeLine",name:"DeliveryTimeLine",slot:h==null?void 0:h.DeliveryTimeLine,context:{}}):null]},T)}),g!=null&&g.length?S(A,{variant:"secondary",className:"order-shipping-status-card","data-testid":"dropinAccordionNotYetShipped2",children:[i(x,{title:r.notYetShippedTitle}),i(G,{actionIconPosition:"right",children:i(V,{defaultOpen:u>=(g==null?void 0:g.length),title:i(U,{id:"Order.ShippingStatusCard.notYetShippedImagesTitle",plural:y,fields:{count:y}}),children:i(B,{maxColumns:6,emptyGridContent:i(w,{}),className:"order-shipping-status-card__images",children:g==null?void 0:g.map(p=>{var f,T;return i(b,{href:(l==null?void 0:l(p))??"#",children:i(M,{alt:(f=p.thumbnail)==null?void 0:f.label,src:((T=p.thumbnail)==null?void 0:T.url)||"",width:85,height:114})},p.id)})})})})]}):null]}):S(A,{variant:"secondary",className:"order-shipping-status-card",children:[i(x,{title:r.shippingInfoTitle}),i("div",{className:"order-shipping-status-card__header",children:S("div",{className:"order-shipping-status-card__header--content",children:[n!=null&&n.carrier?i("p",{children:n==null?void 0:n.carrier}):null,i("p",{children:r.noInfoTitle})]})})]})},wn=({slots:s,className:r,collapseThreshold:h,orderData:n,routeOrderDetails:u,routeTracking:l,routeProductDetails:m})=>{const{loading:d,order:o,isVirtualProduct:b}=dn({orderData:n}),e=sn(),C=un({carrier:"Order.ShippingStatusCard.carrier",prepositionOf:"Order.ShippingStatusCard.prepositionOf",returnOrderCardTitle:"Order.ShippingStatusCard.returnOrderCardTitle",shippingCardTitle:"Order.ShippingStatusCard.shippingCardTitle",shippingInfoTitle:"Order.ShippingStatusCard.shippingInfoTitle",notYetShippedTitle:"Order.ShippingStatusCard.notYetShippedTitle",noInfoTitle:"Order.ShippingStatusCard.noInfoTitle",returnNumber:"Order.ShippingStatusCard.returnNumber",orderNumber:"Order.ShippingStatusCard.orderNumber",trackButton:"Order.ShippingStatusCard.trackButton"});if(!d&&b)return null;const c=(e==null?void 0:e.baseMediaUrl)??"";return i("div",{className:$(["order-shipping-status",r]),children:!d&&o?i(mn,{placeholderImage:c,translations:C,routeOrderDetails:u,routeTracking:l,slots:s,orderData:o,collapseThreshold:h,routeProductDetails:m}):i(rn,{withCard:!1})})};export{wn as ShippingStatus,wn as default}; +import{jsx as i,jsxs as S,Fragment as w}from"@dropins/tools/preact-jsx-runtime.js";import{classes as $,VComponent as R,Slot as G}from"@dropins/tools/lib.js";import{Card as A,Header as x,Accordion as V,AccordionSection as B,ContentGrid as M,Image as U}from"@dropins/tools/components.js";import{useState as q,useEffect as sn}from"@dropins/tools/preact-hooks.js";import"../chunks/ShippingStatusCard.js";import"@dropins/tools/preact-compat.js";import{u as tn}from"../chunks/useGetStoreConfig.js";import"@dropins/tools/preact.js";import{events as ln}from"@dropins/tools/event-bus.js";import{C as rn}from"../chunks/OrderLoaders.js";import{u as hn}from"../chunks/useIsMobile.js";import{Text as H,useText as un}from"@dropins/tools/i18n.js";import"../chunks/getStoreConfig.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";var j=(t=>(t.PENDING="pending",t.SHIPPING="shipping",t.COMPLETE="complete",t.PROCESSING="processing",t.HOLD="on hold",t.CANCELED="Canceled",t.SUSPECTED_FRAUD="suspected fraud",t.PAYMENT_REVIEW="payment review",t))(j||{});const cn=({orderData:t})=>{const[r,h]=q(!0),[n,u]=q(t),[l,m]=q(!1);return sn(()=>{const c=ln.on("order/data",o=>{u(o),m(o==null?void 0:o.isVirtual),h(!1)},{eager:!0});return t!=null&&t.id&&h(!1),()=>{c==null||c.off()}},[t]),{loading:r,order:n,isVirtualProduct:l}},en=({value:t,variant:r="primary",size:h="medium",icon:n,className:u,children:l,disabled:m=!1,active:c=!1,activeChildren:o,activeIcon:b,href:e,...C})=>{let d="dropin-button";(n&&!l||n&&c&&!o||!n&&c&&b)&&(d="dropin-iconButton"),c&&o&&(d="dropin-button"),u=$([d,`${d}--${h}`,`${d}--${r}`,[`${d}--${r}--disabled`,m],l&&n&&`${d}--with-icon`,!l&&o&&n&&`${d}--with-icon`,c&&b&&`${d}--with-icon`,u]);const I=$(["dropin-button-icon",`dropin-button-icon--${r}`,[`dropin-button-icon--${r}--disabled`,m],n==null?void 0:n.props.className]),g=e?{node:i("a",{}),role:"link",href:e,...C,disabled:m,active:c,onKeyDown:y=>{m&&y.preventDefault()},tabIndex:m?-1:0}:{node:i("button",{}),role:"button",...C,value:t,disabled:m,active:c};return S(R,{...g,className:u,children:[n&&!c&&i(R,{node:n,className:I}),b&&c&&i(R,{node:b,className:I}),l&&!c&&(typeof l=="string"?i("span",{children:l}):l),c&&o&&(typeof o=="string"?i("span",{children:o}):o)]})},dn=({placeholderImage:t,slots:r,collapseThreshold:h,translations:n,returnData:u,routeTracking:l,routeProductDetails:m})=>{var b;const c=hn(),o=m?"a":"span";return console.log("returnData.items",u),console.log("returnData.items",u.items),S(A,{variant:"secondary",className:$(["order-shipping-status-card","order-shipping-status-card--return-order"]),children:[i(x,{title:n.returnOrderCardTitle}),S("div",{children:[(b=u==null?void 0:u.tracking)==null?void 0:b.map((e,C)=>{var y,O;const d={title:"",number:(e==null?void 0:e.trackingNumber)??"",carrier:((y=e==null?void 0:e.carrier)==null?void 0:y.label)??""},I=l==null?void 0:l(d),g=I?()=>{window.open(I,"_blank","noreferrer")}:null;return S("div",{className:"order-shipping-status-card__header",children:[S("div",{children:[`${n.carrier} `,`${(O=d.carrier)==null?void 0:O.toLocaleUpperCase()} | `,d.number]}),g?i(en,{onClick:g,children:n.trackButton}):null]},`${d.number}_${C}`)}),r!=null&&r.ReturnItemsDetails?i(G,{"data-testid":"returnItemsDetails",name:"ReturnItemsDetails",slot:r==null?void 0:r.ReturnItemsDetails,context:{items:u.items}}):null,i(V,{actionIconPosition:"right","data-testid":"dropinAccordion",children:i(B,{defaultOpen:h>=u.items.length,title:i(H,{id:"Order.ShippingStatusCard.itemText",plural:u.items.reduce((e,C)=>e+C.requestQuantity,0),fields:{count:u.items.reduce((e,C)=>e+C.requestQuantity,0)}}),children:i(M,{maxColumns:c?3:9,emptyGridContent:i(w,{}),className:$(["order-shipping-status-card__images",["order-shipping-status-card__images-3",c]]),children:u.items.map((e,C)=>{var g,y,O,T;const d=(g=e.thumbnail)==null?void 0:g.label,I=(O=(y=e.thumbnail)==null?void 0:y.url)!=null&&O.length?(T=e.thumbnail)==null?void 0:T.url:t;return i(o,{href:(m==null?void 0:m(e))??"#","data-testid":`${C}${e.uid}`,children:i(U,{alt:d,src:I,width:85,height:114})},`${C}${e.uid}`)})})})})]})]})},mn=({placeholderImage:t,translations:r,slots:h,orderData:n,collapseThreshold:u=10,routeProductDetails:l,routeTracking:m})=>{var O,T,F,Q,K,W,Y;const c=!!(n!=null&&n.returnNumber),o=n==null?void 0:n.returnNumber,b=l?"a":"span",e=(O=n==null?void 0:n.status)==null?void 0:O.toLocaleLowerCase(),d=((T=n==null?void 0:n.shipments)==null?void 0:T.length)===1&&(e==null?void 0:e.includes(j.COMPLETE)),I=(F=n==null?void 0:n.shipments)==null?void 0:F.every(p=>p.tracking.length===0),g=(Q=n==null?void 0:n.items)==null?void 0:Q.filter(p=>(p==null?void 0:p.quantityShipped)===0||(p==null?void 0:p.quantityShipped)<(p==null?void 0:p.quantityOrdered)),y=(K=n==null?void 0:n.items)==null?void 0:K.reduce((p,f)=>{const a=f.quantityOrdered-f.quantityShipped;return p+(a>0?a:0)},0);if(console.log("0",0),c&&(n!=null&&n.returns.length)){console.log("1",1);const p=n.returns.find(f=>f.returnNumber===o);return!p||p.tracking.length===0?null:(console.log("2",2),i(dn,{placeholderImage:t,slots:h,collapseThreshold:u,translations:r,returnData:p,routeTracking:m,routeProductDetails:l}))}return!n||e!=null&&e.includes(j.CANCELED)?null:(W=n==null?void 0:n.shipments)!=null&&W.length?I&&!(g!=null&&g.length)&&d?null:S(w,{children:[(Y=n==null?void 0:n.shipments)==null?void 0:Y.map(({tracking:p,items:f,id:a},pn)=>{console.log("5",5),console.log("items",f);const E=f.reduce((s,N)=>s+((N==null?void 0:N.quantityShipped)??0),0);return console.log("accordionValue",E),S(A,{variant:"secondary",className:"order-shipping-status-card",children:[i(x,{title:r.shippingCardTitle}),p==null?void 0:p.map(s=>{var _;const N=m==null?void 0:m(s),L=N?()=>{window.open(N,"_blank","noreferrer")}:null;return S("div",{className:"order-shipping-status-card__header",role:"status",children:[S("div",{className:"order-shipping-status-card__header--content",children:[S("p",{children:[r.carrier," ",(_=s==null?void 0:s.carrier)==null?void 0:_.toLocaleUpperCase()," | ",s==null?void 0:s.number]}),i("p",{children:s==null?void 0:s.title})]}),h!=null&&h.DeliveryTrackActions?i(G,{"data-testid":"deliverySlotActions",name:"DeliveryTrackActions",slot:h==null?void 0:h.DeliveryTrackActions,context:{trackInformation:s}}):L?i(en,{onClick:L,children:r.trackButton}):null]},s.number)}),d?null:i(V,{actionIconPosition:"right","data-testid":"dropinAccordion",children:i(B,{"data-position":pn+1,defaultOpen:u>=(f==null?void 0:f.length),title:i(H,{id:"Order.ShippingStatusCard.notYetShippedImagesTitle",plural:E,fields:{count:E}}),children:i(M,{maxColumns:6,emptyGridContent:i(w,{}),className:"order-shipping-status-card__images",children:f==null?void 0:f.map(s=>{var _,z,J,X,Z,v,P,k,D,nn;const N=(J=(z=(_=s==null?void 0:s.orderItem)==null?void 0:_.product)==null?void 0:z.thumbnail)==null?void 0:J.label,L=(P=(v=(Z=(X=s==null?void 0:s.orderItem)==null?void 0:X.product)==null?void 0:Z.thumbnail)==null?void 0:v.url)!=null&&P.length?(nn=(D=(k=s==null?void 0:s.orderItem)==null?void 0:k.product)==null?void 0:D.thumbnail)==null?void 0:nn.url:t;return i(b,{href:(l==null?void 0:l(s))??"#",children:i(U,{alt:N,src:L,width:85,height:114})},s.id)})})})}),h!=null&&h.DeliveryTimeLine?i(G,{"data-testid":"deliverySlotTimeLine",name:"DeliveryTimeLine",slot:h==null?void 0:h.DeliveryTimeLine,context:{}}):null]},a)}),g!=null&&g.length?S(A,{variant:"secondary",className:"order-shipping-status-card","data-testid":"dropinAccordionNotYetShipped2",children:[i(x,{title:r.notYetShippedTitle}),i(V,{actionIconPosition:"right",children:i(B,{defaultOpen:u>=(g==null?void 0:g.length),title:i(H,{id:"Order.ShippingStatusCard.notYetShippedImagesTitle",plural:y,fields:{count:y}}),children:i(M,{maxColumns:6,emptyGridContent:i(w,{}),className:"order-shipping-status-card__images",children:g==null?void 0:g.map(p=>{var f,a;return i(b,{href:(l==null?void 0:l(p))??"#",children:i(U,{alt:(f=p.thumbnail)==null?void 0:f.label,src:((a=p.thumbnail)==null?void 0:a.url)||"",width:85,height:114})},p.id)})})})})]}):null]}):S(A,{variant:"secondary",className:"order-shipping-status-card",children:[i(x,{title:r.shippingInfoTitle}),i("div",{className:"order-shipping-status-card__header",children:S("div",{className:"order-shipping-status-card__header--content",children:[n!=null&&n.carrier?i("p",{children:n==null?void 0:n.carrier}):null,i("p",{children:r.noInfoTitle})]})})]})},wn=({slots:t,className:r,collapseThreshold:h,orderData:n,routeOrderDetails:u,routeTracking:l,routeProductDetails:m})=>{const{loading:c,order:o,isVirtualProduct:b}=cn({orderData:n}),e=tn(),C=un({carrier:"Order.ShippingStatusCard.carrier",prepositionOf:"Order.ShippingStatusCard.prepositionOf",returnOrderCardTitle:"Order.ShippingStatusCard.returnOrderCardTitle",shippingCardTitle:"Order.ShippingStatusCard.shippingCardTitle",shippingInfoTitle:"Order.ShippingStatusCard.shippingInfoTitle",notYetShippedTitle:"Order.ShippingStatusCard.notYetShippedTitle",noInfoTitle:"Order.ShippingStatusCard.noInfoTitle",returnNumber:"Order.ShippingStatusCard.returnNumber",orderNumber:"Order.ShippingStatusCard.orderNumber",trackButton:"Order.ShippingStatusCard.trackButton"});if(!c&&b)return null;const d=(e==null?void 0:e.baseMediaUrl)??"";return i("div",{className:$(["order-shipping-status",r]),children:!c&&o?i(mn,{placeholderImage:d,translations:C,routeOrderDetails:u,routeTracking:l,slots:t,orderData:o,collapseThreshold:h,routeProductDetails:m}):i(rn,{withCard:!1})})};export{wn as ShippingStatus,wn as default};