Files
Shifted/.next/server/app/cart/page.js
2026-02-10 01:14:19 +00:00

1 line
5.6 KiB
JavaScript

(()=>{var e={};e.id=1565,e.ids=[1565],e.modules={72934:e=>{"use strict";e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{"use strict";e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{"use strict";e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},88900:(e,t,a)=>{"use strict";a.r(t),a.d(t,{GlobalError:()=>n.a,__next_app__:()=>p,originalPathname:()=>u,pages:()=>d,routeModule:()=>h,tree:()=>l}),a(56826),a(88242),a(35866);var r=a(23191),s=a(88716),i=a(37922),n=a.n(i),o=a(95231),c={};for(let e in o)0>["default","tree","pages","GlobalError","originalPathname","__next_app__","routeModule"].indexOf(e)&&(c[e]=()=>o[e]);a.d(t,c);let l=["",{children:["cart",{children:["__PAGE__",{},{page:[()=>Promise.resolve().then(a.bind(a,56826)),"/root/ShiftedOffRoad/app/cart/page.tsx"]}]},{}]},{layout:[()=>Promise.resolve().then(a.bind(a,88242)),"/root/ShiftedOffRoad/app/layout.tsx"],"not-found":[()=>Promise.resolve().then(a.t.bind(a,35866,23)),"next/dist/client/components/not-found-error"]}],d=["/root/ShiftedOffRoad/app/cart/page.tsx"],u="/cart/page",p={require:a,loadChunk:()=>Promise.resolve()},h=new r.AppPageRouteModule({definition:{kind:s.x.APP_PAGE,page:"/cart/page",pathname:"/cart",bundlePath:"",filename:"",appPaths:[]},userland:{loaderTree:l}})},57692:(e,t,a)=>{Promise.resolve().then(a.bind(a,27403))},27403:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>l});var r=a(10326),s=a(17577),i=a(77109),n=a(86293),o=a(19640),c=a(90725);function l(){let[e,t]=(0,s.useState)("storeshifted"),[a,l]=(0,s.useState)(null),[d,u]=(0,s.useState)(!1),[p,h]=(0,s.useState)(""),{data:m,status:x}=(0,i.useSession)(),[g,f]=(0,s.useState)({name:"",street1:"",city:"",state:"",zip:"",country:"US",phone:""});async function j(e){u(!0),h("");try{let t=await fetch(`/api/cart/get?slug=${e}`),a=await t.json();if(!t.ok)throw Error(a.error||"Failed to load cart");l(a.cart)}catch(e){h(e.message||"Failed to load cart.")}finally{u(!1)}}async function v(t,a){u(!0);try{let r=await fetch("/api/cart/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({itemId:t,quantity:a})}),s=await r.json();if(!r.ok)throw Error(s.error||"Failed to update cart");await j(e)}catch(e){h(e.message||"Failed to update cart.")}finally{u(!1)}}async function y(t){u(!0);try{let a=await fetch("/api/cart/remove",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({itemId:t})}),r=await a.json();if(!a.ok)throw Error(r.error||"Failed to remove item");await j(e)}catch(e){h(e.message||"Failed to remove item.")}finally{u(!1)}}async function _(){u(!0),h("");try{let t=await fetch("/api/cart/checkout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,shippingAddress:g})}),a=await t.json();if(!t.ok)throw Error(a.error||"Checkout failed");window.location.href=a.url}catch(e){h(e.message||"Checkout failed.")}finally{u(!1)}}let S=a?.items.reduce((e,t)=>e+t.unitAmount*t.quantity,0)??0;return(0,r.jsxs)("main",{className:"cart-page",children:[r.jsx(n.default,{}),r.jsx(o.default,{}),r.jsx("section",{className:"section",children:(0,r.jsxs)("div",{className:"container cart-page__inner",children:[r.jsx("h1",{className:"page-title",children:"Cart"}),"authenticated"===x?(0,r.jsxs)("p",{className:"connect-muted",children:["Signed in as ",m.user.email]}):(0,r.jsxs)("p",{className:"connect-muted",children:["Sign in to save your cart across devices. ",r.jsx("a",{href:"/login",children:"Sign in"})]}),p?r.jsx("div",{className:"connect-message",children:p}):null,(0,r.jsxs)("div",{className:"cart-list",children:[a?.items.map(e=>r.jsxs("div",{className:"cart-item",children:[r.jsxs("div",{className:"cart-item__info",children:[r.jsx("div",{className:"cart-item__name",children:e.name}),r.jsxs("div",{className:"cart-item__price",children:[(e.unitAmount/100).toFixed(2)," ",e.currency.toUpperCase()]})]}),r.jsxs("div",{className:"cart-item__actions",children:[r.jsx("input",{type:"number",min:1,value:e.quantity,onChange:t=>v(e.id,Number(t.target.value))}),r.jsx("button",{className:"btn btn--ghost",onClick:()=>y(e.id),children:"Remove"})]})]},e.id)),a?.items.length?null:r.jsx("div",{className:"storefront-muted",children:"Your cart is empty."})]}),(0,r.jsxs)("div",{className:"cart-shipping",children:[r.jsx("h2",{children:"Shipping"}),r.jsx("div",{className:"cart-shipping__grid",children:(0,r.jsxs)("div",{className:"cart-shipping__card",children:[r.jsx("h3",{children:"Ship To"}),r.jsx("input",{value:g.name,onChange:e=>f({...g,name:e.target.value}),placeholder:"Name"}),r.jsx("input",{value:g.street1,onChange:e=>f({...g,street1:e.target.value}),placeholder:"Street"}),r.jsx("input",{value:g.city,onChange:e=>f({...g,city:e.target.value}),placeholder:"City"}),r.jsx("input",{value:g.state,onChange:e=>f({...g,state:e.target.value}),placeholder:"State/Province"}),r.jsx("input",{value:g.zip,onChange:e=>f({...g,zip:e.target.value}),placeholder:"Postal Code"}),r.jsx("input",{value:g.country,onChange:e=>f({...g,country:e.target.value}),placeholder:"Country"})]})})]}),(0,r.jsxs)("div",{className:"cart-summary",children:[(0,r.jsxs)("div",{children:["Total: ",(S/100).toFixed(2)," USD"]}),r.jsx("button",{className:"btn",onClick:_,disabled:d||!a?.items.length,children:"Checkout"})]})]})}),r.jsx(c.Z,{})]})}},56826:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>r});let r=(0,a(68570).createProxy)(String.raw`/root/ShiftedOffRoad/app/cart/page.tsx#default`)}};var t=require("../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[9276,1159,9404,6056],()=>a(88900));module.exports=r})();