@hszrdm/create-commerce 1.17.0 → 1.20.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/package.json +1 -1
- package/templates/backend/.env.example +19 -24
- package/templates/backend/medusa-config.ts +14 -1
- package/templates/backend/package.json +1 -1
- package/templates/backend/scripts/core-backup.mjs +3 -1
- package/templates/backend/scripts/core-restore.mjs +17 -2
- package/templates/backend/scripts/lib/core-backup-common.mjs +32 -0
- package/templates/backend/src/scripts/core-init.ts +0 -5
- package/templates/storefront/package.json +3 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +2 -2
- package/templates/storefront/src/app/layout.tsx +6 -0
- package/templates/storefront/src/components/account-access-gate.tsx +88 -0
- package/templates/storefront/src/components/account-dashboard.tsx +112 -24
- package/templates/storefront/src/components/account-verification-panel.tsx +145 -0
- package/templates/storefront/src/components/address-street-fields.tsx +47 -0
- package/templates/storefront/src/components/checkout-flow.tsx +132 -34
- package/templates/storefront/src/components/product-card.tsx +2 -1
- package/templates/storefront/src/lib/core/account.ts +49 -8
- package/templates/storefront/src/lib/core/checkout-addresses.ts +14 -6
- package/templates/storefront/src/lib/core/checkout-feedback-state.ts +15 -0
- package/templates/storefront/src/lib/core/checkout.ts +18 -19
- package/templates/storefront/src/lib/core/commerce.ts +11 -0
- package/templates/storefront/src/lib/core/structured-address.ts +92 -0
- package/templates/storefront/src/lib/core/use-checkout-feedback.ts +53 -0
- package/templates/storefront/tests/account-verification.test.mjs +40 -0
- package/templates/storefront/tests/checkout-addresses.test.mjs +59 -0
- package/templates/storefront/tests/checkout-feedback.test.mjs +27 -0
- package/templates/storefront/tests/product-image.test.mjs +31 -0
- package/templates/storefront/tsconfig.json +1 -0
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import Link from "next/link"
|
|
4
4
|
import { usePathname } from "next/navigation"
|
|
5
5
|
import { useCallback, useEffect, useMemo, useState, type FormEvent } from "react"
|
|
6
|
-
import { accountApi } from "@/lib/core/account"
|
|
6
|
+
import { accountApi, isAccountEmailVerified } from "@/lib/core/account"
|
|
7
|
+
import { AccountVerificationPanel } from "./account-verification-panel"
|
|
7
8
|
import { stringValue, type JsonRecord } from "@/lib/core/commerce"
|
|
8
9
|
import { CoreApiError } from "@/lib/core/client"
|
|
9
10
|
import type { CoreConfig } from "@/lib/core/types"
|
|
@@ -15,11 +16,17 @@ import {
|
|
|
15
16
|
type StorefrontLocale,
|
|
16
17
|
} from "@/lib/storefront-routes"
|
|
17
18
|
import { useCart } from "./cart-provider"
|
|
19
|
+
import { AddressStreetFields } from "./address-street-fields"
|
|
20
|
+
import {
|
|
21
|
+
addressDetailsFromRecord, addressLine1, addressLine2,
|
|
22
|
+
addressStructuredSnapshot, emptyAddressDetails, isHungarianAddress,
|
|
23
|
+
missingAddressParts, type AddressDetails, CUSTOMER_STRUCTURED_ADDRESS_KEY,
|
|
24
|
+
} from "@/lib/core/structured-address"
|
|
18
25
|
|
|
19
26
|
type AuthMode = "login" | "register" | "forgot"
|
|
20
27
|
type AccountTab = "profile" | "addresses" | "orders" | "security"
|
|
21
28
|
|
|
22
|
-
type AddressForm = {
|
|
29
|
+
type AddressForm = AddressDetails & {
|
|
23
30
|
id: string
|
|
24
31
|
address_name: string
|
|
25
32
|
first_name: string
|
|
@@ -32,6 +39,7 @@ type AddressForm = {
|
|
|
32
39
|
province: string
|
|
33
40
|
address_1: string
|
|
34
41
|
address_2: string
|
|
42
|
+
metadata: Record<string, unknown>
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
@@ -45,6 +53,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
45
53
|
const [busy, setBusy] = useState<string | null>(null)
|
|
46
54
|
const [error, setError] = useState<string | null>(null)
|
|
47
55
|
const [message, setMessage] = useState<string | null>(null)
|
|
56
|
+
const [accountNotice, setAccountNotice] = useState<{ tone: "success" | "error"; text: string } | null>(null)
|
|
48
57
|
const [mode, setMode] = useState<AuthMode>("login")
|
|
49
58
|
const [tab, setTab] = useState<AccountTab>("profile")
|
|
50
59
|
const [email, setEmail] = useState("")
|
|
@@ -69,6 +78,22 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
69
78
|
useEffect(() => {
|
|
70
79
|
void refresh().catch(() => setCustomer(null)).finally(() => setLoading(false))
|
|
71
80
|
}, [refresh])
|
|
81
|
+
// The Email Center template is shared with registration verification.
|
|
82
|
+
// Existing email-change links must keep working after adding link support.
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (!customer || !isAccountEmailVerified(customer)) return
|
|
85
|
+
const url = new URL(window.location.href)
|
|
86
|
+
const code = url.searchParams.get("change_email_code")
|
|
87
|
+
if (!code) return
|
|
88
|
+
url.searchParams.delete("change_email_code")
|
|
89
|
+
window.history.replaceState(window.history.state, "", url.pathname + url.search + url.hash)
|
|
90
|
+
void api.confirmEmailChange(code).then(() => refresh()).then(() => {
|
|
91
|
+
setAccountNotice({ tone: "success", text: localized(locale, "E-mail-cím módosítva.", "Email address updated.") })
|
|
92
|
+
}).catch((error) => {
|
|
93
|
+
setAccountNotice({ tone: "error", text: error instanceof Error ? error.message : localized(locale, "Az e-mail módosítása nem sikerült.", "Could not change email.") })
|
|
94
|
+
})
|
|
95
|
+
}, [api, customer, refresh, locale])
|
|
96
|
+
|
|
72
97
|
|
|
73
98
|
const authSubmit = async (event: FormEvent) => {
|
|
74
99
|
event.preventDefault()
|
|
@@ -88,8 +113,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
88
113
|
return
|
|
89
114
|
}
|
|
90
115
|
if (mode === "register") {
|
|
91
|
-
await api.register({ email, password, first_name: firstName, last_name: lastName })
|
|
92
|
-
|
|
116
|
+
const registered = await api.register({ email, password, first_name: firstName, last_name: lastName })
|
|
117
|
+
if (registered.customer && isAccountEmailVerified(registered.customer)) {
|
|
118
|
+
await transferToCustomer().catch(() => undefined)
|
|
119
|
+
}
|
|
93
120
|
await refresh()
|
|
94
121
|
setMessage(
|
|
95
122
|
localized(
|
|
@@ -101,8 +128,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
101
128
|
return
|
|
102
129
|
}
|
|
103
130
|
await api.login(email, password)
|
|
104
|
-
await
|
|
105
|
-
|
|
131
|
+
const signedIn = await refresh()
|
|
132
|
+
if (signedIn && isAccountEmailVerified(signedIn)) {
|
|
133
|
+
await transferToCustomer().catch(() => undefined)
|
|
134
|
+
}
|
|
106
135
|
setPassword("")
|
|
107
136
|
} catch (cause) {
|
|
108
137
|
setError(
|
|
@@ -115,6 +144,18 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
115
144
|
}
|
|
116
145
|
}
|
|
117
146
|
|
|
147
|
+
const onVerificationComplete = useCallback(async () => {
|
|
148
|
+
const updated = await refresh()
|
|
149
|
+
if (updated && isAccountEmailVerified(updated)) {
|
|
150
|
+
await transferToCustomer().catch(() => undefined)
|
|
151
|
+
}
|
|
152
|
+
}, [refresh, transferToCustomer])
|
|
153
|
+
|
|
154
|
+
const onVerificationLogout = useCallback(async () => {
|
|
155
|
+
await api.logout()
|
|
156
|
+
setCustomer(null)
|
|
157
|
+
}, [api])
|
|
158
|
+
|
|
118
159
|
if (loading) return <div className="empty-state">{copy.accountLoading}</div>
|
|
119
160
|
|
|
120
161
|
if (!customer) {
|
|
@@ -155,6 +196,20 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
155
196
|
)
|
|
156
197
|
}
|
|
157
198
|
|
|
199
|
+
if (!isAccountEmailVerified(customer)) {
|
|
200
|
+
return (
|
|
201
|
+
<div className="account-layout">
|
|
202
|
+
<AccountVerificationPanel
|
|
203
|
+
api={api}
|
|
204
|
+
email={stringValue(customer.email)}
|
|
205
|
+
locale={locale}
|
|
206
|
+
onVerified={onVerificationComplete}
|
|
207
|
+
onLogout={onVerificationLogout}
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
158
213
|
return (
|
|
159
214
|
<div className="account-layout">
|
|
160
215
|
<aside className="account-sidebar panel">
|
|
@@ -174,6 +229,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
174
229
|
</aside>
|
|
175
230
|
|
|
176
231
|
<main className="stack">
|
|
232
|
+
{accountNotice ? <p role="status" className={accountNotice.tone === "error" ? "error" : "success"}>{accountNotice.text}</p> : null}
|
|
177
233
|
{tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} copy={copy} locale={locale} /> : null}
|
|
178
234
|
{tab === "addresses" ? <AddressesSection config={config} api={api} copy={copy} locale={locale} /> : null}
|
|
179
235
|
{tab === "orders" ? <OrdersSection config={config} api={api} copy={copy} locale={locale} /> : null}
|
|
@@ -203,10 +259,7 @@ function ProfileSection({
|
|
|
203
259
|
const [first, setFirst] = useState(stringValue(customer.first_name))
|
|
204
260
|
const [last, setLast] = useState(stringValue(customer.last_name))
|
|
205
261
|
const [phone, setPhone] = useState(stringValue(customer.phone))
|
|
206
|
-
const [code, setCode] = useState("")
|
|
207
262
|
const [message, setMessage] = useState<string | null>(null)
|
|
208
|
-
const metadata = isRecordSafe(customer.metadata) ? customer.metadata : {}
|
|
209
|
-
const verified = metadata.email_verified === true
|
|
210
263
|
|
|
211
264
|
return (
|
|
212
265
|
<>
|
|
@@ -231,18 +284,9 @@ function ProfileSection({
|
|
|
231
284
|
|
|
232
285
|
<section className="panel stack-sm">
|
|
233
286
|
<div className="section-title-row">
|
|
234
|
-
<div><p className="eyebrow">{copy.email}</p><h2>{
|
|
235
|
-
<span className=
|
|
287
|
+
<div><p className="eyebrow">{copy.email}</p><h2>{copy.emailVerified}</h2></div>
|
|
288
|
+
<span className="status-pill success-pill">{copy.verified}</span>
|
|
236
289
|
</div>
|
|
237
|
-
{!verified ? (
|
|
238
|
-
<>
|
|
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>
|
|
244
|
-
</>
|
|
245
|
-
) : null}
|
|
246
290
|
</section>
|
|
247
291
|
</>
|
|
248
292
|
)
|
|
@@ -266,7 +310,36 @@ function AddressesSection({
|
|
|
266
310
|
useEffect(() => { void load() }, [load])
|
|
267
311
|
|
|
268
312
|
const save = async () => {
|
|
269
|
-
const
|
|
313
|
+
const required = [form.first_name, form.last_name, form.postal_code, form.city, form.country_code]
|
|
314
|
+
if (required.some(part => !part.trim()) ||
|
|
315
|
+
(isHungarianAddress(form) ? missingAddressParts(form).length > 0 : !form.address_1.trim())) {
|
|
316
|
+
setMessage(localized(locale,
|
|
317
|
+
"Hiba: töltsd ki a kötelező név- és címmezőket.",
|
|
318
|
+
"Error: fill in all required name and address fields."))
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
if (!/^[a-z]{2}$/i.test(form.country_code.trim())) {
|
|
322
|
+
setMessage(localized(locale, "Hiba: kétbetűs országkód szükséges.", "Error: enter a two-letter country code."))
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
const snapshot = addressStructuredSnapshot(form)
|
|
326
|
+
const metadata = { ...form.metadata }
|
|
327
|
+
if (snapshot) metadata[CUSTOMER_STRUCTURED_ADDRESS_KEY] = snapshot
|
|
328
|
+
else metadata[CUSTOMER_STRUCTURED_ADDRESS_KEY] = "" // Medusa metadata deletion contract
|
|
329
|
+
const body = {
|
|
330
|
+
address_name: form.address_name,
|
|
331
|
+
first_name: form.first_name.trim(),
|
|
332
|
+
last_name: form.last_name.trim(),
|
|
333
|
+
company: form.company.trim() || undefined,
|
|
334
|
+
phone: form.phone.trim() || undefined,
|
|
335
|
+
country_code: form.country_code.trim().toLowerCase(),
|
|
336
|
+
postal_code: form.postal_code.trim(),
|
|
337
|
+
city: form.city.trim(),
|
|
338
|
+
province: form.province.trim() || undefined,
|
|
339
|
+
address_1: addressLine1(form),
|
|
340
|
+
address_2: addressLine2(form) || undefined,
|
|
341
|
+
metadata,
|
|
342
|
+
}
|
|
270
343
|
if (form.id) await api.updateAddress(form.id, body)
|
|
271
344
|
else await api.createAddress(body)
|
|
272
345
|
setForm(emptyAddressForm(config.store.default_country))
|
|
@@ -292,10 +365,12 @@ function AddressesSection({
|
|
|
292
365
|
<div className="divider" />
|
|
293
366
|
<h2>{form.id ? copy.editAddress : copy.newAddress}</h2>
|
|
294
367
|
<div className="form-grid two-col">
|
|
295
|
-
{(["address_name", "first_name", "last_name", "company", "phone", "country_code", "postal_code", "city", "province"
|
|
368
|
+
{(["address_name", "first_name", "last_name", "company", "phone", "country_code", "postal_code", "city", "province"] as const).map((key) => (
|
|
296
369
|
<Field key={key} label={addressLabel(key, copy)} value={form[key]} onChange={(value) => setForm((current) => ({ ...current, [key]: value }))} />
|
|
297
370
|
))}
|
|
298
371
|
</div>
|
|
372
|
+
<AddressStreetFields address={form} locale={locale}
|
|
373
|
+
onChange={(key, value) => setForm(current => ({ ...current, [key]: value }))} />
|
|
299
374
|
<div className="button-row">
|
|
300
375
|
<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
376
|
{form.id ? <button className="button secondary" type="button" onClick={() => setForm(emptyAddressForm(config.store.default_country))}>{copy.cancel}</button> : null}
|
|
@@ -402,12 +477,25 @@ function Field({ label, value, onChange, type = "text", required = false }: { la
|
|
|
402
477
|
}
|
|
403
478
|
|
|
404
479
|
function emptyAddressForm(country: string): AddressForm {
|
|
405
|
-
return {
|
|
480
|
+
return {
|
|
481
|
+
id: "", address_name: "", first_name: "", last_name: "", company: "", phone: "",
|
|
482
|
+
country_code: country.toUpperCase(), postal_code: "", city: "", province: "",
|
|
483
|
+
address_1: "", address_2: "", metadata: {}, ...emptyAddressDetails(),
|
|
484
|
+
}
|
|
406
485
|
}
|
|
407
486
|
|
|
408
487
|
function addressToForm(address: JsonRecord, country: string): AddressForm {
|
|
409
488
|
const base = emptyAddressForm(country)
|
|
410
|
-
|
|
489
|
+
const native = Object.fromEntries(
|
|
490
|
+
Object.keys(base).filter(key => key !== "metadata").map(
|
|
491
|
+
key => [key, stringValue(address[key]) || base[key as keyof AddressForm]],
|
|
492
|
+
),
|
|
493
|
+
) as unknown as AddressForm
|
|
494
|
+
return {
|
|
495
|
+
...native,
|
|
496
|
+
metadata: isRecordSafe(address.metadata) ? address.metadata : {},
|
|
497
|
+
...addressDetailsFromRecord(address),
|
|
498
|
+
}
|
|
411
499
|
}
|
|
412
500
|
|
|
413
501
|
function addressLabel(key: keyof Omit<AddressForm, "id">, copy: StorefrontCopy) {
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react"
|
|
4
|
+
import { accountApi } from "@/lib/core/account"
|
|
5
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
6
|
+
|
|
7
|
+
type VerificationStatus = {
|
|
8
|
+
verified: boolean
|
|
9
|
+
retry_after_seconds: number
|
|
10
|
+
resend_available_at: string | null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AccountVerificationPanel({
|
|
14
|
+
api,
|
|
15
|
+
email,
|
|
16
|
+
locale,
|
|
17
|
+
onVerified,
|
|
18
|
+
onLogout,
|
|
19
|
+
}: {
|
|
20
|
+
api: ReturnType<typeof accountApi>
|
|
21
|
+
email: string
|
|
22
|
+
locale: "hu" | "en"
|
|
23
|
+
onVerified: () => Promise<unknown>
|
|
24
|
+
onLogout: () => Promise<unknown>
|
|
25
|
+
}) {
|
|
26
|
+
const en = locale === "en"
|
|
27
|
+
const [code, setCode] = useState("")
|
|
28
|
+
const [retryAt, setRetryAt] = useState<number | null>(null)
|
|
29
|
+
const [now, setNow] = useState(0)
|
|
30
|
+
const [loading, setLoading] = useState(true)
|
|
31
|
+
const [busy, setBusy] = useState<"resend" | "verify" | "logout" | null>(null)
|
|
32
|
+
const [message, setMessage] = useState("")
|
|
33
|
+
const usedLink = useRef("")
|
|
34
|
+
const onVerifiedRef = useRef(onVerified)
|
|
35
|
+
onVerifiedRef.current = onVerified
|
|
36
|
+
|
|
37
|
+
const refreshStatus = useCallback(async () => {
|
|
38
|
+
const result = await api.emailVerificationStatus() as VerificationStatus
|
|
39
|
+
if (result.verified) {
|
|
40
|
+
await onVerifiedRef.current()
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
const millis = result.resend_available_at ? Date.parse(result.resend_available_at) : NaN
|
|
44
|
+
setRetryAt(Number.isFinite(millis) ? millis : null)
|
|
45
|
+
}, [api])
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
void refreshStatus().catch((error) => {
|
|
49
|
+
setMessage(error instanceof Error ? error.message : (en ? "Could not check verification status." : "A megerősítés állapota nem ellenőrizhető."))
|
|
50
|
+
}).finally(() => setLoading(false))
|
|
51
|
+
}, [refreshStatus, en])
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const tick = () => setNow(Date.now())
|
|
55
|
+
tick()
|
|
56
|
+
const timer = window.setInterval(tick, 1000)
|
|
57
|
+
return () => window.clearInterval(timer)
|
|
58
|
+
}, [])
|
|
59
|
+
|
|
60
|
+
const confirm = useCallback(async (value: string) => {
|
|
61
|
+
if (!value.trim()) return
|
|
62
|
+
setBusy("verify")
|
|
63
|
+
setMessage("")
|
|
64
|
+
try {
|
|
65
|
+
await api.confirmEmailVerification(value.trim())
|
|
66
|
+
await onVerifiedRef.current()
|
|
67
|
+
} catch (error) {
|
|
68
|
+
setMessage(error instanceof Error ? error.message : (en ? "Verification failed." : "A megerősítés nem sikerült."))
|
|
69
|
+
} finally {
|
|
70
|
+
setBusy(null)
|
|
71
|
+
}
|
|
72
|
+
}, [api, en])
|
|
73
|
+
|
|
74
|
+
// Links are usable from the same session, or after the customer logs in.
|
|
75
|
+
// Remove the sensitive code from browser history as soon as it is consumed.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
const url = new URL(window.location.href)
|
|
78
|
+
const linkCode = url.searchParams.get("verify_email")
|
|
79
|
+
if (!linkCode || usedLink.current === linkCode) return
|
|
80
|
+
usedLink.current = linkCode
|
|
81
|
+
url.searchParams.delete("verify_email")
|
|
82
|
+
window.history.replaceState(window.history.state, "", url.pathname + url.search + url.hash)
|
|
83
|
+
setCode(linkCode)
|
|
84
|
+
void confirm(linkCode)
|
|
85
|
+
}, [confirm])
|
|
86
|
+
|
|
87
|
+
const retrySeconds = retryAt && now ? Math.max(0, Math.ceil((retryAt - now) / 1000)) : 0
|
|
88
|
+
const countdown = `${Math.floor(retrySeconds / 60).toString().padStart(2, "0")}:${(retrySeconds % 60).toString().padStart(2, "0")}`
|
|
89
|
+
|
|
90
|
+
const resend = async () => {
|
|
91
|
+
if (busy || loading || retrySeconds > 0) return
|
|
92
|
+
setBusy("resend")
|
|
93
|
+
setMessage("")
|
|
94
|
+
try {
|
|
95
|
+
const result = await api.requestEmailVerification() as {
|
|
96
|
+
resend_available_at?: string | null
|
|
97
|
+
retry_after_seconds?: number
|
|
98
|
+
}
|
|
99
|
+
const millis = result.resend_available_at ? Date.parse(result.resend_available_at) : NaN
|
|
100
|
+
setRetryAt(Number.isFinite(millis) ? millis : Date.now() + 600_000)
|
|
101
|
+
setMessage(en ? "A new verification email has been requested." : "Új megerősítő e-mailt kértünk.")
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof CoreApiError && error.status === 429) {
|
|
104
|
+
const payload = error.payload as { retry_after_seconds?: number } | null
|
|
105
|
+
setRetryAt(Date.now() + Math.max(1, Number(payload?.retry_after_seconds ?? 600)) * 1000)
|
|
106
|
+
} else {
|
|
107
|
+
setMessage(error instanceof Error ? error.message : (en ? "Could not resend email." : "Az újraküldés nem sikerült."))
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
setBusy(null)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<section className="panel stack" aria-live="polite">
|
|
116
|
+
<p className="eyebrow">{en ? "Account verification" : "Fiók megerősítése"}</p>
|
|
117
|
+
<h1>{en ? "Your email is not verified yet" : "Az e-mail-címed még nincs megerősítve"}</h1>
|
|
118
|
+
<p>{en
|
|
119
|
+
? `We sent a confirmation link and code to ${email}. Verify your email to use the store.`
|
|
120
|
+
: `Megerősítő linket és kódot küldtünk a(z) ${email} címre. A webshop használatához erősítsd meg az e-mail-címed.`}</p>
|
|
121
|
+
<button className="button secondary" type="button" onClick={() => void resend()} disabled={loading || busy !== null || retrySeconds > 0}>
|
|
122
|
+
{busy === "resend"
|
|
123
|
+
? (en ? "Sending…" : "Küldés…")
|
|
124
|
+
: (en ? "Resend verification email" : "Megerősítő e-mail újraküldése")}
|
|
125
|
+
</button>
|
|
126
|
+
{retrySeconds > 0 ? (
|
|
127
|
+
<p className="muted small" role="status">{en ? `Try again in ${countdown}` : `Újraküldés ${countdown} múlva`}</p>
|
|
128
|
+
) : null}
|
|
129
|
+
<form className="inline-form" onSubmit={(event) => { event.preventDefault(); void confirm(code) }}>
|
|
130
|
+
<label>
|
|
131
|
+
{en ? "Verification code" : "Megerősítő kód"}
|
|
132
|
+
<input autoComplete="one-time-code" value={code} onChange={(event) => setCode(event.target.value)} />
|
|
133
|
+
</label>
|
|
134
|
+
<button className="button" type="submit" disabled={!code.trim() || busy !== null}>
|
|
135
|
+
{en ? "Verify email" : "E-mail megerősítése"}
|
|
136
|
+
</button>
|
|
137
|
+
</form>
|
|
138
|
+
{message ? <p role="status">{message}</p> : null}
|
|
139
|
+
<button className="button secondary" type="button" disabled={busy !== null} onClick={() => {
|
|
140
|
+
setBusy("logout")
|
|
141
|
+
void onLogout().catch((error) => setMessage(error instanceof Error ? error.message : (en ? "Sign out failed." : "A kijelentkezés nem sikerült."))).finally(() => setBusy(null))
|
|
142
|
+
}}>{en ? "Sign out" : "Kijelentkezés"}</button>
|
|
143
|
+
</section>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useId } from "react"
|
|
4
|
+
import { isHungarianAddress, type StructuredAddress } from "@/lib/core/structured-address"
|
|
5
|
+
|
|
6
|
+
type AddressKey = keyof StructuredAddress
|
|
7
|
+
|
|
8
|
+
/** Shared native-Medusa-compatible input for checkout and address book. */
|
|
9
|
+
export function AddressStreetFields({
|
|
10
|
+
address, locale, onChange, errors, onBlur,
|
|
11
|
+
}: {
|
|
12
|
+
address: StructuredAddress
|
|
13
|
+
locale: "hu" | "en"
|
|
14
|
+
onChange: (key: AddressKey, value: string) => void
|
|
15
|
+
errors?: Partial<Record<AddressKey, string>>
|
|
16
|
+
onBlur?: (key: AddressKey) => void
|
|
17
|
+
}) {
|
|
18
|
+
const id = useId()
|
|
19
|
+
const localized = (hu: string, en: string) => locale === "en" ? en : hu
|
|
20
|
+
const field = (key: AddressKey, hu: string, en: string) => {
|
|
21
|
+
const error = errors?.[key]
|
|
22
|
+
return <label key={key}>
|
|
23
|
+
{localized(hu, en)}
|
|
24
|
+
<input type="text" value={address[key]}
|
|
25
|
+
onChange={event => onChange(key, event.target.value)}
|
|
26
|
+
onBlur={() => onBlur?.(key)}
|
|
27
|
+
aria-invalid={Boolean(error)}
|
|
28
|
+
aria-describedby={error ? id + "-" + key : undefined} />
|
|
29
|
+
{error ? <small id={id + "-" + key} role="alert" className="error">{error}</small> : null}
|
|
30
|
+
</label>
|
|
31
|
+
}
|
|
32
|
+
if (!isHungarianAddress(address)) return <div className="form-grid two-col">
|
|
33
|
+
{field("address_1", "Cím első sora *", "Street address *")}
|
|
34
|
+
{field("address_2", "Cím második sora", "Address line 2")}
|
|
35
|
+
</div>
|
|
36
|
+
return <div className="form-grid two-col">
|
|
37
|
+
{field("street_name", "Közterület neve *", "Street name *")}
|
|
38
|
+
{field("street_type", "Közterület típusa * (utca, út, tér…)", "Street type * (street, road, square…)")}
|
|
39
|
+
{field("house_number", "Házszám *", "House number *")}
|
|
40
|
+
{field("house_number_suffix", "Házszám kiegészítés (pl. A)", "House number suffix (e.g. A)")}
|
|
41
|
+
{field("building", "Épület (opcionális)", "Building (optional)")}
|
|
42
|
+
{field("staircase", "Lépcsőház (opcionális)", "Staircase (optional)")}
|
|
43
|
+
{field("floor", "Emelet (opcionális)", "Floor (optional)")}
|
|
44
|
+
{field("door", "Ajtó (opcionális)", "Door (optional)")}
|
|
45
|
+
{field("address_extra", "Egyéb címadat (opcionális)", "Additional address information (optional)")}
|
|
46
|
+
</div>
|
|
47
|
+
}
|