@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.
- package/bin/create-commerce.mjs +9 -2
- package/package.json +1 -1
- package/templates/backend/.env.example +66 -7
- package/templates/backend/medusa-config.ts +17 -1
- package/templates/backend/package.json +2 -1
- package/templates/backend/src/scripts/core-init.ts +13 -1
- package/templates/storefront/next-env.d.ts +4 -1
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +9 -3
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +9 -5
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +17 -10
- package/templates/storefront/src/app/checkout/page.tsx +12 -3
- package/templates/storefront/src/app/checkout/success/page.tsx +58 -18
- package/templates/storefront/src/app/layout.tsx +10 -3
- package/templates/storefront/src/app/legal/page.tsx +11 -5
- package/templates/storefront/src/app/page.tsx +18 -12
- package/templates/storefront/src/app/reset-password/page.tsx +8 -2
- package/templates/storefront/src/components/account-dashboard.tsx +197 -76
- package/templates/storefront/src/components/add-to-cart.tsx +24 -10
- package/templates/storefront/src/components/cart-provider.tsx +29 -12
- package/templates/storefront/src/components/cart-view.tsx +28 -20
- package/templates/storefront/src/components/checkout-analytics.tsx +23 -0
- package/templates/storefront/src/components/checkout-flow.tsx +354 -102
- package/templates/storefront/src/components/order-detail.tsx +84 -45
- package/templates/storefront/src/components/product-card.tsx +16 -8
- package/templates/storefront/src/components/reset-password-form.tsx +19 -13
- package/templates/storefront/src/components/storefront-header.tsx +25 -11
- package/templates/storefront/src/components/stripe-payment.tsx +20 -4
- package/templates/storefront/src/lib/core/catalog.ts +37 -5
- package/templates/storefront/src/lib/core/client.ts +5 -0
- package/templates/storefront/src/lib/core/cms.ts +112 -0
- package/templates/storefront/src/lib/core/commerce.ts +14 -4
- package/templates/storefront/src/lib/core/leads.ts +50 -0
- package/templates/storefront/src/lib/core/pricing.ts +68 -0
- package/templates/storefront/src/lib/core/quotes.ts +43 -0
- package/templates/storefront/src/lib/core/seo.ts +44 -6
- package/templates/storefront/src/lib/storefront-copy.ts +435 -0
- package/templates/storefront/src/lib/storefront-locale-server.ts +11 -0
- package/templates/storefront/src/lib/storefront-routes.ts +91 -0
- package/templates/storefront/src/proxy.ts +142 -0
- package/templates/storefront/tsconfig.json +23 -5
|
@@ -4,43 +4,49 @@ import { getCoreConfig } from "@/lib/core/client"
|
|
|
4
4
|
import { checkoutApi } from "@/lib/core/checkout"
|
|
5
5
|
import { listCategories, listProducts } from "@/lib/core/catalog"
|
|
6
6
|
import { stringValue } from "@/lib/core/commerce"
|
|
7
|
+
import { storefrontCopy } from "@/lib/storefront-copy"
|
|
8
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
9
|
+
import { categoryPath, medusaLocale, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
7
10
|
|
|
8
11
|
export default async function HomePage() {
|
|
9
12
|
const config = await getCoreConfig()
|
|
13
|
+
const locale = await requestStorefrontLocale()
|
|
14
|
+
const copy = storefrontCopy(locale)
|
|
15
|
+
const apiLocale = medusaLocale(locale)
|
|
10
16
|
const region = await checkoutApi(config).resolveDefaultRegion().catch(() => null)
|
|
11
17
|
const regionId = region ? stringValue(region.id) : undefined
|
|
12
18
|
const [{ products }, { product_categories: categories }] = await Promise.all([
|
|
13
|
-
listProducts({ limit: 8, order: "-created_at", regionId }).catch(() => ({ products: [] })),
|
|
14
|
-
listCategories().catch(() => ({ product_categories: [] })),
|
|
19
|
+
listProducts({ limit: 8, order: "-created_at", regionId, locale: apiLocale }).catch(() => ({ products: [] })),
|
|
20
|
+
listCategories(apiLocale).catch(() => ({ product_categories: [] })),
|
|
15
21
|
])
|
|
16
|
-
const
|
|
22
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
17
23
|
|
|
18
24
|
return (
|
|
19
25
|
<div className="stack page-section">
|
|
20
26
|
<section className="hero storefront-hero">
|
|
21
27
|
<div className="hero-copy">
|
|
22
28
|
<p className="eyebrow">{config.store.name}</p>
|
|
23
|
-
<h1>
|
|
24
|
-
<p className="hero-text">
|
|
25
|
-
<div className="button-row"><Link className="button button-large" href={
|
|
29
|
+
<h1>{copy.homeHeroTitle}</h1>
|
|
30
|
+
<p className="hero-text">{copy.homeHeroText}</p>
|
|
31
|
+
<div className="button-row"><Link className="button button-large" href={routes.products}>{copy.products}</Link>{config.features.account ? <Link className="button secondary button-large" href={routes.account}>{copy.account}</Link> : null}</div>
|
|
26
32
|
</div>
|
|
27
33
|
<div className="hero-card">
|
|
28
34
|
<span className="hero-stat">Core</span>
|
|
29
|
-
<strong>
|
|
30
|
-
<p>
|
|
35
|
+
<strong>{copy.homeCoreTitle}</strong>
|
|
36
|
+
<p>{copy.homeCoreText}</p>
|
|
31
37
|
</div>
|
|
32
38
|
</section>
|
|
33
39
|
|
|
34
40
|
{categories.length ? (
|
|
35
41
|
<section className="stack-sm">
|
|
36
|
-
<div className="section-heading"><div><p className="eyebrow">
|
|
37
|
-
<div className="category-row">{categories.slice(0, 8).map((category) => <Link className="category-chip" key={stringValue(category.id)} href={
|
|
42
|
+
<div className="section-heading"><div><p className="eyebrow">{copy.categories}</p><h2>{copy.discoverOffer}</h2></div><Link className="text-link" href={routes.products}>{copy.allProducts}</Link></div>
|
|
43
|
+
<div className="category-row">{categories.slice(0, 8).map((category) => <Link className="category-chip" key={stringValue(category.id)} href={categoryPath(locale, stringValue(category.handle))}>{stringValue(category.name)}</Link>)}</div>
|
|
38
44
|
</section>
|
|
39
45
|
) : null}
|
|
40
46
|
|
|
41
47
|
<section className="stack-sm">
|
|
42
|
-
<div className="section-heading"><div><p className="eyebrow"
|
|
43
|
-
{products.length ? <div className="product-grid">{products.map((product) => <ProductCard key={stringValue(product.id)} product={product} config={config} />)}</div> : <div className="empty-state">
|
|
48
|
+
<div className="section-heading"><div><p className="eyebrow">{copy.newProducts}</p><h2>{copy.latestProducts}</h2></div><Link className="text-link" href={routes.products}>{copy.fullCatalog}</Link></div>
|
|
49
|
+
{products.length ? <div className="product-grid">{products.map((product) => <ProductCard key={stringValue(product.id)} product={product} config={config} locale={locale} />)}</div> : <div className="empty-state">{copy.noPublishedProducts}</div>}
|
|
44
50
|
</section>
|
|
45
51
|
</div>
|
|
46
52
|
)
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Suspense } from "react"
|
|
2
2
|
import { ResetPasswordForm } from "@/components/reset-password-form"
|
|
3
3
|
import { getCoreConfig } from "@/lib/core/client"
|
|
4
|
+
import { storefrontCopy } from "@/lib/storefront-copy"
|
|
5
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
4
6
|
|
|
5
7
|
export default async function ResetPasswordPage() {
|
|
6
|
-
const config = await
|
|
8
|
+
const [config, locale] = await Promise.all([
|
|
9
|
+
getCoreConfig(),
|
|
10
|
+
requestStorefrontLocale(),
|
|
11
|
+
])
|
|
12
|
+
const copy = storefrontCopy(locale)
|
|
7
13
|
return (
|
|
8
14
|
<div className="page-section narrow-page">
|
|
9
|
-
<Suspense fallback={<div className="empty-state">
|
|
15
|
+
<Suspense fallback={<div className="empty-state">{copy.loading}</div>}>
|
|
10
16
|
<ResetPasswordForm config={config} />
|
|
11
17
|
</Suspense>
|
|
12
18
|
</div>
|
|
@@ -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 {
|
|
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(
|
|
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(
|
|
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(
|
|
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">
|
|
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">
|
|
99
|
-
<h1>{mode === "register" ?
|
|
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")}>
|
|
103
|
-
<button type="button" className={mode === "register" ? "active" : ""} onClick={() => setMode("register")}>
|
|
104
|
-
<button type="button" className={mode === "forgot" ? "active" : ""} onClick={() => setMode("forgot")}>
|
|
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=
|
|
110
|
-
<Field label=
|
|
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=
|
|
114
|
-
{mode !== "forgot" ? <Field label=
|
|
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" ?
|
|
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">
|
|
124
|
-
<h2>
|
|
125
|
-
<p className="muted">
|
|
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">
|
|
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")}>
|
|
139
|
-
<TabButton active={tab === "addresses"} onClick={() => setTab("addresses")}>
|
|
140
|
-
<TabButton active={tab === "orders"} onClick={() => setTab("orders")}>
|
|
141
|
-
<TabButton active={tab === "security"} onClick={() => setTab("security")}>
|
|
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
|
-
}}>
|
|
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({
|
|
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">
|
|
214
|
+
<div><p className="eyebrow">{copy.profile}</p><h1>{copy.personalData}</h1></div>
|
|
172
215
|
<div className="form-grid two-col">
|
|
173
|
-
<Field label=
|
|
174
|
-
<Field label=
|
|
175
|
-
<Field label=
|
|
176
|
-
<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 })
|
|
181
|
-
|
|
182
|
-
|
|
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"
|
|
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."))}>
|
|
190
|
-
<div className="inline-form"
|
|
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({
|
|
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">
|
|
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"
|
|
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">
|
|
290
|
+
))}</div> : <div className="empty-state">{copy.noSavedAddress}</div>}
|
|
225
291
|
|
|
226
292
|
<div className="divider" />
|
|
227
|
-
<h2>{form.id ?
|
|
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"
|
|
234
|
-
|
|
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({
|
|
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
|
|
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">
|
|
247
|
-
{!orders.length ? <div className="empty-state">
|
|
248
|
-
<Link className="order-row" href={
|
|
249
|
-
<div><strong>#{stringValue(order.display_id || order.id)}</strong><span className="muted">{formatDate(order.created_at,
|
|
250
|
-
<div className="order-row-right"><span>{stringValue(order.status || "—")}</span><strong>{typeof order.total === "number" ? new Intl.NumberFormat(
|
|
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({
|
|
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">
|
|
268
|
-
<Field label=
|
|
269
|
-
<Field label=
|
|
270
|
-
<button className="button" type="button" onClick={() => void api.changePassword(currentPassword, newPassword).then(() => {
|
|
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">
|
|
275
|
-
<p className="muted">Jelenlegi cím: {stringValue(customer.email)}</p>
|
|
276
|
-
<Field label=
|
|
277
|
-
<Field label=
|
|
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."))}>
|
|
279
|
-
<div className="inline-form"
|
|
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">
|
|
284
|
-
<p className="muted">
|
|
285
|
-
<Field label=
|
|
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(
|
|
288
|
-
void api.deleteAccount(currentPassword).then(onDeleted).catch((e) => setMessage(e instanceof Error ? e.message : "A törlés nem sikerült."))
|
|
289
|
-
}}>
|
|
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
|
|
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> = {
|
|
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
|
+
}
|