1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2905],{2118:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/account/orders/[token]/reorder",function(){return r(8072)}])},2386:(e,t,r)=>{"use strict";r.d(t,{Ix:()=>o,j$:()=>s,kn:()=>i});var n=r(2009),a=r(8032);async function o(e,t){let r=(0,n.rJ)((0,a.s$)(),"customers",e,"orders");return(await (0,n.GG)((0,n.P)(r,(0,n._M)("siteCode","==",t),(0,n.My)("placedAt","desc")))).docs.map(e=>{var t;let r=e.data();return{orderToken:String(r.orderToken??e.id),invoiceNumber:String(r.invoiceNumber??""),placedAt:(t=r.placedAt)&&"object"==typeof t&&"function"==typeof t.toDate?t.toDate().toISOString():"string"==typeof t?t:null,siteCode:String(r.siteCode??""),status:String(r.status??""),total:"number"==typeof r.total?r.total:0,currency:String(r.currency??"GBP"),itemCount:"number"==typeof r.itemCount?r.itemCount:0,primaryItemName:"string"==typeof r.primaryItemName?r.primaryItemName:null}})}async function i(e,t){let r=await fetch(`/api/app/customers/orders/${encodeURIComponent(e)}`,{headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},cache:"no-store"});if(404===r.status)return null;if(!r.ok)throw Error(`Could not load the order (HTTP ${r.status}).`);return await r.json()}async function s(e,t){let r=await fetch(`/api/app/customers/orders/${encodeURIComponent(e)}/reorder`,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},cache:"no-store"});if(!r.ok)throw Error(`Reorder failed (HTTP ${r.status}).`);return await r.json()}},7328:(e,t,r)=>{e.exports=r(8005)},8072:(e,t,r)=>{"use strict";r.r(t),r.d(t,{__N_SSP:()=>g,default:()=>y});var n=r(7876),a=r(4232),o=r(7328),i=r.n(o),s=r(8230),d=r.n(s),c=r(9099),l=r(282),u=r(2386);function m(e){return{id:e.product.itemId,name:e.product.name,price:e.product.price,url:e.product.url,description:e.product.description,image:e.product.imageUrl||void 0,quantity:e.quantity,stackable:e.product.buttonAttributes?.["data-item-stackable"]||void 0,customFields:(e.product.customFields??[]).map(e=>({name:e.name,type:e.type,required:e.required,value:e.value||void 0,options:e.optionsText||void 0}))}}async function p(e=3e4){let t=window,r=Date.now();for(;Date.now()-r<e;){let e=t.Snipcart?.api?.cart?.items;if(e&&(e.replace||e.add))return e;await new Promise(e=>setTimeout(e,200))}return null}async function f(e,t){if("function"==typeof e.replace)return void await e.replace(...t);let r=window;for(let t of r.Snipcart?.store?.getState?.()?.cart?.items?.items??[])t?.uniqueId&&await e.remove?.(t.uniqueId);t.length>0&&e.add&&await e.add(...t)}function h(e){switch(e){case"product_not_found":return"One or more items from this order are no longer on the menu.";case"variant_option_invalid":case"variant_required":return"The options on this order are no longer available.";case"site_mismatch":return"This order was placed on a different Aso Rock store.";case"manifest_empty":return"This order has no reorderable items.";default:return"This order can't be reordered right now."}}var g=!0;function y(){let e=(0,c.useRouter)(),{user:t,loading:r,getIdToken:o}=(0,l.t)(),s="string"==typeof e.query.token?e.query.token:"",[g,y]=(0,a.useState)({kind:"loading",message:"Preparing your previous order..."}),x=(0,a.useRef)(!1);return((0,a.useEffect)(()=>{r||t||e.replace("/sign-in")},[r,t,e]),(0,a.useEffect)(()=>{if(!t||!s||x.current)return;x.current=!0;let e=!1;return async function(){try{y({kind:"loading",message:"Looking up your previous order..."});let r=await o();if(!r)throw Error("no-token");let n=await (0,u.j$)(s,r);if(e)return;if(!n.canReorder)return void y({kind:"cannot-reorder",reason:h(n.reason)});let a=n.lines??[];if(0===a.length)return void y({kind:"cannot-reorder",reason:h("manifest_empty")});y({kind:"loading",message:"Adding the items to your basket..."});let i=await p();if(e)return;if(!i)return void y({kind:"error",message:"Your basket isn't ready yet. Please refresh and try again."});let d=window;t?.uid&&(d.__rlFirebaseUid=t.uid,t.email&&(d.__rlFirebaseEmail=t.email));let c=a.map(m);if(await f(i,c),e)return;try{d.Snipcart?.api?.theme?.cart?.open?.()}catch{}if(await new Promise(e=>setTimeout(e,600)),e)return;let l=d.Snipcart?.api?.cart?.update;if(l&&t?.uid)try{let e={...function(e){try{let t=e.Snipcart?.store?.getState?.()?.cart?.metadata;if(t&&"object"==typeof t&&!Array.isArray(t))return{...t}}catch{}return{}}(d),firebaseUid:t.uid};t.email&&(e.firebaseEmail=t.email),await l({metadata:e}),console.log("[reorder] firebaseUid stamped on cart metadata",{uid:t.uid.slice(0,8)+"...",metadataKeys:Object.keys(e)})}catch(e){console.error("[reorder] failed to stamp firebaseUid",e)}y({kind:"ready"})}catch(t){console.error("[reorder] failed",t),e||y({kind:"error",message:"We couldn't reorder this right now. Please try again or browse the menu."})}}(),()=>{e=!0}},[t,s,o]),r||!t)?(0,n.jsx)("div",{className:"storefront-page-backdrop min-h-[60vh] px-4 py-16 text-center",children:(0,n.jsx)("p",{className:"storefront-page-body",children:"Loading..."})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(i(),{children:[(0,n.jsx)("title",{children:"Order again"}),(0,n.jsx)("meta",{name:"robots",content:"noindex,nofollow"})]}),(0,n.jsx)("div",{className:"storefront-page-backdrop min-h-[60vh] px-4 py-12 sm:py-16",children:(0,n.jsxs)("div",{className:"mx-auto w-full max-w-xl text-center",children:[(0,n.jsx)(d(),{href:s?`/account/orders/${encodeURIComponent(s)}`:"/account/orders",className:"storefront-page-link text-sm font-semibold",children:"â Back to the order"}),(0,n.jsx)("h1",{className:"storefront-page-title mt-3 text-[1.75rem] font-bold tracking-tight",children:"Order again"}),"loading"===g.kind?(0,n.jsx)("p",{className:"storefront-page-body mt-6 text-sm leading-6",children:g.message}):null,"ready"===g.kind?(0,n.jsxs)("div",{className:"storefront-page-panel mt-6 rounded-[2rem] px-6 py-6 sm:px-8",children:[(0,n.jsxs)("p",{className:"storefront-page-body text-sm leading-6",children:["Your previous order is in your basket. Review it on the right and tap ",(0,n.jsx)("strong",{children:"Checkout"})," when you're ready."]}),(0,n.jsx)(d(),{href:"/menu",className:"storefront-page-link mt-4 inline-block text-sm font-semibold",children:"Or keep browsing the menu â"})]}):null,"cannot-reorder"===g.kind?(0,n.jsxs)("div",{className:"storefront-page-panel mt-6 rounded-[2rem] px-6 py-6 sm:px-8",children:[(0,n.jsx)("p",{className:"storefront-page-body text-sm leading-6",children:g.reason}),(0,n.jsx)(d(),{href:"/menu",className:"storefront-page-button mt-5 inline-flex min-h-12 items-center justify-center rounded-full px-6 text-base font-semibold",children:"Browse the menu"})]}):null,"error"===g.kind?(0,n.jsxs)("div",{className:"storefront-page-panel mt-6 rounded-[2rem] px-6 py-6 sm:px-8",children:[(0,n.jsx)("p",{className:"storefront-page-body text-sm leading-6 text-red-700",children:g.message}),(0,n.jsx)("button",{type:"button",onClick:()=>{x.current=!1,y({kind:"loading",message:"Trying again..."}),e.replace(e.asPath)},className:"storefront-page-button mt-5 inline-flex min-h-12 items-center justify-center rounded-full px-6 text-base font-semibold",children:"Try again"})]}):null]})})]})}},9099:(e,t,r)=>{e.exports=r(7640)}},e=>{e.O(0,[636,6593,8792],()=>e(e.s=2118)),_N_E=e.O()}]);
2//# sourceMappingURL=reorder-6f4eef6b1bebef6c.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.