@hszrdm/create-commerce 1.1.0 → 1.2.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/package.json +1 -1
- package/src/cli.mjs +5 -2
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +41 -9
- package/templates/storefront/src/app/account/page.tsx +12 -1
- package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
- package/templates/storefront/src/app/core-ux.css +244 -0
- package/templates/storefront/src/app/layout.tsx +31 -12
- package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
- package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
- package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
- package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
- package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
- package/templates/storefront/src/components/account-wishlist.tsx +95 -0
- package/templates/storefront/src/components/add-to-cart.tsx +110 -15
- package/templates/storefront/src/components/back-to-top.tsx +26 -0
- package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
- package/templates/storefront/src/components/cart-view.tsx +72 -16
- package/templates/storefront/src/components/form-ux.tsx +47 -0
- package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
- package/templates/storefront/src/components/newsletter-action.tsx +66 -0
- package/templates/storefront/src/components/product-gallery.tsx +64 -0
- package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
- package/templates/storefront/src/components/share-button.tsx +63 -0
- package/templates/storefront/src/components/storefront-header.tsx +72 -18
- package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
- package/templates/storefront/src/components/toast-provider.tsx +92 -0
- package/templates/storefront/src/components/variant-price-display.tsx +31 -0
- package/templates/storefront/src/components/wishlist-button.tsx +88 -0
- package/templates/storefront/src/lib/core/account.ts +3 -0
- package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
- package/templates/storefront/src/lib/core/cms.ts +66 -7
- package/templates/storefront/src/lib/core/form-ux.ts +57 -0
- package/templates/storefront/src/lib/core/newsletter.ts +53 -0
- package/templates/storefront/src/lib/core/reviews.ts +40 -0
- package/templates/storefront/src/lib/core/share.ts +57 -0
- package/templates/storefront/src/lib/core/wishlist.ts +88 -0
- package/templates/storefront/src/lib/storefront-routes.ts +3 -0
- package/templates/storefront/src/proxy.ts +3 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, type ReactNode } from "react"
|
|
4
|
+
|
|
5
|
+
const FOCUSABLE = [
|
|
6
|
+
"a[href]",
|
|
7
|
+
"button:not([disabled])",
|
|
8
|
+
"input:not([disabled])",
|
|
9
|
+
"select:not([disabled])",
|
|
10
|
+
"textarea:not([disabled])",
|
|
11
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
12
|
+
].join(",")
|
|
13
|
+
|
|
14
|
+
export function AccessibleDialog({
|
|
15
|
+
open,
|
|
16
|
+
onClose,
|
|
17
|
+
labelledBy,
|
|
18
|
+
children,
|
|
19
|
+
className = "drawer",
|
|
20
|
+
}: {
|
|
21
|
+
open: boolean
|
|
22
|
+
onClose: () => void
|
|
23
|
+
labelledBy: string
|
|
24
|
+
children: ReactNode
|
|
25
|
+
className?: string
|
|
26
|
+
}) {
|
|
27
|
+
const ref = useRef<HTMLElement>(null)
|
|
28
|
+
const previousFocus = useRef<HTMLElement | null>(null)
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!open) return
|
|
32
|
+
previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
|
33
|
+
const dialog = ref.current
|
|
34
|
+
const first = dialog?.querySelector<HTMLElement>(FOCUSABLE)
|
|
35
|
+
window.setTimeout(() => first?.focus(), 0)
|
|
36
|
+
|
|
37
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
38
|
+
if (event.key === "Escape") {
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
onClose()
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (event.key !== "Tab" || !dialog) return
|
|
44
|
+
const focusable = Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((element) => !element.hasAttribute("hidden"))
|
|
45
|
+
if (!focusable.length) {
|
|
46
|
+
event.preventDefault()
|
|
47
|
+
dialog.focus()
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const firstElement = focusable[0]
|
|
51
|
+
const lastElement = focusable[focusable.length - 1]
|
|
52
|
+
if (event.shiftKey && document.activeElement === firstElement) {
|
|
53
|
+
event.preventDefault()
|
|
54
|
+
lastElement.focus()
|
|
55
|
+
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
firstElement.focus()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.addEventListener("keydown", onKeyDown)
|
|
62
|
+
const originalOverflow = document.body.style.overflow
|
|
63
|
+
document.body.style.overflow = "hidden"
|
|
64
|
+
return () => {
|
|
65
|
+
document.removeEventListener("keydown", onKeyDown)
|
|
66
|
+
document.body.style.overflow = originalOverflow
|
|
67
|
+
previousFocus.current?.focus()
|
|
68
|
+
}
|
|
69
|
+
}, [onClose, open])
|
|
70
|
+
|
|
71
|
+
if (!open) return null
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div className="drawer-backdrop" role="presentation" onMouseDown={onClose}>
|
|
75
|
+
<aside
|
|
76
|
+
ref={ref}
|
|
77
|
+
className={className}
|
|
78
|
+
role="dialog"
|
|
79
|
+
aria-modal="true"
|
|
80
|
+
aria-labelledby={labelledBy}
|
|
81
|
+
tabIndex={-1}
|
|
82
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</aside>
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from "react"
|
|
11
|
+
|
|
12
|
+
const ITEM_SELECTOR = "a[href], button:not([disabled]), [role='menuitem']:not([aria-disabled='true'])"
|
|
13
|
+
|
|
14
|
+
export function AccessibleDropdown({
|
|
15
|
+
label,
|
|
16
|
+
children,
|
|
17
|
+
}: {
|
|
18
|
+
label: ReactNode
|
|
19
|
+
children: ReactNode
|
|
20
|
+
}) {
|
|
21
|
+
const id = useId()
|
|
22
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
23
|
+
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
24
|
+
const [open, setOpen] = useState(false)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!open) return
|
|
28
|
+
const onPointerDown = (event: MouseEvent) => {
|
|
29
|
+
if (!rootRef.current?.contains(event.target as Node)) setOpen(false)
|
|
30
|
+
}
|
|
31
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
32
|
+
if (event.key === "Escape") {
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
setOpen(false)
|
|
35
|
+
triggerRef.current?.focus()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
document.addEventListener("mousedown", onPointerDown)
|
|
39
|
+
document.addEventListener("keydown", onKeyDown)
|
|
40
|
+
return () => {
|
|
41
|
+
document.removeEventListener("mousedown", onPointerDown)
|
|
42
|
+
document.removeEventListener("keydown", onKeyDown)
|
|
43
|
+
}
|
|
44
|
+
}, [open])
|
|
45
|
+
|
|
46
|
+
const focusItem = (position: "first" | "last") => {
|
|
47
|
+
const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
|
|
48
|
+
const item = position === "first" ? items[0] : items[items.length - 1]
|
|
49
|
+
item?.focus()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const navigate = (event: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
53
|
+
const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
|
|
54
|
+
if (!items.length) return
|
|
55
|
+
const index = items.indexOf(document.activeElement as HTMLElement)
|
|
56
|
+
if (event.key === "ArrowDown") {
|
|
57
|
+
event.preventDefault()
|
|
58
|
+
items[(index + 1 + items.length) % items.length]?.focus()
|
|
59
|
+
} else if (event.key === "ArrowUp") {
|
|
60
|
+
event.preventDefault()
|
|
61
|
+
items[(index - 1 + items.length) % items.length]?.focus()
|
|
62
|
+
} else if (event.key === "Home") {
|
|
63
|
+
event.preventDefault()
|
|
64
|
+
items[0]?.focus()
|
|
65
|
+
} else if (event.key === "End") {
|
|
66
|
+
event.preventDefault()
|
|
67
|
+
items[items.length - 1]?.focus()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className="accessible-dropdown" ref={rootRef} onKeyDown={navigate}>
|
|
73
|
+
<button
|
|
74
|
+
ref={triggerRef}
|
|
75
|
+
type="button"
|
|
76
|
+
className="accessible-dropdown-trigger"
|
|
77
|
+
aria-haspopup="menu"
|
|
78
|
+
aria-expanded={open}
|
|
79
|
+
aria-controls={id}
|
|
80
|
+
onClick={() => setOpen((current) => !current)}
|
|
81
|
+
onKeyDown={(event) => {
|
|
82
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
83
|
+
event.preventDefault()
|
|
84
|
+
setOpen(true)
|
|
85
|
+
requestAnimationFrame(() => focusItem(event.key === "ArrowDown" ? "first" : "last"))
|
|
86
|
+
}
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{label}
|
|
90
|
+
</button>
|
|
91
|
+
{open ? (
|
|
92
|
+
<div id={id} className="accessible-dropdown-menu" role="menu">
|
|
93
|
+
{children}
|
|
94
|
+
</div>
|
|
95
|
+
) : null}
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
5
|
+
import { useCallback, useEffect, useState } from "react"
|
|
6
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
7
|
+
import {
|
|
8
|
+
listWishlist,
|
|
9
|
+
removeWishlistProduct,
|
|
10
|
+
type WishlistItem,
|
|
11
|
+
} from "@/lib/core/wishlist"
|
|
12
|
+
import { localeFromPathname, productPath, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
13
|
+
|
|
14
|
+
export function AccountWishlist() {
|
|
15
|
+
const pathname = usePathname()
|
|
16
|
+
const locale = localeFromPathname(pathname)
|
|
17
|
+
const english = locale === "en"
|
|
18
|
+
const [items, setItems] = useState<WishlistItem[]>([])
|
|
19
|
+
const [loading, setLoading] = useState(true)
|
|
20
|
+
const [error, setError] = useState<string | null>(null)
|
|
21
|
+
const [busy, setBusy] = useState<string | null>(null)
|
|
22
|
+
|
|
23
|
+
const load = useCallback(async () => {
|
|
24
|
+
setLoading(true)
|
|
25
|
+
setError(null)
|
|
26
|
+
try {
|
|
27
|
+
const result = await listWishlist()
|
|
28
|
+
setItems(result.items)
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
if (cause instanceof CoreApiError && cause.status === 401) {
|
|
31
|
+
setError(english ? "Sign in to view your wishlist." : "A kedvencek megtekintéséhez jelentkezz be.")
|
|
32
|
+
} else {
|
|
33
|
+
setError(cause instanceof Error ? cause.message : (english ? "Wishlist could not be loaded." : "A kedvencek nem tölthetők be."))
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
setLoading(false)
|
|
37
|
+
}
|
|
38
|
+
}, [english])
|
|
39
|
+
|
|
40
|
+
useEffect(() => { void load() }, [load])
|
|
41
|
+
|
|
42
|
+
const remove = async (productId: string) => {
|
|
43
|
+
setBusy(productId)
|
|
44
|
+
try {
|
|
45
|
+
await removeWishlistProduct(productId)
|
|
46
|
+
setItems((current) => current.filter((item) => item.product_id !== productId))
|
|
47
|
+
} finally {
|
|
48
|
+
setBusy(null)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (loading) return <section className="panel"><p>{english ? "Loading wishlist…" : "Kedvencek betöltése…"}</p></section>
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<section className="panel stack">
|
|
56
|
+
<div>
|
|
57
|
+
<p className="eyebrow">{english ? "Customer account" : "Ügyfélfiók"}</p>
|
|
58
|
+
<h1>{english ? "Wishlist" : "Kedvencek"}</h1>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
{error ? (
|
|
62
|
+
<div className="empty-state stack-sm">
|
|
63
|
+
<p>{error}</p>
|
|
64
|
+
<Link className="button" href={STOREFRONT_ROUTES[locale].account}>{english ? "Go to account" : "Tovább a fiókhoz"}</Link>
|
|
65
|
+
</div>
|
|
66
|
+
) : null}
|
|
67
|
+
|
|
68
|
+
{!error && !items.length ? <div className="empty-state">{english ? "Your wishlist is empty." : "Még nincs mentett kedvenced."}</div> : null}
|
|
69
|
+
|
|
70
|
+
{!error && items.length ? (
|
|
71
|
+
<div className="product-grid">
|
|
72
|
+
{items.map((item) => {
|
|
73
|
+
const product = item.product
|
|
74
|
+
const handle = product?.handle || ""
|
|
75
|
+
return (
|
|
76
|
+
<article className="panel stack-sm" key={item.id}>
|
|
77
|
+
{product?.thumbnail ? <img src={product.thumbnail} alt={product.title || ""} className="product-card-image" /> : null}
|
|
78
|
+
<div>
|
|
79
|
+
<strong>{product?.title || item.product_id}</strong>
|
|
80
|
+
<p className="muted small">{english ? "Saved product" : "Mentett termék"}</p>
|
|
81
|
+
</div>
|
|
82
|
+
<div className="button-row">
|
|
83
|
+
{handle ? <Link className="button secondary" href={productPath(locale, handle)}>{english ? "View" : "Megnézem"}</Link> : null}
|
|
84
|
+
<button className="button secondary" type="button" disabled={busy === item.product_id} onClick={() => void remove(item.product_id)}>
|
|
85
|
+
{busy === item.product_id ? (english ? "Removing…" : "Törlés…") : (english ? "Remove" : "Törlés")}
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
</article>
|
|
89
|
+
)
|
|
90
|
+
})}
|
|
91
|
+
</div>
|
|
92
|
+
) : null}
|
|
93
|
+
</section>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMemo, useState } from "react"
|
|
4
4
|
import { usePathname } from "next/navigation"
|
|
5
|
+
import { QuantityStepper } from "./quantity-stepper"
|
|
6
|
+
import { useToast } from "./toast-provider"
|
|
5
7
|
import { useCart } from "./cart-provider"
|
|
6
8
|
import {
|
|
7
9
|
asRecords,
|
|
8
10
|
formatMoney,
|
|
11
|
+
numberValue,
|
|
9
12
|
productVariantCurrency,
|
|
10
13
|
productVariantPrice,
|
|
11
14
|
stringValue,
|
|
12
15
|
} from "@/lib/core/commerce"
|
|
16
|
+
import { humanizeStorefrontError } from "@/lib/core/form-ux"
|
|
17
|
+
import { copyText } from "@/lib/core/share"
|
|
13
18
|
import type { CoreConfig } from "@/lib/core/types"
|
|
14
19
|
import { localeFromPathname } from "@/lib/storefront-routes"
|
|
15
20
|
|
|
@@ -18,18 +23,30 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
18
23
|
const locale = localeFromPathname(pathname)
|
|
19
24
|
const en = locale === "en"
|
|
20
25
|
const variants = useMemo(() => asRecords(product.variants), [product])
|
|
26
|
+
const productMetadata = isRecord(product.metadata) ? product.metadata : {}
|
|
21
27
|
const [variantId, setVariantId] = useState(() => stringValue(variants[0]?.id))
|
|
22
|
-
const [quantity, setQuantity] = useState(
|
|
28
|
+
const [quantity, setQuantity] = useState(() => variantMinimum(variants[0], productMetadata))
|
|
23
29
|
const [message, setMessage] = useState<string | null>(null)
|
|
24
30
|
const [success, setSuccess] = useState(false)
|
|
25
31
|
const { addItem, mutating } = useCart()
|
|
32
|
+
const { showToast } = useToast()
|
|
26
33
|
const selected = variants.find((variant) => stringValue(variant.id) === variantId) || variants[0]
|
|
27
34
|
const price = productVariantPrice(selected)
|
|
28
35
|
const currency = productVariantCurrency(selected, config.store.default_currency)
|
|
29
36
|
const formatLocale = en ? "en-US" : "hu-HU"
|
|
37
|
+
const minQuantity = variantMinimum(selected, productMetadata)
|
|
38
|
+
const inventory = Number(selected?.inventory_quantity)
|
|
39
|
+
const managesInventory = selected?.manage_inventory === true
|
|
40
|
+
const allowBackorder = selected?.allow_backorder === true
|
|
41
|
+
const hasKnownInventory = Number.isFinite(inventory)
|
|
42
|
+
const purchasable = !managesInventory || allowBackorder || !hasKnownInventory || inventory >= minQuantity
|
|
43
|
+
const maxQuantity = managesInventory && !allowBackorder && hasKnownInventory
|
|
44
|
+
? Math.max(1, Math.trunc(inventory))
|
|
45
|
+
: 999
|
|
46
|
+
const sku = stringValue(selected?.sku)
|
|
30
47
|
|
|
31
48
|
if (!variants.length) {
|
|
32
|
-
return <div className="notice warning">{en ? "This product has no purchasable variant." : "Ehhez a termékhez nincs megvásárolható variáns."}</div>
|
|
49
|
+
return <div className="notice warning" role="status">{en ? "This product has no purchasable variant." : "Ehhez a termékhez nincs megvásárolható variáns."}</div>
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
return (
|
|
@@ -37,7 +54,28 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
37
54
|
{variants.length > 1 ? (
|
|
38
55
|
<label>
|
|
39
56
|
{en ? "Variant" : "Változat"}
|
|
40
|
-
<select
|
|
57
|
+
<select
|
|
58
|
+
value={variantId}
|
|
59
|
+
onChange={(event) => {
|
|
60
|
+
const nextId = event.target.value
|
|
61
|
+
const next = variants.find((variant) => stringValue(variant.id) === nextId)
|
|
62
|
+
const nextPrice = productVariantPrice(next)
|
|
63
|
+
const nextCurrency = productVariantCurrency(next, config.store.default_currency)
|
|
64
|
+
setVariantId(nextId)
|
|
65
|
+
setQuantity(variantMinimum(next, productMetadata))
|
|
66
|
+
setMessage(null)
|
|
67
|
+
if (typeof window !== "undefined") {
|
|
68
|
+
window.dispatchEvent(new CustomEvent("hszrdm:product-variant-change", {
|
|
69
|
+
detail: {
|
|
70
|
+
variantId: nextId,
|
|
71
|
+
imageUrl: variantImageUrl(next),
|
|
72
|
+
price: nextPrice,
|
|
73
|
+
currency: nextCurrency,
|
|
74
|
+
},
|
|
75
|
+
}))
|
|
76
|
+
}
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
41
79
|
{variants.map((variant) => (
|
|
42
80
|
<option key={stringValue(variant.id)} value={stringValue(variant.id)}>
|
|
43
81
|
{stringValue(variant.title || variant.sku || variant.id)}
|
|
@@ -49,37 +87,94 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
49
87
|
</select>
|
|
50
88
|
</label>
|
|
51
89
|
) : null}
|
|
90
|
+
|
|
52
91
|
<div className="buy-row">
|
|
53
|
-
<
|
|
54
|
-
{en ? "Quantity" : "Mennyiség"}
|
|
55
|
-
<
|
|
56
|
-
|
|
92
|
+
<div className="quantity-field">
|
|
93
|
+
<span className="field-label">{en ? "Quantity" : "Mennyiség"}</span>
|
|
94
|
+
<QuantityStepper
|
|
95
|
+
value={Math.max(minQuantity, quantity)}
|
|
96
|
+
min={minQuantity}
|
|
97
|
+
max={Math.max(minQuantity, maxQuantity)}
|
|
98
|
+
disabled={mutating || !purchasable}
|
|
99
|
+
label={en ? "Quantity" : "Mennyiség"}
|
|
100
|
+
decreaseLabel={en ? "Decrease quantity" : "Mennyiség csökkentése"}
|
|
101
|
+
increaseLabel={en ? "Increase quantity" : "Mennyiség növelése"}
|
|
102
|
+
onChange={setQuantity}
|
|
103
|
+
/>
|
|
104
|
+
{minQuantity > 1 ? <span className="field-hint">{en ? `Minimum order: ${minQuantity}` : `Minimum rendelés: ${minQuantity} db`}</span> : null}
|
|
105
|
+
</div>
|
|
57
106
|
<div className="buy-price">
|
|
58
|
-
<span className="muted">{en ? "
|
|
107
|
+
<span className="muted">{en ? "Selected price" : "Kiválasztott ár"}</span>
|
|
59
108
|
<strong>{Number.isFinite(price) ? formatMoney(price, currency, formatLocale) : "—"}</strong>
|
|
60
109
|
</div>
|
|
61
110
|
</div>
|
|
111
|
+
|
|
112
|
+
<div className={`stock-status ${purchasable ? "is-available" : "is-unavailable"}`} role="status">
|
|
113
|
+
{purchasable
|
|
114
|
+
? hasKnownInventory && managesInventory
|
|
115
|
+
? (en ? `${Math.max(0, Math.trunc(inventory))} in stock` : `${Math.max(0, Math.trunc(inventory))} db készleten`)
|
|
116
|
+
: (en ? "Available to order" : "Rendelhető")
|
|
117
|
+
: hasKnownInventory && managesInventory && inventory > 0
|
|
118
|
+
? (en ? `Only ${Math.max(0, Math.trunc(inventory))} in stock; minimum order is ${minQuantity}.` : `Csak ${Math.max(0, Math.trunc(inventory))} db van készleten, a minimum rendelés ${minQuantity} db.`)
|
|
119
|
+
: (en ? "Currently unavailable" : "Jelenleg nem vásárolható")}
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
{sku ? (
|
|
123
|
+
<div className="sku-row">
|
|
124
|
+
<span><span className="muted">SKU:</span> <code>{sku}</code></span>
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
className="text-button"
|
|
128
|
+
onClick={() => void copyText(sku).then(() => showToast({ message: en ? "SKU copied" : "SKU másolva", tone: "success" }))}
|
|
129
|
+
>
|
|
130
|
+
{en ? "Copy SKU" : "SKU másolása"}
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
) : null}
|
|
134
|
+
|
|
62
135
|
<button
|
|
63
|
-
className="button button-large"
|
|
136
|
+
className="button button-large sticky-mobile-cta"
|
|
64
137
|
type="button"
|
|
65
|
-
disabled={mutating || !variantId}
|
|
138
|
+
disabled={mutating || !variantId || !purchasable || quantity < minQuantity}
|
|
139
|
+
aria-busy={mutating}
|
|
66
140
|
onClick={() => {
|
|
67
141
|
setMessage(null)
|
|
68
142
|
setSuccess(false)
|
|
69
|
-
void addItem(variantId, quantity)
|
|
143
|
+
void addItem(variantId, Math.max(minQuantity, quantity))
|
|
70
144
|
.then(() => {
|
|
145
|
+
const next = en ? "The product was added to your cart." : "A termék bekerült a kosárba."
|
|
71
146
|
setSuccess(true)
|
|
72
|
-
setMessage(
|
|
147
|
+
setMessage(next)
|
|
148
|
+
showToast({ message: next, tone: "success" })
|
|
73
149
|
})
|
|
74
150
|
.catch((error) => {
|
|
151
|
+
const next = humanizeStorefrontError(error, locale)
|
|
75
152
|
setSuccess(false)
|
|
76
|
-
setMessage(
|
|
153
|
+
setMessage(next)
|
|
154
|
+
showToast({ message: next, tone: "error" })
|
|
77
155
|
})
|
|
78
156
|
}}
|
|
79
157
|
>
|
|
80
|
-
{mutating ? (en ? "Updating cart…" : "Kosár frissítése…") : (en ? "Add to cart" : "Kosárba")}
|
|
158
|
+
{mutating ? (en ? "Updating cart…" : "Kosár frissítése…") : purchasable ? (en ? "Add to cart" : "Kosárba") : (en ? "Unavailable" : "Nem vásárolható")}
|
|
81
159
|
</button>
|
|
82
|
-
{message ? <p className={success ? "success" : "error"}>{message}</p> : null}
|
|
160
|
+
{message ? <p className={success ? "success" : "error"} aria-live="polite">{message}</p> : null}
|
|
83
161
|
</div>
|
|
84
162
|
)
|
|
85
163
|
}
|
|
164
|
+
|
|
165
|
+
function variantMinimum(variant: Record<string, unknown> | undefined, productMetadata: Record<string, unknown>) {
|
|
166
|
+
const metadata = isRecord(variant?.metadata) ? variant.metadata : {}
|
|
167
|
+
return Math.max(1, Math.trunc(numberValue(metadata.minimum_order_quantity ?? productMetadata.minimum_order_quantity, 1)))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function variantImageUrl(variant: Record<string, unknown> | undefined) {
|
|
171
|
+
if (!variant) return ""
|
|
172
|
+
const direct = stringValue(variant.thumbnail)
|
|
173
|
+
if (direct) return direct
|
|
174
|
+
const images = asRecords(variant.images)
|
|
175
|
+
return stringValue(images[0]?.url)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
179
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value))
|
|
180
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react"
|
|
4
|
+
import { prefersReducedMotion } from "@/lib/core/form-ux"
|
|
5
|
+
|
|
6
|
+
export function BackToTop({ label = "Vissza a tetejére" }: { label?: string }) {
|
|
7
|
+
const [visible, setVisible] = useState(false)
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const onScroll = () => setVisible(window.scrollY > 700)
|
|
11
|
+
onScroll()
|
|
12
|
+
window.addEventListener("scroll", onScroll, { passive: true })
|
|
13
|
+
return () => window.removeEventListener("scroll", onScroll)
|
|
14
|
+
}, [])
|
|
15
|
+
|
|
16
|
+
if (!visible) return null
|
|
17
|
+
return (
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
className="back-to-top"
|
|
21
|
+
onClick={() => window.scrollTo({ top: 0, behavior: prefersReducedMotion() ? "auto" : "smooth" })}
|
|
22
|
+
>
|
|
23
|
+
{label}
|
|
24
|
+
</button>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Link from "next/link"
|
|
2
|
+
|
|
3
|
+
type BreadcrumbItem = {
|
|
4
|
+
label: string
|
|
5
|
+
href?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function Breadcrumbs({ items, label = "Morzsanavigáció" }: { items: BreadcrumbItem[]; label?: string }) {
|
|
9
|
+
if (!items.length) return null
|
|
10
|
+
return (
|
|
11
|
+
<nav className="breadcrumbs" aria-label={label}>
|
|
12
|
+
<ol>
|
|
13
|
+
{items.map((item, index) => {
|
|
14
|
+
const current = index === items.length - 1
|
|
15
|
+
return (
|
|
16
|
+
<li key={`${item.label}:${index}`}>
|
|
17
|
+
{item.href && !current
|
|
18
|
+
? <Link href={item.href}>{item.label}</Link>
|
|
19
|
+
: <span aria-current={current ? "page" : undefined}>{item.label}</span>}
|
|
20
|
+
</li>
|
|
21
|
+
)
|
|
22
|
+
})}
|
|
23
|
+
</ol>
|
|
24
|
+
</nav>
|
|
25
|
+
)
|
|
26
|
+
}
|