@hszrdm/create-commerce 1.0.3 → 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.
Files changed (69) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/src/cli.mjs +5 -2
  4. package/templates/backend/.env.example +66 -7
  5. package/templates/backend/medusa-config.ts +17 -1
  6. package/templates/backend/package.json +2 -1
  7. package/templates/backend/src/scripts/core-init.ts +13 -1
  8. package/templates/storefront/next-env.d.ts +4 -1
  9. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
  10. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +46 -10
  11. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  12. package/templates/storefront/src/app/account/page.tsx +12 -1
  13. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  14. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  15. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  16. package/templates/storefront/src/app/core-ux.css +244 -0
  17. package/templates/storefront/src/app/layout.tsx +40 -14
  18. package/templates/storefront/src/app/legal/page.tsx +11 -5
  19. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  20. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  21. package/templates/storefront/src/app/page.tsx +18 -12
  22. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  23. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  24. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  25. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  26. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  27. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  28. package/templates/storefront/src/components/add-to-cart.tsx +127 -18
  29. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  30. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  31. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  32. package/templates/storefront/src/components/cart-view.tsx +96 -32
  33. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  34. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  35. package/templates/storefront/src/components/form-ux.tsx +47 -0
  36. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  37. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  38. package/templates/storefront/src/components/order-detail.tsx +84 -45
  39. package/templates/storefront/src/components/product-card.tsx +16 -8
  40. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  41. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  42. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  43. package/templates/storefront/src/components/share-button.tsx +63 -0
  44. package/templates/storefront/src/components/storefront-header.tsx +88 -20
  45. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  46. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  47. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  48. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  49. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  50. package/templates/storefront/src/lib/core/account.ts +3 -0
  51. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  52. package/templates/storefront/src/lib/core/client.ts +5 -0
  53. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  54. package/templates/storefront/src/lib/core/cms.ts +171 -0
  55. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  56. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  57. package/templates/storefront/src/lib/core/leads.ts +50 -0
  58. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  59. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  60. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  61. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  62. package/templates/storefront/src/lib/core/seo.ts +44 -6
  63. package/templates/storefront/src/lib/core/share.ts +57 -0
  64. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  65. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  66. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  67. package/templates/storefront/src/lib/storefront-routes.ts +94 -0
  68. package/templates/storefront/src/proxy.ts +145 -0
  69. package/templates/storefront/tsconfig.json +23 -5
@@ -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
+ }
@@ -0,0 +1,66 @@
1
+ "use client"
2
+
3
+ import { useEffect, useState } from "react"
4
+ import { confirmNewsletter, unsubscribeNewsletter } from "@/lib/core/newsletter"
5
+
6
+ type Props = {
7
+ action: "confirm" | "unsubscribe"
8
+ token: string
9
+ locale: "hu" | "en"
10
+ }
11
+
12
+ export function NewsletterAction({ action, token, locale }: Props) {
13
+ const english = locale === "en"
14
+ const [status, setStatus] = useState<"idle" | "loading" | "success" | "error">("idle")
15
+ const [message, setMessage] = useState("")
16
+
17
+ const run = async () => {
18
+ if (!token || status === "loading" || status === "success") return
19
+ setStatus("loading")
20
+ setMessage("")
21
+ try {
22
+ const response = action === "confirm"
23
+ ? await confirmNewsletter(token)
24
+ : await unsubscribeNewsletter(token)
25
+ setStatus("success")
26
+ setMessage(response.message)
27
+ } catch (cause) {
28
+ setStatus("error")
29
+ setMessage(cause instanceof Error ? cause.message : (english ? "The operation failed." : "A művelet nem sikerült."))
30
+ }
31
+ }
32
+
33
+ useEffect(() => {
34
+ if (action === "confirm" && token) void run()
35
+ // The confirmation link intentionally performs the POST only in the browser.
36
+ // Server-side page fetching must never mutate newsletter state.
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, [action, token])
39
+
40
+ if (!token) {
41
+ return <div className="empty-state">{english ? "The link is invalid." : "A link érvénytelen."}</div>
42
+ }
43
+
44
+ if (status === "success") {
45
+ return <div className="empty-state">{message}</div>
46
+ }
47
+
48
+ if (status === "error") {
49
+ return <div className="empty-state"><p>{message}</p></div>
50
+ }
51
+
52
+ if (action === "confirm") {
53
+ return <div className="empty-state">{english ? "Confirming your subscription…" : "Feliratkozás megerősítése…"}</div>
54
+ }
55
+
56
+ return (
57
+ <div className="empty-state">
58
+ <p>{english ? "Do you want to unsubscribe from the newsletter?" : "Biztosan le szeretnél iratkozni a hírlevélről?"}</p>
59
+ <button type="button" className="button button-large" onClick={() => void run()} disabled={status === "loading"}>
60
+ {status === "loading"
61
+ ? (english ? "Unsubscribing…" : "Leiratkozás…")
62
+ : (english ? "Unsubscribe" : "Leiratkozom")}
63
+ </button>
64
+ </div>
65
+ )
66
+ }
@@ -1,6 +1,7 @@
1
1
  "use client"
2
2
 
3
3
  import Link from "next/link"
4
+ import { usePathname } from "next/navigation"
4
5
  import { useCallback, useEffect, useMemo, useState } from "react"
5
6
  import { accountApi } from "@/lib/core/account"
6
7
  import { afterSalesApi, type AfterSalesCaseType } from "@/lib/core/after-sales"
@@ -15,6 +16,13 @@ import {
15
16
  type JsonRecord,
16
17
  } from "@/lib/core/commerce"
17
18
  import type { CoreConfig } from "@/lib/core/types"
19
+ import { storefrontCopy } from "@/lib/storefront-copy"
20
+ import {
21
+ localeFromPathname,
22
+ medusaLocale,
23
+ STOREFRONT_ROUTES,
24
+ type StorefrontLocale,
25
+ } from "@/lib/storefront-routes"
18
26
 
19
27
  type CaseMode = "return" | "exchange" | "claim"
20
28
  type VisibleCase = JsonRecord & { __case_type: AfterSalesCaseType }
@@ -22,6 +30,11 @@ type VisibleCase = JsonRecord & { __case_type: AfterSalesCaseType }
22
30
  export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId: string }) {
23
31
  const account = useMemo(() => accountApi(config), [config])
24
32
  const afterSales = useMemo(() => afterSalesApi(config), [config])
33
+ const pathname = usePathname()
34
+ const locale = localeFromPathname(pathname)
35
+ const apiLocale = medusaLocale(locale)
36
+ const copy = storefrontCopy(locale)
37
+ const routes = STOREFRONT_ROUTES[locale]
25
38
  const [order, setOrder] = useState<JsonRecord | null>(null)
26
39
  const [after, setAfter] = useState<JsonRecord | null>(null)
27
40
  const [reasons, setReasons] = useState<JsonRecord[]>([])
@@ -54,11 +67,15 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
54
67
  const first = asRecords(orderResult.order.items)[0]
55
68
  if (first && !itemId) setItemId(stringValue(first.id))
56
69
  } catch (cause) {
57
- setError(cause instanceof Error ? cause.message : "A rendelés nem tölthető be.")
70
+ setError(
71
+ cause instanceof Error
72
+ ? cause.message
73
+ : localized(locale, "A rendelés nem tölthető be.", "The order could not be loaded."),
74
+ )
58
75
  } finally {
59
76
  setLoading(false)
60
77
  }
61
- }, [account, afterSales, config.after_sales.enabled, itemId, orderId])
78
+ }, [account, afterSales, config.after_sales.enabled, itemId, locale, orderId])
62
79
 
63
80
  useEffect(() => { void load() }, [load])
64
81
 
@@ -72,7 +89,7 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
72
89
  useEffect(() => {
73
90
  if (mode !== "exchange" || variants.length) return
74
91
  void medusaFetch<{ products: JsonRecord[] }>(
75
- "/store/products?limit=100&fields=+variants",
92
+ `/store/products?limit=100&fields=+variants&locale=${encodeURIComponent(apiLocale)}`,
76
93
  { cache: "no-store" },
77
94
  )
78
95
  .then((result) => setVariants(
@@ -84,10 +101,10 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
84
101
  ),
85
102
  ))
86
103
  .catch(() => setVariants([]))
87
- }, [mode, variants.length])
104
+ }, [apiLocale, mode, variants.length])
88
105
 
89
- if (loading) return <div className="empty-state">Rendelés betöltése…</div>
90
- if (error || !order) return <div className="notice error-box">{error || "A rendelés nem található."}</div>
106
+ if (loading) return <div className="empty-state">{localized(locale, "Rendelés betöltése…", "Loading order…")}</div>
107
+ if (error || !order) return <div className="notice error-box">{error || localized(locale, "A rendelés nem található.", "Order not found.")}</div>
91
108
 
92
109
  const items = asRecords(order.items)
93
110
  const selectedItem = items.find((item) => stringValue(item.id) === itemId) || items[0]
@@ -103,7 +120,9 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
103
120
  ].sort((a: VisibleCase, b: VisibleCase) => stringValue(b.created_at).localeCompare(stringValue(a.created_at)))
104
121
 
105
122
  const submit = async () => {
106
- if (!selectedItem) throw new Error("Válassz rendelési tételt.")
123
+ if (!selectedItem) {
124
+ throw new Error(localized(locale, "Válassz rendelési tételt.", "Choose an order item."))
125
+ }
107
126
  setBusy(true)
108
127
  setError(null)
109
128
  setMessage(null)
@@ -117,29 +136,35 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
117
136
  await afterSales.createReturn(orderId, {
118
137
  items: [{ ...baseItem, reason_id: reasonId || undefined }],
119
138
  description: description || undefined,
120
- locale: config.store.locale,
139
+ locale: apiLocale,
121
140
  })
122
141
  } else if (mode === "exchange") {
123
- if (!newVariantId) throw new Error("Válassz csereterméket.")
142
+ if (!newVariantId) {
143
+ throw new Error(localized(locale, "Válassz csereterméket.", "Choose a replacement product."))
144
+ }
124
145
  await afterSales.createExchange(orderId, {
125
146
  return_items: [{ ...baseItem, reason_id: reasonId || undefined }],
126
147
  new_items: [{ variant_id: newVariantId, quantity }],
127
148
  description: description || undefined,
128
- locale: config.store.locale,
149
+ locale: apiLocale,
129
150
  })
130
151
  } else {
131
152
  await afterSales.createClaim(orderId, {
132
153
  type: claimType,
133
154
  items: [{ ...baseItem, reason: claimReason }],
134
155
  description: description || undefined,
135
- locale: config.store.locale,
156
+ locale: apiLocale,
136
157
  })
137
158
  }
138
- setMessage("A kérelem elküldve.")
159
+ setMessage(localized(locale, "A kérelem elküldve.", "Request submitted."))
139
160
  setDescription("")
140
161
  await load()
141
162
  } catch (cause) {
142
- setError(cause instanceof Error ? cause.message : "A kérelem nem küldhető el.")
163
+ setError(
164
+ cause instanceof Error
165
+ ? cause.message
166
+ : localized(locale, "A kérelem nem küldhető el.", "The request could not be submitted."),
167
+ )
143
168
  } finally {
144
169
  setBusy(false)
145
170
  }
@@ -153,16 +178,16 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
153
178
  <div className="stack">
154
179
  <div className="page-heading">
155
180
  <div>
156
- <p className="eyebrow">Rendelés</p>
181
+ <p className="eyebrow">{copy.order}</p>
157
182
  <h1>#{orderDisplayId(order)}</h1>
158
- <p className="muted">{formatDate(order.created_at, config.store.locale)} · {stringValue(order.status)}</p>
183
+ <p className="muted">{formatDate(order.created_at, apiLocale)} · {stringValue(order.status)}</p>
159
184
  </div>
160
- <Link className="button secondary" href="/account">Vissza a fiókhoz</Link>
185
+ <Link className="button secondary" href={routes.account}>{copy.backToAccount}</Link>
161
186
  </div>
162
187
 
163
188
  <div className="order-detail-grid">
164
189
  <section className="panel stack">
165
- <h2>Termékek</h2>
190
+ <h2>{copy.products}</h2>
166
191
  {items.map((item) => (
167
192
  <div className="order-item" key={stringValue(item.id)}>
168
193
  {stringValue(item.thumbnail)
@@ -171,65 +196,65 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
171
196
  <div>
172
197
  <strong>{stringValue(item.product_title || item.title)}</strong>
173
198
  <span className="muted">{stringValue(item.variant_title)}</span>
174
- <span>{numberValue(item.quantity, 1)} db</span>
199
+ <span>{numberValue(item.quantity, 1)} {locale === "en" ? "pcs" : "db"}</span>
175
200
  </div>
176
- <strong>{typeof item.total === "number" ? formatMoney(item.total, currency, config.store.locale) : ""}</strong>
201
+ <strong>{typeof item.total === "number" ? formatMoney(item.total, currency, apiLocale) : ""}</strong>
177
202
  </div>
178
203
  ))}
179
204
  {typeof order.total === "number"
180
- ? <div className="summary-total"><span>Összesen</span><strong>{formatMoney(order.total, currency, config.store.locale)}</strong></div>
205
+ ? <div className="summary-total"><span>{copy.total}</span><strong>{formatMoney(order.total, currency, apiLocale)}</strong></div>
181
206
  : null}
182
207
  </section>
183
208
 
184
209
  <aside className="panel stack-sm">
185
- <h2>Rendelési adatok</h2>
186
- <Info label="Státusz" value={stringValue(order.status)} />
187
- <Info label="Fizetés" value={stringValue(order.payment_status)} />
188
- <Info label="Teljesítés" value={stringValue(order.fulfillment_status)} />
189
- <Info label="E-mail" value={stringValue(order.email)} />
210
+ <h2>{copy.orderData}</h2>
211
+ <Info label={copy.status} value={stringValue(order.status)} />
212
+ <Info label={copy.payment} value={stringValue(order.payment_status)} />
213
+ <Info label={copy.fulfillment} value={stringValue(order.fulfillment_status)} />
214
+ <Info label={copy.email} value={stringValue(order.email)} />
190
215
  {isRecord(order.shipping_address)
191
- ? <Info label="Szállítási cím" value={formatAddress(order.shipping_address)} />
216
+ ? <Info label={copy.shippingAddress} value={formatAddress(order.shipping_address)} />
192
217
  : null}
193
218
  {asRecords(order.fulfillments)
194
219
  .flatMap((fulfillment) => asRecords(fulfillment.labels))
195
220
  .map((label) => stringValue(label.tracking_url))
196
221
  .filter(Boolean)
197
- .map((url) => <a className="text-link" href={url} target="_blank" rel="noreferrer" key={url}>Csomagkövetés</a>)}
222
+ .map((url) => <a className="text-link" href={url} target="_blank" rel="noreferrer" key={url}>{copy.tracking}</a>)}
198
223
  </aside>
199
224
  </div>
200
225
 
201
226
  {config.after_sales.enabled ? (
202
227
  <section className="panel stack">
203
- <div><p className="eyebrow">After-sales</p><h2>Visszaküldés, csere vagy reklamáció</h2></div>
228
+ <div><p className="eyebrow">After-sales</p><h2>{copy.afterSales}</h2></div>
204
229
  <div className="segmented">
205
- {canReturn ? <button type="button" className={mode === "return" ? "active" : ""} onClick={() => setMode("return")}>Visszaküldés</button> : null}
206
- {canExchange ? <button type="button" className={mode === "exchange" ? "active" : ""} onClick={() => setMode("exchange")}>Csere</button> : null}
207
- {canClaim ? <button type="button" className={mode === "claim" ? "active" : ""} onClick={() => setMode("claim")}>Reklamáció</button> : null}
230
+ {canReturn ? <button type="button" className={mode === "return" ? "active" : ""} onClick={() => setMode("return")}>{copy.return}</button> : null}
231
+ {canExchange ? <button type="button" className={mode === "exchange" ? "active" : ""} onClick={() => setMode("exchange")}>{copy.exchange}</button> : null}
232
+ {canClaim ? <button type="button" className={mode === "claim" ? "active" : ""} onClick={() => setMode("claim")}>{copy.claim}</button> : null}
208
233
  </div>
209
234
 
210
235
  <div className="form-grid two-col">
211
236
  <label>
212
- Rendelési tétel
237
+ {copy.orderItem}
213
238
  <select value={itemId} onChange={(event) => setItemId(event.target.value)}>
214
239
  {items.map((item) => <option key={stringValue(item.id)} value={stringValue(item.id)}>{stringValue(item.product_title || item.title)} · {stringValue(item.variant_title)}</option>)}
215
240
  </select>
216
241
  </label>
217
- <label>Mennyiség<input type="number" min={1} max={Math.max(1, numberValue(selectedItem?.quantity, 1))} value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} /></label>
242
+ <label>{copy.quantity}<input type="number" min={1} max={Math.max(1, numberValue(selectedItem?.quantity, 1))} value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} /></label>
218
243
  {mode !== "claim" ? (
219
- <label>Ok<select value={reasonId} onChange={(event) => setReasonId(event.target.value)}><option value="">Nincs megadva</option>{reasons.map((reason) => <option key={stringValue(reason.id)} value={stringValue(reason.id)}>{stringValue(reason.label || reason.value)}</option>)}</select></label>
244
+ <label>{copy.reason}<select value={reasonId} onChange={(event) => setReasonId(event.target.value)}><option value="">{copy.noReason}</option>{reasons.map((reason) => <option key={stringValue(reason.id)} value={stringValue(reason.id)}>{stringValue(reason.label || reason.value)}</option>)}</select></label>
220
245
  ) : null}
221
246
  {mode === "claim" ? (
222
247
  <>
223
- <label>Reklamáció típusa<select value={claimType} onChange={(event) => setClaimType(event.target.value)}><option value="refund">Visszatérítés</option><option value="replace">Cserepótlás</option></select></label>
224
- <label>Hiba oka<select value={claimReason} onChange={(event) => setClaimReason(event.target.value)}><option value="production_failure">Gyártási hiba</option><option value="wrong_item">Rossz termék</option><option value="missing_item">Hiányzó termék</option><option value="other">Egyéb</option></select></label>
248
+ <label>{copy.claimType}<select value={claimType} onChange={(event) => setClaimType(event.target.value)}><option value="refund">{copy.refund}</option><option value="replace">{copy.replacement}</option></select></label>
249
+ <label>{copy.issueReason}<select value={claimReason} onChange={(event) => setClaimReason(event.target.value)}><option value="production_failure">{copy.productionFailure}</option><option value="wrong_item">{copy.wrongItem}</option><option value="missing_item">{copy.missingItem}</option><option value="other">{copy.other}</option></select></label>
225
250
  </>
226
251
  ) : null}
227
252
  {mode === "exchange" ? (
228
- <label>Cseretermék<select value={newVariantId} onChange={(event) => setNewVariantId(event.target.value)}><option value="">Válassz variánst</option>{variants.map((variant) => <option value={stringValue(variant.id)} key={stringValue(variant.id)}>{stringValue(variant.product_title)} · {stringValue(variant.title || variant.sku)}</option>)}</select></label>
253
+ <label>{copy.exchangeProduct}<select value={newVariantId} onChange={(event) => setNewVariantId(event.target.value)}><option value="">{copy.chooseVariant}</option>{variants.map((variant) => <option value={stringValue(variant.id)} key={stringValue(variant.id)}>{stringValue(variant.product_title)} · {stringValue(variant.title || variant.sku)}</option>)}</select></label>
229
254
  ) : null}
230
255
  </div>
231
- <label>Leírás<textarea value={description} rows={4} onChange={(event) => setDescription(event.target.value)} placeholder="Írd le röviden a kérést vagy problémát." /></label>
232
- <button className="button" type="button" disabled={busy} onClick={() => void submit()}>{busy ? "Küldés…" : "Kérelem elküldése"}</button>
256
+ <label>{copy.description}<textarea value={description} rows={4} onChange={(event) => setDescription(event.target.value)} placeholder={copy.requestDescriptionPlaceholder} /></label>
257
+ <button className="button" type="button" disabled={busy} onClick={() => void submit()}>{busy ? copy.sending : copy.sendRequest}</button>
233
258
  {message ? <p className="success">{message}</p> : null}
234
259
  {error ? <p className="error">{error}</p> : null}
235
260
  </section>
@@ -237,17 +262,17 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
237
262
 
238
263
  {cases.length ? (
239
264
  <section className="panel stack">
240
- <h2>Korábbi kérelmek</h2>
265
+ <h2>{copy.previousRequests}</h2>
241
266
  {cases.map((entry) => (
242
267
  <div className="case-row" key={`${entry.__case_type}:${stringValue(entry.id)}`}>
243
268
  <div>
244
- <strong>{caseLabel(entry.__case_type)}</strong>
269
+ <strong>{caseLabel(entry.__case_type, locale)}</strong>
245
270
  <span className="muted">#{stringValue(entry.display_id || entry.id)}</span>
246
271
  </div>
247
272
  <div>
248
273
  <span className="status-pill">{stringValue(entry.request_status || entry.status || entry.change_status || "—")}</span>
249
274
  {stringValue(entry.request_status) === "submitted"
250
- ? <button className="text-button danger" type="button" onClick={() => void afterSales.cancel(orderId, entry.__case_type, stringValue(entry.id)).then(load)}>Visszavonás</button>
275
+ ? <button className="text-button danger" type="button" onClick={() => void afterSales.cancel(orderId, entry.__case_type, stringValue(entry.id)).then(load)}>{copy.withdraw}</button>
251
276
  : null}
252
277
  </div>
253
278
  </div>
@@ -261,13 +286,27 @@ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId:
261
286
  function Info({ label, value }: { label: string; value: string }) {
262
287
  return <div className="info-row"><span className="muted">{label}</span><strong>{value || "—"}</strong></div>
263
288
  }
289
+
264
290
  function formatDate(value: unknown, locale: string) {
265
291
  const date = new Date(stringValue(value))
266
292
  return Number.isNaN(date.valueOf()) ? "" : date.toLocaleString(locale)
267
293
  }
294
+
268
295
  function formatAddress(address: JsonRecord) {
269
- return [stringValue(address.postal_code), stringValue(address.city), stringValue(address.address_1), stringValue(address.address_2)].filter(Boolean).join(" ")
296
+ return [
297
+ stringValue(address.postal_code),
298
+ stringValue(address.city),
299
+ stringValue(address.address_1),
300
+ stringValue(address.address_2),
301
+ ].filter(Boolean).join(" ")
270
302
  }
271
- function caseLabel(type: AfterSalesCaseType) {
272
- return type === "return" ? "Visszaküldés" : type === "exchange" ? "Csere" : "Reklamáció"
303
+
304
+ function caseLabel(type: AfterSalesCaseType, locale: StorefrontLocale) {
305
+ if (type === "return") return localized(locale, "Visszaküldés", "Return")
306
+ if (type === "exchange") return localized(locale, "Csere", "Exchange")
307
+ return localized(locale, "Reklamáció", "Claim")
308
+ }
309
+
310
+ function localized(locale: StorefrontLocale, hu: string, en: string) {
311
+ return locale === "en" ? en : hu
273
312
  }
@@ -7,31 +7,39 @@ import {
7
7
  productVariantPrice,
8
8
  stringValue,
9
9
  } from "@/lib/core/commerce"
10
- import { renderPathTemplate } from "@/lib/core/client"
11
10
  import type { CoreConfig } from "@/lib/core/types"
11
+ import { storefrontCopy } from "@/lib/storefront-copy"
12
+ import { productPath, storefrontLocale, type StorefrontLocale } from "@/lib/storefront-routes"
12
13
 
13
- export function ProductCard({ product, config }: { product: Record<string, unknown>; config: CoreConfig }) {
14
+ export function ProductCard({
15
+ product,
16
+ config,
17
+ locale,
18
+ }: {
19
+ product: Record<string, unknown>
20
+ config: CoreConfig
21
+ locale?: StorefrontLocale
22
+ }) {
14
23
  const variants = asRecords(product.variants)
15
24
  const variant = variants[0] || null
16
25
  const price = productVariantPrice(variant)
17
26
  const currency = productVariantCurrency(variant, config.store.default_currency)
18
27
  const handle = stringValue(product.handle)
19
- const href = renderPathTemplate(config.seo.product_path_template, {
20
- country_code: config.seo.default_country_code,
21
- handle,
22
- })
28
+ const activeLocale = locale || storefrontLocale(config.store.locale)
29
+ const copy = storefrontCopy(activeLocale)
30
+ const href = productPath(activeLocale, handle)
23
31
  const thumbnail = stringValue(product.thumbnail)
24
32
  const categories = asRecords(product.categories)
25
33
 
26
34
  return (
27
35
  <article className="product-card">
28
36
  <Link href={href} className="product-media">
29
- {thumbnail ? <img src={thumbnail} alt={stringValue(product.title)} /> : <span className="media-placeholder">Nincs kép</span>}
37
+ {thumbnail ? <img src={thumbnail} alt={stringValue(product.title)} /> : <span className="media-placeholder">{copy.noImage}</span>}
30
38
  </Link>
31
39
  <div className="product-card-body">
32
40
  {categories[0] && isRecord(categories[0]) ? <span className="eyebrow">{stringValue(categories[0].name)}</span> : null}
33
41
  <Link href={href}><h2>{stringValue(product.title)}</h2></Link>
34
- {Number.isFinite(price) ? <strong>{formatMoney(price, currency, config.store.locale)}</strong> : <span className="muted">Ár a termékoldalon</span>}
42
+ {Number.isFinite(price) ? <strong>{formatMoney(price, currency, activeLocale === "en" ? "en-US" : "hu-HU")}</strong> : <span className="muted">{copy.priceOnProductPage}</span>}
35
43
  </div>
36
44
  </article>
37
45
  )
@@ -0,0 +1,64 @@
1
+ "use client"
2
+
3
+ import { useEffect, useMemo, useState } from "react"
4
+
5
+ export type ProductGalleryImage = {
6
+ id?: string
7
+ url: string
8
+ alt?: string
9
+ }
10
+
11
+ export function ProductGallery({
12
+ title,
13
+ images,
14
+ emptyLabel = "Nincs kép",
15
+ galleryLabel = "Termékképek",
16
+ }: {
17
+ title: string
18
+ images: ProductGalleryImage[]
19
+ emptyLabel?: string
20
+ galleryLabel?: string
21
+ }) {
22
+ const normalized = useMemo(() => images.filter((image) => image.url), [images])
23
+ const [activeUrl, setActiveUrl] = useState(normalized[0]?.url || "")
24
+
25
+ useEffect(() => {
26
+ const listener = (event: Event) => {
27
+ const custom = event as CustomEvent<{ imageUrl?: string }>
28
+ const imageUrl = String(custom.detail?.imageUrl || "").trim()
29
+ if (imageUrl) setActiveUrl(imageUrl)
30
+ }
31
+ window.addEventListener("hszrdm:product-variant-change", listener)
32
+ return () => window.removeEventListener("hszrdm:product-variant-change", listener)
33
+ }, [])
34
+
35
+ const allImages = activeUrl && !normalized.some((image) => image.url === activeUrl)
36
+ ? [{ url: activeUrl, alt: title }, ...normalized]
37
+ : normalized
38
+
39
+ return (
40
+ <div className="product-gallery">
41
+ <div className="product-main-image">
42
+ {activeUrl
43
+ ? <img src={activeUrl} alt={title} />
44
+ : <span className="media-placeholder">{emptyLabel}</span>}
45
+ </div>
46
+ {allImages.length > 1 ? (
47
+ <div className="thumbnail-row" aria-label={galleryLabel}>
48
+ {allImages.slice(0, 8).map((image, index) => (
49
+ <button
50
+ type="button"
51
+ className={`thumbnail-button${image.url === activeUrl ? " is-active" : ""}`}
52
+ key={`${image.id || image.url}:${index}`}
53
+ aria-label={`${title} – ${index + 1}`}
54
+ aria-pressed={image.url === activeUrl}
55
+ onClick={() => setActiveUrl(image.url)}
56
+ >
57
+ <img src={image.url} alt="" loading="lazy" />
58
+ </button>
59
+ ))}
60
+ </div>
61
+ ) : null}
62
+ </div>
63
+ )
64
+ }
@@ -0,0 +1,41 @@
1
+ "use client"
2
+
3
+ export function QuantityStepper({
4
+ value,
5
+ onChange,
6
+ min = 1,
7
+ max = 999,
8
+ disabled = false,
9
+ label = "Mennyiség",
10
+ decreaseLabel,
11
+ increaseLabel,
12
+ }: {
13
+ value: number
14
+ onChange: (value: number) => void
15
+ min?: number
16
+ max?: number
17
+ disabled?: boolean
18
+ label?: string
19
+ decreaseLabel?: string
20
+ increaseLabel?: string
21
+ }) {
22
+ const clamped = Math.max(min, Math.min(max, Math.trunc(value || min)))
23
+ const set = (next: number) => onChange(Math.max(min, Math.min(max, Math.trunc(next || min))))
24
+
25
+ return (
26
+ <div className="quantity-stepper" role="group" aria-label={label}>
27
+ <button type="button" disabled={disabled || clamped <= min} aria-label={decreaseLabel || `${label}: csökkentés`} onClick={() => set(clamped - 1)}>−</button>
28
+ <input
29
+ type="number"
30
+ inputMode="numeric"
31
+ min={min}
32
+ max={max}
33
+ value={clamped}
34
+ disabled={disabled}
35
+ aria-label={label}
36
+ onChange={(event) => set(Number(event.target.value))}
37
+ />
38
+ <button type="button" disabled={disabled || clamped >= max} aria-label={increaseLabel || `${label}: növelés`} onClick={() => set(clamped + 1)}>+</button>
39
+ </div>
40
+ )
41
+ }