@hszrdm/create-commerce 1.0.3 → 1.1.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 (40) hide show
  1. package/bin/create-commerce.mjs +9 -2
  2. package/package.json +1 -1
  3. package/templates/backend/.env.example +66 -7
  4. package/templates/backend/medusa-config.ts +17 -1
  5. package/templates/backend/package.json +2 -1
  6. package/templates/backend/src/scripts/core-init.ts +13 -1
  7. package/templates/storefront/next-env.d.ts +4 -1
  8. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
  9. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +9 -5
  10. package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
  11. package/templates/storefront/src/app/checkout/page.tsx +12 -3
  12. package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
  13. package/templates/storefront/src/app/layout.tsx +10 -3
  14. package/templates/storefront/src/app/legal/page.tsx +11 -5
  15. package/templates/storefront/src/app/page.tsx +18 -12
  16. package/templates/storefront/src/app/reset-password/page.tsx +8 -2
  17. package/templates/storefront/src/components/account-dashboard.tsx +197 -76
  18. package/templates/storefront/src/components/add-to-cart.tsx +24 -10
  19. package/templates/storefront/src/components/cart-provider.tsx +29 -12
  20. package/templates/storefront/src/components/cart-view.tsx +28 -20
  21. package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
  22. package/templates/storefront/src/components/checkout-flow.tsx +354 -102
  23. package/templates/storefront/src/components/order-detail.tsx +84 -45
  24. package/templates/storefront/src/components/product-card.tsx +16 -8
  25. package/templates/storefront/src/components/reset-password-form.tsx +19 -13
  26. package/templates/storefront/src/components/storefront-header.tsx +25 -11
  27. package/templates/storefront/src/components/stripe-payment.tsx +20 -4
  28. package/templates/storefront/src/lib/core/catalog.ts +37 -5
  29. package/templates/storefront/src/lib/core/client.ts +5 -0
  30. package/templates/storefront/src/lib/core/cms.ts +112 -0
  31. package/templates/storefront/src/lib/core/commerce.ts +14 -4
  32. package/templates/storefront/src/lib/core/leads.ts +50 -0
  33. package/templates/storefront/src/lib/core/pricing.ts +68 -0
  34. package/templates/storefront/src/lib/core/quotes.ts +43 -0
  35. package/templates/storefront/src/lib/core/seo.ts +44 -6
  36. package/templates/storefront/src/lib/storefront-copy.ts +435 -0
  37. package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
  38. package/templates/storefront/src/lib/storefront-routes.ts +91 -0
  39. package/templates/storefront/src/proxy.ts +142 -0
  40. package/templates/storefront/tsconfig.json +23 -5
@@ -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
  )
@@ -1,13 +1,19 @@
1
1
  "use client"
2
2
 
3
3
  import Link from "next/link"
4
- import { useSearchParams } from "next/navigation"
4
+ import { usePathname, useSearchParams } from "next/navigation"
5
5
  import { useMemo, useState } from "react"
6
6
  import { accountApi } from "@/lib/core/account"
7
7
  import type { CoreConfig } from "@/lib/core/types"
8
+ import { storefrontCopy } from "@/lib/storefront-copy"
9
+ import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
8
10
 
9
11
  export function ResetPasswordForm({ config }: { config: CoreConfig }) {
10
12
  const api = useMemo(() => accountApi(config), [config])
13
+ const pathname = usePathname()
14
+ const locale = localeFromPathname(pathname)
15
+ const copy = storefrontCopy(locale)
16
+ const routes = STOREFRONT_ROUTES[locale]
11
17
  const search = useSearchParams()
12
18
  const token = search.get("token") || ""
13
19
  const initialEmail = search.get("email") || ""
@@ -22,29 +28,29 @@ export function ResetPasswordForm({ config }: { config: CoreConfig }) {
22
28
  setError(null)
23
29
  setMessage(null)
24
30
  if (!token) {
25
- setError("Hiányzik a jelszó-visszaállítási token. Kérj új visszaállító e-mailt.")
31
+ setError(locale === "en" ? "The password reset token is missing. Request a new reset email." : "Hiányzik a jelszó-visszaállítási token. Kérj új visszaállító e-mailt.")
26
32
  return
27
33
  }
28
34
  if (!email.trim()) {
29
- setError("Add meg az e-mail címedet.")
35
+ setError(locale === "en" ? "Enter your email address." : "Add meg az e-mail címedet.")
30
36
  return
31
37
  }
32
38
  if (password.length < 8) {
33
- setError("Az új jelszó legalább 8 karakter legyen.")
39
+ setError(locale === "en" ? "The new password must be at least 8 characters long." : "Az új jelszó legalább 8 karakter legyen.")
34
40
  return
35
41
  }
36
42
  if (password !== confirm) {
37
- setError("A két jelszó nem egyezik.")
43
+ setError(locale === "en" ? "The passwords do not match." : "A két jelszó nem egyezik.")
38
44
  return
39
45
  }
40
46
  setBusy(true)
41
47
  try {
42
48
  await api.completePasswordReset(token, email, password)
43
- setMessage("A jelszó sikeresen módosult. Most már bejelentkezhetsz.")
49
+ setMessage(locale === "en" ? "Your password has been changed. You can now sign in." : "A jelszó sikeresen módosult. Most már bejelentkezhetsz.")
44
50
  setPassword("")
45
51
  setConfirm("")
46
52
  } catch (cause) {
47
- setError(cause instanceof Error ? cause.message : "A jelszó-visszaállítás nem sikerült.")
53
+ setError(cause instanceof Error ? cause.message : locale === "en" ? "Password reset failed." : "A jelszó-visszaállítás nem sikerült.")
48
54
  } finally {
49
55
  setBusy(false)
50
56
  }
@@ -52,14 +58,14 @@ export function ResetPasswordForm({ config }: { config: CoreConfig }) {
52
58
 
53
59
  return (
54
60
  <section className="panel stack narrow-card">
55
- <div><p className="eyebrow">Fiók biztonság</p><h1>Új jelszó beállítása</h1></div>
56
- <label>E-mail<input type="email" value={email} onChange={(event) => setEmail(event.target.value)} /></label>
57
- <label>Új jelszó<input type="password" value={password} onChange={(event) => setPassword(event.target.value)} /></label>
58
- <label>Új jelszó újra<input type="password" value={confirm} onChange={(event) => setConfirm(event.target.value)} /></label>
61
+ <div><p className="eyebrow">{copy.resetSecurity}</p><h1>{copy.resetTitle}</h1></div>
62
+ <label>{copy.email}<input type="email" value={email} onChange={(event) => setEmail(event.target.value)} /></label>
63
+ <label>{copy.newPassword}<input type="password" value={password} onChange={(event) => setPassword(event.target.value)} /></label>
64
+ <label>{copy.repeatPassword}<input type="password" value={confirm} onChange={(event) => setConfirm(event.target.value)} /></label>
59
65
  {error ? <p className="error">{error}</p> : null}
60
66
  {message ? <p className="success">{message}</p> : null}
61
- <button className="button button-large" type="button" disabled={busy} onClick={() => void submit()}>{busy ? "Mentés…" : "Jelszó mentése"}</button>
62
- <Link className="text-link" href="/account">Vissza a belépéshez</Link>
67
+ <button className="button button-large" type="button" disabled={busy} onClick={() => void submit()}>{busy ? copy.saving : copy.savePassword}</button>
68
+ <Link className="text-link" href={routes.account}>{copy.backToLogin}</Link>
63
69
  </section>
64
70
  )
65
71
  }
@@ -1,37 +1,51 @@
1
1
  "use client"
2
2
 
3
3
  import Link from "next/link"
4
+ import { usePathname } from "next/navigation"
4
5
  import { useCart } from "./cart-provider"
5
6
  import { CartView } from "./cart-view"
6
7
  import type { CoreConfig } from "@/lib/core/types"
8
+ import { storefrontCopy } from "@/lib/storefront-copy"
9
+ import {
10
+ equivalentLocalePath,
11
+ localeFromPathname,
12
+ STOREFRONT_ROUTES,
13
+ } from "@/lib/storefront-routes"
7
14
 
8
15
  export function StorefrontHeader({ config }: { config: CoreConfig }) {
9
16
  const { count, drawerOpen, setDrawerOpen } = useCart()
10
- const country = config.seo.default_country_code
17
+ const pathname = usePathname()
18
+ const locale = localeFromPathname(pathname)
19
+ const routes = STOREFRONT_ROUTES[locale]
20
+ const copy = storefrontCopy(locale)
11
21
 
12
22
  return (
13
23
  <>
14
24
  <header className="shell header">
15
- <Link className="brand" href="/">{config.store.name}</Link>
16
- <nav className="nav" aria-label="Fő navigáció">
17
- <Link href={`/${country}/products`}>Termékek</Link>
18
- <Link href="/legal">Jogi dokumentumok</Link>
19
- {config.features.account ? <Link href="/account">Fiókom</Link> : null}
25
+ <Link className="brand" href={routes.home}>{config.store.name}</Link>
26
+ <nav className="nav" aria-label={locale === "en" ? "Main navigation" : "Fő navigáció"}>
27
+ <Link href={routes.products}>{copy.products}</Link>
28
+ <Link href={routes.legal}>{copy.legalDocuments}</Link>
29
+ {config.features.account ? <Link href={routes.account}>{copy.account}</Link> : null}
30
+ <span className="locale-switch" aria-label={locale === "en" ? "Language" : "Nyelv"}>
31
+ <Link aria-current={locale === "hu" ? "page" : undefined} href={equivalentLocalePath(pathname, "hu")}>HU</Link>
32
+ <Link aria-current={locale === "en" ? "page" : undefined} href={equivalentLocalePath(pathname, "en")}>EN</Link>
33
+ </span>
20
34
  <button className="nav-cart" type="button" onClick={() => setDrawerOpen(true)}>
21
- Kosár <span className="cart-count">{count}</span>
35
+ {copy.cart} <span className="cart-count">{count}</span>
22
36
  </button>
23
37
  </nav>
24
38
  </header>
25
39
 
26
40
  {drawerOpen ? (
27
41
  <div className="drawer-backdrop" onMouseDown={() => setDrawerOpen(false)}>
28
- <aside className="drawer" onMouseDown={(event) => event.stopPropagation()} aria-label="Kosár">
42
+ <aside className="drawer" onMouseDown={(event) => event.stopPropagation()} aria-label={copy.cart}>
29
43
  <div className="drawer-head">
30
44
  <div>
31
- <p className="eyebrow">Kosár</p>
32
- <h2>{count} termék</h2>
45
+ <p className="eyebrow">{copy.cart}</p>
46
+ <h2>{count} {copy.productCountSuffix}</h2>
33
47
  </div>
34
- <button className="icon-button" type="button" aria-label="Bezárás" onClick={() => setDrawerOpen(false)}>×</button>
48
+ <button className="icon-button" type="button" aria-label={copy.close} onClick={() => setDrawerOpen(false)}>×</button>
35
49
  </div>
36
50
  <CartView config={config} compact />
37
51
  </aside>
@@ -1,8 +1,10 @@
1
1
  "use client"
2
2
 
3
3
  import { useMemo, useState } from "react"
4
+ import { usePathname } from "next/navigation"
4
5
  import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js"
5
6
  import { loadStripe } from "@stripe/stripe-js/pure"
7
+ import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
6
8
 
7
9
  export function StripePayment({
8
10
  publishableKey,
@@ -45,6 +47,9 @@ function StripePaymentForm({
45
47
  }) {
46
48
  const stripe = useStripe()
47
49
  const elements = useElements()
50
+ const pathname = usePathname()
51
+ const locale = localeFromPathname(pathname)
52
+ const checkoutPath = STOREFRONT_ROUTES[locale].checkout
48
53
  const [busy, setBusy] = useState(false)
49
54
  const [error, setError] = useState<string | null>(null)
50
55
 
@@ -54,7 +59,7 @@ function StripePaymentForm({
54
59
  setError(null)
55
60
  try {
56
61
  if (beforeConfirm) await beforeConfirm()
57
- const returnUrl = new URL("/checkout", window.location.origin)
62
+ const returnUrl = new URL(checkoutPath, window.location.origin)
58
63
  returnUrl.searchParams.set("cart_id", cartId)
59
64
  returnUrl.searchParams.set("stripe_return", "1")
60
65
  const result = await stripe.confirmPayment({
@@ -63,11 +68,20 @@ function StripePaymentForm({
63
68
  confirmParams: { return_url: returnUrl.toString() },
64
69
  })
65
70
  if (result.error) {
66
- throw new Error(result.error.message || "A bankkártyás fizetés nem sikerült.")
71
+ throw new Error(
72
+ result.error.message ||
73
+ (locale === "en" ? "Card payment failed." : "A bankkártyás fizetés nem sikerült."),
74
+ )
67
75
  }
68
76
  await onConfirmed()
69
77
  } catch (cause) {
70
- setError(cause instanceof Error ? cause.message : "A bankkártyás fizetés nem sikerült.")
78
+ setError(
79
+ cause instanceof Error
80
+ ? cause.message
81
+ : locale === "en"
82
+ ? "Card payment failed."
83
+ : "A bankkártyás fizetés nem sikerült.",
84
+ )
71
85
  } finally {
72
86
  setBusy(false)
73
87
  }
@@ -83,7 +97,9 @@ function StripePaymentForm({
83
97
  disabled={!stripe || !elements || disabled || busy}
84
98
  onClick={() => void submit()}
85
99
  >
86
- {busy ? "Fizetés feldolgozása…" : "Fizetés bankkártyával"}
100
+ {busy
101
+ ? locale === "en" ? "Processing payment…" : "Fizetés feldolgozása…"
102
+ : locale === "en" ? "Pay by card" : "Fizetés bankkártyával"}
87
103
  </button>
88
104
  </div>
89
105
  )
@@ -5,10 +5,20 @@ export type ProductListQuery = {
5
5
  categoryId?: string
6
6
  order?: string
7
7
  regionId?: string
8
+ locale?: string
8
9
  limit?: number
9
10
  offset?: number
10
11
  }
11
12
 
13
+ export type FeaturedProduct = {
14
+ id: string
15
+ title?: string | null
16
+ handle?: string | null
17
+ subtitle?: string | null
18
+ thumbnail?: string | null
19
+ featured_order: number
20
+ }
21
+
12
22
  export function listProducts(query: ProductListQuery = {}) {
13
23
  const params = new URLSearchParams()
14
24
  params.set("limit", String(query.limit ?? 24))
@@ -18,6 +28,7 @@ export function listProducts(query: ProductListQuery = {}) {
18
28
  if (query.categoryId?.trim()) params.set("category_id", query.categoryId.trim())
19
29
  if (query.order?.trim()) params.set("order", query.order.trim())
20
30
  if (query.regionId?.trim()) params.set("region_id", query.regionId.trim())
31
+ if (query.locale?.trim()) params.set("locale", query.locale.trim())
21
32
  return medusaFetch<{
22
33
  products: Array<Record<string, unknown>>
23
34
  count?: number
@@ -26,29 +37,50 @@ export function listProducts(query: ProductListQuery = {}) {
26
37
  }>(`/store/products?${params.toString()}`, { cache: "no-store" })
27
38
  }
28
39
 
29
- export function listCategories() {
40
+ export function listFeaturedProducts(limit = 8, locale?: string) {
41
+ const normalizedLimit = Number.isFinite(limit)
42
+ ? Math.max(1, Math.min(100, Math.trunc(limit)))
43
+ : 8
44
+ const params = new URLSearchParams({ limit: String(normalizedLimit) })
45
+ if (locale?.trim()) params.set("locale", locale.trim())
46
+
47
+ return medusaFetch<{
48
+ products: FeaturedProduct[]
49
+ count: number
50
+ limit: number
51
+ }>(`/store/featured-products?${params.toString()}`, {
52
+ next: { revalidate: 60 },
53
+ })
54
+ }
55
+
56
+ export function listCategories(locale?: string) {
57
+ const params = new URLSearchParams({ limit: "100", order: "rank" })
58
+ if (locale?.trim()) params.set("locale", locale.trim())
30
59
  return medusaFetch<{
31
60
  product_categories: Array<Record<string, unknown>>
32
61
  count?: number
33
- }>("/store/product-categories?limit=100&order=rank", {
62
+ }>(`/store/product-categories?${params.toString()}`, {
34
63
  next: { revalidate: 60 },
35
64
  })
36
65
  }
37
66
 
38
- export function getCategoryByHandle(handle: string) {
67
+ export function getCategoryByHandle(handle: string, locale?: string) {
68
+ const params = new URLSearchParams({ handle, limit: "1" })
69
+ if (locale?.trim()) params.set("locale", locale.trim())
39
70
  return medusaFetch<{ product_categories: Array<Record<string, unknown>> }>(
40
- `/store/product-categories?handle=${encodeURIComponent(handle)}&limit=1`,
71
+ `/store/product-categories?${params.toString()}`,
41
72
  { next: { revalidate: 60 } },
42
73
  )
43
74
  }
44
75
 
45
- export function getProductByHandle(handle: string, regionId?: string) {
76
+ export function getProductByHandle(handle: string, regionId?: string, locale?: string) {
46
77
  const params = new URLSearchParams({
47
78
  handle,
48
79
  limit: "1",
49
80
  fields: "+variants.calculated_price,+categories,+images",
50
81
  })
51
82
  if (regionId) params.set("region_id", regionId)
83
+ if (locale?.trim()) params.set("locale", locale.trim())
52
84
  return medusaFetch<{ products: Array<Record<string, unknown>> }>(
53
85
  `/store/products?${params.toString()}`,
54
86
  { next: { revalidate: 60 } },