efficient-storefront-blocks 0.115.0 → 0.117.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +9 -10
- package/dist/chunks/EditorPreviewCheckout-JKTRIRSH.js +4 -0
- package/dist/chunks/{SiteEditorProvider-RH2SMNYG.js → SiteEditorProvider-ZVNXSXBQ.js} +1 -1
- package/dist/chunks/{chunk-P3DTJ3CI.js → chunk-3XS3LIPN.js} +1 -1
- package/dist/chunks/chunk-JVAY6GGN.js +1 -0
- package/dist/chunks/chunk-NMYHWA3M.js +96 -0
- package/dist/chunks/chunk-XVPVTQYY.js +342 -0
- package/dist/chunks/chunk-XZPK5PGX.js +1 -0
- package/dist/chunks/{fitment-data-RALB36SU.js → fitment-data-3N56LEBE.js} +1 -1
- package/dist/contract.js +19 -3
- package/dist/editor/components/HeaderSettingsPanel.js +1 -1
- package/dist/editor/components/MenuPicker.d.ts +3 -0
- package/dist/editor/components/MenuPicker.js +1 -1
- package/dist/editor/lib/document/blocks/commerce/GalleryB/fields.js +1 -1
- package/dist/editor/lib/document/blocks/service/Form/fields.js +1 -1
- package/dist/editor/lib/document/config.d.ts +1 -0
- package/dist/editor/lib/document/config.js +1 -1
- package/dist/editor/lib/storefront-editor-words.d.ts +3 -0
- package/dist/editor/lib/storefront-editor-words.js +1 -1
- package/dist/editor.css +1 -1
- package/dist/index.js +104 -33
- package/dist/links.js +1 -1
- package/dist/render/built-with.json +1 -1
- package/dist/render/components/ChatContext.d.ts +1 -1
- package/dist/render/components/ChatContext.js +1 -1
- package/dist/render/components/ChatWidget.js +1 -1
- package/dist/render/components/DeliveryOptionsSource.js +1 -1
- package/dist/render/components/FormBlock.d.ts +10 -2
- package/dist/render/components/FormBlock.js +1 -1
- package/dist/render/components/GalleryCard.d.ts +1 -0
- package/dist/render/components/GalleryCard.js +1 -1
- package/dist/render/components/GalleryGrid.d.ts +3 -1
- package/dist/render/components/GalleryGrid.js +3 -3
- package/dist/render/components/GalleryItem.d.ts +3 -0
- package/dist/render/components/GalleryItem.js +1 -1
- package/dist/render/components/HeaderNavItem.js +1 -1
- package/dist/render/components/cart/drawer-parts.js +1 -1
- package/dist/render/components/checkout/CheckoutPageClient.js +1 -1
- package/dist/render/components/checkout/checkout-parts.js +1 -1
- package/dist/render/components/checkout/checkout-state.d.ts +3 -1
- package/dist/render/components/checkout/checkout-state.js +3 -3
- package/dist/render/components/fitment/FitmentFinder.js +1 -1
- package/dist/render/components/fitment/FitmentPickerGrid.js +1 -1
- package/dist/render/components/fitment/PickerField.d.ts +2 -1
- package/dist/render/components/fitment/PickerField.js +1 -1
- package/dist/render/components/fitment/useFitmentCascade.d.ts +8 -0
- package/dist/render/components/fitment/useFitmentCascade.js +1 -1
- package/dist/render/components/fitment/useVehicleFit.js +1 -1
- package/dist/render/components/fitment/vehicle-level-state.d.ts +1 -0
- package/dist/render/components/fitment/vehicle-level-state.js +1 -1
- package/dist/render/components/pdp-dynamic/DynamicGalleryGrid.d.ts +3 -0
- package/dist/render/components/pdp-dynamic/DynamicGalleryGrid.js +1 -1
- package/dist/render/lib/api/types.d.ts +1 -0
- package/dist/render/lib/checkout/checkout-memory.d.ts +14 -6
- package/dist/render/lib/checkout/checkout-memory.js +1 -1
- package/dist/render/lib/checkout/wallet-return.d.ts +13 -2
- package/dist/render/lib/checkout/wallet-return.js +1 -1
- package/dist/render/lib/document/blocks/commerce/GalleryB/meta.d.ts +4 -0
- package/dist/render/lib/document/blocks/commerce/GalleryB/meta.js +1 -1
- package/dist/render/lib/document/blocks/commerce/GalleryB/render.js +1 -1
- package/dist/render/lib/document/blocks/service/Form/render.js +1 -1
- package/dist/render/lib/document/card-templates.d.ts +2 -0
- package/dist/render/lib/document/card-templates.js +1 -1
- package/dist/render/lib/document/render-config.d.ts +1 -0
- package/dist/render/lib/document/render-config.js +1 -1
- package/dist/render/lib/document/section-to-box-rows-gallery.d.ts +1 -0
- package/dist/render/lib/document/section-to-box-rows-gallery.js +1 -0
- package/dist/render/lib/sections/gallery-frame.d.ts +3 -0
- package/dist/render/lib/sections/gallery-frame.js +1 -0
- package/dist/render/lib/wheels/price-display.d.ts +0 -1
- package/dist/render/lib/wheels/price-display.js +1 -1
- package/dist/words.d.ts +12 -0
- package/dist/words.js +4 -4
- package/package.json +5 -4
- package/dist/chunks/EditorPreviewCheckout-KJ7WBAJJ.js +0 -4
- package/dist/chunks/chunk-25XGYFU3.js +0 -80
- package/dist/chunks/chunk-H7576DO5.js +0 -1
- package/dist/chunks/chunk-ISCYSRBG.js +0 -1
- package/dist/chunks/chunk-WWVWTSGF.js +0 -340
- /package/dist/chunks/{chunk-WWVWTSGF.js.LEGAL.txt → chunk-XVPVTQYY.js.LEGAL.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as r,Fragment as x}from"react/jsx-runtime";import R from"next/link";import{useEffect as D,useMemo as Y,useRef as j,useState as v}from"react";import{holdTime as X}from"../../lib/checkout/hold-time.js";import{stripeAppearance as J}from"../../lib/checkout/stripe-appearance.js";import{userZone as ee}from"efficient-shell/format";import{Elements as te,PaymentElement as re,useElements as ne,useStripe as ae}from"@stripe/react-stripe-js";import{loadStripe as ie}from"@stripe/stripe-js";import{useCurrency as E}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{resolveCopyright as oe}from"../../lib/content/site.js";import{ApiError as L,products as q}from"../../lib/api/index.js";import ce,{WORDMARK_FIT_FLOOR_PX as se}from"efficient-web-builder/render/components/Logo";import{NOT_CHECKED as I,orderReference as le}from"../../lib/checkout/pay-first.js";import{CheckoutStateProvider as de,useCheckout as me}from"./checkout-state.js";import{CheckoutContact as pe,CheckoutOrderSummary as ue,CheckoutPayment as fe,CheckoutShippingAddress as xe,CheckoutShippingMethod as ge,FormLock as M,LeaveLink as z}from"./checkout-parts.js";function he(t){return e(de,{...t,children:e(ke,{})})}function ye({order:t,paid:n}){const{formatMoney:i}=E();if(!t.grandTotal||!t.currency)return null;const m=c=>i(Number(c),t.currency),y=Number(t.freightCharge??0),p=Number(t.discountAmount??0);return r("dl",{className:"grid w-full max-w-sm grid-cols-[1fr_auto] gap-x-6 gap-y-1 border-y border-line py-3 text-left text-sm",children:[(t.shippingMethod||y>0)&&r(x,{children:[r("dt",{className:"text-fg-dim",children:["Delivery",t.shippingMethod?` · ${t.shippingMethod}`:""]}),e("dd",{className:"text-right font-mono",children:m(t.freightCharge??"0")})]}),p>0&&r(x,{children:[r("dt",{className:"text-fg-dim",children:["Discount",t.couponCode?` · ${t.couponCode}`:""]}),r("dd",{className:"text-right font-mono",children:["−",m(t.discountAmount??"0")]})]}),e("dt",{className:"text-fg",children:n?"Total paid":"Order total"}),e("dd",{className:"text-right font-mono text-fg",children:m(t.grandTotal)})]})}function be({result:t,lostChangeNote:n=null}){const i=e("span",{className:"font-mono text-fg",children:t.checkoutNumber});return r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:t.kind==="refunded"||t.kind==="expired"?"Order not placed":t.kind==="processing"?"Payment processing":"Payment received"}),e("p",{className:"text-fg-dim",children:t.kind==="refunded"?r(x,{children:["An item sold out or an offer ended while you paid for checkout ",i,". Your payment goes back to your card."]}):t.kind==="expired"?r(x,{children:["The hold on checkout ",i," ran out before your payment arrived. Your payment goes back to your card."]}):t.kind==="processing"?r(x,{children:["Your payment for checkout ",i," is being processed. When it goes through, we will email your order confirmation."]}):r(x,{children:["Thank you — your payment",t.checkoutNumber?r(x,{children:[" for checkout ",i]}):null," has gone through. We will email you the order number shortly."]})}),n&&t.kind!=="refunded"&&t.kind!=="expired"&&e("p",{className:"text-sm text-fg-dim",children:n}),e(R,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]})}function ke(){const{site:t,logo:n,items:i,placing:m,formLocked:y,email:p,me:c,addressSaveNote:g,lostChangeNote:d,idemKey:f,confirmation:o,setConfirmation:u,payment:h,paypalStep:k,squareStep:N,pendingConf:l,paid:b,setPaid:C,payNote:s,afterpayConfirming:a,gocardlessConfirming:w,zipConfirming:P,klarnaConfirming:O,cardConfirming:$,checkoutResult:A,confirmCardPayment:U,cardStillProcessing:W,renewCardPayment:H,holdRenewed:G,leaveCardPayment:Z,checkoutRootRef:Q,setCheckoutHeaderEl:V}=me();return o?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:b?"Payment received":"Order received"}),r("p",{className:"text-fg-dim",children:[b?r(x,{children:["Thank you — your payment for order"," ",e("span",{className:"font-mono text-fg",children:o.orderNumber})," has gone through."," "]}):r(x,{children:["Thank you — your order ",e("span",{className:"font-mono text-fg",children:o.orderNumber})," is being reviewed by our team."," "]}),c?r(x,{children:["Track it under"," ",e(R,{href:"/account/orders",className:"text-accent underline",children:"your orders"}),"."]}):e(x,{children:"We’ve emailed you a link to set a password and track it."})]}),e(ye,{order:o,paid:b}),d&&e("p",{className:"text-sm text-fg-dim",children:d}),s&&e("p",{className:"text-sm text-fg-dim",children:s}),g&&e("p",{className:"text-sm text-fg-dim",children:g}),!c&&r("p",{className:"text-sm text-fg-dim",children:["You can also"," ",e(R,{href:`/track?order=${encodeURIComponent(o.orderNumber)}`,className:"text-accent underline",children:"track this order"})," ","anytime with just your order number and email — no password needed."]}),e(R,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]}):A?e(be,{result:A,lostChangeNote:d}):$?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Placing your order — one moment."})]}):a?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Afterpay — one moment."})]}):w?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Setting up your direct debit…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Confirming with GoCardless — one moment."})]}):P?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Zip — one moment."})]}):O?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Klarna — one moment."})]}):h&&l?e(Ne,{payment:h,checkout:l,holdRenewed:G,onPaid:U,onProcessing:W,onRenew:H,onBack:Z}):k&&l?e(Ce,{confirmation:l,clientId:t.paypalClientId??"",idemKey:f,onPaid:()=>{C(!0),u(l)},onSkip:()=>u(l)}):N&&l?e(je,{confirmation:l,applicationId:t.squareApplicationId??"",locationId:t.squareLocationId??"",environment:t.squareEnvironment??"production",idemKey:f,onPaid:()=>{C(!0),u(l)},onSkip:()=>u(l)}):r("div",{ref:Q,className:"bg-bg text-fg",children:[r("header",{ref:V,className:"sticky top-0 z-30 grid grid-cols-[1fr_auto_1fr] items-center gap-8 max-[640px]:grid-cols-[auto_minmax(0,1fr)_auto] max-[640px]:gap-3 border-b border-line px-[var(--sf-site-gutter,40px)] py-6 backdrop-blur-md max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))] max-[640px]:py-4",style:{background:"color-mix(in oklab, var(--bg) 92%, transparent)"},children:[r(z,{href:"/",className:"inline-flex items-center gap-3 font-mono text-[14px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["←",e("span",{className:"max-[640px]:hidden",children:"Back to shop"})]}),e("div",{className:"flex min-w-0 justify-center max-[640px]:[container-type:inline-size]",children:e(z,{href:"/","aria-label":`${t.name} home`,className:"inline-flex max-w-full items-center justify-center overflow-x-clip",children:e(ce,{variant:"header",scrolled:!0,src:n?.url??null,reverse:n?.reverse??!1,reversedSrc:n?.reversed??null,inkIsDark:n?.inkIsDark??null,size:n?.size??"medium",sizePx:n?.sizePx??null,sizeUnit:n?.sizeUnit??null,siteName:t.name,fitWordmarkToContainer:!0,fitFloorPx:se})})}),t.cardPayments?r("span",{className:"flex items-center justify-end gap-3 font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim",children:[e("span",{className:"text-green",children:"●"}),e("span",{className:"max-[640px]:hidden",children:"Encrypted ·"})," Stripe"]}):e("span",{})]}),r("section",{className:"mx-auto flex max-w-[var(--sf-site-width,1600px)] flex-wrap items-center justify-between gap-x-8 gap-y-3 border-b border-line bg-surface px-[var(--sf-site-gutter,40px)] py-4 font-mono text-[13px] font-medium uppercase tracking-[0.24em] text-fg max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))]",children:[e("span",{className:"inline-flex items-center bg-accent px-3 py-1 font-bold text-bg",children:"Checkout"}),e("nav",{"aria-label":"Checkout steps",className:"flex flex-wrap items-center gap-5",children:[{n:"01",label:"Cart",state:"done"},{n:"02",label:"Ship & pay",state:"active"},{n:"03",label:"Confirmed",state:"pending"}].map(S=>r("span",{className:["relative flex items-center gap-2 transition-colors",S.state==="pending"?"text-fg-dim":"text-fg",S.state==="active"?"font-bold after:absolute after:inset-x-0 after:-bottom-1 after:h-[2px] after:bg-accent":""].join(" "),children:[e("span",{className:S.state==="done"?"text-accent font-bold":"",children:S.n}),e("span",{children:S.label})]},S.n))})]}),r("main",{className:"mx-auto grid max-w-[var(--sf-site-width,1600px)] grid-cols-[1fr_420px] items-start gap-16 px-[var(--sf-site-gutter,40px)] pt-10 pb-[100px] max-view-desktop:grid-cols-1 max-view-desktop:gap-10 max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))] max-view-desktop:pt-8 max-view-desktop:pb-20",children:[r("div",{children:[r(M,{locked:y,children:[e(pe,{}),e(xe,{}),e(ge,{})]}),e(M,{locked:m,children:e(fe,{})})]}),e(ue,{})]}),e("footer",{className:"flex flex-wrap items-center justify-between gap-4 border-t border-line px-[var(--sf-site-gutter,40px)] py-6 font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))]",children:e("span",{children:oe({legalName:t.legalName,foundedYear:t.foundedYear,siteName:t.name})})})]})}function Ne({payment:t,checkout:n,holdRenewed:i,onPaid:m,onProcessing:y,onRenew:p,onBack:c}){const{formatMoney:g}=E(),d=e("span",{className:"text-fg",children:g(Number(t.amount),t.currency)}),f=Y(()=>ie(t.publishableKey),[t.publishableKey]),o=Y(()=>J(),[]),u=X(n.expiresAt??"",ee()??"");return e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:le(n)}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Payment"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:n.orderNumber?r(x,{children:["Your order is placed. Pay ",d," by card to confirm it now."]}):i?r(x,{children:["Your hold ran out, so your items are held again",u?` until ${u}`:"",". Enter your card again, then pay ",d,"."]}):r(x,{children:["Your items are held",u?` until ${u}`:"",". Pay ",d," by card to place your order."]})}),e(te,{stripe:f,options:{clientSecret:t.clientSecret,appearance:o},children:e(Pe,{payment:t,checkout:n,onPaid:m,onProcessing:y,onRenew:p,onBack:c})},t.clientSecret)]})]})})}const we=5;function Pe({payment:t,checkout:n,onPaid:i,onProcessing:m,onRenew:y,onBack:p}){const{formatMoney:c}=E(),g=ae(),d=ne(),[f,o]=v(!1),[u,h]=v(null),k=j(!1);async function N(){try{return(await g.retrievePaymentIntent(t.clientSecret)).paymentIntent?.status}catch{return}}async function l(s){let a=s;for(let w=0;a==="processing"&&w<we;w+=1)await new Promise(P=>setTimeout(P,1e3)),a=await N()??a;if(a==="succeeded"){i();return}if(a==="processing"){m();return}h("Payment did not complete. Please try again."),o(!1)}async function b(){if(!g||!d||f)return;o(!0),h(null),k.current=!0;const s=await g.confirmPayment({elements:d,redirect:"if_required"}).catch(()=>null);if(!s){const a=await N();if(a==="succeeded"||a==="processing"){await l(a);return}h(a===void 0?I:"Payment failed. Please try again."),o(!1);return}if(s.error){if(!n.orderNumber&&s.error.code==="payment_intent_unexpected_state"){const a=await N();if(a==="succeeded"||a==="processing"){await l(a);return}if(a===void 0){h(I),o(!1);return}await y(a==="canceled"),o(!1);return}h(s.error.message??"Payment failed. Please try again."),o(!1);return}await l(s.paymentIntent?.status)}async function C(){if(f)return;if(!k.current){p();return}o(!0),h(null);const s=await N();if(s==="succeeded"||s==="processing"){await l(s);return}if(o(!1),s===void 0){h(I);return}p()}return r("div",{className:"flex flex-col gap-4",children:[e(re,{}),u&&e(_,{role:"alert",children:u}),e("button",{type:"button",onClick:b,disabled:!g||!d||f,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!g||!d||f?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:f?r(x,{children:["Processing… ",e("span",{children:"·"})]}):r(x,{children:["Pay ",c(Number(t.amount),t.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})}),!n.orderNumber&&!f&&r("button",{type:"button",onClick:C,className:"inline-flex items-center gap-3 self-start font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["←",e("span",{children:"Back to checkout"})]})]})}const B="paypal-sdk-js";let T=null;function ve(t,n){const i=`${t}|${n}`;if(T?.key===i)return T.promise;const m=new Promise((y,p)=>{document.getElementById(B)?.remove();const c=document.createElement("script");c.id=B;const g=new URLSearchParams({"client-id":t,currency:n,intent:"capture"});c.src=`https://www.paypal.com/sdk/js?${g}`,c.onload=()=>{const d=window.paypal;d?y(d):p(new Error("PayPal SDK loaded without its namespace"))},c.onerror=()=>p(new Error("PayPal SDK failed to load")),document.head.appendChild(c)});return T={key:i,promise:m},m}function Ce({confirmation:t,clientId:n,idemKey:i,onPaid:m,onSkip:y}){const{formatMoney:p}=E(),c=j(null),[g,d]=v(!1),[f,o]=v(null),u=j(m);return u.current=m,D(()=>{let h=!1,k=null;return ve(n,t.currency).then(N=>{if(!(h||!c.current))return k=N.Buttons({style:{layout:"vertical",color:"gold",shape:"rect",label:"paypal"},createOrder:async()=>(await q.createPaypalOrder({idempotencyKey:i})).paypalOrderId,onApprove:async l=>{try{if((await q.capturePaypalOrder({idempotencyKey:i,paypalOrderId:l.orderID})).status==="paid"){u.current();return}o("PayPal did not complete the payment. Please try again.")}catch(b){o(b instanceof L?b.message:"PayPal payment failed. Please try again.")}},onError:()=>{o("PayPal could not process the payment. Please try again.")}}),k.render(c.current).then(()=>{h||d(!0)})}).catch(()=>{h||o("PayPal could not be loaded. You can pay later — your order stands either way.")}),()=>{h=!0,k?.close?.()}},[n,t.currency,i]),e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t.orderNumber}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"PayPal"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[r("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",e("span",{className:"text-fg",children:p(Number(t.grandTotal),t.currency)})," ","with PayPal to confirm it now."]}),!g&&!f&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading PayPal…"}),e("div",{ref:c}),f&&e(_,{role:"alert",children:f}),e("button",{type:"button",onClick:y,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later — our team will be in touch"})]})]})})}const F="square-web-sdk";let K=null;function Se(t){const n=t==="sandbox"?"sandbox":"production";if(K?.key===n)return K.promise;const i=new Promise((m,y)=>{document.getElementById(F)?.remove();const p=document.createElement("script");p.id=F,p.src=n==="sandbox"?"https://sandbox.web.squarecdn.com/v1/square.js":"https://web.squarecdn.com/v1/square.js",p.onload=()=>{const c=window.Square;c?m(c):y(new Error("Square SDK loaded without its namespace"))},p.onerror=()=>y(new Error("Square SDK failed to load")),document.head.appendChild(p)});return K={key:n,promise:i},i}function je({confirmation:t,applicationId:n,locationId:i,environment:m,idemKey:y,onPaid:p,onSkip:c}){const{formatMoney:g}=E(),d=j(null),f=j(null),o=j(null),[u,h]=v(!1),[k,N]=v(!1),[l,b]=v(null);D(()=>{let s=!1,a=null;return Se(m).then(async w=>{if(s||!d.current)return;const P=w.payments(n,i);o.current=P,a=await P.card(),await a.attach(d.current),f.current=a,s||h(!0)}).catch(()=>{s||b("Square could not be loaded. You can pay later — your order stands either way.")}),()=>{s=!0,a?.destroy?.()}},[n,i,m]);async function C(){const s=f.current;if(!(!s||k)){N(!0),b(null);try{const a=await s.tokenize();if(a.status!=="OK"||!a.token){b(a.errors?.[0]?.message??"Please check the card details and try again."),N(!1);return}let w;try{w=(await o.current?.verifyBuyer?.(a.token,{amount:String(t.grandTotal),currencyCode:t.currency,intent:"CHARGE"}))?.token}catch{}if((await q.chargeSquare({idempotencyKey:y,sourceId:a.token,...w?{verificationToken:w}:{}})).status==="paid"){p();return}b("Square did not complete the payment. Please try again.")}catch(a){b(a instanceof L?a.message:"Square payment failed. Please try again.")}N(!1)}}return e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t.orderNumber}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Card"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[r("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",e("span",{className:"text-fg",children:g(Number(t.grandTotal),t.currency)})," ","by card to confirm it now."]}),!u&&!l&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading card form…"}),e("div",{ref:d}),l&&e(_,{role:"alert",children:l}),e("button",{type:"button",onClick:C,disabled:!u||k,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!u||k?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:k?r(x,{children:["Processing… ",e("span",{children:"·"})]}):r(x,{children:["Pay ",g(Number(t.grandTotal),t.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})}),e("button",{type:"button",onClick:c,disabled:k,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later — our team will be in touch"})]})]})})}export{be as PayFirstResultView,he as default};
|
|
1
|
+
"use client";import{jsx as e,jsxs as r,Fragment as x}from"react/jsx-runtime";import R from"next/link";import{useEffect as D,useMemo as Y,useRef as j,useState as C}from"react";import{holdTime as X}from"../../lib/checkout/hold-time.js";import{stripeAppearance as J}from"../../lib/checkout/stripe-appearance.js";import{userZone as ee}from"efficient-shell/format";import{Elements as te,PaymentElement as re,useElements as ne,useStripe as ae}from"@stripe/react-stripe-js";import{loadStripe as ie}from"@stripe/stripe-js";import{useCurrency as E}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{resolveCopyright as oe}from"../../lib/content/site.js";import{ApiError as L,products as q}from"../../lib/api/index.js";import ce,{WORDMARK_FIT_FLOOR_PX as se}from"efficient-web-builder/render/components/Logo";import{NOT_CHECKED as I,orderReference as le}from"../../lib/checkout/pay-first.js";import{CheckoutStateProvider as de,useCheckout as me}from"./checkout-state.js";import{CheckoutContact as pe,CheckoutOrderSummary as ue,CheckoutPayment as fe,CheckoutShippingAddress as xe,CheckoutShippingMethod as ge,FormLock as M,LeaveLink as z}from"./checkout-parts.js";function he(t){return e(de,{...t,children:e(ke,{})})}function ye({order:t,paid:n}){const{formatMoney:i}=E();if(!t.grandTotal||!t.currency)return null;const m=c=>i(Number(c),t.currency),y=Number(t.freightCharge??0),p=Number(t.discountAmount??0);return r("dl",{className:"grid w-full max-w-sm grid-cols-[1fr_auto] gap-x-6 gap-y-1 border-y border-line py-3 text-left text-sm",children:[(t.shippingMethod||y>0)&&r(x,{children:[r("dt",{className:"text-fg-dim",children:["Delivery",t.shippingMethod?` · ${t.shippingMethod}`:""]}),e("dd",{className:"text-right font-mono",children:m(t.freightCharge??"0")})]}),p>0&&r(x,{children:[r("dt",{className:"text-fg-dim",children:["Discount",t.couponCode?` · ${t.couponCode}`:""]}),r("dd",{className:"text-right font-mono",children:["−",m(t.discountAmount??"0")]})]}),e("dt",{className:"text-fg",children:n?"Total paid":"Order total"}),e("dd",{className:"text-right font-mono text-fg",children:m(t.grandTotal)})]})}function be({result:t,lostChangeNote:n=null}){const i=e("span",{className:"font-mono text-fg",children:t.checkoutNumber});return r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:t.kind==="refunded"||t.kind==="expired"?"Order not placed":t.kind==="processing"?"Payment processing":"Payment received"}),e("p",{className:"text-fg-dim",children:t.kind==="refunded"?r(x,{children:["An item sold out or an offer ended while you paid for checkout ",i,". Your payment goes back to your card."]}):t.kind==="expired"?r(x,{children:["The hold on checkout ",i," ran out before your payment arrived. Your payment goes back to your card."]}):t.kind==="processing"?r(x,{children:["Your payment for checkout ",i," is being processed. When it goes through, we will email your order confirmation."]}):r(x,{children:["Thank you — your payment",t.checkoutNumber?r(x,{children:[" for checkout ",i]}):null," has gone through. We will email you the order number shortly."]})}),n&&t.kind!=="refunded"&&t.kind!=="expired"&&e("p",{className:"text-sm text-fg-dim",children:n}),e(R,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]})}function ke(){const{site:t,logo:n,items:i,placing:m,formLocked:y,email:p,me:c,addressSaveNote:g,lostChangeNote:d,idemKey:f,confirmation:o,setConfirmation:u,payment:h,paypalStep:k,squareStep:N,pendingConf:l,paid:b,setPaid:S,payNote:s,afterpayConfirming:a,gocardlessConfirming:P,zipConfirming:v,klarnaConfirming:O,cardConfirming:$,checkoutResult:A,confirmCardPayment:U,cardStillProcessing:W,renewCardPayment:H,holdRenewed:G,leaveCardPayment:Z,checkoutRootRef:Q,setCheckoutHeaderEl:V}=me();return o?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:b?"Payment received":"Order received"}),r("p",{className:"text-fg-dim",children:[b?r(x,{children:["Thank you — your payment for order"," ",e("span",{className:"font-mono text-fg",children:o.orderNumber})," has gone through."," "]}):r(x,{children:["Thank you — your order ",e("span",{className:"font-mono text-fg",children:o.orderNumber})," is being reviewed by our team."," "]}),c?r(x,{children:["Track it under"," ",e(R,{href:"/account/orders",className:"text-accent underline",children:"your orders"}),"."]}):e(x,{children:"We’ve emailed you a link to set a password and track it."})]}),e(ye,{order:o,paid:b}),d&&e("p",{className:"text-sm text-fg-dim",children:d}),s&&e("p",{className:"text-sm text-fg-dim",children:s}),g&&e("p",{className:"text-sm text-fg-dim",children:g}),!c&&r("p",{className:"text-sm text-fg-dim",children:["You can also"," ",e(R,{href:`/track?order=${encodeURIComponent(o.orderNumber)}`,className:"text-accent underline",children:"track this order"})," ","anytime with just your order number and email — no password needed."]}),e(R,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]}):A?e(be,{result:A,lostChangeNote:d}):$?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Placing your order — one moment."})]}):a?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Afterpay — one moment."})]}):P?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Setting up your direct debit…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Confirming with GoCardless — one moment."})]}):v?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Zip — one moment."})]}):O?r("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[e("h1",{className:"font-display text-3xl",children:"Confirming your payment…"}),e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Klarna — one moment."})]}):h&&l?e(Ne,{payment:h,checkout:l,holdRenewed:G,onPaid:U,onProcessing:W,onRenew:H,onBack:Z}):k&&l?e(Ce,{confirmation:l,clientId:t.paypalClientId??"",idemKey:f,onPaid:()=>{S(!0),u(l)},onSkip:()=>u(l)}):N&&l?e(je,{confirmation:l,applicationId:t.squareApplicationId??"",locationId:t.squareLocationId??"",environment:t.squareEnvironment??"production",idemKey:f,onPaid:()=>{S(!0),u(l)},onSkip:()=>u(l)}):r("div",{ref:Q,className:"bg-bg text-fg",children:[r("header",{ref:V,className:"sticky top-0 z-30 grid grid-cols-[1fr_auto_1fr] items-center gap-8 max-[640px]:grid-cols-[auto_minmax(0,1fr)_auto] max-[640px]:gap-3 border-b border-line px-[var(--sf-site-gutter,40px)] py-6 backdrop-blur-md max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))] max-[640px]:py-4",style:{background:"color-mix(in oklab, var(--bg) 92%, transparent)"},children:[r(z,{href:"/",className:"inline-flex items-center gap-3 font-mono text-[14px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["←",e("span",{className:"max-[640px]:hidden",children:"Back to shop"})]}),e("div",{className:"flex min-w-0 justify-center max-[640px]:[container-type:inline-size]",children:e(z,{href:"/","aria-label":`${t.name} home`,className:"inline-flex max-w-full items-center justify-center max-[640px]:overflow-x-clip",children:[!0,!1].map(w=>e(ce,{hideClass:w?"min-[641px]:hidden":"max-[640px]:hidden",variant:"header",scrolled:!0,src:n?.url??null,reverse:n?.reverse??!1,reversedSrc:n?.reversed??null,inkIsDark:n?.inkIsDark??null,size:n?.size??"medium",sizePx:n?.sizePx??null,sizeUnit:n?.sizeUnit??null,siteName:t.name,fitWordmarkToContainer:w,fitFloorPx:w?se:void 0},w?"phone":"wide"))})}),t.cardPayments?r("span",{className:"flex items-center justify-end gap-3 font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim",children:[e("span",{className:"text-green",children:"●"}),e("span",{className:"max-[640px]:hidden",children:"Encrypted ·"})," Stripe"]}):e("span",{})]}),r("section",{className:"mx-auto flex max-w-[var(--sf-site-width,1600px)] flex-wrap items-center justify-between gap-x-8 gap-y-3 border-b border-line bg-surface px-[var(--sf-site-gutter,40px)] py-4 font-mono text-[13px] font-medium uppercase tracking-[0.24em] text-fg max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))]",children:[e("span",{className:"inline-flex items-center bg-accent px-3 py-1 font-bold text-bg",children:"Checkout"}),e("nav",{"aria-label":"Checkout steps",className:"flex flex-wrap items-center gap-5",children:[{n:"01",label:"Cart",state:"done"},{n:"02",label:"Ship & pay",state:"active"},{n:"03",label:"Confirmed",state:"pending"}].map(w=>r("span",{className:["relative flex items-center gap-2 transition-colors",w.state==="pending"?"text-fg-dim":"text-fg",w.state==="active"?"font-bold after:absolute after:inset-x-0 after:-bottom-1 after:h-[2px] after:bg-accent":""].join(" "),children:[e("span",{className:w.state==="done"?"text-accent font-bold":"",children:w.n}),e("span",{children:w.label})]},w.n))})]}),r("main",{className:"mx-auto grid max-w-[var(--sf-site-width,1600px)] grid-cols-[1fr_420px] items-start gap-16 px-[var(--sf-site-gutter,40px)] pt-10 pb-[100px] max-view-desktop:grid-cols-1 max-view-desktop:gap-10 max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))] max-view-desktop:pt-8 max-view-desktop:pb-20",children:[r("div",{children:[r(M,{locked:y,children:[e(pe,{}),e(xe,{}),e(ge,{})]}),e(M,{locked:m,children:e(fe,{})})]}),e(ue,{})]}),e("footer",{className:"flex flex-wrap items-center justify-between gap-4 border-t border-line px-[var(--sf-site-gutter,40px)] py-6 font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))]",children:e("span",{children:oe({legalName:t.legalName,foundedYear:t.foundedYear,siteName:t.name})})})]})}function Ne({payment:t,checkout:n,holdRenewed:i,onPaid:m,onProcessing:y,onRenew:p,onBack:c}){const{formatMoney:g}=E(),d=e("span",{className:"text-fg",children:g(Number(t.amount),t.currency)}),f=Y(()=>ie(t.publishableKey),[t.publishableKey]),o=Y(()=>J(),[]),u=X(n.expiresAt??"",ee()??"");return e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:le(n)}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Payment"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[e("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:n.orderNumber?r(x,{children:["Your order is placed. Pay ",d," by card to confirm it now."]}):i?r(x,{children:["Your hold ran out, so your items are held again",u?` until ${u}`:"",". Enter your card again, then pay ",d,"."]}):r(x,{children:["Your items are held",u?` until ${u}`:"",". Pay ",d," by card to place your order."]})}),e(te,{stripe:f,options:{clientSecret:t.clientSecret,appearance:o},children:e(Pe,{payment:t,checkout:n,onPaid:m,onProcessing:y,onRenew:p,onBack:c})},t.clientSecret)]})]})})}const we=5;function Pe({payment:t,checkout:n,onPaid:i,onProcessing:m,onRenew:y,onBack:p}){const{formatMoney:c}=E(),g=ae(),d=ne(),[f,o]=C(!1),[u,h]=C(null),k=j(!1);async function N(){try{return(await g.retrievePaymentIntent(t.clientSecret)).paymentIntent?.status}catch{return}}async function l(s){let a=s;for(let P=0;a==="processing"&&P<we;P+=1)await new Promise(v=>setTimeout(v,1e3)),a=await N()??a;if(a==="succeeded"){i();return}if(a==="processing"){m();return}h("Payment did not complete. Please try again."),o(!1)}async function b(){if(!g||!d||f)return;o(!0),h(null),k.current=!0;const s=await g.confirmPayment({elements:d,redirect:"if_required"}).catch(()=>null);if(!s){const a=await N();if(a==="succeeded"||a==="processing"){await l(a);return}h(a===void 0?I:"Payment failed. Please try again."),o(!1);return}if(s.error){if(!n.orderNumber&&s.error.code==="payment_intent_unexpected_state"){const a=await N();if(a==="succeeded"||a==="processing"){await l(a);return}if(a===void 0){h(I),o(!1);return}await y(a==="canceled"),o(!1);return}h(s.error.message??"Payment failed. Please try again."),o(!1);return}await l(s.paymentIntent?.status)}async function S(){if(f)return;if(!k.current){p();return}o(!0),h(null);const s=await N();if(s==="succeeded"||s==="processing"){await l(s);return}if(o(!1),s===void 0){h(I);return}p()}return r("div",{className:"flex flex-col gap-4",children:[e(re,{}),u&&e(_,{role:"alert",children:u}),e("button",{type:"button",onClick:b,disabled:!g||!d||f,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!g||!d||f?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:f?r(x,{children:["Processing… ",e("span",{children:"·"})]}):r(x,{children:["Pay ",c(Number(t.amount),t.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})}),!n.orderNumber&&!f&&r("button",{type:"button",onClick:S,className:"inline-flex items-center gap-3 self-start font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["←",e("span",{children:"Back to checkout"})]})]})}const B="paypal-sdk-js";let T=null;function ve(t,n){const i=`${t}|${n}`;if(T?.key===i)return T.promise;const m=new Promise((y,p)=>{document.getElementById(B)?.remove();const c=document.createElement("script");c.id=B;const g=new URLSearchParams({"client-id":t,currency:n,intent:"capture"});c.src=`https://www.paypal.com/sdk/js?${g}`,c.onload=()=>{const d=window.paypal;d?y(d):p(new Error("PayPal SDK loaded without its namespace"))},c.onerror=()=>p(new Error("PayPal SDK failed to load")),document.head.appendChild(c)});return T={key:i,promise:m},m}function Ce({confirmation:t,clientId:n,idemKey:i,onPaid:m,onSkip:y}){const{formatMoney:p}=E(),c=j(null),[g,d]=C(!1),[f,o]=C(null),u=j(m);return u.current=m,D(()=>{let h=!1,k=null;return ve(n,t.currency).then(N=>{if(!(h||!c.current))return k=N.Buttons({style:{layout:"vertical",color:"gold",shape:"rect",label:"paypal"},createOrder:async()=>(await q.createPaypalOrder({idempotencyKey:i})).paypalOrderId,onApprove:async l=>{try{if((await q.capturePaypalOrder({idempotencyKey:i,paypalOrderId:l.orderID})).status==="paid"){u.current();return}o("PayPal did not complete the payment. Please try again.")}catch(b){o(b instanceof L?b.message:"PayPal payment failed. Please try again.")}},onError:()=>{o("PayPal could not process the payment. Please try again.")}}),k.render(c.current).then(()=>{h||d(!0)})}).catch(()=>{h||o("PayPal could not be loaded. You can pay later — your order stands either way.")}),()=>{h=!0,k?.close?.()}},[n,t.currency,i]),e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t.orderNumber}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"PayPal"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[r("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",e("span",{className:"text-fg",children:p(Number(t.grandTotal),t.currency)})," ","with PayPal to confirm it now."]}),!g&&!f&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading PayPal…"}),e("div",{ref:c}),f&&e(_,{role:"alert",children:f}),e("button",{type:"button",onClick:y,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later — our team will be in touch"})]})]})})}const F="square-web-sdk";let K=null;function Se(t){const n=t==="sandbox"?"sandbox":"production";if(K?.key===n)return K.promise;const i=new Promise((m,y)=>{document.getElementById(F)?.remove();const p=document.createElement("script");p.id=F,p.src=n==="sandbox"?"https://sandbox.web.squarecdn.com/v1/square.js":"https://web.squarecdn.com/v1/square.js",p.onload=()=>{const c=window.Square;c?m(c):y(new Error("Square SDK loaded without its namespace"))},p.onerror=()=>y(new Error("Square SDK failed to load")),document.head.appendChild(p)});return K={key:n,promise:i},i}function je({confirmation:t,applicationId:n,locationId:i,environment:m,idemKey:y,onPaid:p,onSkip:c}){const{formatMoney:g}=E(),d=j(null),f=j(null),o=j(null),[u,h]=C(!1),[k,N]=C(!1),[l,b]=C(null);D(()=>{let s=!1,a=null;return Se(m).then(async P=>{if(s||!d.current)return;const v=P.payments(n,i);o.current=v,a=await v.card(),await a.attach(d.current),f.current=a,s||h(!0)}).catch(()=>{s||b("Square could not be loaded. You can pay later — your order stands either way.")}),()=>{s=!0,a?.destroy?.()}},[n,i,m]);async function S(){const s=f.current;if(!(!s||k)){N(!0),b(null);try{const a=await s.tokenize();if(a.status!=="OK"||!a.token){b(a.errors?.[0]?.message??"Please check the card details and try again."),N(!1);return}let P;try{P=(await o.current?.verifyBuyer?.(a.token,{amount:String(t.grandTotal),currencyCode:t.currency,intent:"CHARGE"}))?.token}catch{}if((await q.chargeSquare({idempotencyKey:y,sourceId:a.token,...P?{verificationToken:P}:{}})).status==="paid"){p();return}b("Square did not complete the payment. Please try again.")}catch(a){b(a instanceof L?a.message:"Square payment failed. Please try again.")}N(!1)}}return e("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:r("div",{className:"w-full max-w-xl border border-line bg-bg",children:[r("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t.orderNumber}),e("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Card"})]}),r("div",{className:"flex flex-col gap-4 px-6 py-6",children:[r("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",e("span",{className:"text-fg",children:g(Number(t.grandTotal),t.currency)})," ","by card to confirm it now."]}),!u&&!l&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading card form…"}),e("div",{ref:d}),l&&e(_,{role:"alert",children:l}),e("button",{type:"button",onClick:S,disabled:!u||k,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!u||k?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:k?r(x,{children:["Processing… ",e("span",{children:"·"})]}):r(x,{children:["Pay ",g(Number(t.grandTotal),t.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})}),e("button",{type:"button",onClick:c,disabled:k,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later — our team will be in touch"})]})]})})}export{be as PayFirstResultView,he as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,Fragment as v,jsxs as a}from"react/jsx-runtime";import{useId as I}from"react";import Q from"next/image";import V from"next/link";import{lineTotal as X,useCart as Z}from"../CartContext.js";import{useCurrency as J}from"../CurrencyContext.js";import{Notice as S}from"../Notice.js";import{FREE_PRICE as j}from"../../lib/wheels/price-display.js";import ee from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as te}from"../../lib/cart/coupon-preview.js";import{orderReference as ne}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as ae}from"../../lib/checkout/checkout-memory.js";import{shippingWords as re,TAX_PENDING as ie}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as le}from"../../lib/wheels/finish-defaults.js";import M from"../ThemedSelect.js";import g from"../WebFormField.js";import oe from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as se,placedOrderLockNote as ce,SHIPPING_RETRY_NOTE as de,useCheckout as _}from"./checkout-state.js";import{FIELD_INPUT_CLASS as u}from"../../lib/field-input.js";import{FIGURE_TO_COME as pe,FIGURE_UPDATING as me}from"../../lib/wheels/price-display.js";function Ue(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:s,setLastName:c,company:f,setCompany:y,me:b,checkoutSignOut:h,orderLocked:x,unpaidOrder:o}=_(),d=I();return a(E,{num:"N° 01",title:"Contact",children:[x&&o&&e(ge,{orderNumber:o.orderNumber}),e(g,{label:"Email",htmlFor:d,hint:b?a(v,{children:["Signed in ·"," ",e("button",{type:"button",onClick:h,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):void 0,children:e("input",{id:d,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:b!==null,className:u})}),a(D,{children:[e(g,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:u})}),e(g,{label:"Last name",children:e("input",{type:"text",value:s,onChange:p=>c(p.target.value),className:u})})]}),e(g,{label:"Company (optional)",children:e("input",{type:"text",value:f,onChange:p=>y(p.target.value),autoComplete:"organization",className:u})})]})}function $e(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:s,setAddress2:c,city:f,setCity:y,postcode:b,setPostcode:h,phone:x,setPhone:o,country:d,setCountry:p,subdivision:C,setSubdivision:m,subdivisions:w,destination:N,postcodeLabel:Y,subdivisionLabel:q,me:P,savedAddresses:A,selectedAddressId:F,setSelectedAddressId:T,saveAddress:B,setSaveAddress:z,saveLabel:G,setSaveLabel:H,fillFromAddress:W,orderLocked:K}=_(),R=I(),O=I();return a(E,{num:"N° 02",title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(v,{children:[P!==null&&A.length>0&&a("div",{className:"grid gap-3",children:[A.map(r=>e(L,{active:F===r.id,onClick:()=>{T(r.id),W(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(L,{active:F==="new",onClick:()=>T("new"),title:"New address",body:null,price:null})]}),e(g,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:u})}),e(g,{label:"Address line 2",children:e("input",{type:"text",value:s,onChange:r=>c(r.target.value),placeholder:"Apartment, unit, garage bay…",className:u})}),a(D,{cols:"three",children:[e(g,{label:"City",children:e("input",{type:"text",value:f,onChange:r=>y(r.target.value),className:u})}),e(g,{label:Y,children:e("input",{type:"text",value:b,onChange:r=>h(r.target.value),className:u})}),e(g,{label:"Country",separate:!0,htmlFor:R,children:e(M,{id:R,value:d,onChange:r=>p(r.target.value),className:u+" pr-10",style:$,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(g,{label:q,separate:!0,htmlFor:O,children:w.length>0?a(M,{id:O,value:C,onChange:r=>m(r.target.value),className:u+" pr-10",style:$,children:[e("option",{value:"",children:"Select…"}),w.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:O,type:"text",value:C,onChange:r=>m(r.target.value),className:u})})]}),e(g,{label:"Phone",children:e("input",{type:"tel",value:x,onChange:r=>o(r.target.value),className:u})}),!t&&P!==null&&F==="new"&&!K&&a(v,{children:[e(fe,{checked:B,onChange:z,label:"Save this address to my account"}),B&&e(g,{label:"Address label",children:e("input",{type:"text",value:G,onChange:r=>H(r.target.value),placeholder:"Home",className:u})})]})]})}function De(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:s,pickupLocation:c,formatMoney:f,city:y,destination:b,courierUnavailable:h,retryCourier:x}=_();return e(E,{num:"N° 03",title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const d=o.pickupLocation,p=d?[d.address,d.city,d.state,d.zipCode].filter(Boolean).join(", "):null;return e(L,{active:l===o.id,onClick:()=>s(o.id),title:d?`${o.name} — ${d.name}`:o.name,body:d?[p,d.openingHours,d.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?j:f(o.amount,t.currency),tag:o.tag||void 0},o.id)}),h?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[de," ",e("button",{type:"button",onClick:x,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function Ye(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:s}=_();return a(E,{num:"N° 04",title:"Payment",children:[s&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:se}),e("div",{className:"grid gap-3",children:l.map(c=>e(L,{active:t===c.key,onClick:()=>i(c.key),title:c.title,body:c.body,price:c.price,tag:c.tag},c.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="bank"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Our team emails you the invoice and bank details after review."}):null]})}function qe(){const{site:t,items:i,totals:n,coupon:l,formatMoney:s,payChoice:c,placing:f,email:y,orderError:b,payment:h,noPaymentMethod:x,unpaidOrder:o,formLocked:d,restoredPrices:p,placeOrder:C}=_(),m=p==="waiting",w=p==="changed";return a("aside",{className:"sticky top-[var(--sf-checkout-header-h,88px)] border border-line max-view-desktop:static",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--site-surface) 70%, var(--bg)) 0%, var(--bg) 100%)"},children:[a("header",{className:"flex items-center justify-between border-b border-accent bg-accent px-6 py-4 font-mono text-[13px] font-bold uppercase tracking-[0.28em] text-bg",children:[e("span",{children:"Your order"}),e(U,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:i.length===0?a("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",e(U,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(N=>e(xe,{slug:N.slug,name:N.name,qty:N.qty,config:N.config,configSummary:be(N.config),price:w||m?null:X(N,n.currency)??0,currency:n.currency},N.id))}),e(he,{locked:d,className:"border-t border-line px-6 pt-5",children:e(ee,{customerEmail:y,disabled:d})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(k,{label:"Subtotal",value:m?me:s(w?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&l?.valid&&e(k,{label:`Coupon · ${l.code}`,value:a("span",{className:"font-semibold text-green",children:["− ",s(n.discount,n.currency)]})}),l?.deferred&&e(k,{label:`Coupon · ${l.code}`,value:te}),l?.valid&&l.effects?.gift&&e(k,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:j})}),e(k,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:j}):re(n.shippingStatus)??s(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(k,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:s(n.tax.amount,n.currency)}):n.tax.name?e(k,{label:n.tax.name,value:ie}):null)]}),a("div",{className:"mt-4 flex items-end justify-between border-y-2 border-accent px-6 py-4",style:{background:"color-mix(in oklab, var(--accent) 10%, var(--bg))"},children:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?pe:s(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[w&&e(S,{tone:"quiet",children:ae}),b&&e(S,{role:"alert",children:b}),n.hasUnpricedLine&&a(S,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:C,disabled:f||!o&&(x||i.length===0||n.hasUnpricedLine||n.repricing),className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",f||!o&&(i.length===0||x||n.hasUnpricedLine||n.repricing)?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:f?a(v,{children:["Building order… ",e("span",{children:"·"})]}):x?a(v,{children:["No online payment ",e("span",{children:"·"})]}):o?a(v,{children:["Try payment again · ",ne(o),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):n.repricing?a(v,{children:["Updating total… ",e("span",{children:"·"})]}):a(v,{children:[c==="bank"?"Place order":"Continue to payment"," ·"," ",s(n.grand,n.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const ue=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function he({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+ue,children:n})}function U({href:t,className:i="",children:n,...l}){const{placing:s}=_();return s?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(V,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function ge({orderNumber:t}){return e(S,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("svg",{"aria-hidden":!0,viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mt-[3px] shrink-0",children:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:ce(t)})]})})}const $={backgroundImage:"linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%)",backgroundPosition:"calc(100% - 18px) 50%, calc(100% - 12px) 50%",backgroundSize:"6px 6px",backgroundRepeat:"no-repeat"};function E({num:t,title:i,children:n}){return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function D({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function L({active:t,onClick:i,title:n,body:l,price:s,tag:c}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"border-accent outline outline-1 outline-accent -outline-offset-1":"border-line enabled:hover:border-[color-mix(in_oklab,var(--accent)_50%,var(--site-line))]"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,c&&e("span",{className:"border px-2 py-0.5 font-mono text-[11px] font-normal uppercase tracking-[0.24em] text-accent",style:{background:"color-mix(in oklab, var(--accent) 14%, transparent)",borderColor:"color-mix(in oklab, var(--accent) 45%, var(--site-line))"},children:c})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:s})]})}function fe({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function xe({slug:t,name:i,qty:n,config:l,configSummary:s,price:c,currency:f}){const{catalog:y}=Z(),{formatMoney:b}=J(),h=y.find(m=>m.slug===t),x=h?.spokes??5,o=h?.mesh??!1,d=l.find(m=>m.gold)?.label,p=h?.finishes.find(m=>m.name===d&&m.src)??h?.finishes.find(m=>m.src),C=h?.finishes[0]?.color??le;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:p?.src?e(Q,{src:p.src,alt:`${i.lead}${i.accent} — ${p.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:C},children:e(oe,{spokes:x,mesh:o,className:"block w-full"})})}),e("span",{className:"absolute -right-1.5 -top-1.5 z-[2] flex h-[18px] w-[18px] items-center justify-center rounded-full bg-accent font-mono text-[11px] font-bold text-bg",children:n})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:s})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:c===null?null:b(c,f)})]})}function k({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function be(t){return t.map(i=>i.label).join(" · ")}export{Ue as CheckoutContact,qe as CheckoutOrderSummary,Ye as CheckoutPayment,$e as CheckoutShippingAddress,De as CheckoutShippingMethod,he as FormLock,U as LeaveLink};
|
|
1
|
+
"use client";import{jsx as e,Fragment as v,jsxs as a}from"react/jsx-runtime";import{useId as j}from"react";import V from"next/image";import X from"next/link";import{lineTotal as Z,useCart as J}from"../CartContext.js";import{useCurrency as ee}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as O}from"../../lib/wheels/price-display.js";import te from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ne}from"../../lib/cart/coupon-preview.js";import{orderReference as ae}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as re}from"../../lib/checkout/checkout-memory.js";import{shippingWords as ie,TAX_PENDING as le}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as oe}from"../../lib/wheels/finish-defaults.js";import D from"../ThemedSelect.js";import g from"../WebFormField.js";import se from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as ce,placedOrderLockNote as de,SHIPPING_RETRY_NOTE as pe,useCheckout as S}from"./checkout-state.js";import{FIELD_INPUT_CLASS as u}from"../../lib/field-input.js";import{FIGURE_UPDATING as P}from"../../lib/wheels/price-display.js";function $e(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:c,setLastName:d,company:f,setCompany:y,me:b,checkoutSignOut:h,orderLocked:x,unpaidOrder:o}=S(),s=j();return a(L,{num:"N° 01",title:"Contact",children:[x&&o&&e(he,{orderNumber:o.orderNumber}),e(g,{label:"Email",htmlFor:s,hint:b?a(v,{children:["Signed in ·"," ",e("button",{type:"button",onClick:h,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):void 0,children:e("input",{id:s,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:b!==null,className:u})}),a(U,{children:[e(g,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:u})}),e(g,{label:"Last name",children:e("input",{type:"text",value:c,onChange:p=>d(p.target.value),className:u})})]}),e(g,{label:"Company (optional)",children:e("input",{type:"text",value:f,onChange:p=>y(p.target.value),autoComplete:"organization",className:u})})]})}function De(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:c,setAddress2:d,city:f,setCity:y,postcode:b,setPostcode:h,phone:x,setPhone:o,country:s,setCountry:p,subdivision:C,setSubdivision:m,subdivisions:w,destination:N,postcodeLabel:q,subdivisionLabel:z,me:A,savedAddresses:B,selectedAddressId:I,setSelectedAddressId:T,saveAddress:R,setSaveAddress:H,saveLabel:G,setSaveLabel:W,fillFromAddress:K,orderLocked:Q}=S(),$=j(),F=j();return a(L,{num:"N° 02",title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.readyIn&&e("span",{className:"opacity-80",children:t.readyIn}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(v,{children:[A!==null&&B.length>0&&a("div",{className:"grid gap-3",children:[B.map(r=>e(E,{active:I===r.id,onClick:()=>{T(r.id),K(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(E,{active:I==="new",onClick:()=>T("new"),title:"New address",body:null,price:null})]}),e(g,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:u})}),e(g,{label:"Address line 2",children:e("input",{type:"text",value:c,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:u})}),a(U,{cols:"three",children:[e(g,{label:"City",children:e("input",{type:"text",value:f,onChange:r=>y(r.target.value),className:u})}),e(g,{label:q,children:e("input",{type:"text",value:b,onChange:r=>h(r.target.value),className:u})}),e(g,{label:"Country",separate:!0,htmlFor:$,children:e(D,{id:$,value:s,onChange:r=>p(r.target.value),className:u+" pr-10",style:Y,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(g,{label:z,separate:!0,htmlFor:F,children:w.length>0?a(D,{id:F,value:C,onChange:r=>m(r.target.value),className:u+" pr-10",style:Y,children:[e("option",{value:"",children:"Select…"}),w.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:F,type:"text",value:C,onChange:r=>m(r.target.value),className:u})})]}),e(g,{label:"Phone",children:e("input",{type:"tel",value:x,onChange:r=>o(r.target.value),className:u})}),!t&&A!==null&&I==="new"&&!Q&&a(v,{children:[e(ge,{checked:R,onChange:H,label:"Save this address to my account"}),R&&e(g,{label:"Address label",children:e("input",{type:"text",value:G,onChange:r=>W(r.target.value),placeholder:"Home",className:u})})]})]})}function Me(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:c,pickupLocation:d,formatMoney:f,city:y,destination:b,courierUnavailable:h,retryCourier:x}=S();return e(L,{num:"N° 03",title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const s=o.pickupLocation,p=s?[s.address,s.city,s.state,s.zipCode].filter(Boolean).join(", "):null;return e(E,{active:l===o.id,onClick:()=>c(o.id),title:s?`${o.name} — ${s.name}`:o.name,body:s?[p,s.openingHours,s.readyIn,s.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?O:f(o.amount,t.currency),tag:o.tag||void 0},o.id)}),h?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[pe," ",e("button",{type:"button",onClick:x,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function Ye(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:c}=S();return a(L,{num:"N° 04",title:"Payment",children:[c&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:ce}),e("div",{className:"grid gap-3",children:l.map(d=>e(E,{active:t===d.key,onClick:()=>i(d.key),title:d.title,body:d.body,price:d.price,tag:d.tag},d.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="bank"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Our team emails you the invoice and bank details after review."}):null]})}function Ue(){const{site:t,items:i,totals:n,coupon:l,formatMoney:c,payChoice:d,placing:f,email:y,orderError:b,payment:h,noPaymentMethod:x,unpaidOrder:o,formLocked:s,restoredPrices:p,placeOrder:C}=S(),m=p==="waiting",w=p==="changed";return a("aside",{className:"sticky top-[var(--sf-checkout-header-h,88px)] border border-line max-view-desktop:static",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--site-surface) 70%, var(--bg)) 0%, var(--bg) 100%)"},children:[a("header",{className:"flex items-center justify-between border-b border-accent bg-accent px-6 py-4 font-mono text-[13px] font-bold uppercase tracking-[0.28em] text-bg",children:[e("span",{children:"Your order"}),e(M,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:i.length===0?a("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",e(M,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(N=>e(fe,{slug:N.slug,name:N.name,qty:N.qty,config:N.config,configSummary:xe(N.config),price:w||m?null:Z(N,n.currency)??0,currency:n.currency},N.id))}),e(ue,{locked:s,className:"border-t border-line px-6 pt-5",children:e(te,{customerEmail:y,disabled:s})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(k,{label:"Subtotal",value:m?P:c(w?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&l?.valid&&e(k,{label:`Coupon · ${l.code}`,value:a("span",{className:"font-semibold text-green",children:["− ",c(n.discount,n.currency)]})}),l?.deferred&&e(k,{label:`Coupon · ${l.code}`,value:ne}),l?.valid&&l.effects?.gift&&e(k,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:O})}),e(k,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:O}):ie(n.shippingStatus)??c(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(k,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:c(n.tax.amount,n.currency)}):n.tax.name?e(k,{label:n.tax.name,value:le}):null)]}),a("div",{className:"mt-4 flex items-end justify-between border-y-2 border-accent px-6 py-4",style:{background:"color-mix(in oklab, var(--accent) 10%, var(--bg))"},children:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?P:c(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[w&&e(_,{tone:"quiet",children:re}),b&&e(_,{role:"alert",children:b}),n.hasUnpricedLine&&a(_,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:C,disabled:f||!o&&(x||i.length===0||n.hasUnpricedLine||n.repricing),className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",f||!o&&(i.length===0||x||n.hasUnpricedLine||n.repricing)?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:f?a(v,{children:["Building order… ",e("span",{children:"·"})]}):x?a(v,{children:["No online payment ",e("span",{children:"·"})]}):o?a(v,{children:["Try payment again · ",ae(o),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):n.repricing?a(v,{children:[P," ",e("span",{children:"·"})]}):a(v,{children:[d==="bank"?"Place order":"Continue to payment"," ·"," ",c(n.grand,n.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const me=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function ue({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+me,children:n})}function M({href:t,className:i="",children:n,...l}){const{placing:c}=S();return c?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(X,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function he({orderNumber:t}){return e(_,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("svg",{"aria-hidden":!0,viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mt-[3px] shrink-0",children:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:de(t)})]})})}const Y={backgroundImage:"linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%)",backgroundPosition:"calc(100% - 18px) 50%, calc(100% - 12px) 50%",backgroundSize:"6px 6px",backgroundRepeat:"no-repeat"};function L({num:t,title:i,children:n}){return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:t}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function U({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function E({active:t,onClick:i,title:n,body:l,price:c,tag:d}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"border-accent outline outline-1 outline-accent -outline-offset-1":"border-line enabled:hover:border-[color-mix(in_oklab,var(--accent)_50%,var(--site-line))]"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,d&&e("span",{className:"border px-2 py-0.5 font-mono text-[11px] font-normal uppercase tracking-[0.24em] text-accent",style:{background:"color-mix(in oklab, var(--accent) 14%, transparent)",borderColor:"color-mix(in oklab, var(--accent) 45%, var(--site-line))"},children:d})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:c})]})}function ge({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function fe({slug:t,name:i,qty:n,config:l,configSummary:c,price:d,currency:f}){const{catalog:y}=J(),{formatMoney:b}=ee(),h=y.find(m=>m.slug===t),x=h?.spokes??5,o=h?.mesh??!1,s=l.find(m=>m.gold)?.label,p=h?.finishes.find(m=>m.name===s&&m.src)??h?.finishes.find(m=>m.src),C=h?.finishes[0]?.color??oe;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:p?.src?e(V,{src:p.src,alt:`${i.lead}${i.accent} — ${p.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:C},children:e(se,{spokes:x,mesh:o,className:"block w-full"})})}),e("span",{className:"absolute -right-1.5 -top-1.5 z-[2] flex h-[18px] w-[18px] items-center justify-center rounded-full bg-accent font-mono text-[11px] font-bold text-bg",children:n})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:c})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:b(d,f)})]})}function k({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function xe(t){return t.map(i=>i.label).join(" · ")}export{$e as CheckoutContact,Ue as CheckoutOrderSummary,Ye as CheckoutPayment,De as CheckoutShippingAddress,Me as CheckoutShippingMethod,ue as FormLock,M as LeaveLink};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CartLine } from "../CartContext.js";
|
|
1
2
|
import { type SiteIdentity } from "../../lib/content/site.js";
|
|
2
3
|
import type { OrderConfirmation, ShopAddress, ShopMe } from "../../lib/api/index.js";
|
|
3
4
|
import { type LandingOrder } from "../../lib/checkout/wallet-return.js";
|
|
@@ -42,7 +43,7 @@ declare function useCheckoutState({ site, logo, preview }: CheckoutProps): {
|
|
|
42
43
|
sizePx: number | null;
|
|
43
44
|
sizeUnit?: LengthUnit | null;
|
|
44
45
|
} | null | undefined;
|
|
45
|
-
items:
|
|
46
|
+
items: CartLine[];
|
|
46
47
|
totals: {
|
|
47
48
|
sets: number;
|
|
48
49
|
units: number;
|
|
@@ -93,6 +94,7 @@ declare function useCheckoutState({ site, logo, preview }: CheckoutProps): {
|
|
|
93
94
|
country: string;
|
|
94
95
|
openingHours: string;
|
|
95
96
|
instructions: string;
|
|
97
|
+
readyIn?: string;
|
|
96
98
|
} | null;
|
|
97
99
|
servedCountries: import("../../lib/content/site.js").SiteCountry[];
|
|
98
100
|
formatMoney: (amount: number, currency?: string) => string;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
2
|
-
`);return g===-1?[
|
|
3
|
-
${Me.trim()}`:ae,ur=Jr({email:Y,firstName:R,lastName:j,company:Ke.trim(),phone:Q,address:Fe,city:U,subdivision:E,postcode:_,country:p,lines:a.map(e=>[e.id,e.qty]),shippingMethodId:ce,couponCode:An(L),currency:C.currency,shopperId:ye?.id??null}),b=JSON.stringify([ur,w]),A=d(null),at=d(null),qe=d(!1),B=d(!1),re=d(null),$e=d(!1),v=d(b);v.current=b;const zt=d(I);zt.current=I;const Be=d(null);f(()=>{const e=()=>{const t=Be.current;t&&(Be.current=null,P(t),Qe(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function Ye(e,t,n,o){const r={idempotencyKey:t,confirmation:n};on()&&(r.lostChange=!0),X.setItem(e,JSON.stringify(r)),window.location.assign(o),Be.current=n}async function Dt(e){Qe(!0);try{await e()}finally{Be.current||Qe(!1)}}const Wt=d(!1),Jt=!!(ot||ge&&ge.kind!=="processing");f(()=>{Jt&&(Wt.current=!0,ke())},[Jt]);const Ue=d(null),we=d(!1),it=d(null);function ke(){it.current=null,_r()}const He=d(null),[oe,lr]=s(!1);function ut(e){if(Wt.current||m||we.current)return;const t=M.current,n={key:e,authed:st.current,parkedAt:it.current??=Date.now(),lastPress:t&&{key:t.key,request:bn(t.request),lines:t.lines,goods:O(t.shape)[0],plainPressed:!!t.plainMethod,plainLines:t.plainLines,plainGoods:O(t.plainShape)[0]},keptCardKey:$.current,placedGoods:A.current===null?null:O(A.current)[0],unpaidOrder:Ge.current&&Br(Ge.current),placedRequest:G.current&&bn(G.current),lines:a.length>0?a:z.current,form:$r({email:Y,firstName:R,lastName:j,company:Ke,address1:ae,address2:Me,city:U,postcode:_,phone:Q,country:p,subdivision:E,selectedAddressId:nt,shippingMethodId:ce,couponCode:L?.valid?L.code:null})};Fr(n)?qr(n):ke()}const Ge=d(y);Ge.current=y;const Xt=d(w);Xt.current=w;function lt(e){return{...Ur(e),...Mn(),...e.payFirst?{checkoutFlow:Je}:{}}}function dr(e,t){let n=e.request.payFirst?"":null,o=e.plainPressed?null:"";const r=()=>Xt.current??"";return{key:e.key,send:()=>t(lt(e.request)),request:lt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return n??r()},set method(u){n=u},get plainMethod(){return o??r()},set plainMethod(u){o=u},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[pr,fr]=s(!1),Zt=pr?!C.quoted||C.serverSubtotal===null?"waiting":Math.abs(C.serverSubtotal-C.subtotal)<Qr?"same":"changed":null,dt=!y&&Zt==="waiting",mr=dt?{...C,repricing:!0}:C,jt=dt&&C.quoteFailed;f(()=>{if(!jt)return;const e=setInterval(Ze,jr);return()=>clearInterval(e)},[jt,Ze]);function Qt(e,t=!0){ve(e.email),Oe(e.firstName),Ee(e.lastName),Ve(e.company),ie(e.address1),ue(e.address2),le(e.city),de(e.postcode),pe(e.phone),e.country&&fe(e.country),V({country:e.country||null,state:e.subdivision}),Le(e.selectedAddressId),e.shippingMethodId&&wt(e.shippingMethodId),t&&(Ue.current=e.couponCode)}f(()=>{let e=m?null:Yr();if(e&&a.length>0&&(ke(),e=null),e){const t=e.authed?k.createOrderAuthed:k.createOrder;Ie(e.key),it.current=e.parkedAt,M.current=e.lastPress&&dr(e.lastPress,t),$.current=e.keptCardKey,A.current=e.placedGoods===null?null:JSON.stringify([e.placedGoods,null]),st.current=e.authed;const n=e.placedRequest&<(e.placedRequest);G.current=n,q.current=n?()=>t(n):null,e.unpaidOrder&&P(e.unpaidOrder),e.lines.length>0&&(je(e.lines),z.current=e.lines,fr(!0)),e.form&&(He.current=e.form,Qt(e.form))}lr(!0)},[]),f(()=>{!oe||a.length>0||Ge.current||I||(we.current=!0,ke())},[oe,a.length]),f(()=>{const e=Ue.current;!oe||!e||a.length===0||(Ue.current=null,In(e,Y||void 0))},[oe,a.length]),f(()=>{!oe||I||ut(H)},[oe,I,H,y]);const D=d(null);f(()=>{zt.current||(b!==D.current&&(D.current=null),!(!B.current||!y||y.orderNumber)&&(b===A.current||b===D.current||Dt(()=>Vt(y))))},[b,y]);async function Vt(e){if($e.current)return null;$e.current=!0;try{const t=re.current?await Dr(re.current):"none";if(t==="succeeded"||t==="processing")return B.current=!1,P(null),T("card"),t==="succeeded"?await W(void 0,e):ln(e),null;if(t===void 0||!Gr.has(t))return D.current=v.current,P(e),N(t==="requires_action"?Hr:ht),null;const n=await Pn(H);if(n==="committed")return B.current=!1,P(null),T("card"),await W(void 0,e),null;if(n!=="released")return D.current=v.current,P(e),N(ht),null;B.current=!1,re.current=null,D.current=null,N(null),P(null);const o=We();return Ie(o),o}finally{$e.current=!1}}async function yr(){m||I||$e.current||await Dt(hr)}async function hr(){if(y){if((B.current?b!==A.current:Ce())&&!y.orderNumber){const o=await Vt(y);o&&v.current===b&&await en(o);return}N(null),qe.current=!1,await pt();const t=O(v.current)[1],n=y.orderNumber?t:"card";if(n&&Kn.has(n)&&Ce()&&O(v.current)[0]!==at.current){tn(y);return}T(n),n!==w&&Ae(n),await dn(y,n,!y.orderNumber);return}await en(H)}async function en(e){if(a.length===0||C.repricing||dt||!w||!ne.some(i=>i.key===w))return;const t=a.filter(wn).flatMap(i=>Kr(i.components,i.qty));if(t.length===0){N("Pick a size on each wheel's product page before checking out.");return}N(null);let n,o=e,r=w,u=!1;try{const i=ye?k.createOrderAuthed:k.createOrder,l={customer:{email:Y,name:`${R} ${j}`.trim(),phone:Q.trim()||void 0,companyName:Ke.trim()||void 0,address:Fe,city:U,state:E||void 0,zipCode:_,country:p},items:t,currency:C.currency,idempotencyKey:e,shippingMethodId:ce??void 0,couponCode:An(L),...Mn(),...zr(w)?{checkoutFlow:Je}:{}};q.current=()=>i(l),G.current=l,st.current=!!ye,we.current=!1,he(null),at.current=null,qe.current=!1,re.current=null,B.current=!1,D.current=null,A.current=b,z.current=a;const h=M.current,ze=h?.key===l.idempotencyKey&&(h.shape!==b&&(!!l.checkoutFlow||!!h.method||!!h.plainMethod)||!!l.checkoutFlow&&!!h.plainMethod);ze&&($.current=l.idempotencyKey);const mn=sn(l,i),yn=ze||!l.checkoutFlow&&$.current===l.idempotencyKey,hn=!mn&&!yn&&!l.checkoutFlow&&!!h&&!h.method;hn&&(h.plainMethod=w,h.plainLines=a,h.plainShape=b,ut(l.idempotencyKey));const J=await(yn?rn(l,i):i(l).then(be=>({answer:be,request:l})).catch(be=>(mn?nn(be,l.idempotencyKey):hn&&Sn(be)&&(h.plainMethod=""),gr(be,l,i))));if(!J)return;n=J.answer,o=J.request.idempotencyKey,r=J.method??r,T(r),u=Ce()||r!==O(v.current)[1],J.method&&J.method!==w&&Ae(J.method),n.orderNumber&&(an(n),Z()),await pt()}catch(i){const l=Zr(i);l?(xn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):i instanceof Xe?N(ht):N(i instanceof De?i.message:"Could not place the order. Please try again.");return}if(r&&Kn.has(r)&&(u||Ce())){tn(n);return}await dn(n,r,!1,o)}function tn(e){at.current=O(v.current)[0],N(`${En(e,null)} ${Pe}`),P(e)}function nn(e,t){Sn(e)&&!Nn(e)&&M.current?.key===t&&(M.current=null)}async function gr(e,t,n){if(yt(e))return cn(t,n);if(!Nn(e))throw e;return $.current=t.idempotencyKey,rn(t,n,!0)}async function rn(e,t,n=!1){const o=await Pn(e.idempotencyKey);if(o==="released")return cn(e,t);if(o!=="committed")throw new Xe;const r=M.current?.key===e.idempotencyKey?M.current:null;if(z.current=r?.lines??a,r?.method&&!n){$.current=null,q.current=r.send,G.current=r.request;const l=await r.send().catch(()=>{throw new Xe});return A.current=r.shape,{answer:l,request:e,method:r.method}}const u=r&&!r.method?r.send:()=>t({...e,checkoutFlow:Je});q.current=u,G.current=r&&!r.method?r.request:{...e,checkoutFlow:Je};const i=await u().catch(()=>null);if(!i&&r?.plainMethod)throw new Xe;return i?.orderNumber&&i.status!==Wr?($.current=null,r?.plainMethod&&(z.current=r.plainLines),r&&(A.current=r.plainMethod?r.plainShape:r.shape),{answer:i,request:e,method:r?.plainMethod||void 0}):(r&&(A.current=r.shape),T("card"),await un("",i?async()=>i:()=>Promise.reject(new Error("The order request did not answer."))),await pt(),null)}function Ce(){const e=A.current;return e!==null&&O(e)[0]!==O(v.current)[0]}function T(e){e!==O(v.current)[1]&&(qe.current=!0),he(on()?Pe:null)}function on(){return qe.current||Ce()}async function cn(e,t){const n={...e,idempotencyKey:We()};$.current=null,Ie(n.idempotencyKey),q.current=()=>t(n),G.current=n,sn(n,t);try{return{answer:await t(n),request:n}}catch(o){throw nn(o,n.idempotencyKey),o}}function sn(e,t){return M.current?.key===e.idempotencyKey?!1:(M.current={key:e.idempotencyKey,send:()=>t(e),request:e,lines:a,shape:b,method:e.checkoutFlow?"":w??"",plainMethod:"",plainLines:a,plainShape:b},we.current=!1,ut(e.idempotencyKey),!0)}function an(e){Or({confirmation:e,lines:z.current,adsSendTo:c.googleAdsId&&c.googleAdsConversionLabel?`${c.googleAdsId}/${c.googleAdsConversionLabel}`:null}),Er({confirmation:e,lines:z.current})}async function W(e,t=F){if(!t)return;const n=e?async()=>e:q.current;if(t.orderNumber||!n){te(!0),S(t);return}await un(t.checkoutNumber,n)}async function un(e,t){Z(),await Xr({checkoutNumber:e,resend:t,page:{setConfirming:or,land:S,markPaid:()=>te(!0),track:an,unplaced:Bt}})}function ln(e=F){if(e){if(e.orderNumber){S(e);return}Z(),Bt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function pt(){const e=JSON.stringify([rt.trim(),R,j,Q.trim(),Fe,U,E,_,p]);if(!(!ye||!Kt||nt!=="new"||xt.current===e))try{await Ne.createAddress({label:rt.trim()||"Home",contact_name:`${R} ${j}`.trim(),phone:Q.trim(),address:Fe,city:U,zip_code:_,state:E,country:p}),xt.current=e,Tt("Address saved to your account.")}catch{Tt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function dn(e,t=w,n=!1,o=H){P(null);try{if(t==="card"&&c.paymentMethods.includes("card")){const r=await k.createPaymentIntent({idempotencyKey:o});re.current=r;let u=e;if(n){const i=await q.current?.().catch(()=>null);if(i?.orderNumber){T("card"),await W(i,e);return}u=pn(e,i)??{...e,expiresAt:null}}T("card"),ee(u),ct(!1),Re(r)}else if(t==="paypal"&&c.paymentMethods.includes("paypal"))ee(e),Wn(!0);else if(t==="afterpay"&&c.paymentMethods.includes("afterpay")){const r=window.location.origin,u=await k.createAfterpayCheckout({idempotencyKey:o,confirmUrl:`${r}/checkout?afterpay=confirm`,cancelUrl:`${r}/checkout?afterpay=cancel`});Ye(Tr,o,e,u.redirectCheckoutUrl);return}else if(t==="square"&&c.paymentMethods.includes("square"))ee(e),Jn(!0);else if(t==="gocardless"&&c.paymentMethods.includes("gocardless")){const r=window.location.origin,u=await k.createGocardlessBillingRequest({idempotencyKey:o,confirmUrl:`${r}/checkout?gocardless=confirm`,cancelUrl:`${r}/checkout?gocardless=cancel`});Ye(ft,o,e,u.authorisationUrl);return}else if(t==="zip"&&c.paymentMethods.includes("zip")){const r=window.location.origin,u=await k.createZipCheckout({idempotencyKey:o,redirectUrl:`${r}/checkout?zip=return`});Ye(Lr,o,e,u.redirectUrl);return}else if(t==="klarna"&&c.paymentMethods.includes("klarna")){const r=window.location.origin,u=await k.createKlarnaCheckout({idempotencyKey:o,confirmUrl:`${r}/checkout?klarna=confirm`,cancelUrl:`${r}/checkout?klarna=cancel`});Ye(mt,o,e,u.redirectUrl);return}else T(t),S(e)}catch(r){if((n||t==="card")&&r instanceof De&&r.status===409){T(t),await W(void 0,e);return}fn(e,r)}}function pn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function fn(e,t){N(En(e,t)),!e.orderNumber&&yt(t)?(B.current=!1,Ie(We())):P(e)}async function wr(e){if(!F)return;const t=F;try{const n=await k.createPaymentIntent({idempotencyKey:H}),o=await q.current?.().catch(()=>null);if(o?.orderNumber){await W(o);return}const r=pn(t,o);ee(r??{...t,expiresAt:null}),ct(e&&r!==null),re.current=n,Re(n)}catch(n){if(n instanceof De&&n.status===409){await W();return}Re(null),ee(null),fn(t,n)}}function kr(){F&&(B.current=!0,P(F),Re(null),ee(null),ct(!1))}return{site:c,logo:g,items:a,totals:mr,coupon:L,deliveryOptions:gt,courierUnavailable:Bn,retryCourier:Yn,shippingMethodId:ce,setShippingMethodId:wt,pickupLocation:Rn,servedCountries:se,formatMoney:_n,payChoice:w,setPayChoice:Ae,placing:I,email:Y,setEmail:ve,firstName:R,setFirstName:Oe,lastName:j,setLastName:Ee,company:Ke,setCompany:Ve,address1:ae,setAddress1:ie,address2:Me,setAddress2:ue,city:U,setCity:le,postcode:_,setPostcode:de,phone:Q,setPhone:pe,country:p,setCountry:fe,subdivision:E,setSubdivision:Te,subdivisions:me,destination:At,postcodeLabel:qn,subdivisionLabel:$n,me:ye,savedAddresses:Un,selectedAddressId:nt,setSelectedAddressId:Le,saveAddress:Kt,setSaveAddress:Mt,saveLabel:rt,setSaveLabel:Hn,addressSaveNote:Gn,lostChangeNote:zn,idemKey:H,confirmation:ot,setConfirmation:S,orderError:Dn,payment:Lt,paypalStep:It,squareStep:Rt,pendingConf:F,paid:Xn,setPaid:te,unpaidOrder:y,orderLocked:_t,formLocked:Zn,restoredPrices:Zt,payNote:jn,afterpayConfirming:Qn,gocardlessConfirming:er,zipConfirming:tr,klarnaConfirming:rr,cardConfirming:$t,checkoutResult:ge,confirmCardPayment:W,cardStillProcessing:ln,renewCardPayment:wr,holdRenewed:cr,leaveCardPayment:kr,checkoutRootRef:Ht,setCheckoutHeaderEl:sr,fillFromAddress:Gt,checkoutSignOut:ar,payOptions:ne,noPaymentMethod:ir,placeOrder:yr}}const Tn=Cr(null);function No({children:c,...g}){const m=Vr(g);return x(Tn.Provider,{value:m,children:c})}function Po(){const c=br(Tn);if(!c)throw new Error("useCheckout must be used inside CheckoutStateProvider");return c}export{No as CheckoutStateProvider,ko as NO_PAYMENT_METHOD_NOTE,Co as SHIPPING_RETRY_NOTE,On as buildPayOptions,En as paymentNotStartedMessage,bo as placedOrderLockNote,Po as useCheckout};
|
|
1
|
+
"use client";import{jsx as R}from"react/jsx-runtime";import{createContext as fr,useContext as mr,useEffect as h,useMemo as an,useRef as y,useState as s}from"react";import{isOrderable as un,useCart as yr}from"../CartContext.js";import{useCurrency as hr}from"../CurrencyContext.js";import{getClickIds as gr}from"../../lib/click-ids.js";import{adConsentForOrder as kr}from"../../lib/consent/choice.js";import{trackBeginCheckout as Cr,trackPurchase as wr}from"../../lib/google-tag.js";import{trackMetaPurchase as Pr}from"../../lib/meta-pixel.js";import{ApiError as Fe,api as me,products as w}from"../../lib/api/index.js";import{uuid as qe}from"../../lib/uuid.js";import{orderLinesForSets as br}from"../../lib/commerce.js";import{canPersist as Nr,safeSessionStorage as st}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Sr,AFTERPAY_RETURN as Ar,GOCARDLESS_CONTEXT_KEY as vr,GOCARDLESS_RETURN as Or,KLARNA_CONTEXT_KEY as Er,KLARNA_RETURN as Rr,ZIP_CONTEXT_KEY as Kr,ZIP_RETURN as Mr,runWalletReturn as $e}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Lr}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as Tr,holdsPress as _r,parkCheckoutMemory as xr,parkForm as Ir,parkOrder as Fr,parkRequest as ln,readCheckoutMemory as qr,sameGoods as $r,sendableRequest as Br}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as ct,checkoutWaiting as dn,BANK_WAITING as Ur,DROPPABLE_INTENT as Yr,NOT_CHECKED as at,LOST_CHANGE as it,PAY_FIRST_FLOW as ut,paysFirst as Hr,readIntentStatus as Gr,releaseHeldCheckout as pn,CHECKOUT_COMMITTED as Dr,goodsShapeOf as zr,refusedForGood as fn,settlePayFirst as Wr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as mn,couponRefusedByOrder as Jr}from"../../lib/cart/coupon-preview.js";function yn(o){const g=o.indexOf(`
|
|
2
|
+
`);return g===-1?[o,""]:[o.slice(0,g),o.slice(g+1)]}function hn(o,{canParkContext:g}={canParkContext:!0}){const f=o.paymentMethods,a=[];return f.includes("card")&&a.push({key:"card",title:"Card",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),f.includes("paypal")&&o.paypalClientId&&a.push({key:"paypal",title:"PayPal",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),f.includes("afterpay")&&a.push({key:"afterpay",title:"Afterpay",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),f.includes("square")&&o.squareApplicationId&&o.squareLocationId&&a.push({key:"square",title:"Card (Square)",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),f.includes("gocardless")&&g&&a.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),f.includes("zip")&&a.push({key:"zip",title:"Zip",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),f.includes("klarna")&&g&&a.push({key:"klarna",title:"Klarna",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),f.includes("bank")&&a.push({key:"bank",title:"Bank transfer",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),a}const Co="This shop does not take payment online yet. Please contact the shop to order.";class Be extends Error{}function gn(o,g){if(!o.orderNumber&&ct(g))return g.message;const f=g instanceof Fe?` (${g.message})`:"";return o.orderNumber?`Your order ${o.orderNumber} is saved, but the payment did not start${f}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${o.checkoutNumber}, but the payment did not start${f}. Try the payment again — you will not be charged twice.`}const Xr=3e3,Zr=.005,kn=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function Cn(){const o=kr();return{...o==="denied"?{}:gr(),...o?{adConsent:o}:{}}}const v=o=>JSON.parse(o),jr={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null},Qr={lastPress:o=>o&&{key:o.key,request:ln(o.request),lines:o.lines,goods:v(o.shape)[0],plainPressed:!!o.plainMethod,plainLines:o.plainLines,plainGoods:v(o.plainShape)[0]},keptCardKey:o=>o,placedShape:o=>o===null?null:v(o)[0],placedRequest:o=>o&&ln(o.body),unpaidOrder:o=>o&&Fr(o)};function wn(o,g){const f={};for(const a of Object.keys(o))f[a]=o[a](g[a]);return f}const wo="Shipping cannot be calculated right now. Please try again.";function Po(o){return`Your order is saved, so its contact, address, delivery and discount can't change here. To change any of them, contact the shop and quote ${o}.`}function Vr({site:o,logo:g,preview:f=!1}){const{items:a,totals:P,coupon:K,refuseCoupon:bn,deliveryOptions:lt,shippingMethodId:Q,setShippingMethodId:dt,setQuoteDestination:ye,courier:Nn,requote:Ue,identify:pt,clearCapturedCart:he,replaceItems:Ye,removeCoupon:ft,applyCoupon:Sn}=yr(),An=lt.find(e=>e.id===Q)?.pickupLocation??null,{country:mt,countries:V,activeCountry:yt,formatMoney:vn}=hr(),[C,ge]=s(()=>hn(o)[0]?.key??null),[ht,On]=s(!0);h(()=>{On(Nr(st))},[]);const[M,He]=s(!1),[I,ke]=s(""),[L,Ce]=s(""),[H,we]=s(""),[Pe,Ge]=s(""),[ee,te]=s(""),[be,ne]=s(""),[F,re]=s(""),[T,oe]=s(""),[G,se]=s(""),[m,ce]=s(()=>mt||V[0]?.code||""),[O,Ne]=s(""),[ae,gt]=s([]),[De,ze]=s(null),[Se,D]=s(null),kt=an(()=>V.find(e=>e.code===m)??yt,[V,m,yt]),En=kt?.postalLabel||"Postal Code",Rn=ae[0]?.divisionType||"State / Province";h(()=>{if(!m){gt([]),ze(m);return}ze(null);let e=!1;return w.listCountrySubdivisions(m).then(t=>{e||(gt(t),ze(m),Ne(""))}),()=>{e=!0}},[m]);const Ct=ee.trim()!==""&&F.trim()!==""&&T.trim()!==""&&De===m&&(ae.length===0||O!=="")?T.trim():"";h(()=>{ye(m?{country:m,subdivision:O,postcode:Ct}:null)},[m,O,Ct,ye]),h(()=>()=>ye(null),[ye]);const Kn=Nn?.status==="unavailable",Mn=Ue,[ie,wt]=s(null),[Ln,Pt]=s([]),[We,Ae]=s("new"),[bt,Nt]=s(!1),[Je,Tn]=s("Home"),[_n,St]=s(null),[xn,Xe]=s(null),[q,ve]=s(()=>qe()),At=y(null),[Ze,z]=s(null),[In,N]=s(null),[vt,Oe]=s(null),[Ot,Fn]=s(!1),[Et,qn]=s(!1),[_,W]=s(null),[$n,Ee]=s(!1),[k,S]=s(null),Rt=!!k?.orderNumber,Bn=Rt||M,[Un,Yn]=s(null),[Hn,Gn]=s(!1),[Dn,zn]=s(!1),[Wn,Jn]=s(!1),[Xn,Zn]=s(!1),[Kt,jn]=s(!1),[Qn,je]=s(!1),[ue,Mt]=s(null),i=y({...jr});i.current.unpaidOrder=k;const Qe=y(!1),$=y(a),Lt=!!(Ze||ue&&ue.kind!=="processing"||Kt||Ot||Et||vt&&_?.orderNumber);h(()=>{Lt&&(Ye([]),ft())},[Lt,Ye,ft]);const Tt=y(!1);h(()=>{f||Tt.current||!a.some(un)||(Tt.current=!0,Cr({lines:a,currency:P.currency,value:P.subtotal-P.discount,coupon:K?.valid?K.code:void 0}))},[a,P,K,f]),h(()=>{pt(I,L.trim()||void 0)},[I,L,pt]);const _t=y(null),[Re,Vn]=s(null);h(()=>{const e=_t.current;if(!Re||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Re.offsetHeight}px`);t();const r=new ResizeObserver(t);return r.observe(Re),()=>r.disconnect()},[Re]),h(()=>{const e=r=>({setConfirming:r,land:z,markPaid:()=>Ee(!0),note:Yn,fail:N,clearCart:he,lostChange:()=>Xe(it)}),t={search:window.location.search,storage:st,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};$e(Ar,{...t,capture:w.captureAfterpayPayment,page:e(Gn)}),$e(Mr,{...t,capture:w.captureZipPayment,page:e(Jn)}),$e(Or,{...t,capture:w.completeGocardlessPayment,page:e(zn)}),$e(Rr,{...t,capture:w.captureKlarnaPayment,page:e(Zn)})},[]);function xt(e){const[t,r]=yn(e.address);te(t),ne(r),re(e.city),oe(e.zip_code),e.country&&ce(e.country),e.phone&&se(e.phone),D({country:e.country||null,state:e.state??""})}h(()=>{if(Se){if((Se.country||m)!==m){D(null);return}De===m&&(Ne(Lr(m,Se.state,ae)),D(null))}},[Se,m,De,ae]),h(()=>{let e=!1;return(async()=>{try{const[t,r,c]=await Promise.all([me.me(),me.myProfile().catch(()=>null),me.myAddresses().catch(()=>[])]);if(e)return;wt(t);const n=c.filter(p=>p.is_active);Pt(n),ke(t.email);const u=(r?.contact_name??"").split(/\s+/);Ce(t.first_name||u[0]||""),we(t.last_name||u.slice(1).join(" "));const d=t.phone||r?.phone;d&&se(d);const l=n.find(p=>p.id===t.default_delivery_location)??n[0];if(l)Ae(l.id),xt(l);else if(r){const[p,j]=yn(r.address??"");te(p),ne(j),re(r.city??""),oe(r.zip_code??""),r.country&&ce(r.country),D({country:r.country||null,state:r.state??""})}Ie.current&&Ht(Ie.current,!1)}catch{}})(),()=>{e=!0}},[]);function er(){me.logout(),le.current=!0,Ie.current=null,xe.current=null,de(),wt(null),Pt([]),Ae("new"),Nt(!1),ke(""),Ce(""),we(""),Ge(""),te(""),ne(""),re(""),oe(""),se(""),ce(mt||V[0]?.code||""),Ne(""),D(null)}const J=an(()=>hn(o,{canParkContext:ht}),[o,ht]);h(()=>{J.some(e=>e.key===C)||ge(J[0]?.key??null)},[J,C]);const tr=J.length===0,Ke=be.trim()?`${ee}
|
|
3
|
+
${be.trim()}`:ee,nr=zr({email:I,firstName:L,lastName:H,company:Pe.trim(),phone:G,address:Ke,city:F,subdivision:O,postcode:T,country:m,lines:a.map(e=>[e.id,e.qty]),shippingMethodId:Q,couponCode:mn(K),currency:P.currency,shopperId:ie?.id??null}),b=JSON.stringify([nr,C]),Ve=y(null),Me=y(!1),x=y(!1),X=y(null),Le=y(!1),A=y(b);A.current=b;const It=y(M);It.current=M;const Te=y(null);h(()=>{const e=()=>{const t=Te.current;t&&(Te.current=null,S(t),He(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function _e(e,t,r,c){const n={idempotencyKey:t,confirmation:r};Xt()&&(n.lostChange=!0),st.setItem(e,JSON.stringify(n)),window.location.assign(c),Te.current=r}async function Ft(e){He(!0);try{await e()}finally{Te.current||He(!1)}}const qt=y(!1),$t=!!(Ze||ue&&ue.kind!=="processing");h(()=>{$t&&(qt.current=!0,de())},[$t]);const xe=y(null),le=y(!1),et=y(null);function de(){et.current=null,Tr()}const Ie=y(null),[Z,rr]=s(!1);function tt(e){if(qt.current||f||le.current)return;const t={key:e,authed:Qe.current,parkedAt:et.current??=Date.now(),press:wn(Qr,i.current),lines:a.length>0?a:$.current,form:Ir({email:I,firstName:L,lastName:H,company:Pe,address1:ee,address2:be,city:F,postcode:T,phone:G,country:m,subdivision:O,selectedAddressId:We,shippingMethodId:Q,couponCode:K?.valid?K.code:null})};_r(t.press)?xr(t):de()}const Bt=y(C);Bt.current=C;function nt(e){return{...Br(e),...Cn(),...e.payFirst?{checkoutFlow:ut}:{}}}function or(e,t){let r=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Bt.current??"";return{key:e.key,send:()=>t(nt(e.request)),request:nt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return r??n()},set method(u){r=u},get plainMethod(){return c??n()},set plainMethod(u){c=u},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[sr,cr]=s(!1),Ut=sr?!P.quoted||P.serverSubtotal===null?"waiting":Math.abs(P.serverSubtotal-P.subtotal)<Zr?"same":"changed":null,rt=!k&&Ut==="waiting",ar=rt?{...P,repricing:!0}:P,Yt=rt&&P.quoteFailed;h(()=>{if(!Yt)return;const e=setInterval(Ue,Xr);return()=>clearInterval(e)},[Yt,Ue]);function Ht(e,t=!0){ke(e.email),Ce(e.firstName),we(e.lastName),Ge(e.company),te(e.address1),ne(e.address2),re(e.city),oe(e.postcode),se(e.phone),e.country&&ce(e.country),D({country:e.country||null,state:e.subdivision}),Ae(e.selectedAddressId),e.shippingMethodId&&dt(e.shippingMethodId),t&&(xe.current=e.couponCode)}h(()=>{let e=f?null:qr();const t=!!(e&&a.length>0);if(e&&t&&!$r(e.lines,a)&&(de(),e=null),e){const r=e.authed?w.createOrderAuthed:w.createOrder;ve(e.key),et.current=e.parkedAt,Qe.current=e.authed;const c={lastPress:n=>n&&or(n,r),keptCardKey:n=>n,placedShape:n=>n===null?null:JSON.stringify([n,null]),placedRequest:n=>{if(!n)return null;const u=nt(n);return{body:u,send:()=>r(u)}},unpaidOrder:n=>n};i.current=wn(c,e.press),e.press.unpaidOrder&&S(e.press.unpaidOrder),e.lines.length>0&&!t&&(Ye(e.lines),$.current=e.lines,cr(!0)),e.form&&(Ie.current=e.form,Ht(e.form))}rr(!0)},[]),h(()=>{!Z||a.length>0||i.current.unpaidOrder||M||(le.current=!0,de())},[Z,a.length]),h(()=>{const e=xe.current;!Z||!e||a.length===0||(xe.current=null,Sn(e,I||void 0))},[Z,a.length]),h(()=>{!Z||M||tt(q)},[Z,M,q,k]);const B=y(null);h(()=>{It.current||(b!==B.current&&(B.current=null),!(!x.current||!k||k.orderNumber)&&(b===i.current.placedShape||b===B.current||Ft(()=>Gt(k))))},[b,k]);async function Gt(e){if(Le.current)return null;Le.current=!0;try{const t=X.current?await Gr(X.current):"none";if(t==="succeeded"||t==="processing")return x.current=!1,S(null),E("card"),t==="succeeded"?await U(void 0,e):en(e),null;if(t===void 0||!Yr.has(t))return B.current=A.current,S(e),N(t==="requires_action"?Ur:at),null;const r=await pn(q);if(r==="committed")return x.current=!1,S(null),E("card"),await U(void 0,e),null;if(r!=="released")return B.current=A.current,S(e),N(at),null;x.current=!1,X.current=null,B.current=null,N(null),S(null);const c=qe();return ve(c),c}finally{Le.current=!1}}async function ir(){f||M||Le.current||await Ft(ur)}async function ur(){if(k){if((x.current?b!==i.current.placedShape:pe())&&!k.orderNumber){const c=await Gt(k);c&&A.current===b&&await Dt(c);return}N(null),Me.current=!1,await ot();const t=v(A.current)[1],r=k.orderNumber?t:"card";if(r&&kn.has(r)&&pe()&&v(A.current)[0]!==Ve.current){zt(k);return}E(r),r!==C&&ge(r),await tn(k,r,!k.orderNumber);return}await Dt(q)}async function Dt(e){if(a.length===0||P.repricing||rt||!C||!J.some(d=>d.key===C))return;const t=a.filter(un).flatMap(d=>br(d.components,d.qty));if(t.length===0){N("Pick a size on each wheel's product page before checking out.");return}N(null);let r,c=e,n=C,u=!1;try{const d=ie?w.createOrderAuthed:w.createOrder,l={customer:{email:I,name:`${L} ${H}`.trim(),phone:G.trim()||void 0,companyName:Pe.trim()||void 0,address:Ke,city:F,state:O||void 0,zipCode:T,country:m},items:t,currency:P.currency,idempotencyKey:e,shippingMethodId:Q??void 0,couponCode:mn(K),...Cn(),...Hr(C)?{checkoutFlow:ut}:{}};i.current.placedRequest={body:l,send:()=>d(l)},Qe.current=!!ie,le.current=!1,Xe(null),Ve.current=null,Me.current=!1,X.current=null,x.current=!1,B.current=null,i.current.placedShape=b,$.current=a;const p=i.current.lastPress,j=p?.key===l.idempotencyKey&&(p.shape!==b&&(!!l.checkoutFlow||!!p.method||!!p.plainMethod)||!!l.checkoutFlow&&!!p.plainMethod);j&&(i.current.keptCardKey=l.idempotencyKey);const on=jt(l,d),sn=j||!l.checkoutFlow&&i.current.keptCardKey===l.idempotencyKey,cn=!on&&!sn&&!l.checkoutFlow&&!!p&&!p.method;cn&&(p.plainMethod=C,p.plainLines=a,p.plainShape=b,tt(l.idempotencyKey));const Y=await(sn?Jt(l,d):d(l).then(fe=>({answer:fe,request:l})).catch(fe=>(on?Wt(fe,l.idempotencyKey):cn&&fn(fe)&&(p.plainMethod=""),lr(fe,l,d))));if(!Y)return;r=Y.answer,c=Y.request.idempotencyKey,n=Y.method??n,E(n),u=pe()||n!==v(A.current)[1],Y.method&&Y.method!==C&&ge(Y.method),r.orderNumber&&(Qt(r),he()),await ot()}catch(d){const l=Jr(d);l?(bn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):d instanceof Be?N(at):N(d instanceof Fe?d.message:"Could not place the order. Please try again.");return}if(n&&kn.has(n)&&(u||pe())){zt(r);return}await tn(r,n,!1,c)}function zt(e){Ve.current=v(A.current)[0],N(`${gn(e,null)} ${it}`),S(e)}function Wt(e,t){fn(e)&&!dn(e)&&i.current.lastPress?.key===t&&(i.current.lastPress=null)}async function lr(e,t,r){if(ct(e))return Zt(t,r);if(!dn(e))throw e;return i.current.keptCardKey=t.idempotencyKey,Jt(t,r,!0)}async function Jt(e,t,r=!1){const c=await pn(e.idempotencyKey);if(c==="released")return Zt(e,t);if(c!=="committed")throw new Be;const n=i.current.lastPress?.key===e.idempotencyKey?i.current.lastPress:null;if($.current=n?.lines??a,n?.method&&!r){i.current.keptCardKey=null,i.current.placedRequest={body:n.request,send:n.send};const j=await n.send().catch(()=>{throw new Be});return i.current.placedShape=n.shape,{answer:j,request:e,method:n.method}}const u={...e,checkoutFlow:ut},d=n&&!n.method?{body:n.request,send:n.send}:{body:u,send:()=>t(u)};i.current.placedRequest=d;const l=d.send,p=await l().catch(()=>null);if(!p&&n?.plainMethod)throw new Be;return p?.orderNumber&&p.status!==Dr?(i.current.keptCardKey=null,n?.plainMethod&&($.current=n.plainLines),n&&(i.current.placedShape=n.plainMethod?n.plainShape:n.shape),{answer:p,request:e,method:n?.plainMethod||void 0}):(n&&(i.current.placedShape=n.shape),E("card"),await Vt("",p?async()=>p:()=>Promise.reject(new Error("The order request did not answer."))),await ot(),null)}function pe(){const e=i.current.placedShape;return e!==null&&v(e)[0]!==v(A.current)[0]}function E(e){e!==v(A.current)[1]&&(Me.current=!0),Xe(Xt()?it:null)}function Xt(){return Me.current||pe()}async function Zt(e,t){const r={...e,idempotencyKey:qe()};i.current.keptCardKey=null,ve(r.idempotencyKey),i.current.placedRequest={body:r,send:()=>t(r)},jt(r,t);try{return{answer:await t(r),request:r}}catch(c){throw Wt(c,r.idempotencyKey),c}}function jt(e,t){return i.current.lastPress?.key===e.idempotencyKey?!1:(i.current.lastPress={key:e.idempotencyKey,send:()=>t(e),request:e,lines:a,shape:b,method:e.checkoutFlow?"":C??"",plainMethod:"",plainLines:a,plainShape:b},le.current=!1,tt(e.idempotencyKey),!0)}function Qt(e){wr({confirmation:e,lines:$.current,adsSendTo:o.googleAdsId&&o.googleAdsConversionLabel?`${o.googleAdsId}/${o.googleAdsConversionLabel}`:null}),Pr({confirmation:e,lines:$.current})}async function U(e,t=_){if(!t)return;const r=e?async()=>e:i.current.placedRequest?.send;if(t.orderNumber||!r){Ee(!0),z(t);return}await Vt(t.checkoutNumber,r)}async function Vt(e,t){he(),await Wr({checkoutNumber:e,resend:t,page:{setConfirming:jn,land:z,markPaid:()=>Ee(!0),track:Qt,unplaced:Mt}})}function en(e=_){if(e){if(e.orderNumber){z(e);return}he(),Mt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function ot(){const e=JSON.stringify([Je.trim(),L,H,G.trim(),Ke,F,O,T,m]);if(!(!ie||!bt||We!=="new"||At.current===e))try{await me.createAddress({label:Je.trim()||"Home",contact_name:`${L} ${H}`.trim(),phone:G.trim(),address:Ke,city:F,zip_code:T,state:O,country:m}),At.current=e,St("Address saved to your account.")}catch{St("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function tn(e,t=C,r=!1,c=q){S(null);try{if(t==="card"&&o.paymentMethods.includes("card")){const n=await w.createPaymentIntent({idempotencyKey:c});X.current=n;let u=e;if(r){const d=await i.current.placedRequest?.send().catch(()=>null);if(d?.orderNumber){E("card"),await U(d,e);return}u=nn(e,d)??{...e,expiresAt:null}}E("card"),W(u),je(!1),Oe(n)}else if(t==="paypal"&&o.paymentMethods.includes("paypal"))W(e),Fn(!0);else if(t==="afterpay"&&o.paymentMethods.includes("afterpay")){const n=window.location.origin,u=await w.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?afterpay=confirm`,cancelUrl:`${n}/checkout?afterpay=cancel`});_e(Sr,c,e,u.redirectCheckoutUrl);return}else if(t==="square"&&o.paymentMethods.includes("square"))W(e),qn(!0);else if(t==="gocardless"&&o.paymentMethods.includes("gocardless")){const n=window.location.origin,u=await w.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${n}/checkout?gocardless=confirm`,cancelUrl:`${n}/checkout?gocardless=cancel`});_e(vr,c,e,u.authorisationUrl);return}else if(t==="zip"&&o.paymentMethods.includes("zip")){const n=window.location.origin,u=await w.createZipCheckout({idempotencyKey:c,redirectUrl:`${n}/checkout?zip=return`});_e(Kr,c,e,u.redirectUrl);return}else if(t==="klarna"&&o.paymentMethods.includes("klarna")){const n=window.location.origin,u=await w.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?klarna=confirm`,cancelUrl:`${n}/checkout?klarna=cancel`});_e(Er,c,e,u.redirectUrl);return}else E(t),z(e)}catch(n){if((r||t==="card")&&n instanceof Fe&&n.status===409){E(t),await U(void 0,e);return}rn(e,n)}}function nn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function rn(e,t){N(gn(e,t)),!e.orderNumber&&ct(t)?(x.current=!1,ve(qe())):S(e)}async function dr(e){if(!_)return;const t=_;try{const r=await w.createPaymentIntent({idempotencyKey:q}),c=await i.current.placedRequest?.send().catch(()=>null);if(c?.orderNumber){await U(c);return}const n=nn(t,c);W(n??{...t,expiresAt:null}),je(e&&n!==null),X.current=r,Oe(r)}catch(r){if(r instanceof Fe&&r.status===409){await U();return}Oe(null),W(null),rn(t,r)}}function pr(){_&&(x.current=!0,S(_),Oe(null),W(null),je(!1))}return{site:o,logo:g,items:a,totals:ar,coupon:K,deliveryOptions:lt,courierUnavailable:Kn,retryCourier:Mn,shippingMethodId:Q,setShippingMethodId:dt,pickupLocation:An,servedCountries:V,formatMoney:vn,payChoice:C,setPayChoice:ge,placing:M,email:I,setEmail:ke,firstName:L,setFirstName:Ce,lastName:H,setLastName:we,company:Pe,setCompany:Ge,address1:ee,setAddress1:te,address2:be,setAddress2:ne,city:F,setCity:re,postcode:T,setPostcode:oe,phone:G,setPhone:se,country:m,setCountry:ce,subdivision:O,setSubdivision:Ne,subdivisions:ae,destination:kt,postcodeLabel:En,subdivisionLabel:Rn,me:ie,savedAddresses:Ln,selectedAddressId:We,setSelectedAddressId:Ae,saveAddress:bt,setSaveAddress:Nt,saveLabel:Je,setSaveLabel:Tn,addressSaveNote:_n,lostChangeNote:xn,idemKey:q,confirmation:Ze,setConfirmation:z,orderError:In,payment:vt,paypalStep:Ot,squareStep:Et,pendingConf:_,paid:$n,setPaid:Ee,unpaidOrder:k,orderLocked:Rt,formLocked:Bn,restoredPrices:Ut,payNote:Un,afterpayConfirming:Hn,gocardlessConfirming:Dn,zipConfirming:Wn,klarnaConfirming:Xn,cardConfirming:Kt,checkoutResult:ue,confirmCardPayment:U,cardStillProcessing:en,renewCardPayment:dr,holdRenewed:Qn,leaveCardPayment:pr,checkoutRootRef:_t,setCheckoutHeaderEl:Vn,fillFromAddress:xt,checkoutSignOut:er,payOptions:J,noPaymentMethod:tr,placeOrder:ir}}const Pn=fr(null);function bo({children:o,...g}){const f=Vr(g);return R(Pn.Provider,{value:f,children:o})}function No(){const o=mr(Pn);if(!o)throw new Error("useCheckout must be used inside CheckoutStateProvider");return o}export{bo as CheckoutStateProvider,Co as NO_PAYMENT_METHOD_NOTE,wo as SHIPPING_RETRY_NOTE,hn as buildPayOptions,gn as paymentNotStartedMessage,Po as placedOrderLockNote,No as useCheckout};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t,jsxs as i,Fragment as x}from"react/jsx-runtime";import P from"../SectionBand.js";import S from"next/link";import{useEffect as M,useMemo as F,useRef as $}from"react";import{appendVehicleParams as E}from"../../lib/wheels/plp-vehicle-params.js";import{linkParts as j}from"../../lib/links/link-rules.js";import{shopHrefForVehicle as L,shouldLeaveForTheShop as z}from"../../lib/wheels/picker-goes-to-the-shop.js";import T from"efficient-web-builder/render/components/SectionHeader";import{withRMark as V}from"efficient-web-builder/render/components/RMark";import k from"./FitmentPickerGrid.js";import _ from"./StockFitmentCard.js";import{useVehicleFit as O}from"./useVehicleFit.js";import{say as R}from"efficient-web-builder/format/lib/editor-words";const f={body:"text-[length:var(--size-body,18px)]",headingSmall:"text-[length:var(--size-headingSmall,30px)]",labelSmall:"text-[length:var(--size-label,12px)]",labelLarge:"text-[length:var(--size-label,14px)]"};function Y(l,n,s){if(!s)return l;const{path:c,query:m,hash:h}=j(l),r=E(new URLSearchParams(m),n).toString();return`${c}${r?`?${r}`:""}${h}`}function q({num:l,title:n,description:s,ctaText:c,ctaHref:m,layout:h="full",omitHead:r=!1,initialMakes:b=[],editing:o=!1}){const{cascade:e}=O({initialMakes:b,editing:o,autoApply:!0}),a=h==="bar",u=$(!1),w=F(()=>{if(!a)return e;const d=y=>(...N)=>{u.current=!0,y(...N)};return{...e,setMake:d(e.setMake),setModel:d(e.setModel),setYear:d(e.setYear),setModification:d(e.setModification)}},[a,e]);M(()=>{a&&(typeof window>"u"||z({shopperPicked:u.current,fullyPicked:e.fullyPicked,editing:o,pathname:window.location.pathname})&&window.location.assign(L(e.vehicle)))},[a,e.fullyPicked,e.vehicle,o]);const v=!r&&!a&&!!(l||n||s),p=!a&&c&&m?{text:c,href:m}:null,g=p?Y(p.href,e.vehicle,e.fullyPicked):null;return i(P,{className:a?r?"pt-0 pb-8 max-view-desktop:pb-5":"py-8 max-view-desktop:py-5":r?"pt-0 pb-20 max-view-desktop:pb-[60px]":"py-20 max-view-desktop:py-[60px]",children:[v&&t(T,{num:l,title:n,description:s,accent:!0}),a?i("div",{className:"flex flex-wrap items-center gap-5",children:[!r&&n?.trim()&&t("p",{className:`font-heading3 ${f.headingSmall} [font-weight:var(--sf-heading-weight-strong,600)] leading-none tracking-[-0.02em] whitespace-nowrap`,children:V(n)}),t("div",{className:"min-w-[320px] flex-1 basis-0",children:t(k,{cascade:w,compact:!0,editing:o})})]}):t(k,{cascade:e,editing:o}),!a&&t(_,{loading:e.loading.stock,error:e.
|
|
1
|
+
"use client";import{jsx as t,jsxs as i,Fragment as x}from"react/jsx-runtime";import P from"../SectionBand.js";import S from"next/link";import{useEffect as M,useMemo as F,useRef as $}from"react";import{appendVehicleParams as E}from"../../lib/wheels/plp-vehicle-params.js";import{linkParts as j}from"../../lib/links/link-rules.js";import{shopHrefForVehicle as L,shouldLeaveForTheShop as z}from"../../lib/wheels/picker-goes-to-the-shop.js";import T from"efficient-web-builder/render/components/SectionHeader";import{withRMark as V}from"efficient-web-builder/render/components/RMark";import k from"./FitmentPickerGrid.js";import _ from"./StockFitmentCard.js";import{useVehicleFit as O}from"./useVehicleFit.js";import{say as R}from"efficient-web-builder/format/lib/editor-words";const f={body:"text-[length:var(--size-body,18px)]",headingSmall:"text-[length:var(--size-headingSmall,30px)]",labelSmall:"text-[length:var(--size-label,12px)]",labelLarge:"text-[length:var(--size-label,14px)]"};function Y(l,n,s){if(!s)return l;const{path:c,query:m,hash:h}=j(l),r=E(new URLSearchParams(m),n).toString();return`${c}${r?`?${r}`:""}${h}`}function q({num:l,title:n,description:s,ctaText:c,ctaHref:m,layout:h="full",omitHead:r=!1,initialMakes:b=[],editing:o=!1}){const{cascade:e}=O({initialMakes:b,editing:o,autoApply:!0}),a=h==="bar",u=$(!1),w=F(()=>{if(!a)return e;const d=y=>(...N)=>{u.current=!0,y(...N)};return{...e,setMake:d(e.setMake),setModel:d(e.setModel),setYear:d(e.setYear),setModification:d(e.setModification)}},[a,e]);M(()=>{a&&(typeof window>"u"||z({shopperPicked:u.current,fullyPicked:e.fullyPicked,editing:o,pathname:window.location.pathname})&&window.location.assign(L(e.vehicle)))},[a,e.fullyPicked,e.vehicle,o]);const v=!r&&!a&&!!(l||n||s),p=!a&&c&&m?{text:c,href:m}:null,g=p?Y(p.href,e.vehicle,e.fullyPicked):null;return i(P,{className:a?r?"pt-0 pb-8 max-view-desktop:pb-5":"py-8 max-view-desktop:py-5":r?"pt-0 pb-20 max-view-desktop:pb-[60px]":"py-20 max-view-desktop:py-[60px]",children:[v&&t(T,{num:l,title:n,description:s,accent:!0}),a?i("div",{className:"flex flex-wrap items-center gap-5",children:[!r&&n?.trim()&&t("p",{className:`font-heading3 ${f.headingSmall} [font-weight:var(--sf-heading-weight-strong,600)] leading-none tracking-[-0.02em] whitespace-nowrap`,children:V(n)}),t("div",{className:"min-w-[320px] flex-1 basis-0",children:t(k,{cascade:w,compact:!0,editing:o})})]}):t(k,{cascade:e,editing:o}),!a&&t(_,{loading:e.loading.stock,error:e.stockError,data:e.fullyPicked?e.stock:null}),!a&&i("div",{className:"mt-10 flex flex-wrap items-center justify-between gap-6 border-t border-line pt-8",children:[t("p",{className:`max-w-[680px] font-serif ${f.body} italic leading-[1.55] text-fg-dim`,children:e.fullyPicked?i(x,{children:["Your car ·"," ",i("strong",{className:"font-display [font-weight:var(--sf-heading-weight-strong,500)] not-italic text-fg",children:[e.vehicle.year," ",e.makeName," ",e.modelName," ",e.modName]}),e.stock&&t("span",{className:"ml-3 not-italic text-accent",children:"OEM fitment loaded."})]}):i(x,{children:["Tell us four things — ",t("em",{className:"not-italic text-accent",children:"make, model, year, trim"})," — and we'll show the OEM stock fitment for your car."]})}),p&&g&&i(S,{href:g,className:`group inline-flex items-center gap-4 border border-btn bg-btn px-8 py-5 font-mono ${f.labelLarge} uppercase tracking-[0.3em] text-btn-ink transition-colors hover:border-fg hover:bg-fg`,children:[p.text,t("span",{className:"transition-transform group-hover:translate-x-[4px]",children:"→"})]})]}),o&&e.makeOptions.length===0&&!e.loading.models&&t("p",{className:`mt-4 font-mono ${f.labelSmall} uppercase tracking-[0.24em] text-fg-dim`,children:R("Vehicle catalog unavailable in this preview — the picker fills from the live fitment API on the published site.")})]})}export{q as default,Y as fitmentCtaHref};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as s,jsxs as p}from"react/jsx-runtime";import{PickerField as
|
|
1
|
+
"use client";import{jsx as s,jsxs as p}from"react/jsx-runtime";import{PickerField as a}from"./PickerField.js";import{vehicleLevelStates as f}from"./vehicle-level-state.js";import{VEHICLE_FIELD_LABEL as t}from"../../lib/wheels/vehicle-field-focus.js";import{HideTaker as g}from"efficient-web-builder/render/components/ViewHideRoot";const b={1:"grid-cols-1",2:"grid-cols-2",3:"grid-cols-3",4:"grid-cols-4"},u={1:"max-view-tablet:grid-cols-1",2:"max-view-tablet:grid-cols-2",3:"max-view-tablet:grid-cols-3",4:"max-view-tablet:grid-cols-4"},c=e=>e===1||e===2||e===3||e===4?e:void 0;function h(e,l,r){const d=c(l),n=c(r);if(d===void 0&&n===void 0)return e?"grid-cols-1 @min-[20rem]:grid-cols-2 @min-[39rem]:grid-cols-4":"grid-cols-4 max-view-desktop:grid-cols-2 max-[700px]:grid-cols-1";const o=d!==void 0?b[d]:e?"grid-cols-1 @min-[20rem]:grid-cols-2 @min-[39rem]:grid-cols-4":"grid-cols-4 max-view-desktop:grid-cols-2";return n!==void 0?`${o} ${u[n]}`:o}function x({cascade:e,compact:l=!1,editing:r=!1,columns:d,columnsPhone:n}){const{vehicle:o}=e,i=f(e),m=p(g,{className:["grid gap-[2px] border border-line bg-line",h(l,d,n)].join(" "),children:[s(a,{label:t.make,placeholder:i.make.placeholder,disabled:i.make.disabled,failed:i.make.failed,value:o.make,options:e.makeOptions,onChange:e.setMake,compact:l,editing:r}),s(a,{label:t.model,placeholder:i.model.placeholder,disabled:i.model.disabled,failed:i.model.failed,value:o.model,options:e.modelOptions,onChange:e.setModel,compact:l,editing:r}),s(a,{label:t.year,placeholder:i.year.placeholder,disabled:i.year.disabled,failed:i.year.failed,value:o.year!==null?String(o.year):"",options:e.yearOptions,onChange:e.setYear,compact:l,editing:r}),s(a,{label:t.trim,placeholder:i.trim.placeholder,disabled:i.trim.disabled,failed:i.trim.failed,value:o.modification,options:e.modOptions,onChange:e.setModification,compact:l,editing:r})]});return l?s(g,{className:"@container",children:m}):m}export{x as default,h as pickerGridColumns};
|
|
@@ -4,13 +4,14 @@ export interface PickerOption {
|
|
|
4
4
|
label: string;
|
|
5
5
|
}
|
|
6
6
|
export declare function pickerItems(options: readonly PickerOption[], placeholder?: string): SelectItem[];
|
|
7
|
-
export declare function PickerField({ label, value, options, onChange, placeholder, disabled, compact, editing, }: {
|
|
7
|
+
export declare function PickerField({ label, value, options, onChange, placeholder, disabled, failed, compact, editing, }: {
|
|
8
8
|
label: string;
|
|
9
9
|
value: string;
|
|
10
10
|
options: PickerOption[];
|
|
11
11
|
onChange: (v: string) => void;
|
|
12
12
|
placeholder?: string;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
+
failed?: boolean;
|
|
14
15
|
compact?: boolean;
|
|
15
16
|
editing?: boolean;
|
|
16
17
|
}): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a,jsxs as
|
|
1
|
+
"use client";import{jsx as a,jsxs as g}from"react/jsx-runtime";import u from"efficient-web-builder/render/components/PartStyledKind";import{ThemedSelectList as I,useThemedSelect as T}from"../ThemedSelect.js";import{PART_KIND_ATTR as b}from"efficient-web-builder/render/lib/document/text-parts";import{TEXT_KIND_BODY as h,TEXT_KIND_NAME as v}from"efficient-web-builder/format/lib/sections/section-text-kinds";const n={body:"text-[length:var(--size-body,15px)]",headingSmall:"text-[length:var(--size-headingSmall,24px)]",labelXs:"text-[length:var(--size-label,10px)]",labelSmall:"text-[length:var(--size-label,11px)]",labelLarge:"text-[length:var(--size-label,12px)]",labelXl:"text-[length:var(--size-label,14px)]"};function k(o,t){return[{value:"",label:t??"—"},...o.map(i=>({value:i.value,label:i.label}))]}function z({label:o,value:t,options:i,onChange:y,placeholder:d,disabled:l,failed:x=!1,compact:s=!1,editing:m=!1}){const c=(i.find(r=>r.value===t)?.label??t)||d||"—",f=k(i,d),e=T({items:f,value:t,onPick:y}),p=e.open;return g("div",{ref:e.wrapRef,className:"relative min-w-0",children:[g("div",{ref:r=>{e.triggerRef.current=r},role:"button",tabIndex:l?-1:0,"aria-haspopup":"listbox","aria-expanded":p,"aria-controls":p?e.listId:void 0,"aria-activedescendant":e.activeId,"aria-label":`${o}, ${c}`,"aria-disabled":l||void 0,onClick:()=>!l&&e.toggle(),onKeyDown:r=>!l&&e.onTriggerKeyDown(r),className:["relative flex h-full flex-col bg-bg transition-colors",s?"gap-1 px-3 py-3":"min-h-[160px] gap-4 px-6 py-8",x?"":l?"opacity-50":"cursor-pointer hover:bg-surface"].join(" "),children:[a("span",{...m?{[b]:v}:{},className:["font-mono uppercase text-accent",s?`${n.labelXs} tracking-[0.2em]`:`${n.labelLarge} tracking-[0.3em]`].join(" "),children:a(u,{kind:v,children:o})}),a("span",{title:c,className:["truncate font-display font-medium tracking-[-0.02em]",s?`${n.body} leading-[1.2]`:`mt-auto ${n.headingSmall} leading-[1.1]`,t?"text-fg":x?"text-alert":"text-fg-dim"].join(" "),...m?{[b]:h}:{},children:a(u,{kind:h,children:c})}),a("span",{className:["pointer-events-none absolute font-mono text-accent",s?`right-3 top-3 ${n.labelSmall}`:`right-[22px] top-[22px] ${n.labelXl}`].join(" "),children:"▾"})]}),p&&!l&&a(I,{id:e.listId,tone:"cell",items:f,value:t,focusIdx:e.focusIdx,onFocus:e.setFocusIdx,onPick:e.pick,listRef:e.listRef})]})}export{z as PickerField,k as pickerItems};
|
|
@@ -20,6 +20,8 @@ export interface FitmentCascade {
|
|
|
20
20
|
yearOptions: PickerOption[];
|
|
21
21
|
modOptions: PickerOption[];
|
|
22
22
|
loading: CascadeLoading;
|
|
23
|
+
failed: CascadeFailed;
|
|
24
|
+
stockError: string | null;
|
|
23
25
|
cascadeError: string | null;
|
|
24
26
|
stock: StockFitment | null;
|
|
25
27
|
fullyPicked: boolean;
|
|
@@ -27,5 +29,11 @@ export interface FitmentCascade {
|
|
|
27
29
|
modelName: string;
|
|
28
30
|
modName: string;
|
|
29
31
|
}
|
|
32
|
+
export interface CascadeFailed {
|
|
33
|
+
makes?: boolean;
|
|
34
|
+
models?: boolean;
|
|
35
|
+
years?: boolean;
|
|
36
|
+
modifications?: boolean;
|
|
37
|
+
}
|
|
30
38
|
export declare function useFitmentCascade(initialMakes?: FitmentMake[], enabled?: boolean): FitmentCascade;
|
|
31
39
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as
|
|
1
|
+
import{useCallback as u,useEffect as r,useMemo as k,useState as o}from"react";import{fitment as f}from"../../lib/api/index.js";import{DEFAULT_VEHICLE as Q}from"../../lib/wheels/fitment-options.js";function R(i){return i instanceof Error?i.message:String(i)}function ee(i=[],y=!0){const[t,m]=o(Q),[g,L]=o(i),[h,p]=o([]),[S,M]=o([]),[c,E]=o([]),[N,T]=o(null),[O,l]=o({makes:y&&i.length===0}),[d,Y]=o({}),[b,F]=o(null),n=(e,a)=>Y(s=>!!s[e]===a?s:{...s,[e]:a}),[v,C]=o(0),[V,x]=o(0),[A,D]=o(0);r(()=>{y&&i.length===0&&(l(e=>({...e,makes:!0})),f.listMakes().then(e=>{L(e),n("makes",!1)}).catch(()=>n("makes",!0)).finally(()=>l(e=>({...e,makes:!1}))))},[y,i.length]),r(()=>{if(n("models",!1),!t.make){p([]);return}let e=!1;return l(a=>({...a,models:!0})),f.listModels(t.make).then(a=>{e||p(a)}).catch(()=>{e||(p([]),n("models",!0))}).finally(()=>{e||l(a=>({...a,models:!1}))}),()=>{e=!0}},[t.make,v]),r(()=>{if(n("years",!1),!t.make||!t.model){M([]);return}let e=!1;return l(a=>({...a,years:!0})),f.listYears(t.make,t.model).then(a=>{e||M(a)}).catch(()=>{e||(M([]),n("years",!0))}).finally(()=>{e||l(a=>({...a,years:!1}))}),()=>{e=!0}},[t.make,t.model,V]),r(()=>{if(n("modifications",!1),!t.make||!t.model||t.year===null){E([]);return}let e=!1;return l(a=>({...a,modifications:!0})),f.listModifications(t.make,t.model,t.year).then(a=>{e||E(a)}).catch(()=>{e||(E([]),n("modifications",!0))}).finally(()=>{e||l(a=>({...a,modifications:!1}))}),()=>{e=!0}},[t.make,t.model,t.year,A]),r(()=>{const e=t.year!==null&&t.make&&t.model&&t.modification;if(F(null),!e){T(null);return}let a=!1;return l(s=>({...s,stock:!0})),f.getStockFitment(t.make,t.model,t.year,t.modification).then(s=>{a||T(s)}).catch(s=>{a||F(R(s))}).finally(()=>{a||l(s=>({...s,stock:!1}))}),()=>{a=!0}},[t.make,t.model,t.year,t.modification]),r(()=>{t.year!==null&&t.make&&t.model&&!t.modification&&c.length===1&&m(e=>({...e,modification:c[0].slug}))},[t.year,t.make,t.model,t.modification,c]);const H=u(e=>{m(a=>({...a,make:e,model:"",year:null,modification:""})),C(a=>a+1)},[]),I=u(e=>{m(a=>({...a,model:e,year:null,modification:""})),x(a=>a+1)},[]),P=u(e=>{m(a=>({...a,year:e?Number(e):null,modification:""})),D(a=>a+1)},[]),U=u(e=>m(a=>({...a,modification:e})),[]),_=k(()=>S.map(e=>({value:String(e),label:String(e)})),[S]),j=k(()=>g.map(e=>({value:e.slug,label:e.name})),[g]),q=k(()=>h.map(e=>({value:e.slug,label:e.name})),[h]),w=k(()=>c.map(e=>({value:e.slug,label:e.name})),[c]),z=t.year!==null&&!!t.make&&!!t.model&&!!t.modification,B=g.find(e=>e.slug===t.make)?.name??t.make,G=h.find(e=>e.slug===t.model)?.name??t.model,J=c.find(e=>e.slug===t.modification)?.name??t.modification,K=!!(d.makes||d.models||d.years||d.modifications);return{vehicle:t,setVehicle:m,setMake:H,setModel:I,setYear:P,setModification:U,makeOptions:j,modelOptions:q,yearOptions:_,modOptions:w,loading:O,failed:d,stockError:b,cascadeError:b??(K?"Vehicle data could not be loaded":null),stock:N,fullyPicked:z,makeName:B,modelName:G,modName:J}}export{ee as useFitmentCascade};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useCallback as
|
|
1
|
+
"use client";import{useCallback as d,useEffect as h,useMemo as x,useRef as F,useState as S}from"react";import{useFitmentCascade as M}from"./useFitmentCascade.js";import{DEFAULT_VEHICLE as L}from"../../lib/wheels/fitment-options.js";import{vehicleFitmentFromStock as P}from"../../lib/wheels/plp-fitment-match.js";import{clearAppliedVehicle as j}from"../../lib/wheels/applied-vehicle.js";import{isCompleteVehicle as p,vehicleFromParams as B}from"../../lib/wheels/plp-vehicle-params.js";import{storefrontVehicleMemory as a}from"../../lib/wheels/vehicle-memory.js";function b(t,i,r){return t!==i?t:r||i}function D(t,i){return t.make===i.make&&t.model===i.model&&t.modification===i.modification}function m(t,i){return t.make===i.make&&t.model===i.model&&t.year===i.year&&t.modification===i.modification}function z({initialMakes:t=[],editing:i=!1,enabled:r=!0,autoApply:N=!1,shareStock:y=!1}={}){const e=M(t,r),{setVehicle:n}=e,[l,f]=S(null),[C,w]=S(!1),k=d(()=>({make:e.makeName,model:e.modelName,modification:e.modName}),[e.makeName,e.modelName,e.modName]);h(()=>{if(i||!r){w(!0);return}const o=B(new URLSearchParams(window.location.search)),s=o?null:a.read(),c=o??s?.vehicle??null;c&&(n(c),f({vehicle:c,labels:s?.labels??{make:c.make,model:c.model,modification:c.modification},stock:null})),w(!0)},[i,r,n]),h(()=>{if(!(i||!r))return a.subscribe(()=>{const o=a.read();f(c=>o?c&&m(c.vehicle,o.vehicle)?D(c.labels,o.labels)?c:{...c,labels:o.labels}:{vehicle:o.vehicle,labels:o.labels,stock:null}:null);const s=o?.vehicle??L;n(c=>m(c,s)?c:s)})},[i,r,n]),h(()=>{!N||!p(e.vehicle)||l&&m(l.vehicle,e.vehicle)||f({vehicle:e.vehicle,labels:k(),stock:e.stock})},[N,l,e.vehicle,e.stock,k]),h(()=>{if(!l||!m(e.vehicle,l.vehicle))return;const o={make:b(e.makeName,e.vehicle.make,l.labels.make),model:b(e.modelName,e.vehicle.model,l.labels.model),modification:b(e.modName,e.vehicle.modification,l.labels.modification)};(l.stock!==e.stock||l.labels.make!==o.make||l.labels.model!==o.model||l.labels.modification!==o.modification)&&f(c=>c&&m(e.vehicle,c.vehicle)?{...c,stock:e.stock,labels:o}:c)},[l,e.vehicle,e.stock,e.makeName,e.modelName,e.modName]);const u=F("");h(()=>{if(!(i||!r))try{if(!l){u.current!==""&&(a.clear(),u.current="");return}const o=JSON.stringify({vehicle:l.vehicle,labels:l.labels});if(o===u.current)return;a.write({vehicle:l.vehicle,labels:l.labels}),u.current=o}catch{}},[l,i,r]);const v=F(!1);h(()=>{if(!y||!r)return;if(!l){v.current&&a.writeStock(null),v.current=!1;return}if(!m(e.vehicle,l.vehicle))return;const o=e.loading.stock!==!1,s=a.readStock();s&&m(s.vehicle,l.vehicle)&&s.stock===e.stock&&s.loading===o&&s.error===e.stockError||(a.writeStock({vehicle:l.vehicle,stock:e.stock,loading:o,error:e.stockError}),v.current=!0)},[y,r,l,e.vehicle,e.stock,e.loading.stock,e.stockError]);const A=d(()=>{p(e.vehicle)&&f({vehicle:e.vehicle,labels:k(),stock:e.stock})},[e.vehicle,e.stock,k]),R=d(()=>{f(null),n(L),!i&&r&&j()},[i,r,n]),E=x(()=>P(l?.stock),[l?.stock]),V=!!l&&m(e.vehicle,l.vehicle)&&e.loading.stock!==!1,U=l?[l.vehicle.year,l.labels.make,l.labels.model,l.labels.modification].filter(Boolean).join(" "):"";return{cascade:e,applied:l,fit:E,resolving:V,unresolved:!!l&&E===null&&!V,apply:A,clear:R,canApply:p(e.vehicle),appliedName:U,restored:C}}export{z as useVehicleFit};
|
|
@@ -4,6 +4,7 @@ import { VEHICLE_FIELD_ORDER, type VehicleField } from "../../lib/wheels/vehicle
|
|
|
4
4
|
export interface VehicleLevelState {
|
|
5
5
|
placeholder: string;
|
|
6
6
|
disabled: boolean;
|
|
7
|
+
failed?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const VEHICLE_FIELD_NEEDED: Record<VehicleField, string>;
|
|
9
10
|
export declare function vehicleLevelStates(cascade: FitmentCascade): Record<VehicleField, VehicleLevelState>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{VEHICLE_FIELD_ORDER as
|
|
1
|
+
import{VEHICLE_FIELD_ORDER as p}from"../../lib/wheels/vehicle-field-focus.js";const o={make:"Pick a make first",model:"Pick a model first",year:"Pick a year first",trim:"Pick a trim first"};function a({parentPicked:e,loading:i,failed:l,options:t,waiting:r,loadingLabel:n,readyLabel:d,emptyLabel:m,failedLabel:s}){return e?i?{placeholder:n,disabled:!0}:l?{placeholder:s,disabled:!0,failed:!0}:t.length===0?{placeholder:m,disabled:!0}:{placeholder:d,disabled:!1}:{placeholder:r,disabled:!0}}function u(e){const{vehicle:i,loading:l,failed:t}=e;return{make:a({parentPicked:!0,loading:l.makes,failed:t.makes,failedLabel:"Couldn't load makes",options:e.makeOptions,waiting:"",loadingLabel:"Loading makes…",readyLabel:"Select make",emptyLabel:"Vehicle list unavailable"}),model:a({parentPicked:!!i.make,loading:l.models,failed:t.models,failedLabel:"Couldn't load models",options:e.modelOptions,waiting:o.make,loadingLabel:"Loading models…",readyLabel:"Select model",emptyLabel:"No models listed"}),year:a({parentPicked:!!i.model,loading:l.years,failed:t.years,failedLabel:"Couldn't load years",options:e.yearOptions,waiting:o.model,loadingLabel:"Loading years…",readyLabel:"Select year",emptyLabel:"No years listed"}),trim:a({parentPicked:i.year!==null,loading:l.modifications,failed:t.modifications,failedLabel:"Couldn't load trims",options:e.modOptions,waiting:o.year,loadingLabel:"Loading trims…",readyLabel:"Select trim",emptyLabel:"No trims listed"})}}function y(e){return{make:e.makeOptions,model:e.modelOptions,year:e.yearOptions,trim:e.modOptions}}function L(e){return{make:e.setMake,model:e.setModel,year:e.setYear,trim:e.setModification}}function k(e){const{vehicle:i}=e;return{make:i.make,model:i.model,year:i.year!==null?String(i.year):"",trim:i.modification}}function b(e){const{vehicle:i}=e;return{make:i.make?e.makeName:"",model:i.model?e.modelName:"",year:i.year!==null?String(i.year):"",trim:i.modification?e.modName:""}}export{o as VEHICLE_FIELD_NEEDED,p as VEHICLE_FIELD_ORDER,b as vehicleLevelNames,y as vehicleLevelOptions,L as vehicleLevelSetters,u as vehicleLevelStates,k as vehicleLevelValues};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SourceRow } from "efficient-web-builder/format/lib/content/block-sources";
|
|
2
|
+
import type { SlotComponent } from "efficient-easel/blocks";
|
|
2
3
|
export declare const supportedKinds: readonly ("alloy-wheel" | "tyre")[];
|
|
3
4
|
export interface DynamicGalleryGridProps {
|
|
4
5
|
num?: string;
|
|
@@ -14,6 +15,8 @@ export interface DynamicGalleryGridProps {
|
|
|
14
15
|
displayPhone?: unknown;
|
|
15
16
|
styleOwner?: string;
|
|
16
17
|
editing?: boolean;
|
|
18
|
+
template?: SlotComponent;
|
|
19
|
+
nodeId?: string;
|
|
17
20
|
omitHead?: boolean;
|
|
18
21
|
pads?: Record<string, unknown>;
|
|
19
22
|
}
|