@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,88 @@
1
+ "use client"
2
+
3
+ import { useEffect, useRef, type ReactNode } from "react"
4
+
5
+ const FOCUSABLE = [
6
+ "a[href]",
7
+ "button:not([disabled])",
8
+ "input:not([disabled])",
9
+ "select:not([disabled])",
10
+ "textarea:not([disabled])",
11
+ "[tabindex]:not([tabindex='-1'])",
12
+ ].join(",")
13
+
14
+ export function AccessibleDialog({
15
+ open,
16
+ onClose,
17
+ labelledBy,
18
+ children,
19
+ className = "drawer",
20
+ }: {
21
+ open: boolean
22
+ onClose: () => void
23
+ labelledBy: string
24
+ children: ReactNode
25
+ className?: string
26
+ }) {
27
+ const ref = useRef<HTMLElement>(null)
28
+ const previousFocus = useRef<HTMLElement | null>(null)
29
+
30
+ useEffect(() => {
31
+ if (!open) return
32
+ previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null
33
+ const dialog = ref.current
34
+ const first = dialog?.querySelector<HTMLElement>(FOCUSABLE)
35
+ window.setTimeout(() => first?.focus(), 0)
36
+
37
+ const onKeyDown = (event: KeyboardEvent) => {
38
+ if (event.key === "Escape") {
39
+ event.preventDefault()
40
+ onClose()
41
+ return
42
+ }
43
+ if (event.key !== "Tab" || !dialog) return
44
+ const focusable = Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((element) => !element.hasAttribute("hidden"))
45
+ if (!focusable.length) {
46
+ event.preventDefault()
47
+ dialog.focus()
48
+ return
49
+ }
50
+ const firstElement = focusable[0]
51
+ const lastElement = focusable[focusable.length - 1]
52
+ if (event.shiftKey && document.activeElement === firstElement) {
53
+ event.preventDefault()
54
+ lastElement.focus()
55
+ } else if (!event.shiftKey && document.activeElement === lastElement) {
56
+ event.preventDefault()
57
+ firstElement.focus()
58
+ }
59
+ }
60
+
61
+ document.addEventListener("keydown", onKeyDown)
62
+ const originalOverflow = document.body.style.overflow
63
+ document.body.style.overflow = "hidden"
64
+ return () => {
65
+ document.removeEventListener("keydown", onKeyDown)
66
+ document.body.style.overflow = originalOverflow
67
+ previousFocus.current?.focus()
68
+ }
69
+ }, [onClose, open])
70
+
71
+ if (!open) return null
72
+
73
+ return (
74
+ <div className="drawer-backdrop" role="presentation" onMouseDown={onClose}>
75
+ <aside
76
+ ref={ref}
77
+ className={className}
78
+ role="dialog"
79
+ aria-modal="true"
80
+ aria-labelledby={labelledBy}
81
+ tabIndex={-1}
82
+ onMouseDown={(event) => event.stopPropagation()}
83
+ >
84
+ {children}
85
+ </aside>
86
+ </div>
87
+ )
88
+ }
@@ -0,0 +1,98 @@
1
+ "use client"
2
+
3
+ import {
4
+ useEffect,
5
+ useId,
6
+ useRef,
7
+ useState,
8
+ type KeyboardEvent as ReactKeyboardEvent,
9
+ type ReactNode,
10
+ } from "react"
11
+
12
+ const ITEM_SELECTOR = "a[href], button:not([disabled]), [role='menuitem']:not([aria-disabled='true'])"
13
+
14
+ export function AccessibleDropdown({
15
+ label,
16
+ children,
17
+ }: {
18
+ label: ReactNode
19
+ children: ReactNode
20
+ }) {
21
+ const id = useId()
22
+ const rootRef = useRef<HTMLDivElement>(null)
23
+ const triggerRef = useRef<HTMLButtonElement>(null)
24
+ const [open, setOpen] = useState(false)
25
+
26
+ useEffect(() => {
27
+ if (!open) return
28
+ const onPointerDown = (event: MouseEvent) => {
29
+ if (!rootRef.current?.contains(event.target as Node)) setOpen(false)
30
+ }
31
+ const onKeyDown = (event: KeyboardEvent) => {
32
+ if (event.key === "Escape") {
33
+ event.preventDefault()
34
+ setOpen(false)
35
+ triggerRef.current?.focus()
36
+ }
37
+ }
38
+ document.addEventListener("mousedown", onPointerDown)
39
+ document.addEventListener("keydown", onKeyDown)
40
+ return () => {
41
+ document.removeEventListener("mousedown", onPointerDown)
42
+ document.removeEventListener("keydown", onKeyDown)
43
+ }
44
+ }, [open])
45
+
46
+ const focusItem = (position: "first" | "last") => {
47
+ const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
48
+ const item = position === "first" ? items[0] : items[items.length - 1]
49
+ item?.focus()
50
+ }
51
+
52
+ const navigate = (event: ReactKeyboardEvent<HTMLDivElement>) => {
53
+ const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
54
+ if (!items.length) return
55
+ const index = items.indexOf(document.activeElement as HTMLElement)
56
+ if (event.key === "ArrowDown") {
57
+ event.preventDefault()
58
+ items[(index + 1 + items.length) % items.length]?.focus()
59
+ } else if (event.key === "ArrowUp") {
60
+ event.preventDefault()
61
+ items[(index - 1 + items.length) % items.length]?.focus()
62
+ } else if (event.key === "Home") {
63
+ event.preventDefault()
64
+ items[0]?.focus()
65
+ } else if (event.key === "End") {
66
+ event.preventDefault()
67
+ items[items.length - 1]?.focus()
68
+ }
69
+ }
70
+
71
+ return (
72
+ <div className="accessible-dropdown" ref={rootRef} onKeyDown={navigate}>
73
+ <button
74
+ ref={triggerRef}
75
+ type="button"
76
+ className="accessible-dropdown-trigger"
77
+ aria-haspopup="menu"
78
+ aria-expanded={open}
79
+ aria-controls={id}
80
+ onClick={() => setOpen((current) => !current)}
81
+ onKeyDown={(event) => {
82
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
83
+ event.preventDefault()
84
+ setOpen(true)
85
+ requestAnimationFrame(() => focusItem(event.key === "ArrowDown" ? "first" : "last"))
86
+ }
87
+ }}
88
+ >
89
+ {label}
90
+ </button>
91
+ {open ? (
92
+ <div id={id} className="accessible-dropdown-menu" role="menu">
93
+ {children}
94
+ </div>
95
+ ) : null}
96
+ </div>
97
+ )
98
+ }
@@ -1,11 +1,19 @@
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, type FormEvent } from "react"
5
6
  import { accountApi } from "@/lib/core/account"
6
- import { asRecords, stringValue, type JsonRecord } from "@/lib/core/commerce"
7
+ import { stringValue, type JsonRecord } from "@/lib/core/commerce"
7
8
  import { CoreApiError } from "@/lib/core/client"
8
9
  import type { CoreConfig } from "@/lib/core/types"
10
+ import { storefrontCopy, type StorefrontCopy } from "@/lib/storefront-copy"
11
+ import {
12
+ localeFromPathname,
13
+ medusaLocale,
14
+ orderPath,
15
+ type StorefrontLocale,
16
+ } from "@/lib/storefront-routes"
9
17
  import { useCart } from "./cart-provider"
10
18
 
11
19
  type AuthMode = "login" | "register" | "forgot"
@@ -28,6 +36,9 @@ type AddressForm = {
28
36
 
29
37
  export function AccountDashboard({ config }: { config: CoreConfig }) {
30
38
  const api = useMemo(() => accountApi(config), [config])
39
+ const pathname = usePathname()
40
+ const locale = localeFromPathname(pathname)
41
+ const copy = storefrontCopy(locale)
31
42
  const { transferToCustomer } = useCart()
32
43
  const [customer, setCustomer] = useState<JsonRecord | null>(null)
33
44
  const [loading, setLoading] = useState(true)
@@ -67,14 +78,26 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
67
78
  try {
68
79
  if (mode === "forgot") {
69
80
  await api.requestPasswordReset(email)
70
- setMessage("Ha az e-mail címhez tartozik fiók, elküldtük a jelszó-visszaállítási levelet.")
81
+ setMessage(
82
+ localized(
83
+ locale,
84
+ "Ha az e-mail címhez tartozik fiók, elküldtük a jelszó-visszaállítási levelet.",
85
+ "If an account exists for this email address, we sent a password reset email.",
86
+ ),
87
+ )
71
88
  return
72
89
  }
73
90
  if (mode === "register") {
74
91
  await api.register({ email, password, first_name: firstName, last_name: lastName })
75
92
  await transferToCustomer().catch(() => undefined)
76
93
  await refresh()
77
- setMessage("A fiók létrejött. Az e-mail megerősítéséhez kövesd a kapott kódot.")
94
+ setMessage(
95
+ localized(
96
+ locale,
97
+ "A fiók létrejött. Az e-mail megerősítéséhez kövesd a kapott kódot.",
98
+ "Your account has been created. Use the code you received to verify your email.",
99
+ ),
100
+ )
78
101
  return
79
102
  }
80
103
  await api.login(email, password)
@@ -82,47 +105,51 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
82
105
  await refresh()
83
106
  setPassword("")
84
107
  } catch (cause) {
85
- setError(cause instanceof Error ? cause.message : "A művelet nem sikerült.")
108
+ setError(
109
+ cause instanceof Error
110
+ ? cause.message
111
+ : localized(locale, "A művelet nem sikerült.", "The operation failed."),
112
+ )
86
113
  } finally {
87
114
  setBusy(null)
88
115
  }
89
116
  }
90
117
 
91
- if (loading) return <div className="empty-state">Fiók betöltése…</div>
118
+ if (loading) return <div className="empty-state">{copy.accountLoading}</div>
92
119
 
93
120
  if (!customer) {
94
121
  return (
95
122
  <div className="account-auth-grid">
96
123
  <section className="panel stack">
97
124
  <div>
98
- <p className="eyebrow">Customer account</p>
99
- <h1>{mode === "register" ? "Regisztráció" : mode === "forgot" ? "Elfelejtett jelszó" : "Belépés"}</h1>
125
+ <p className="eyebrow">{copy.customerAccount}</p>
126
+ <h1>{mode === "register" ? copy.register : mode === "forgot" ? copy.forgotPassword : copy.login}</h1>
100
127
  </div>
101
128
  <div className="segmented">
102
- <button type="button" className={mode === "login" ? "active" : ""} onClick={() => setMode("login")}>Belépés</button>
103
- <button type="button" className={mode === "register" ? "active" : ""} onClick={() => setMode("register")}>Regisztráció</button>
104
- <button type="button" className={mode === "forgot" ? "active" : ""} onClick={() => setMode("forgot")}>Jelszó</button>
129
+ <button type="button" className={mode === "login" ? "active" : ""} onClick={() => setMode("login")}>{copy.login}</button>
130
+ <button type="button" className={mode === "register" ? "active" : ""} onClick={() => setMode("register")}>{copy.register}</button>
131
+ <button type="button" className={mode === "forgot" ? "active" : ""} onClick={() => setMode("forgot")}>{copy.password}</button>
105
132
  </div>
106
133
  <form className="stack-sm" onSubmit={authSubmit}>
107
134
  {mode === "register" ? (
108
135
  <div className="form-grid two-col">
109
- <Field label="Keresztnév" value={firstName} onChange={setFirstName} required />
110
- <Field label="Vezetéknév" value={lastName} onChange={setLastName} required />
136
+ <Field label={copy.firstName} value={firstName} onChange={setFirstName} required />
137
+ <Field label={copy.lastName} value={lastName} onChange={setLastName} required />
111
138
  </div>
112
139
  ) : null}
113
- <Field label="E-mail" type="email" value={email} onChange={setEmail} required />
114
- {mode !== "forgot" ? <Field label="Jelszó" type="password" value={password} onChange={setPassword} required /> : null}
140
+ <Field label={copy.email} type="email" value={email} onChange={setEmail} required />
141
+ {mode !== "forgot" ? <Field label={copy.password} type="password" value={password} onChange={setPassword} required /> : null}
115
142
  {error ? <p className="error">{error}</p> : null}
116
143
  {message ? <p className="success">{message}</p> : null}
117
144
  <button className="button button-large" type="submit" disabled={busy === "auth"}>
118
- {busy === "auth" ? "Feldolgozás…" : mode === "register" ? "Fiók létrehozása" : mode === "forgot" ? "Visszaállító e-mail kérése" : "Belépés"}
145
+ {busy === "auth" ? copy.processing : mode === "register" ? copy.createAccount : mode === "forgot" ? copy.requestResetEmail : copy.login}
119
146
  </button>
120
147
  </form>
121
148
  </section>
122
149
  <aside className="panel stack-sm account-benefits">
123
- <p className="eyebrow">Fiók előnyei</p>
124
- <h2>Rendeléseid egy helyen</h2>
125
- <p className="muted">Mentett címek, rendelési előzmények, jelszó- és e-mail-kezelés, valamint visszaküldés, csere és reklamáció a Core-on keresztül.</p>
150
+ <p className="eyebrow">{copy.accountBenefits}</p>
151
+ <h2>{copy.ordersInOnePlace}</h2>
152
+ <p className="muted">{copy.accountBenefitsText}</p>
126
153
  </aside>
127
154
  </div>
128
155
  )
@@ -131,32 +158,48 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
131
158
  return (
132
159
  <div className="account-layout">
133
160
  <aside className="account-sidebar panel">
134
- <p className="eyebrow">Bejelentkezve</p>
161
+ <p className="eyebrow">{copy.signedIn}</p>
135
162
  <h2>{stringValue(customer.first_name || customer.email)}</h2>
136
163
  <p className="muted small">{stringValue(customer.email)}</p>
137
164
  <nav className="account-nav">
138
- <TabButton active={tab === "profile"} onClick={() => setTab("profile")}>Profil</TabButton>
139
- <TabButton active={tab === "addresses"} onClick={() => setTab("addresses")}>Címek</TabButton>
140
- <TabButton active={tab === "orders"} onClick={() => setTab("orders")}>Rendelések</TabButton>
141
- <TabButton active={tab === "security"} onClick={() => setTab("security")}>Biztonság</TabButton>
165
+ <TabButton active={tab === "profile"} onClick={() => setTab("profile")}>{copy.profile}</TabButton>
166
+ <TabButton active={tab === "addresses"} onClick={() => setTab("addresses")}>{copy.addresses}</TabButton>
167
+ <TabButton active={tab === "orders"} onClick={() => setTab("orders")}>{copy.orders}</TabButton>
168
+ <TabButton active={tab === "security"} onClick={() => setTab("security")}>{copy.security}</TabButton>
142
169
  </nav>
143
170
  <button className="button secondary" type="button" disabled={busy === "logout"} onClick={() => {
144
171
  setBusy("logout")
145
172
  void api.logout().finally(() => { setCustomer(null); setBusy(null) })
146
- }}>Kijelentkezés</button>
173
+ }}>{copy.logout}</button>
147
174
  </aside>
148
175
 
149
176
  <main className="stack">
150
- {tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} /> : null}
151
- {tab === "addresses" ? <AddressesSection config={config} api={api} /> : null}
152
- {tab === "orders" ? <OrdersSection config={config} api={api} /> : null}
153
- {tab === "security" ? <SecuritySection customer={customer} api={api} refresh={refresh} onDeleted={() => setCustomer(null)} /> : null}
177
+ {tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} copy={copy} locale={locale} /> : null}
178
+ {tab === "addresses" ? <AddressesSection config={config} api={api} copy={copy} locale={locale} /> : null}
179
+ {tab === "orders" ? <OrdersSection config={config} api={api} copy={copy} locale={locale} /> : null}
180
+ {tab === "security" ? <SecuritySection customer={customer} api={api} refresh={refresh} onDeleted={() => setCustomer(null)} copy={copy} locale={locale} /> : null}
154
181
  </main>
155
182
  </div>
156
183
  )
157
184
  }
158
185
 
159
- function ProfileSection({ customer, api, refresh, busy, setBusy }: { customer: JsonRecord; api: ReturnType<typeof accountApi>; refresh: () => Promise<JsonRecord | null>; busy: string | null; setBusy: (value: string | null) => void }) {
186
+ function ProfileSection({
187
+ customer,
188
+ api,
189
+ refresh,
190
+ busy,
191
+ setBusy,
192
+ copy,
193
+ locale,
194
+ }: {
195
+ customer: JsonRecord
196
+ api: ReturnType<typeof accountApi>
197
+ refresh: () => Promise<JsonRecord | null>
198
+ busy: string | null
199
+ setBusy: (value: string | null) => void
200
+ copy: StorefrontCopy
201
+ locale: StorefrontLocale
202
+ }) {
160
203
  const [first, setFirst] = useState(stringValue(customer.first_name))
161
204
  const [last, setLast] = useState(stringValue(customer.last_name))
162
205
  const [phone, setPhone] = useState(stringValue(customer.phone))
@@ -168,26 +211,36 @@ function ProfileSection({ customer, api, refresh, busy, setBusy }: { customer: J
168
211
  return (
169
212
  <>
170
213
  <section className="panel stack">
171
- <div><p className="eyebrow">Profil</p><h1>Személyes adatok</h1></div>
214
+ <div><p className="eyebrow">{copy.profile}</p><h1>{copy.personalData}</h1></div>
172
215
  <div className="form-grid two-col">
173
- <Field label="Keresztnév" value={first} onChange={setFirst} />
174
- <Field label="Vezetéknév" value={last} onChange={setLast} />
175
- <Field label="Telefon" value={phone} onChange={setPhone} />
176
- <label>E-mail<input value={stringValue(customer.email)} readOnly /></label>
216
+ <Field label={copy.firstName} value={first} onChange={setFirst} />
217
+ <Field label={copy.lastName} value={last} onChange={setLast} />
218
+ <Field label={copy.phone} value={phone} onChange={setPhone} />
219
+ <label>{copy.email}<input value={stringValue(customer.email)} readOnly /></label>
177
220
  </div>
178
221
  <button className="button" type="button" disabled={busy === "profile"} onClick={() => {
179
222
  setBusy("profile")
180
- void api.updateProfile({ first_name: first, last_name: last, phone }).then(refresh).then(() => setMessage("Profil mentve.")).catch((e) => setMessage(e instanceof Error ? e.message : "Mentési hiba.")).finally(() => setBusy(null))
181
- }}>Profil mentése</button>
182
- {message ? <p className={message.includes("mentve") ? "success" : "error"}>{message}</p> : null}
223
+ void api.updateProfile({ first_name: first, last_name: last, phone })
224
+ .then(refresh)
225
+ .then(() => setMessage(localized(locale, "Profil mentve.", "Profile saved.")))
226
+ .catch((e) => setMessage(e instanceof Error ? e.message : localized(locale, "Mentési hiba.", "Save failed.")))
227
+ .finally(() => setBusy(null))
228
+ }}>{copy.saveProfile}</button>
229
+ {message ? <p className={isFailureMessage(message) ? "error" : "success"}>{message}</p> : null}
183
230
  </section>
184
231
 
185
232
  <section className="panel stack-sm">
186
- <div className="section-title-row"><div><p className="eyebrow">E-mail</p><h2>{verified ? "Megerősítve" : "Megerősítés szükséges"}</h2></div><span className={`status-pill ${verified ? "success-pill" : "warning-pill"}`}>{verified ? "Ellenőrizve" : "Függőben"}</span></div>
233
+ <div className="section-title-row">
234
+ <div><p className="eyebrow">{copy.email}</p><h2>{verified ? copy.emailVerified : copy.verificationNeeded}</h2></div>
235
+ <span className={`status-pill ${verified ? "success-pill" : "warning-pill"}`}>{verified ? copy.verified : copy.pending}</span>
236
+ </div>
187
237
  {!verified ? (
188
238
  <>
189
- <button className="button secondary" type="button" onClick={() => void api.requestEmailVerification().then(() => setMessage("Megerősítő kód elküldve."))}>Kód újraküldése</button>
190
- <div className="inline-form"><input value={code} onChange={(e) => setCode(e.target.value)} placeholder="Megerősítő kód" /><button className="button" type="button" disabled={!code.trim()} onClick={() => void api.confirmEmailVerification(code).then(refresh).then(() => setMessage("E-mail megerősítve."))}>Megerősítés</button></div>
239
+ <button className="button secondary" type="button" onClick={() => void api.requestEmailVerification().then(() => setMessage(localized(locale, "Megerősítő kód elküldve.", "Verification code sent.")))}>{copy.resendCode}</button>
240
+ <div className="inline-form">
241
+ <input value={code} onChange={(e) => setCode(e.target.value)} placeholder={copy.verificationCode} />
242
+ <button className="button" type="button" disabled={!code.trim()} onClick={() => void api.confirmEmailVerification(code).then(refresh).then(() => setMessage(localized(locale, "E-mail megerősítve.", "Email verified.")))}>{copy.verify}</button>
243
+ </div>
191
244
  </>
192
245
  ) : null}
193
246
  </section>
@@ -195,7 +248,17 @@ function ProfileSection({ customer, api, refresh, busy, setBusy }: { customer: J
195
248
  )
196
249
  }
197
250
 
198
- function AddressesSection({ config, api }: { config: CoreConfig; api: ReturnType<typeof accountApi> }) {
251
+ function AddressesSection({
252
+ config,
253
+ api,
254
+ copy,
255
+ locale,
256
+ }: {
257
+ config: CoreConfig
258
+ api: ReturnType<typeof accountApi>
259
+ copy: StorefrontCopy
260
+ locale: StorefrontLocale
261
+ }) {
199
262
  const [addresses, setAddresses] = useState<JsonRecord[]>([])
200
263
  const [form, setForm] = useState<AddressForm>(() => emptyAddressForm(config.store.default_country))
201
264
  const [message, setMessage] = useState<string | null>(null)
@@ -207,54 +270,84 @@ function AddressesSection({ config, api }: { config: CoreConfig; api: ReturnType
207
270
  if (form.id) await api.updateAddress(form.id, body)
208
271
  else await api.createAddress(body)
209
272
  setForm(emptyAddressForm(config.store.default_country))
210
- setMessage("Cím mentve.")
273
+ setMessage(localized(locale, "Cím mentve.", "Address saved."))
211
274
  await load()
212
275
  }
213
276
 
214
277
  return (
215
278
  <section className="panel stack">
216
- <div><p className="eyebrow">Címjegyzék</p><h1>Mentett címek</h1></div>
279
+ <div><p className="eyebrow">{copy.addressBook}</p><h1>{copy.savedAddresses}</h1></div>
217
280
  {addresses.length ? <div className="address-grid">{addresses.map((address) => (
218
281
  <div className="address-card" key={stringValue(address.id)}>
219
282
  <strong>{stringValue(address.address_name || `${stringValue(address.first_name)} ${stringValue(address.last_name)}`)}</strong>
220
283
  <span>{stringValue(address.postal_code)} {stringValue(address.city)}</span>
221
284
  <span>{stringValue(address.address_1)} {stringValue(address.address_2)}</span>
222
- <div className="button-row"><button className="text-button" type="button" onClick={() => setForm(addressToForm(address, config.store.default_country))}>Szerkesztés</button><button className="text-button danger" type="button" onClick={() => void api.deleteAddress(stringValue(address.id)).then(load)}>Törlés</button></div>
285
+ <div className="button-row">
286
+ <button className="text-button" type="button" onClick={() => setForm(addressToForm(address, config.store.default_country))}>{copy.edit}</button>
287
+ <button className="text-button danger" type="button" onClick={() => void api.deleteAddress(stringValue(address.id)).then(load)}>{copy.remove}</button>
288
+ </div>
223
289
  </div>
224
- ))}</div> : <div className="empty-state">Még nincs mentett címed.</div>}
290
+ ))}</div> : <div className="empty-state">{copy.noSavedAddress}</div>}
225
291
 
226
292
  <div className="divider" />
227
- <h2>{form.id ? "Cím szerkesztése" : "Új cím"}</h2>
293
+ <h2>{form.id ? copy.editAddress : copy.newAddress}</h2>
228
294
  <div className="form-grid two-col">
229
295
  {(["address_name", "first_name", "last_name", "company", "phone", "country_code", "postal_code", "city", "province", "address_1", "address_2"] as const).map((key) => (
230
- <Field key={key} label={addressLabel(key)} value={form[key]} onChange={(value) => setForm((current) => ({ ...current, [key]: value }))} />
296
+ <Field key={key} label={addressLabel(key, copy)} value={form[key]} onChange={(value) => setForm((current) => ({ ...current, [key]: value }))} />
231
297
  ))}
232
298
  </div>
233
- <div className="button-row"><button className="button" type="button" onClick={() => void save().catch((e) => setMessage(e instanceof Error ? e.message : "Mentési hiba."))}>{form.id ? "Cím frissítése" : "Cím hozzáadása"}</button>{form.id ? <button className="button secondary" type="button" onClick={() => setForm(emptyAddressForm(config.store.default_country))}>Mégse</button> : null}</div>
234
- {message ? <p className={message.includes("mentve") ? "success" : "error"}>{message}</p> : null}
299
+ <div className="button-row">
300
+ <button className="button" type="button" onClick={() => void save().catch((e) => setMessage(e instanceof Error ? e.message : localized(locale, "Mentési hiba.", "Save failed.")))}>{form.id ? copy.updateAddress : copy.addAddress}</button>
301
+ {form.id ? <button className="button secondary" type="button" onClick={() => setForm(emptyAddressForm(config.store.default_country))}>{copy.cancel}</button> : null}
302
+ </div>
303
+ {message ? <p className={isFailureMessage(message) ? "error" : "success"}>{message}</p> : null}
235
304
  </section>
236
305
  )
237
306
  }
238
307
 
239
- function OrdersSection({ config, api }: { config: CoreConfig; api: ReturnType<typeof accountApi> }) {
308
+ function OrdersSection({
309
+ config,
310
+ api,
311
+ copy,
312
+ locale,
313
+ }: {
314
+ config: CoreConfig
315
+ api: ReturnType<typeof accountApi>
316
+ copy: StorefrontCopy
317
+ locale: StorefrontLocale
318
+ }) {
240
319
  const [orders, setOrders] = useState<JsonRecord[]>([])
241
320
  const [loading, setLoading] = useState(true)
242
321
  useEffect(() => { void api.orders().then((r) => setOrders(r.orders)).finally(() => setLoading(false)) }, [api])
243
- if (loading) return <section className="panel">Rendelések betöltése…</section>
322
+ if (loading) return <section className="panel">{localized(locale, "Rendelések betöltése…", "Loading orders…")}</section>
244
323
  return (
245
324
  <section className="panel stack">
246
- <div><p className="eyebrow">Előzmények</p><h1>Rendeléseim</h1></div>
247
- {!orders.length ? <div className="empty-state">Még nincs rendelésed.</div> : <div className="order-list">{orders.map((order) => (
248
- <Link className="order-row" href={`/account/orders/${encodeURIComponent(stringValue(order.id))}`} key={stringValue(order.id)}>
249
- <div><strong>#{stringValue(order.display_id || order.id)}</strong><span className="muted">{formatDate(order.created_at, config.store.locale)}</span></div>
250
- <div className="order-row-right"><span>{stringValue(order.status || "—")}</span><strong>{typeof order.total === "number" ? new Intl.NumberFormat(config.store.locale, { style: "currency", currency: stringValue(order.currency_code || config.store.default_currency).toUpperCase() }).format(order.total) : ""}</strong></div>
325
+ <div><p className="eyebrow">{copy.history}</p><h1>{copy.myOrders}</h1></div>
326
+ {!orders.length ? <div className="empty-state">{copy.noOrders}</div> : <div className="order-list">{orders.map((order) => (
327
+ <Link className="order-row" href={orderPath(locale, stringValue(order.id))} key={stringValue(order.id)}>
328
+ <div><strong>#{stringValue(order.display_id || order.id)}</strong><span className="muted">{formatDate(order.created_at, medusaLocale(locale))}</span></div>
329
+ <div className="order-row-right"><span>{stringValue(order.status || "—")}</span><strong>{typeof order.total === "number" ? new Intl.NumberFormat(medusaLocale(locale), { style: "currency", currency: stringValue(order.currency_code || config.store.default_currency).toUpperCase() }).format(order.total) : ""}</strong></div>
251
330
  </Link>
252
331
  ))}</div>}
253
332
  </section>
254
333
  )
255
334
  }
256
335
 
257
- function SecuritySection({ customer, api, refresh, onDeleted }: { customer: JsonRecord; api: ReturnType<typeof accountApi>; refresh: () => Promise<JsonRecord | null>; onDeleted: () => void }) {
336
+ function SecuritySection({
337
+ customer,
338
+ api,
339
+ refresh,
340
+ onDeleted,
341
+ copy,
342
+ locale,
343
+ }: {
344
+ customer: JsonRecord
345
+ api: ReturnType<typeof accountApi>
346
+ refresh: () => Promise<JsonRecord | null>
347
+ onDeleted: () => void
348
+ copy: StorefrontCopy
349
+ locale: StorefrontLocale
350
+ }) {
258
351
  const [currentPassword, setCurrentPassword] = useState("")
259
352
  const [newPassword, setNewPassword] = useState("")
260
353
  const [newEmail, setNewEmail] = useState("")
@@ -264,31 +357,38 @@ function SecuritySection({ customer, api, refresh, onDeleted }: { customer: Json
264
357
  return (
265
358
  <>
266
359
  <section className="panel stack-sm">
267
- <div><p className="eyebrow">Jelszó</p><h2>Jelszó módosítása</h2></div>
268
- <Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
269
- <Field label="Új jelszó" type="password" value={newPassword} onChange={setNewPassword} />
270
- <button className="button" type="button" onClick={() => void api.changePassword(currentPassword, newPassword).then(() => { setCurrentPassword(""); setNewPassword(""); setMessage("Jelszó módosítva.") }).catch((e) => setMessage(e instanceof Error ? e.message : "Hiba."))}>Jelszó módosítása</button>
360
+ <div><p className="eyebrow">{copy.password}</p><h2>{copy.changePassword}</h2></div>
361
+ <Field label={copy.currentPassword} type="password" value={currentPassword} onChange={setCurrentPassword} />
362
+ <Field label={copy.newPassword} type="password" value={newPassword} onChange={setNewPassword} />
363
+ <button className="button" type="button" onClick={() => void api.changePassword(currentPassword, newPassword).then(() => {
364
+ setCurrentPassword("")
365
+ setNewPassword("")
366
+ setMessage(localized(locale, "Jelszó módosítva.", "Password changed."))
367
+ }).catch((e) => setMessage(e instanceof Error ? e.message : localized(locale, "Hiba.", "Error.")))}>{copy.changePassword}</button>
271
368
  </section>
272
369
 
273
370
  <section className="panel stack-sm">
274
- <div><p className="eyebrow">E-mail</p><h2>E-mail cím módosítása</h2></div>
275
- <p className="muted">Jelenlegi cím: {stringValue(customer.email)}</p>
276
- <Field label="Új e-mail" type="email" value={newEmail} onChange={setNewEmail} />
277
- <Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
278
- <button className="button secondary" type="button" onClick={() => void api.requestEmailChange(currentPassword, newEmail).then(() => setMessage("Megerősítő kód elküldve az új címhez."))}>E-mail módosítás kérése</button>
279
- <div className="inline-form"><input value={emailCode} onChange={(e) => setEmailCode(e.target.value)} placeholder="Megerősítő kód" /><button className="button" type="button" onClick={() => void api.confirmEmailChange(emailCode).then(refresh).then(() => setMessage("E-mail cím módosítva."))}>Megerősítés</button></div>
371
+ <div><p className="eyebrow">{copy.email}</p><h2>{copy.changeEmail}</h2></div>
372
+ <p className="muted">{localized(locale, "Jelenlegi cím", "Current address")}: {stringValue(customer.email)}</p>
373
+ <Field label={copy.newEmail} type="email" value={newEmail} onChange={setNewEmail} />
374
+ <Field label={copy.currentPassword} type="password" value={currentPassword} onChange={setCurrentPassword} />
375
+ <button className="button secondary" type="button" onClick={() => void api.requestEmailChange(currentPassword, newEmail).then(() => setMessage(localized(locale, "Megerősítő kód elküldve az új címhez.", "A verification code was sent to the new address.")))}>{copy.requestEmailChange}</button>
376
+ <div className="inline-form">
377
+ <input value={emailCode} onChange={(e) => setEmailCode(e.target.value)} placeholder={copy.verificationCode} />
378
+ <button className="button" type="button" onClick={() => void api.confirmEmailChange(emailCode).then(refresh).then(() => setMessage(localized(locale, "E-mail cím módosítva.", "Email address changed.")))}>{copy.verify}</button>
379
+ </div>
280
380
  </section>
281
381
 
282
382
  <section className="panel stack-sm danger-zone">
283
- <div><p className="eyebrow">Veszélyes művelet</p><h2>Fiók törlése</h2></div>
284
- <p className="muted">A törléshez add meg a jelenlegi jelszavad. A rendelési bizonylatok és jogszabály szerint megőrzendő adatok kezelése a backend szabályai szerint történik.</p>
285
- <Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
383
+ <div><p className="eyebrow">{copy.danger}</p><h2>{copy.deleteAccount}</h2></div>
384
+ <p className="muted">{copy.deleteAccountText}</p>
385
+ <Field label={copy.currentPassword} type="password" value={currentPassword} onChange={setCurrentPassword} />
286
386
  <button className="button danger-button" type="button" onClick={() => {
287
- if (!confirm("Biztosan törlöd a fiókodat?")) return
288
- void api.deleteAccount(currentPassword).then(onDeleted).catch((e) => setMessage(e instanceof Error ? e.message : "A törlés nem sikerült."))
289
- }}>Fiók végleges törlése</button>
387
+ if (!confirm(copy.deleteAccountConfirm)) return
388
+ void api.deleteAccount(currentPassword).then(onDeleted).catch((e) => setMessage(e instanceof Error ? e.message : localized(locale, "A törlés nem sikerült.", "Account deletion failed.")))
389
+ }}>{copy.deleteAccountFinal}</button>
290
390
  </section>
291
- {message ? <p className={message.toLowerCase().includes("hiba") ? "error" : "success"}>{message}</p> : null}
391
+ {message ? <p className={isFailureMessage(message) ? "error" : "success"}>{message}</p> : null}
292
392
  </>
293
393
  )
294
394
  }
@@ -310,8 +410,20 @@ function addressToForm(address: JsonRecord, country: string): AddressForm {
310
410
  return Object.fromEntries(Object.keys(base).map((key) => [key, stringValue(address[key]) || base[key as keyof AddressForm]])) as unknown as AddressForm
311
411
  }
312
412
 
313
- function addressLabel(key: keyof Omit<AddressForm, "id">) {
314
- const labels: Record<string, string> = { address_name: "Cím neve", first_name: "Keresztnév", last_name: "Vezetéknév", company: "Cég", phone: "Telefon", country_code: "Ország", postal_code: "Irányítószám", city: "Város", province: "Megye / régió", address_1: "Utca, házszám", address_2: "Cím kiegészítés" }
413
+ function addressLabel(key: keyof Omit<AddressForm, "id">, copy: StorefrontCopy) {
414
+ const labels: Record<string, string> = {
415
+ address_name: copy.addressName,
416
+ first_name: copy.firstName,
417
+ last_name: copy.lastName,
418
+ company: copy.companyOptional,
419
+ phone: copy.phone,
420
+ country_code: copy.country,
421
+ postal_code: copy.postalCode,
422
+ city: copy.city,
423
+ province: copy.province,
424
+ address_1: copy.address1,
425
+ address_2: copy.address2,
426
+ }
315
427
  return labels[key] || key
316
428
  }
317
429
 
@@ -323,3 +435,12 @@ function formatDate(value: unknown, locale: string) {
323
435
  function isRecordSafe(value: unknown): value is JsonRecord {
324
436
  return Boolean(value && typeof value === "object" && !Array.isArray(value))
325
437
  }
438
+
439
+ function localized(locale: StorefrontLocale, hu: string, en: string) {
440
+ return locale === "en" ? en : hu
441
+ }
442
+
443
+ function isFailureMessage(message: string) {
444
+ const value = message.toLowerCase()
445
+ return ["hiba", "error", "failed", "nem sikerült", "could not"].some((token) => value.includes(token))
446
+ }