From 73f251460a9a347b0e6535073b738573c7aceccc Mon Sep 17 00:00:00 2001 From: Konstantin Fandelyuk Date: Thu, 19 Sep 2024 23:41:53 +0300 Subject: [PATCH] updated --- blocks/commerce-search-order/commerce-search-order.js | 3 ++- .../storefront-order/chunks/CustomerDetailsContent.js | 2 +- scripts/__dropins__/storefront-order/containers/OrderSearch.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blocks/commerce-search-order/commerce-search-order.js b/blocks/commerce-search-order/commerce-search-order.js index ee6ca6ad88..e783619774 100644 --- a/blocks/commerce-search-order/commerce-search-order.js +++ b/blocks/commerce-search-order/commerce-search-order.js @@ -39,8 +39,9 @@ function disableCacheForPage() { document.head.appendChild(metaExpires); } +disableCacheForPage(); + export default async function decorate(block) { - disableCacheForPage(); block.innerHTML = ""; const isAuthenticated = !!getCookie("auth_dropin_user_token") || false; diff --git a/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js b/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js index 62055575c1..f58c109d65 100644 --- a/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js +++ b/scripts/__dropins__/storefront-order/chunks/CustomerDetailsContent.js @@ -1 +1 @@ -import{jsx as $,Fragment as V,jsxs as v}from"@dropins/tools/preact-jsx-runtime.js";import{useRef as M,useState as D,useEffect as _,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 w,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:h,defaultValue:c})=>(h&&(u[p]=c),u),{}),S=({fieldsConfig:l,onSubmit:u})=>{const{requiredFieldError:p}=y({requiredFieldError:"Order.Form.notifications.requiredFieldError"}),h=M(null),[c,s]=D({}),[o,t]=D({});_(()=>{if(s({}),!l||!l.length)return;const n=H(l);return s(n),()=>{s({})}},[l==null?void 0:l.length]);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&&h.current){const d=h.current.elements.namedItem(a);d==null||d.focus()}u==null||u(n,e)},[c,f,u]);return{formData:c,errors:o,formRef:h,handleChange:b,handleBlur:x,handleSubmit:F}},U=w(({loading:l,values:u,fields:p=[],errors:h,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 $(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:$(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?$(j,{}):void 0,E=d?"username":"";return $(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:$(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)=>$(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:$(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)=>$(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:$(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)=>$(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:$(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?$(V,{children:p.map(e=>{var d;const r=(h==null?void 0:h[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=w(({name:l,loading:u,children:p,className:h="defaultForm",fieldsConfig:c,onSubmit:s})=>{const{formData:o,errors:t,formRef:f,handleChange:b,handleBlur:x,handleSubmit:F}=S({fieldsConfig:c,onSubmit:s});return v("form",{className:k(["dropin-form",h]),onSubmit:F,name:l,ref:f,children:[$(U,{className:h,loading:u,fields:c,onChange:b,onBlur:x,errors:t,values:o}),p]})});export{K as F}; +import{jsx as $,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:h,defaultValue:c})=>(h&&(u[p]=c),u),{}),S=({fieldsConfig:l,onSubmit:u})=>{const{requiredFieldError:p}=y({requiredFieldError:"Order.Form.notifications.requiredFieldError"}),h=_(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(()=>()=>{s({})},[]);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&&h.current){const d=h.current.elements.namedItem(a);d==null||d.focus()}u==null||u(n,e)},[c,f,u]);return{formData:c,errors:o,formRef:h,handleChange:b,handleBlur:x,handleSubmit:F}},U=V(({loading:l,values:u,fields:p=[],errors:h,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 $(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:$(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?$(j,{}):void 0,E=d?"username":"";return $(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:$(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)=>$(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:$(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)=>$(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:$(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)=>$(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:$(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?$(v,{children:p.map(e=>{var d;const r=(h==null?void 0:h[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:h="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",h]),onSubmit:F,name:l,ref:f,children:[$(U,{className:h,loading:u,fields:c,onChange:b,onBlur:x,errors:t,values:o}),p]})});export{K as F}; diff --git a/scripts/__dropins__/storefront-order/containers/OrderSearch.js b/scripts/__dropins__/storefront-order/containers/OrderSearch.js index 03bd9b9dfe..7d2ba25fa9 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:a,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:a,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:a,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 a=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(r=>{a.has(r.name)||a.set(r.name,"false"),r.checked&&a.set(r.name,"true")}),a&&typeof a.entries=="function"){const r=a.entries();if(r&&typeof r[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(r)))||{}}return{}},p=(e,a)=>{if(typeof e!="function")return;const o=e();if(!a||Object.keys(a).length===0){window.location.href=o;return}const r=new URLSearchParams;Object.entries(a).forEach(([u,m])=>{r.append(u,String(m))});const c=o.includes("?")?"&":"?";window.location.href=`${o}${c}${r.toString()}`},I=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},q=({onError:e,isAuth:a,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:c})=>{const[u,m]=R({text:"",type:"success"}),[E,h]=R(!1),f=H({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),b=D(async t=>{const s=I("orderRef"),i=s&&s.length>20;if(!t&&!s||!(t!=null&&t.number)&&!(t!=null&&t.token)&&!s)return null;if(a){const d=await A();(d==null?void 0:d.email)===t.email?p(r,{orderRef:t==null?void 0:t.number}):i||p(c,{orderRef:t.token})}else i||p(c,{orderRef:t==null?void 0:t.token})},[a,r,c]);O(()=>{const t=w.on("order/data",s=>{b(s)},{eager:!0});return()=>{t==null||t.off()}},[b]),O(()=>{const t=I("orderRef"),s=t&&t.length>20?t:null;t&&(s?p(c,{orderRef:t}):a?p(r,{orderRef:t}):o==null||o({render:!0,formValues:{number:t}}))},[a,r,c,o]);const M=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.email,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.postcode,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.number,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[f]);return{onSubmit:D(async(t,s)=>{if(!s)return null;h(!0);const i=j(t.target);await P(i).then(l=>{l||m({text:f.invalidSearch,type:"warning"}),w.emit("order/data",l)}).catch(async l=>{var N;let d=!0;e==null||e({error:l.message});const y=a?await A():{email:""};(y==null?void 0:y.email)===(i==null?void 0:i.email)?p(r,{orderRef:i.number}):d=o==null?void 0:o({render:(N=l==null?void 0:l.message)==null?void 0:N.includes("Please login to view the order."),formValues:i}),d&&m({text:l.message,type:"warning"})}).finally(()=>{h(!1)})},[a,e,o,r,f.invalidSearch]),inLineAlert:u,loading:E,normalizeFieldsConfig:M}},ae=({className:e,isAuth:a,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:c,onError:u})=>{const{onSubmit:m,loading:E,inLineAlert:h,normalizeFieldsConfig:f}=q({onError:u,isAuth:a,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:c});return n("div",{className:_(["dropin-order-search",e]),children:n(B,{onSubmit:m,loading:E,inLineAlert:h,fieldsConfig:f})})};export{ae as OrderSearch,ae as default}; +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 c=o.includes("?")?"&":"?";window.location.href=`${o}${c}${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:c})=>{const[u,d]=R({text:"",type:"success"}),[E,h]=R(!1),f=H({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),b=D(async a=>{const s=I("orderRef"),i=s&&s.length>20;if(!a&&!s||!(a!=null&&a.number)&&!(a!=null&&a.token)&&!s)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}):i||p(c,{orderRef:a.token})}else i||p(c,{orderRef:a==null?void 0:a.token})},[t,r,c]);O(()=>{const a=w.on("order/data",s=>{b(s)},{eager:!0});return()=>{a==null||a.off()}},[b]),O(()=>{const a=I("orderRef"),s=a&&a.length>20?a:null;a&&(s?p(c,{orderRef:a}):t?p(r,{orderRef:a}):o==null||o({render:!0,formValues:{number:a}}))},[t,r,c,o]);const M=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.email,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.postcode,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.number,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[f]);return{onSubmit:D(async(a,s)=>{if(!s)return null;h(!0);const i=j(a.target);await P(i).then(l=>{l||d({text:f.invalidSearch,type:"warning"}),w.emit("order/data",l)}).catch(async l=>{var N;let m=!0;e==null||e({error:l.message});const y=t?await A():{email:""};(y==null?void 0:y.email)===(i==null?void 0:i.email)?(m=!1,p(r,{orderRef:i.number})):m=o==null?void 0:o({render:(N=l==null?void 0:l.message)==null?void 0:N.includes("Please login to view the order."),formValues:i}),m&&d({text:l.message,type:"warning"})}).finally(()=>{h(!1)})},[t,e,o,r,f.invalidSearch]),inLineAlert:u,loading:E,normalizeFieldsConfig:M}},te=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:c,onError:u})=>{const{onSubmit:d,loading:E,inLineAlert:h,normalizeFieldsConfig:f}=q({onError:u,isAuth:t,renderSignIn:o,routeCustomerOrder:r,routeGuestOrder:c});return n("div",{className:_(["dropin-order-search",e]),children:n(B,{onSubmit:d,loading:E,inLineAlert:h,fieldsConfig:f})})};export{te as OrderSearch,te as default};