From 3ea9d72fa2733aa43ba7f6bc1abaddccb5c27e31 Mon Sep 17 00:00:00 2001 From: Konstantin Fandelyuk Date: Wed, 18 Sep 2024 23:04:46 +0300 Subject: [PATCH] updated 3 --- blocks/commerce-search-order/commerce-search-order.js | 2 +- scripts/__dropins__/storefront-order/containers/OrderSearch.js | 2 +- scripts/dropins.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/blocks/commerce-search-order/commerce-search-order.js b/blocks/commerce-search-order/commerce-search-order.js index bd4cd2bb6f..200ad877d5 100644 --- a/blocks/commerce-search-order/commerce-search-order.js +++ b/blocks/commerce-search-order/commerce-search-order.js @@ -38,7 +38,7 @@ export default async function decorate(block) { // routeCustomerOrder routeCustomerOrderDetails: () => "/customer/order-details/1", // routeGuestOrder - routeOrderDetails: () => "/order-details/1", + routeOrderDetails: () => "/order-details/", onError: async (errorInformation) => { console.info("errorInformation", errorInformation); }, diff --git a/scripts/__dropins__/storefront-order/containers/OrderSearch.js b/scripts/__dropins__/storefront-order/containers/OrderSearch.js index bf61a865fe..a6ab1494db 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 s}from"@dropins/tools/preact-jsx-runtime.js";import{classes as D}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 N,useCallback as R,useEffect as O,useMemo as k}from"@dropins/tools/preact-hooks.js";import*as A from"@dropins/tools/preact-compat.js";import{Text as S,useText as G}from"@dropins/tools/i18n.js";import{events as w}from"@dropins/tools/event-bus.js";import{c as I,g as H}from"../chunks/getCustomer.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const P=e=>A.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},A.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"})),X=({onSubmit:e,loading:t,inLineAlert:o,fieldsConfig:a})=>v(U,{variant:"secondary",className:"dropin-order-search-form",children:[s("h2",{className:"dropin-order-search-form__title",children:s(S,{id:"Order.OrderSearchForm.title"})}),s("p",{children:s(S,{id:"Order.OrderSearchForm.description"})}),o.text?s(C,{"data-testid":"orderAlert",className:"dropin-order-search-form__alert",type:o.type,variant:"secondary",heading:o.text,icon:s(x,{source:P})}):null,s(L,{className:"dropin-order-search-form__wrapper",name:"orderSearchForm",loading:t,fieldsConfig:a,onSubmit:e,children:s("div",{className:"dropin-order-search-form__button-container",children:s(V,{className:"dropin-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:t,children:s(S,{id:"Order.OrderSearchForm.button"})},"logIn")})})]});var h=(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))(h||{});const B=e=>{if(!e)return null;const t=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(a=>{t.has(a.name)||t.set(a.name,"false"),a.checked&&t.set(a.name,"true")}),t&&typeof t.entries=="function"){const a=t.entries();if(a&&typeof a[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(a)))||{}}return{}},d=(e,t)=>{if(typeof e!="function")return;const o=e();if(!t||Object.keys(t).length===0){window.location.href=o;return}const a=new URLSearchParams;Object.entries(t).forEach(([p,m])=>{a.append(p,String(m))});const c=o.includes("?")?"&":"?";window.location.href=`${o}${c}${a.toString()}`},M=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},j=({onError:e,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:c})=>{const[p,m]=N({text:"",type:"success"}),[T,u]=N(!1),f=G({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),y=R(async r=>{const i=M("orderRef"),l=i&&i.length>20;if(!r||!r.number||!r.token||i)return null;if(t&&r&&r.email){const n=await I();(n==null?void 0:n.email)===r.email?d(a,{orderRef:r==null?void 0:r.number}):l||d(c,{orderRef:r.token})}else l||d(c,{orderRef:r==null?void 0:r.token})},[t,a,c]);O(()=>{const r=w.on("order/data",i=>{y(i)},{eager:!0});return()=>{r==null||r.off()}},[y]),O(()=>{const r=M("orderRef"),i=r&&r.length>20?r:null;r&&(i?d(c,{orderRef:r}):t?d(a,{orderRef:r}):o({render:!0,formValues:{number:r}}))},[t,a,c,o]);const _=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.email,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.postcode,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.number,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[f]);return{onSubmit:R(async(r,i)=>{if(!i)return null;u(!0);const l=B(r.target);await H(l).then(n=>{n||m({text:f.invalidSearch,type:"warning"}),w.emit("order/data",n)}).catch(async n=>{var g;let b=!0;e==null||e({error:n.message});const E=await I();(E==null?void 0:E.email)===(l==null?void 0:l.email)?d(a,l.number):b=o==null?void 0:o({render:(g=n==null?void 0:n.message)==null?void 0:g.includes("Please login to view the order."),formValues:l}),b&&m({text:n.message,type:"warning"})}).finally(()=>{u(!1)})},[e,o,a,f]),inLineAlert:p,loading:T,normalizeFieldsConfig:_}},te=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:c,onError:p})=>{const{onSubmit:m,loading:T,inLineAlert:u,normalizeFieldsConfig:f}=j({onError:p,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:c});return s("div",{className:D(["dropin-order-search",e]),children:s(X,{onSubmit:m,loading:T,inLineAlert:u,fieldsConfig:f})})};export{te as OrderSearch,te as default}; +import{jsxs as v,jsx as c}from"@dropins/tools/preact-jsx-runtime.js";import{classes as D}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 N,useCallback as R,useEffect as O,useMemo as k}from"@dropins/tools/preact-hooks.js";import*as A from"@dropins/tools/preact-compat.js";import{Text as S,useText as G}from"@dropins/tools/i18n.js";import{events as w}from"@dropins/tools/event-bus.js";import{c as I,g as H}from"../chunks/getCustomer.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const P=e=>A.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},A.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"})),X=({onSubmit:e,loading:t,inLineAlert:o,fieldsConfig:a})=>v(U,{variant:"secondary",className:"dropin-order-search-form",children:[c("h2",{className:"dropin-order-search-form__title",children:c(S,{id:"Order.OrderSearchForm.title"})}),c("p",{children:c(S,{id:"Order.OrderSearchForm.description"})}),o.text?c(C,{"data-testid":"orderAlert",className:"dropin-order-search-form__alert",type:o.type,variant:"secondary",heading:o.text,icon:c(x,{source:P})}):null,c(L,{className:"dropin-order-search-form__wrapper",name:"orderSearchForm",loading:t,fieldsConfig:a,onSubmit:e,children:c("div",{className:"dropin-order-search-form__button-container",children:c(V,{className:"dropin-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:t,children:c(S,{id:"Order.OrderSearchForm.button"})},"logIn")})})]});var h=(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))(h||{});const B=e=>{if(!e)return null;const t=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(a=>{t.has(a.name)||t.set(a.name,"false"),a.checked&&t.set(a.name,"true")}),t&&typeof t.entries=="function"){const a=t.entries();if(a&&typeof a[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(a)))||{}}return{}},d=(e,t)=>{if(typeof e!="function")return;const o=e();if(!t||Object.keys(t).length===0){window.location.href=o;return}const a=new URLSearchParams;Object.entries(t).forEach(([p,m])=>{a.append(p,String(m))});const i=o.includes("?")?"&":"?";window.location.href=`${o}${i}${a.toString()}`},M=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},j=({onError:e,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:i})=>{const[p,m]=N({text:"",type:"success"}),[T,u]=N(!1),f=G({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),y=R(async r=>{const s=M("orderRef"),l=s&&s.length>20;if(!r||!r.number||!r.token||s)return null;if(t&&r&&r.email){const n=await I();(n==null?void 0:n.email)===r.email?d(a,{orderRef:r==null?void 0:r.number}):l||d(i,{orderRef:r.token})}else l||d(i,{orderRef:r==null?void 0:r.token})},[t,a,i]);O(()=>{const r=w.on("order/data",s=>{console.log("useEffect(() orderSearchRedirect",s),y(s)},{eager:!0});return()=>{r==null||r.off()}},[y]),O(()=>{const r=M("orderRef"),s=r&&r.length>20?r:null;r&&(s?d(i,{orderRef:r}):t?d(a,{orderRef:r}):o({render:!0,formValues:{number:r}}))},[t,a,i,o]);const _=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.email,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.postcode,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.number,options:[],defaultValue:"",fieldType:h.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[f]);return{onSubmit:R(async(r,s)=>{if(!s)return null;u(!0);const l=B(r.target);await H(l).then(n=>{n||m({text:f.invalidSearch,type:"warning"}),w.emit("order/data",n)}).catch(async n=>{var g;let b=!0;e==null||e({error:n.message});const E=await I();(E==null?void 0:E.email)===(l==null?void 0:l.email)?d(a,l.number):b=o==null?void 0:o({render:(g=n==null?void 0:n.message)==null?void 0:g.includes("Please login to view the order."),formValues:l}),b&&m({text:n.message,type:"warning"})}).finally(()=>{u(!1)})},[e,o,a,f]),inLineAlert:p,loading:T,normalizeFieldsConfig:_}},te=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:i,onError:p})=>{const{onSubmit:m,loading:T,inLineAlert:u,normalizeFieldsConfig:f}=j({onError:p,isAuth:t,renderSignIn:o,routeCustomerOrderDetails:a,routeOrderDetails:i});return c("div",{className:D(["dropin-order-search",e]),children:c(X,{onSubmit:m,loading:T,inLineAlert:u,fieldsConfig:f})})};export{te as OrderSearch,te as default}; diff --git a/scripts/dropins.js b/scripts/dropins.js index 3540f82d8c..863cf6dcfd 100644 --- a/scripts/dropins.js +++ b/scripts/dropins.js @@ -24,6 +24,7 @@ import { getMetadata } from "./aem.js"; export const getUserTokenCookie = () => getCookie("auth_dropin_user_token"); const setupInitialHandlers = (orderRef) => { + console.log("orderRef", orderRef); initializers.register(orderApi.initialize, { orderRef, });