@hszrdm/create-commerce 1.1.0 → 1.3.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.
Files changed (54) hide show
  1. package/package.json +2 -2
  2. package/src/cli.mjs +5 -2
  3. package/templates/backend/.env.example +45 -0
  4. package/templates/backend/package.json +1 -1
  5. package/templates/storefront/README.md +14 -1
  6. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +43 -9
  7. package/templates/storefront/src/app/account/page.tsx +12 -1
  8. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  9. package/templates/storefront/src/app/blog/[slug]/page.tsx +36 -0
  10. package/templates/storefront/src/app/blog/page.tsx +25 -0
  11. package/templates/storefront/src/app/contact/page.tsx +25 -0
  12. package/templates/storefront/src/app/core-ux.css +244 -0
  13. package/templates/storefront/src/app/customer-capabilities.css +60 -0
  14. package/templates/storefront/src/app/knowledge-base/[slug]/page.tsx +35 -0
  15. package/templates/storefront/src/app/knowledge-base/page.tsx +25 -0
  16. package/templates/storefront/src/app/layout.tsx +40 -12
  17. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  18. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  19. package/templates/storefront/src/app/pages/[slug]/page.tsx +35 -0
  20. package/templates/storefront/src/app/quote-request/page.tsx +20 -0
  21. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  22. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  23. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  24. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  25. package/templates/storefront/src/components/add-to-cart.tsx +110 -15
  26. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  27. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  28. package/templates/storefront/src/components/cart-view.tsx +72 -16
  29. package/templates/storefront/src/components/cms-content.tsx +75 -0
  30. package/templates/storefront/src/components/form-ux.tsx +47 -0
  31. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  32. package/templates/storefront/src/components/lead-form.tsx +203 -0
  33. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  34. package/templates/storefront/src/components/newsletter-signup.tsx +107 -0
  35. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  36. package/templates/storefront/src/components/product-reviews.tsx +150 -0
  37. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  38. package/templates/storefront/src/components/quote-request-form.tsx +212 -0
  39. package/templates/storefront/src/components/share-button.tsx +63 -0
  40. package/templates/storefront/src/components/storefront-header.tsx +72 -18
  41. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  42. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  43. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  44. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  45. package/templates/storefront/src/lib/core/account.ts +3 -0
  46. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  47. package/templates/storefront/src/lib/core/cms.ts +71 -11
  48. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  49. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  50. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  51. package/templates/storefront/src/lib/core/share.ts +57 -0
  52. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  53. package/templates/storefront/src/lib/storefront-routes.ts +33 -0
  54. package/templates/storefront/src/proxy.ts +25 -28
@@ -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(1)
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 value={variantId} onChange={(event) => setVariantId(event.target.value)}>
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
- <label className="quantity-field">
54
- {en ? "Quantity" : "Mennyiség"}
55
- <input min={1} max={99} type="number" value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} />
56
- </label>
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 ? "Price" : "Ár"}</span>
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(en ? "The product was added to your cart." : "A termék bekerült a kosárba.")
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(error instanceof Error ? error.message : en ? "Could not add the product to the cart." : "Nem sikerült kosárba tenni.")
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
+ }
@@ -3,6 +3,8 @@
3
3
  import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { useState } from "react"
6
+ import { QuantityStepper } from "./quantity-stepper"
7
+ import { useToast } from "./toast-provider"
6
8
  import { useCart } from "./cart-provider"
7
9
  import {
8
10
  cartCurrency,
@@ -17,6 +19,7 @@ import {
17
19
  numberValue,
18
20
  stringValue,
19
21
  } from "@/lib/core/commerce"
22
+ import { humanizeStorefrontError } from "@/lib/core/form-ux"
20
23
  import type { CoreConfig } from "@/lib/core/types"
21
24
  import { storefrontCopy } from "@/lib/storefront-copy"
22
25
  import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
@@ -27,6 +30,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
27
30
  loading,
28
31
  mutating,
29
32
  error,
33
+ addItem,
30
34
  updateItem,
31
35
  removeItem,
32
36
  addPromotion,
@@ -39,8 +43,9 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
39
43
  const copy = storefrontCopy(locale)
40
44
  const formatLocale = locale === "en" ? "en-US" : "hu-HU"
41
45
  const [promo, setPromo] = useState("")
46
+ const { showToast } = useToast()
42
47
 
43
- if (loading) return <div className="empty-state">{copy.cartLoading}</div>
48
+ if (loading) return <div className="empty-state" role="status">{copy.cartLoading}</div>
44
49
  const items = cartItems(cart)
45
50
  if (!cart || !items.length) {
46
51
  return (
@@ -59,29 +64,57 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
59
64
  ? cart.promotions.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === "object"))
60
65
  : []
61
66
 
67
+ const reportError = (cause: unknown) => {
68
+ const message = humanizeStorefrontError(cause, locale)
69
+ showToast({ message, tone: "error" })
70
+ }
71
+
62
72
  return (
63
73
  <div className="stack">
64
- <div className="cart-lines">
74
+ <div className="cart-lines" aria-live="polite">
65
75
  {items.map((item) => {
66
76
  const id = stringValue(item.id)
67
77
  const quantity = Math.max(1, numberValue(item.quantity, 1))
68
78
  const thumbnail = stringValue(item.thumbnail)
79
+ const title = stringValue(item.product_title || item.title)
80
+ const variantId = stringValue(item.variant_id)
69
81
  return (
70
82
  <div className="cart-line" key={id}>
71
83
  <div className="cart-line-image">
72
- {thumbnail ? <img src={thumbnail} alt="" /> : <span />}
84
+ {thumbnail ? <img src={thumbnail} alt={title} loading="lazy" /> : <span className="media-placeholder" aria-hidden="true" />}
73
85
  </div>
74
86
  <div className="cart-line-copy">
75
- <strong>{stringValue(item.product_title || item.title)}</strong>
87
+ <strong>{title}</strong>
76
88
  {item.variant_title ? <span className="muted">{stringValue(item.variant_title)}</span> : null}
77
89
  <span>{formatMoney(lineTotal(item), currency, formatLocale)}</span>
78
90
  </div>
79
- <div className="quantity-control">
80
- <button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity - 1)} aria-label={copy.decreaseQuantity}>−</button>
81
- <span>{quantity}</span>
82
- <button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity + 1)} aria-label={copy.increaseQuantity}>+</button>
83
- </div>
84
- <button className="text-button danger" type="button" disabled={mutating} onClick={() => void removeItem(id)}>
91
+ <QuantityStepper
92
+ value={quantity}
93
+ min={1}
94
+ max={999}
95
+ disabled={mutating}
96
+ label={locale === "en" ? `Quantity for ${title}` : `${title} mennyisége`}
97
+ decreaseLabel={locale === "en" ? `Decrease quantity for ${title}` : `${title} mennyiségének csökkentése`}
98
+ increaseLabel={locale === "en" ? `Increase quantity for ${title}` : `${title} mennyiségének növelése`}
99
+ onChange={(next) => void updateItem(id, next).catch(reportError)}
100
+ />
101
+ <button
102
+ className="text-button danger"
103
+ type="button"
104
+ disabled={mutating}
105
+ onClick={() => {
106
+ void removeItem(id)
107
+ .then(() => {
108
+ showToast({
109
+ message: locale === "en" ? "Item removed from cart." : "A terméket eltávolítottuk a kosárból.",
110
+ tone: "info",
111
+ actionLabel: variantId ? (locale === "en" ? "Undo" : "Visszavonás") : undefined,
112
+ onAction: variantId ? () => addItem(variantId, quantity) : undefined,
113
+ })
114
+ })
115
+ .catch(reportError)
116
+ }}
117
+ >
85
118
  {copy.remove}
86
119
  </button>
87
120
  </div>
@@ -93,17 +126,40 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
93
126
  <div className="panel stack-sm">
94
127
  <strong>{copy.couponCode}</strong>
95
128
  <div className="inline-form">
96
- <input value={promo} onChange={(event) => setPromo(event.target.value)} placeholder={copy.couponCode} />
97
- <button className="button secondary" type="button" disabled={mutating || !promo.trim()} onClick={() => void addPromotion(promo).then(() => setPromo(""))}>
129
+ <input
130
+ value={promo}
131
+ onChange={(event) => setPromo(event.target.value)}
132
+ placeholder={copy.couponCode}
133
+ aria-label={copy.couponCode}
134
+ autoComplete="off"
135
+ />
136
+ <button
137
+ className="button secondary"
138
+ type="button"
139
+ disabled={mutating || !promo.trim()}
140
+ aria-busy={mutating}
141
+ onClick={() => void addPromotion(promo)
142
+ .then(() => {
143
+ setPromo("")
144
+ showToast({ message: locale === "en" ? "Coupon applied." : "Kuponkód alkalmazva.", tone: "success" })
145
+ })
146
+ .catch(reportError)}
147
+ >
98
148
  {copy.redeem}
99
149
  </button>
100
150
  </div>
101
151
  {promotions.length ? (
102
- <div className="chip-row">
152
+ <div className="chip-row" aria-label={locale === "en" ? "Applied promotions" : "Alkalmazott kedvezmények"}>
103
153
  {promotions.map((promotion) => {
104
154
  const code = stringValue(promotion.code)
105
155
  return (
106
- <button className="chip" key={stringValue(promotion.id || code)} type="button" onClick={() => void removePromotion(code)}>
156
+ <button
157
+ className="chip"
158
+ key={stringValue(promotion.id || code)}
159
+ type="button"
160
+ aria-label={locale === "en" ? `Remove promotion ${code}` : `${code} kedvezmény eltávolítása`}
161
+ onClick={() => void removePromotion(code).catch(reportError)}
162
+ >
107
163
  {code || copy.discount} ×
108
164
  </button>
109
165
  )
@@ -113,7 +169,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
113
169
  </div>
114
170
  ) : null}
115
171
 
116
- <div className="totals">
172
+ <div className="totals" aria-live="polite">
117
173
  <TotalRow label={copy.subtotal} value={cartSubtotal(cart)} currency={currency} locale={formatLocale} />
118
174
  {cartDiscountTotal(cart) ? <TotalRow label={copy.discount} value={-cartDiscountTotal(cart)} currency={currency} locale={formatLocale} /> : null}
119
175
  <TotalRow label={copy.shipping} value={cartShippingTotal(cart)} currency={currency} locale={formatLocale} />
@@ -121,7 +177,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
121
177
  <TotalRow label={copy.total} value={cartTotal(cart)} currency={currency} locale={formatLocale} strong />
122
178
  </div>
123
179
 
124
- {error ? <p className="error">{error}</p> : null}
180
+ {error ? <p className="error" role="alert">{humanizeStorefrontError(new Error(error), locale)}</p> : null}
125
181
 
126
182
  <div className="button-row">
127
183
  {compact ? (
@@ -0,0 +1,75 @@
1
+ import Link from "next/link"
2
+ import type { CmsEntry } from "@/lib/core/cms"
3
+
4
+ type Locale = "hu" | "en"
5
+
6
+ export function CmsEntryCard({ entry, href, locale }: { entry: CmsEntry; href: string; locale: Locale }) {
7
+ const english = locale === "en"
8
+ return (
9
+ <article className="panel cms-card stack-sm">
10
+ {entry.featured_image_url ? (
11
+ <img className="cms-card-image" src={entry.featured_image_url} alt={entry.featured_image_alt || entry.title} />
12
+ ) : null}
13
+ <div className="stack-sm">
14
+ <CmsEntryMeta entry={entry} locale={locale} />
15
+ <h2><Link href={href}>{entry.title}</Link></h2>
16
+ {entry.excerpt ? <p>{entry.excerpt}</p> : null}
17
+ <Link className="text-link" href={href}>{english ? "Read more" : "Tovább olvasom"}</Link>
18
+ </div>
19
+ </article>
20
+ )
21
+ }
22
+
23
+ export function CmsEntryMeta({ entry, locale }: { entry: CmsEntry; locale: Locale }) {
24
+ const english = locale === "en"
25
+ const date = entry.published_at || entry.created_at
26
+ return (
27
+ <div className="cms-meta muted small">
28
+ {entry.author_name ? <span>{entry.author_name}</span> : null}
29
+ {date ? (
30
+ <time dateTime={date}>
31
+ {new Intl.DateTimeFormat(english ? "en-US" : "hu-HU", { dateStyle: "medium" }).format(new Date(date))}
32
+ </time>
33
+ ) : null}
34
+ {entry.terms?.length ? <span>{entry.terms.map((term) => term.name).join(" · ")}</span> : null}
35
+ </div>
36
+ )
37
+ }
38
+
39
+ export function CmsEntryBody({ entry }: { entry: CmsEntry }) {
40
+ if (entry.body_format === "html" && entry.body) {
41
+ return <div className="cms-body" dangerouslySetInnerHTML={{ __html: entry.body }} />
42
+ }
43
+
44
+ if (entry.body_format === "blocks" && Array.isArray(entry.blocks)) {
45
+ return (
46
+ <div className="cms-body stack-sm">
47
+ {entry.blocks.map((block, index) => <CmsBlock block={block} index={index} key={index} />)}
48
+ </div>
49
+ )
50
+ }
51
+
52
+ const paragraphs = String(entry.body || "")
53
+ .split(/\n\s*\n/)
54
+ .map((paragraph) => paragraph.trim())
55
+ .filter(Boolean)
56
+
57
+ return (
58
+ <div className="cms-body stack-sm">
59
+ {paragraphs.map((paragraph, index) => <p key={index}>{paragraph}</p>)}
60
+ </div>
61
+ )
62
+ }
63
+
64
+ function CmsBlock({ block, index }: { block: unknown; index: number }) {
65
+ if (typeof block === "string") return <p>{block}</p>
66
+ if (!block || typeof block !== "object" || Array.isArray(block)) return null
67
+ const row = block as Record<string, unknown>
68
+ const type = typeof row.type === "string" ? row.type : ""
69
+ const raw = row.text ?? row.content ?? row.value ?? (row.data && typeof row.data === "object" && !Array.isArray(row.data) ? (row.data as Record<string, unknown>).text : null)
70
+ const text = typeof raw === "string" ? raw : ""
71
+ if (!text) return null
72
+ if (type === "heading" || type === "h2" || type === "h3") return <h3>{text}</h3>
73
+ if (type === "quote") return <blockquote>{text}</blockquote>
74
+ return <p data-block-index={index}>{text}</p>
75
+ }
@@ -0,0 +1,47 @@
1
+ "use client"
2
+
3
+ import { useCallback, useState, type FormEvent } from "react"
4
+ import { fieldErrorId, focusFirstInvalidField, humanizeStorefrontError } from "@/lib/core/form-ux"
5
+
6
+ export function FieldError({ name, error }: { name: string; error?: string | null }) {
7
+ if (!error) return null
8
+ return <p id={fieldErrorId(name)} className="field-error" role="alert">{error}</p>
9
+ }
10
+
11
+ export function RequiredMark({ label = "kötelező" }: { label?: string }) {
12
+ return <span className="required-mark" aria-label={label}>*</span>
13
+ }
14
+
15
+ export function useAccessibleSubmit(options: {
16
+ locale?: "hu" | "en"
17
+ onSubmit: () => Promise<void>
18
+ onSuccess?: () => void
19
+ }) {
20
+ const [submitting, setSubmitting] = useState(false)
21
+ const [submitError, setSubmitError] = useState<string | null>(null)
22
+
23
+ const submit = useCallback(async (event?: FormEvent<HTMLFormElement>) => {
24
+ event?.preventDefault()
25
+ if (submitting) return
26
+ const form = event?.currentTarget
27
+ if (form && !form.checkValidity()) {
28
+ form.reportValidity()
29
+ focusFirstInvalidField(form)
30
+ return
31
+ }
32
+
33
+ setSubmitting(true)
34
+ setSubmitError(null)
35
+ try {
36
+ await options.onSubmit()
37
+ options.onSuccess?.()
38
+ } catch (error) {
39
+ setSubmitError(humanizeStorefrontError(error, options.locale || "hu"))
40
+ requestAnimationFrame(() => focusFirstInvalidField(form || document))
41
+ } finally {
42
+ setSubmitting(false)
43
+ }
44
+ }, [options, submitting])
45
+
46
+ return { submit, submitting, submitError, setSubmitError }
47
+ }
@@ -0,0 +1,35 @@
1
+ import { formatMoney } from "@/lib/core/commerce"
2
+
3
+ export function FreeShippingProgress({
4
+ subtotal,
5
+ threshold,
6
+ currency,
7
+ locale = "hu-HU",
8
+ }: {
9
+ subtotal: number
10
+ threshold: number
11
+ currency: string
12
+ locale?: string
13
+ }) {
14
+ if (!Number.isFinite(threshold) || threshold <= 0) return null
15
+ const remaining = Math.max(0, threshold - subtotal)
16
+ const progress = Math.max(0, Math.min(100, (subtotal / threshold) * 100))
17
+ const reached = remaining <= 0
18
+ const en = locale.toLowerCase().startsWith("en")
19
+
20
+ return (
21
+ <div className="shipping-progress stack-sm" role="status" aria-live="polite">
22
+ <div className="shipping-progress-copy">
23
+ <strong>
24
+ {reached
25
+ ? (en ? "You've reached the free shipping threshold." : "Elérted az ingyenes szállítási küszöböt.")
26
+ : (en
27
+ ? `${formatMoney(remaining, currency, locale)} more for free shipping.`
28
+ : `Még ${formatMoney(remaining, currency, locale)} az ingyenes szállításig.`)}
29
+ </strong>
30
+ <span>{formatMoney(subtotal, currency, locale)} / {formatMoney(threshold, currency, locale)}</span>
31
+ </div>
32
+ <div className="progress-track" aria-hidden="true"><span style={{ width: `${progress}%` }} /></div>
33
+ </div>
34
+ )
35
+ }