@hszrdm/create-commerce 1.19.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 +15 -24
- package/templates/backend/medusa-config.ts +14 -1
- package/templates/backend/package.json +1 -1
- 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 +56 -19
- package/templates/storefront/src/components/account-verification-panel.tsx +145 -0
- package/templates/storefront/src/components/checkout-flow.tsx +63 -19
- 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-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/use-checkout-feedback.ts +53 -0
- package/templates/storefront/tests/account-verification.test.mjs +40 -0
- package/templates/storefront/tests/checkout-feedback.test.mjs +27 -0
- package/templates/storefront/tests/product-image.test.mjs +31 -0
package/package.json
CHANGED
|
@@ -271,27 +271,25 @@ SHIPPING_STATUS_SYNC_BATCH_SIZE=100
|
|
|
271
271
|
# Prefer Admin -> Settings -> Integrációk.
|
|
272
272
|
# -----------------------------------------------------------------------------
|
|
273
273
|
FOXPOST_ENABLED=false
|
|
274
|
-
#
|
|
274
|
+
# FOXPOST transport: operator-owned ENV only, never editable in Admin.
|
|
275
|
+
# A blank FOXPOST_SANDBOX follows APP_ENV (production=false, other=true).
|
|
275
276
|
# Egyedi környezetben itt felülírható.
|
|
276
277
|
FOXPOST_API_URL=
|
|
277
278
|
FOXPOST_API_USERNAME=
|
|
278
279
|
FOXPOST_API_PASSWORD=
|
|
279
280
|
FOXPOST_API_KEY=
|
|
280
|
-
FOXPOST_SANDBOX=
|
|
281
|
+
FOXPOST_SANDBOX=
|
|
281
282
|
# Fixed FOXPOST parcel size sent during Create Fulfillment (XS/S/M/L/XL); default M.
|
|
282
283
|
FOXPOST_PACKAGE_SIZE=M
|
|
283
284
|
FOXPOST_LOCKER_FEED_URL=https://cdn.foxpost.hu/foxplus.json
|
|
284
|
-
FOXPOST_LOCKER_PRICE_HUF=1290
|
|
285
|
-
FOXPOST_HOME_DELIVERY_PRICE_HUF=1990
|
|
286
|
-
FOXPOST_FREE_SHIPPING_THRESHOLD_HUF=
|
|
287
285
|
FOXPOST_TIMEOUT_MS=10000
|
|
288
286
|
|
|
289
287
|
GLS_ENABLED=false
|
|
290
|
-
GLS_API_URL=https://api.
|
|
288
|
+
GLS_API_URL=https://api.mygls.hu
|
|
291
289
|
GLS_USERNAME=
|
|
292
290
|
GLS_PASSWORD=
|
|
293
291
|
GLS_CLIENT_NUMBER=
|
|
294
|
-
GLS_SANDBOX=
|
|
292
|
+
GLS_SANDBOX=false
|
|
295
293
|
GLS_DELIVERY_POINTS_URL=https://map.gls-hungary.com/data/deliveryPoints/hu.json
|
|
296
294
|
GLS_POINT_PRICE_HUF=1490
|
|
297
295
|
GLS_HOME_DELIVERY_PRICE_HUF=1990
|
|
@@ -320,9 +318,9 @@ PACKETA_API_KEY=
|
|
|
320
318
|
PACKETA_API_PASSWORD=
|
|
321
319
|
PACKETA_SENDER_INDICATION=
|
|
322
320
|
PACKETA_HOME_CARRIER_ID=
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
# Optional JSON map of destination country to contracted Packeta HOME carrier ID.
|
|
322
|
+
PACKETA_HOME_CARRIER_IDS=
|
|
323
|
+
# Technical, fixed at server deployment; not mutable from Admin.
|
|
326
324
|
PACKETA_TIMEOUT_MS=15000
|
|
327
325
|
PACKETA_DEFAULT_WEIGHT_KG=1
|
|
328
326
|
PACKETA_LABEL_FORMAT=A6 on A6
|
|
@@ -331,8 +329,10 @@ PACKETA_LANGUAGE=hu
|
|
|
331
329
|
# raw body and timestamp are mandatory. Rotate separately from other webhook secrets.
|
|
332
330
|
PACKETA_WEBHOOK_SIGNING_KEY=
|
|
333
331
|
|
|
332
|
+
# DPD technical settings are deployment-controlled. Blank sandbox follows APP_ENV.
|
|
333
|
+
# Shipping prices are fixed Medusa Shipping Options, not DPD ENV fields.
|
|
334
334
|
DPD_ENABLED=false
|
|
335
|
-
DPD_SANDBOX=
|
|
335
|
+
DPD_SANDBOX=
|
|
336
336
|
DPD_API_URL=
|
|
337
337
|
DPD_TOKEN=
|
|
338
338
|
DPD_BU_CODE=
|
|
@@ -346,9 +346,6 @@ DPD_PUDO_LOCATOR_URL=
|
|
|
346
346
|
DPD_PUDO_DELIS_ID=
|
|
347
347
|
DPD_PUDO_PASSWORD=
|
|
348
348
|
DPD_PUDO_MESSAGE_LANGUAGE=en_US
|
|
349
|
-
DPD_POINT_PRICE_HUF=1490
|
|
350
|
-
DPD_HOME_DELIVERY_PRICE_HUF=1990
|
|
351
|
-
DPD_FREE_SHIPPING_THRESHOLD_HUF=
|
|
352
349
|
DPD_TIMEOUT_MS=15000
|
|
353
350
|
DPD_DEFAULT_WEIGHT_KG=1
|
|
354
351
|
DPD_LABEL_SIZE=A6
|
|
@@ -398,18 +395,12 @@ MPL_TRACKING_ACCOUNT_CODE=
|
|
|
398
395
|
MPL_PUSH_READ_WINDOW_MS=8000
|
|
399
396
|
MPL_TRACKING_LANGUAGE=hu
|
|
400
397
|
|
|
401
|
-
|
|
402
|
-
|
|
398
|
+
# Csomagpiac technical transport is operator-owned; credentials, sender ID,
|
|
399
|
+
# label format and service profiles are configured in the encrypted Admin DB.
|
|
400
|
+
# Leave CSOMAGPIAC_LIVE unset to follow APP_ENV automatically.
|
|
401
|
+
CSOMAGPIAC_LIVE=
|
|
403
402
|
CSOMAGPIAC_API_URL=
|
|
404
|
-
CSOMAGPIAC_TOKEN=
|
|
405
|
-
CSOMAGPIAC_USERNAME=
|
|
406
|
-
CSOMAGPIAC_PASSWORD=
|
|
407
|
-
CSOMAGPIAC_PICKUP_POINT_ID=
|
|
408
|
-
CSOMAGPIAC_PRICE_HUF=1990
|
|
409
|
-
CSOMAGPIAC_FREE_SHIPPING_THRESHOLD_HUF=
|
|
410
403
|
CSOMAGPIAC_TIMEOUT_MS=15000
|
|
411
|
-
CSOMAGPIAC_DEFAULT_WEIGHT_KG=1
|
|
412
|
-
CSOMAGPIAC_LABEL_FORMAT=A4
|
|
413
404
|
|
|
414
405
|
# -----------------------------------------------------------------------------
|
|
415
406
|
# Product feeds / trust widgets - optional
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename, dirname, resolve } from "node:path"
|
|
1
2
|
import { loadEnv } from "@medusajs/framework/utils"
|
|
2
3
|
import { createHszrdmCommerceConfig } from "@hszrdm/core/config"
|
|
3
4
|
|
|
@@ -6,7 +7,19 @@ const envFile =
|
|
|
6
7
|
? "test"
|
|
7
8
|
: process.env.NODE_ENV || "development"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
// In a production build, Medusa starts inside backend/.medusa/server.
|
|
11
|
+
// Read the original backend env file, not a generated directory that is
|
|
12
|
+
// replaced on every build. Development and test working directories are kept.
|
|
13
|
+
const cwd = process.cwd()
|
|
14
|
+
const runningFromBuiltServer =
|
|
15
|
+
basename(cwd) === "server" &&
|
|
16
|
+
basename(dirname(cwd)) === ".medusa"
|
|
17
|
+
|
|
18
|
+
const envRoot = runningFromBuiltServer
|
|
19
|
+
? resolve(cwd, "../..")
|
|
20
|
+
: cwd
|
|
21
|
+
|
|
22
|
+
loadEnv(envFile, envRoot)
|
|
10
23
|
|
|
11
24
|
const baseConfig = createHszrdmCommerceConfig()
|
|
12
25
|
const configuredPlugins = (
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ExecArgs } from "@medusajs/framework/types"
|
|
2
2
|
import coreInit from "@hszrdm/core/scripts/core-init"
|
|
3
3
|
import ensureLocales from "@hszrdm/core/scripts/ensure-locales"
|
|
4
|
-
import ensureShipping from "@hszrdm/core/scripts/ensure-shipping"
|
|
5
4
|
import { normalizeMedusaExecArgs } from "@hszrdm/core/scripts/exec-args"
|
|
6
5
|
|
|
7
6
|
export default async function runCoreInit(params: ExecArgs) {
|
|
@@ -28,8 +27,4 @@ export default async function runCoreInit(params: ExecArgs) {
|
|
|
28
27
|
args: [],
|
|
29
28
|
})
|
|
30
29
|
|
|
31
|
-
await ensureShipping({
|
|
32
|
-
...params,
|
|
33
|
-
args: [],
|
|
34
|
-
})
|
|
35
30
|
}
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"test:stripe": "node --experimental-strip-types --test tests/stripe-checkout-phase.test.mjs",
|
|
15
15
|
"test:company-tax": "node --experimental-strip-types --test tests/company-tax.test.mjs",
|
|
16
16
|
"test:ga4": "node --experimental-strip-types --test tests/ga4-bootstrap.test.mjs",
|
|
17
|
-
"test:seo": "node --experimental-strip-types --test tests/technical-seo.test.mjs"
|
|
17
|
+
"test:seo": "node --experimental-strip-types --test tests/technical-seo.test.mjs",
|
|
18
|
+
"test:account-verification": "node --test tests/account-verification.test.mjs",
|
|
19
|
+
"test:product-images": "node --experimental-strip-types --test tests/product-image.test.mjs"
|
|
18
20
|
},
|
|
19
21
|
"dependencies": {
|
|
20
22
|
"@stripe/react-stripe-js": "7.0.0",
|
|
@@ -11,7 +11,7 @@ import { WishlistButton } from "@/components/wishlist-button"
|
|
|
11
11
|
import { getCoreConfig } from "@/lib/core/client"
|
|
12
12
|
import { checkoutApi } from "@/lib/core/checkout"
|
|
13
13
|
import { getProductByHandle } from "@/lib/core/catalog"
|
|
14
|
-
import { asRecords, productVariantCurrency, productVariantPriceBreakdown, stringValue } from "@/lib/core/commerce"
|
|
14
|
+
import { asRecords, productImageUrl, productVariantCurrency, productVariantPriceBreakdown, stringValue } from "@/lib/core/commerce"
|
|
15
15
|
import { googleAdsRemarketingItemFromProduct } from "@/lib/core/google-ads"
|
|
16
16
|
import { metadataFromCore, serializeJsonLd, structuredDataForEntity } from "@/lib/core/seo"
|
|
17
17
|
import { ecommerceItemFromProduct } from "@/lib/core/tracking"
|
|
@@ -49,7 +49,7 @@ export default async function ProductPage({ params }: { params: Promise<{ countr
|
|
|
49
49
|
const images = asRecords(product.images)
|
|
50
50
|
const productId = stringValue(product.id)
|
|
51
51
|
const title = stringValue(product.title)
|
|
52
|
-
const thumbnail =
|
|
52
|
+
const thumbnail = productImageUrl(product)
|
|
53
53
|
const formatLocale = locale === "en" ? "en-US" : "hu-HU"
|
|
54
54
|
const galleryImages = [
|
|
55
55
|
...(thumbnail ? [{ id: "thumbnail", url: thumbnail, alt: title }] : []),
|
|
@@ -8,6 +8,7 @@ import { AnalyticsGate } from "@/components/analytics"
|
|
|
8
8
|
import { ArukeresoBacklink } from "@/components/arukereso-backlink"
|
|
9
9
|
import { ArukeresoTrustedShopWidget } from "@/components/arukereso-trusted-shop-widget"
|
|
10
10
|
import { CartProvider } from "@/components/cart-provider"
|
|
11
|
+
import { AccountAccessGate } from "@/components/account-access-gate"
|
|
11
12
|
import { ConsentBanner } from "@/components/consent-banner"
|
|
12
13
|
import { CustomerCartResumeGate } from "@/components/customer-cart-resume-gate"
|
|
13
14
|
import { GoogleAdsCartRemarketing } from "@/components/google-ads-cart-remarketing"
|
|
@@ -70,6 +71,10 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
70
71
|
<AccessibilityPreferencesProvider>
|
|
71
72
|
<ToastProvider locale={locale}>
|
|
72
73
|
<CartProvider config={config}>
|
|
74
|
+
<AccountAccessGate
|
|
75
|
+
config={config}
|
|
76
|
+
restrictedChildren={<main id="main-content" className="shell main" tabIndex={-1}>{children}</main>}
|
|
77
|
+
>
|
|
73
78
|
<GoogleAdsCartRemarketing googleAds={config.marketing.google_ads} />
|
|
74
79
|
<a className="skip-link" href="#main-content">
|
|
75
80
|
{en ? "Skip to content" : "Ugrás a tartalomhoz"}
|
|
@@ -107,6 +112,7 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
107
112
|
{fogyasztobarat.enabled && fogyasztobarat.placement === "global" ? (
|
|
108
113
|
<FogyasztobaratEmbed embed={fogyasztobarat} />
|
|
109
114
|
) : null}
|
|
115
|
+
</AccountAccessGate>
|
|
110
116
|
</CartProvider>
|
|
111
117
|
</ToastProvider>
|
|
112
118
|
</AccessibilityPreferencesProvider>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"
|
|
4
|
+
import { usePathname, useRouter } from "next/navigation"
|
|
5
|
+
import {
|
|
6
|
+
ACCOUNT_AUTH_CHANGED_EVENT,
|
|
7
|
+
accountApi,
|
|
8
|
+
isAccountEmailVerified,
|
|
9
|
+
} from "@/lib/core/account"
|
|
10
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
11
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
12
|
+
|
|
13
|
+
type AccountAccessState = "guest" | "checking" | "verified" | "unverified" | "error"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Public pages stay SSR-rendered for search engines. Once hydrated, a signed-in
|
|
17
|
+
* unverified customer is redirected to the profile-only verification view.
|
|
18
|
+
* Authorization itself is enforced on the Core Store API, never by this UI.
|
|
19
|
+
*/
|
|
20
|
+
export function AccountAccessGate({
|
|
21
|
+
config,
|
|
22
|
+
children,
|
|
23
|
+
restrictedChildren,
|
|
24
|
+
}: {
|
|
25
|
+
config: CoreConfig
|
|
26
|
+
children: ReactNode
|
|
27
|
+
restrictedChildren: ReactNode
|
|
28
|
+
}) {
|
|
29
|
+
const api = useMemo(() => accountApi(config), [config])
|
|
30
|
+
const pathname = usePathname()
|
|
31
|
+
const router = useRouter()
|
|
32
|
+
const [state, setState] = useState<AccountAccessState>("guest")
|
|
33
|
+
const requestId = useRef(0)
|
|
34
|
+
|
|
35
|
+
const refresh = useCallback(async () => {
|
|
36
|
+
const current = ++requestId.current
|
|
37
|
+
try {
|
|
38
|
+
const { customer } = await api.profile()
|
|
39
|
+
if (requestId.current !== current) return
|
|
40
|
+
setState(isAccountEmailVerified(customer) ? "verified" : "unverified")
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (requestId.current !== current) return
|
|
43
|
+
if (error instanceof CoreApiError && error.status === 401) {
|
|
44
|
+
setState("guest")
|
|
45
|
+
} else {
|
|
46
|
+
setState("error")
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [api])
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
void refresh()
|
|
53
|
+
const authChanged = () => {
|
|
54
|
+
setState("checking")
|
|
55
|
+
void refresh()
|
|
56
|
+
}
|
|
57
|
+
window.addEventListener(ACCOUNT_AUTH_CHANGED_EVENT, authChanged)
|
|
58
|
+
return () => {
|
|
59
|
+
requestId.current++
|
|
60
|
+
window.removeEventListener(ACCOUNT_AUTH_CHANGED_EVENT, authChanged)
|
|
61
|
+
}
|
|
62
|
+
}, [refresh])
|
|
63
|
+
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (state === "unverified" && pathname !== "/account") {
|
|
66
|
+
router.replace("/account")
|
|
67
|
+
}
|
|
68
|
+
}, [state, pathname, router])
|
|
69
|
+
|
|
70
|
+
if (state === "checking" || (state === "unverified" && pathname !== "/account")) {
|
|
71
|
+
return <main className="shell main" role="status">A fiók ellenőrzése…</main>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (state === "error") {
|
|
75
|
+
return (
|
|
76
|
+
<main className="shell main">
|
|
77
|
+
<section className="panel stack">
|
|
78
|
+
<h1>A fiók állapota nem ellenőrizhető</h1>
|
|
79
|
+
<p>Próbáld meg újra. A megerősítés ellenőrzése nélkül a fiók nem használható.</p>
|
|
80
|
+
<button className="button" type="button" onClick={() => { setState("checking"); void refresh() }}>Újrapróbálkozás</button>
|
|
81
|
+
</section>
|
|
82
|
+
</main>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (state === "unverified") return <>{restrictedChildren}</>
|
|
87
|
+
return <>{children}</>
|
|
88
|
+
}
|
|
@@ -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"
|
|
@@ -52,6 +53,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
52
53
|
const [busy, setBusy] = useState<string | null>(null)
|
|
53
54
|
const [error, setError] = useState<string | null>(null)
|
|
54
55
|
const [message, setMessage] = useState<string | null>(null)
|
|
56
|
+
const [accountNotice, setAccountNotice] = useState<{ tone: "success" | "error"; text: string } | null>(null)
|
|
55
57
|
const [mode, setMode] = useState<AuthMode>("login")
|
|
56
58
|
const [tab, setTab] = useState<AccountTab>("profile")
|
|
57
59
|
const [email, setEmail] = useState("")
|
|
@@ -76,6 +78,22 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
76
78
|
useEffect(() => {
|
|
77
79
|
void refresh().catch(() => setCustomer(null)).finally(() => setLoading(false))
|
|
78
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
|
+
|
|
79
97
|
|
|
80
98
|
const authSubmit = async (event: FormEvent) => {
|
|
81
99
|
event.preventDefault()
|
|
@@ -95,8 +113,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
95
113
|
return
|
|
96
114
|
}
|
|
97
115
|
if (mode === "register") {
|
|
98
|
-
await api.register({ email, password, first_name: firstName, last_name: lastName })
|
|
99
|
-
|
|
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
|
+
}
|
|
100
120
|
await refresh()
|
|
101
121
|
setMessage(
|
|
102
122
|
localized(
|
|
@@ -108,8 +128,10 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
108
128
|
return
|
|
109
129
|
}
|
|
110
130
|
await api.login(email, password)
|
|
111
|
-
await
|
|
112
|
-
|
|
131
|
+
const signedIn = await refresh()
|
|
132
|
+
if (signedIn && isAccountEmailVerified(signedIn)) {
|
|
133
|
+
await transferToCustomer().catch(() => undefined)
|
|
134
|
+
}
|
|
113
135
|
setPassword("")
|
|
114
136
|
} catch (cause) {
|
|
115
137
|
setError(
|
|
@@ -122,6 +144,18 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
122
144
|
}
|
|
123
145
|
}
|
|
124
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
|
+
|
|
125
159
|
if (loading) return <div className="empty-state">{copy.accountLoading}</div>
|
|
126
160
|
|
|
127
161
|
if (!customer) {
|
|
@@ -162,6 +196,20 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
162
196
|
)
|
|
163
197
|
}
|
|
164
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
|
+
|
|
165
213
|
return (
|
|
166
214
|
<div className="account-layout">
|
|
167
215
|
<aside className="account-sidebar panel">
|
|
@@ -181,6 +229,7 @@ export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
|
181
229
|
</aside>
|
|
182
230
|
|
|
183
231
|
<main className="stack">
|
|
232
|
+
{accountNotice ? <p role="status" className={accountNotice.tone === "error" ? "error" : "success"}>{accountNotice.text}</p> : null}
|
|
184
233
|
{tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} copy={copy} locale={locale} /> : null}
|
|
185
234
|
{tab === "addresses" ? <AddressesSection config={config} api={api} copy={copy} locale={locale} /> : null}
|
|
186
235
|
{tab === "orders" ? <OrdersSection config={config} api={api} copy={copy} locale={locale} /> : null}
|
|
@@ -210,10 +259,7 @@ function ProfileSection({
|
|
|
210
259
|
const [first, setFirst] = useState(stringValue(customer.first_name))
|
|
211
260
|
const [last, setLast] = useState(stringValue(customer.last_name))
|
|
212
261
|
const [phone, setPhone] = useState(stringValue(customer.phone))
|
|
213
|
-
const [code, setCode] = useState("")
|
|
214
262
|
const [message, setMessage] = useState<string | null>(null)
|
|
215
|
-
const metadata = isRecordSafe(customer.metadata) ? customer.metadata : {}
|
|
216
|
-
const verified = metadata.email_verified === true
|
|
217
263
|
|
|
218
264
|
return (
|
|
219
265
|
<>
|
|
@@ -238,18 +284,9 @@ function ProfileSection({
|
|
|
238
284
|
|
|
239
285
|
<section className="panel stack-sm">
|
|
240
286
|
<div className="section-title-row">
|
|
241
|
-
<div><p className="eyebrow">{copy.email}</p><h2>{
|
|
242
|
-
<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>
|
|
243
289
|
</div>
|
|
244
|
-
{!verified ? (
|
|
245
|
-
<>
|
|
246
|
-
<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>
|
|
247
|
-
<div className="inline-form">
|
|
248
|
-
<input value={code} onChange={(e) => setCode(e.target.value)} placeholder={copy.verificationCode} />
|
|
249
|
-
<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>
|
|
250
|
-
</div>
|
|
251
|
-
</>
|
|
252
|
-
) : null}
|
|
253
290
|
</section>
|
|
254
291
|
</>
|
|
255
292
|
)
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useCallback, useEffect, useMemo, useRef, useState, useId } from "react"
|
|
3
|
+
import { Fragment, useCallback, useEffect, useMemo, useRef, useState, useId } from "react"
|
|
4
4
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
|
5
5
|
import { useCart } from "./cart-provider"
|
|
6
6
|
import { AddressStreetFields } from "./address-street-fields"
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
CART_STRUCTURED_ADDRESSES_KEY, isHungarianAddress, missingAddressParts,
|
|
10
10
|
} from "@/lib/core/structured-address"
|
|
11
11
|
import { StripePayment } from "./stripe-payment"
|
|
12
|
+
import { useCheckoutFeedback } from "@/lib/core/use-checkout-feedback"
|
|
12
13
|
import { stripeCheckoutPhase } from "@/lib/core/stripe-checkout-phase"
|
|
13
14
|
import { carrierPointToShippingData, type CarrierPickupPoint } from "./carrier-pickup-map"
|
|
14
15
|
import { CarrierPickupDialog } from "./carrier-pickup-dialog"
|
|
@@ -118,13 +119,13 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
118
119
|
const [pickupDialogOpen, setPickupDialogOpen] = useState(false)
|
|
119
120
|
const [providers, setProviders] = useState<JsonRecord[]>([])
|
|
120
121
|
const [selectedProvider, setSelectedProvider] = useState("")
|
|
122
|
+
const [selectedPaymentMode, setSelectedPaymentMode] = useState<"cod" | "bank_transfer" | "online">("online")
|
|
121
123
|
const [preparedCart, setPreparedCart] = useState<JsonRecord | null>(null)
|
|
122
124
|
const [stripeInitError, setStripeInitError] = useState<string | null>(null)
|
|
123
125
|
const [legalDocs, setLegalDocs] = useState<LegalDocument[]>([])
|
|
124
126
|
const [accepted, setAccepted] = useState<Record<string, boolean>>({})
|
|
125
127
|
const [busy, setBusy] = useState<string | null>(null)
|
|
126
|
-
const
|
|
127
|
-
const [message, setMessage] = useState<string | null>(null)
|
|
128
|
+
const { error, setError, setMessage } = useCheckoutFeedback(cartError)
|
|
128
129
|
|
|
129
130
|
const setBillingTaxDefaults = useCallback((
|
|
130
131
|
cartData: JsonRecord,
|
|
@@ -616,6 +617,11 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
616
617
|
const verifiedPoint = await verifyCarrierPickupPoint(kind, selectedPickupPoint)
|
|
617
618
|
const data = shippingData(kind, verifiedPoint, locale)
|
|
618
619
|
const result = await api.addShippingMethod(cartId, optionId, data)
|
|
620
|
+
// Shipping choice invalidates the previously selected payment and its fee.
|
|
621
|
+
await api.markPaymentMode(cartId, "online", "online")
|
|
622
|
+
setSelectedProvider("")
|
|
623
|
+
setSelectedPaymentMode("online")
|
|
624
|
+
setPreparedCart(null)
|
|
619
625
|
await refresh(cartId)
|
|
620
626
|
await loadProviders(result.cart)
|
|
621
627
|
setMessage(localized(locale, "Szállítási mód kiválasztva.", "Shipping method selected."))
|
|
@@ -630,7 +636,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
630
636
|
}
|
|
631
637
|
}
|
|
632
638
|
|
|
633
|
-
const preparePayment = async (id: string) => {
|
|
639
|
+
const preparePayment = async (id: string, mode: "cod" | "bank_transfer" | "online") => {
|
|
634
640
|
if (!addressOnCart) {
|
|
635
641
|
setError(localized(locale,
|
|
636
642
|
"Előbb mentsd a szállítási és számlázási címet.",
|
|
@@ -645,7 +651,10 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
645
651
|
setStripeInitError(null)
|
|
646
652
|
setPreparedCart(null)
|
|
647
653
|
setSelectedProvider(id)
|
|
654
|
+
setSelectedPaymentMode(mode)
|
|
648
655
|
try {
|
|
656
|
+
// Apply the surcharge and refresh any existing collection BEFORE creating a payment session.
|
|
657
|
+
await api.markPaymentMode(cartId, id, mode)
|
|
649
658
|
let current = (await api.getCart(cartId)).cart
|
|
650
659
|
let collection = cartPaymentCollection(current)
|
|
651
660
|
let collectionId = stringValue(collection?.id)
|
|
@@ -669,6 +678,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
669
678
|
setMessage(copy.paymentPrepared)
|
|
670
679
|
} catch (cause) {
|
|
671
680
|
setPreparedCart(null)
|
|
681
|
+
setSelectedProvider("")
|
|
672
682
|
const message = cause instanceof Error
|
|
673
683
|
? cause.message
|
|
674
684
|
: localized(locale, "A fizetési mód nem készíthető elő.", "The payment method could not be prepared.")
|
|
@@ -727,6 +737,21 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
727
737
|
const simplePaySelected = activeProviderId.toLowerCase().includes("simplepay")
|
|
728
738
|
const systemSelected = activeProviderId.toLowerCase().includes("system")
|
|
729
739
|
const currency = cartCurrency(cart, config.store.default_currency)
|
|
740
|
+
const selectedMethod = asRecords(cart.shipping_methods)[0]
|
|
741
|
+
const activeShippingOption = shippingOptions.find(option =>
|
|
742
|
+
stringValue(option.id) === stringValue(selectedMethod?.shipping_option_id))
|
|
743
|
+
const optionData = isRecord(activeShippingOption?.data) ? activeShippingOption.data : {}
|
|
744
|
+
const selectedShippingData = isRecord(selectedMethod?.data) ? selectedMethod.data : {}
|
|
745
|
+
const csomagpiacData = isRecord(selectedShippingData.csomagpiac) ? selectedShippingData.csomagpiac : {}
|
|
746
|
+
const codAvailable = currency === "HUF" &&
|
|
747
|
+
activeShippingOption?.price_type === "flat" &&
|
|
748
|
+
csomagpiacData.codEnabled !== false &&
|
|
749
|
+
(optionData.hszrdm_cod_enabled === true ||
|
|
750
|
+
(optionData.hszrdm_cod_enabled === undefined && optionData.cod === true)) &&
|
|
751
|
+
asRecords(cart.shipping_methods).length === 1
|
|
752
|
+
const appliedCodFee = shippingMethodIsCod(cart)
|
|
753
|
+
? Number(selectedShippingData.hszrdm_cod_applied_fee_huf || 0)
|
|
754
|
+
: 0
|
|
730
755
|
|
|
731
756
|
return (
|
|
732
757
|
<div className="checkout-layout">
|
|
@@ -1009,18 +1034,33 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
1009
1034
|
<div className="choice-list">
|
|
1010
1035
|
{providers.map((provider) => {
|
|
1011
1036
|
const id = stringValue(provider.id)
|
|
1012
|
-
const
|
|
1037
|
+
const system = id.toLowerCase().includes("system")
|
|
1038
|
+
const normalMode = system ? "bank_transfer" : "online"
|
|
1013
1039
|
return (
|
|
1014
|
-
<
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1040
|
+
<Fragment key={id}>
|
|
1041
|
+
{system && codAvailable ? (
|
|
1042
|
+
<button
|
|
1043
|
+
className={`choice-card choice-button${selectedProvider === id && selectedPaymentMode === "cod" ? " selected" : ""}`}
|
|
1044
|
+
type="button"
|
|
1045
|
+
disabled={busy === "payment" || !addressOnCart}
|
|
1046
|
+
onClick={() => void preparePayment(id, "cod")}
|
|
1047
|
+
>
|
|
1048
|
+
<strong>{localized(locale, "Utánvét", "Cash on delivery")}</strong>
|
|
1049
|
+
<small>{localized(locale, "Fizetés kézbesítéskor", "Pay on delivery")}</small>
|
|
1050
|
+
</button>
|
|
1051
|
+
) : null}
|
|
1052
|
+
{(!system || config.payments.bank_transfer.enabled) ? (
|
|
1053
|
+
<button
|
|
1054
|
+
className={`choice-card choice-button${selectedProvider === id && selectedPaymentMode === normalMode ? " selected" : ""}`}
|
|
1055
|
+
type="button"
|
|
1056
|
+
disabled={busy === "payment" || !addressOnCart}
|
|
1057
|
+
onClick={() => void preparePayment(id, normalMode)}
|
|
1058
|
+
>
|
|
1059
|
+
<strong>{providerLabel(id, false)}</strong>
|
|
1060
|
+
<small>{id}</small>
|
|
1061
|
+
</button>
|
|
1062
|
+
) : null}
|
|
1063
|
+
</Fragment>
|
|
1024
1064
|
)
|
|
1025
1065
|
})}
|
|
1026
1066
|
</div>
|
|
@@ -1051,7 +1091,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
1051
1091
|
className="button secondary"
|
|
1052
1092
|
type="button"
|
|
1053
1093
|
disabled={busy === "payment" || !addressOnCart}
|
|
1054
|
-
onClick={() => void preparePayment(activeProviderId)}
|
|
1094
|
+
onClick={() => void preparePayment(activeProviderId, "online")}
|
|
1055
1095
|
>
|
|
1056
1096
|
{localized(locale, "Stripe fizetés újrapróbálása", "Retry Stripe payment")}
|
|
1057
1097
|
</button>
|
|
@@ -1100,7 +1140,7 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
1100
1140
|
>
|
|
1101
1141
|
{busy === "complete"
|
|
1102
1142
|
? copy.orderSubmitting
|
|
1103
|
-
: shippingMethodIsCod(cart)
|
|
1143
|
+
: (selectedPaymentMode === "cod" || (!selectedProvider && shippingMethodIsCod(cart)))
|
|
1104
1144
|
? copy.orderSubmitCod
|
|
1105
1145
|
: copy.orderSubmit}
|
|
1106
1146
|
</button>
|
|
@@ -1132,8 +1172,6 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
1132
1172
|
)}
|
|
1133
1173
|
</section>
|
|
1134
1174
|
|
|
1135
|
-
{message ? <div className="notice success-box">{message}</div> : null}
|
|
1136
|
-
{error || cartError ? <div className="notice error-box">{error || cartError}</div> : null}
|
|
1137
1175
|
{(stripeReturn || simplePayReturn) && error ? (
|
|
1138
1176
|
<button
|
|
1139
1177
|
className="button secondary"
|
|
@@ -1162,6 +1200,12 @@ export function CheckoutFlow({ config }: { config: CoreConfig }) {
|
|
|
1162
1200
|
<span>{typeof item.total === "number" ? formatMoney(item.total, currency, numberLocale) : ""}</span>
|
|
1163
1201
|
</div>
|
|
1164
1202
|
))}
|
|
1203
|
+
{appliedCodFee > 0 && Number.isFinite(appliedCodFee) ? (
|
|
1204
|
+
<div className="summary-line">
|
|
1205
|
+
<span>{localized(locale, "Ebből utánvét kezelési díj", "Including COD handling fee")}</span>
|
|
1206
|
+
<span>{formatMoney(appliedCodFee, currency, numberLocale)}</span>
|
|
1207
|
+
</div>
|
|
1208
|
+
) : null}
|
|
1165
1209
|
<div className="summary-total">
|
|
1166
1210
|
<span>{copy.total}</span>
|
|
1167
1211
|
<strong>{formatMoney(cartTotal(cart), currency, numberLocale)}</strong>
|
|
@@ -3,6 +3,7 @@ import { PriceDisplay } from "./price-display"
|
|
|
3
3
|
import {
|
|
4
4
|
asRecords,
|
|
5
5
|
isRecord,
|
|
6
|
+
productImageUrl,
|
|
6
7
|
productVariantPriceBreakdown,
|
|
7
8
|
stringValue,
|
|
8
9
|
} from "@/lib/core/commerce"
|
|
@@ -27,7 +28,7 @@ export function ProductCard({
|
|
|
27
28
|
const formatLocale = activeLocale === "en" ? "en-US" : "hu-HU"
|
|
28
29
|
const copy = storefrontCopy(activeLocale)
|
|
29
30
|
const href = productPath(activeLocale, handle)
|
|
30
|
-
const thumbnail =
|
|
31
|
+
const thumbnail = productImageUrl(product)
|
|
31
32
|
const categories = asRecords(product.categories)
|
|
32
33
|
const title = stringValue(product.title)
|
|
33
34
|
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { endpoint, medusaFetch } from "./client"
|
|
2
2
|
import type { CoreConfig } from "./types"
|
|
3
|
+
|
|
4
|
+
export function isAccountEmailVerified(customer: Record<string, unknown>) {
|
|
5
|
+
const metadata = customer.metadata
|
|
6
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) return false
|
|
7
|
+
const state = metadata as Record<string, unknown>
|
|
8
|
+
const email = String(customer.email ?? "").trim().toLowerCase()
|
|
9
|
+
return Boolean(email) && state.email_verified === true
|
|
10
|
+
&& String(state.email_verified_address ?? "").trim().toLowerCase() === email
|
|
11
|
+
}
|
|
3
12
|
import { mergeGuestWishlistAfterLogin } from "./wishlist"
|
|
4
13
|
|
|
14
|
+
export const ACCOUNT_AUTH_CHANGED_EVENT = "hszrdm:account-auth-changed"
|
|
15
|
+
function notifyAuthChanged() {
|
|
16
|
+
if (typeof window !== "undefined") window.dispatchEvent(new Event(ACCOUNT_AUTH_CHANGED_EVENT))
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
export function accountApi(config: CoreConfig) {
|
|
6
20
|
const paths = config.account.endpoints
|
|
7
21
|
|
|
@@ -53,8 +67,12 @@ export function accountApi(config: CoreConfig) {
|
|
|
53
67
|
method: "POST",
|
|
54
68
|
headers: { Authorization: `Bearer ${login.token}` },
|
|
55
69
|
})
|
|
56
|
-
await
|
|
57
|
-
|
|
70
|
+
const result = await profile()
|
|
71
|
+
notifyAuthChanged()
|
|
72
|
+
if (isAccountEmailVerified(result.customer)) {
|
|
73
|
+
await mergeGuestWishlistAfterLogin().catch(() => undefined)
|
|
74
|
+
}
|
|
75
|
+
return result
|
|
58
76
|
},
|
|
59
77
|
|
|
60
78
|
login: async (email: string, password: string) => {
|
|
@@ -66,11 +84,19 @@ export function accountApi(config: CoreConfig) {
|
|
|
66
84
|
method: "POST",
|
|
67
85
|
headers: { Authorization: `Bearer ${result.token}` },
|
|
68
86
|
})
|
|
69
|
-
await
|
|
87
|
+
const current = await profile().catch(() => null)
|
|
88
|
+
if (current?.customer && isAccountEmailVerified(current.customer)) {
|
|
89
|
+
await mergeGuestWishlistAfterLogin().catch(() => undefined)
|
|
90
|
+
}
|
|
91
|
+
notifyAuthChanged()
|
|
70
92
|
return result
|
|
71
93
|
},
|
|
72
94
|
|
|
73
|
-
logout: () =>
|
|
95
|
+
logout: async () => {
|
|
96
|
+
const result = await medusaFetch(paths.logout, { method: "DELETE" })
|
|
97
|
+
notifyAuthChanged()
|
|
98
|
+
return result
|
|
99
|
+
},
|
|
74
100
|
|
|
75
101
|
profile,
|
|
76
102
|
|
|
@@ -137,17 +163,32 @@ export function accountApi(config: CoreConfig) {
|
|
|
137
163
|
body: JSON.stringify({ email, password }),
|
|
138
164
|
}),
|
|
139
165
|
|
|
166
|
+
emailVerificationStatus: () =>
|
|
167
|
+
medusaFetch<{
|
|
168
|
+
verified: boolean
|
|
169
|
+
retry_after_seconds: number
|
|
170
|
+
resend_available_at: string | null
|
|
171
|
+
}>(paths.email_verification, { cache: "no-store" }),
|
|
172
|
+
|
|
140
173
|
requestEmailVerification: () =>
|
|
141
|
-
medusaFetch
|
|
174
|
+
medusaFetch<{
|
|
175
|
+
success: boolean
|
|
176
|
+
retry_after_seconds: number
|
|
177
|
+
resend_available_at: string | null
|
|
178
|
+
}>(paths.email_verification, {
|
|
142
179
|
method: "PUT",
|
|
143
180
|
body: JSON.stringify({}),
|
|
144
181
|
}),
|
|
145
182
|
|
|
146
|
-
confirmEmailVerification: (code: string) =>
|
|
147
|
-
medusaFetch(paths.email_verification, {
|
|
183
|
+
confirmEmailVerification: async (code: string) => {
|
|
184
|
+
const result = await medusaFetch(paths.email_verification, {
|
|
148
185
|
method: "POST",
|
|
149
186
|
body: JSON.stringify({ code }),
|
|
150
|
-
})
|
|
187
|
+
})
|
|
188
|
+
await mergeGuestWishlistAfterLogin().catch(() => undefined)
|
|
189
|
+
notifyAuthChanged()
|
|
190
|
+
return result
|
|
191
|
+
},
|
|
151
192
|
|
|
152
193
|
requestEmailChange: (currentPassword: string, newEmail: string) =>
|
|
153
194
|
medusaFetch(paths.email_change, {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared checkout notice policy. The checkout owns the domain errors; the
|
|
3
|
+
* notification layer only decides which safe, already-localized text to show.
|
|
4
|
+
*/
|
|
5
|
+
export function checkoutErrorMessage(error?: string | null, cartError?: string | null): string | null {
|
|
6
|
+
return error?.trim() || cartError?.trim() || null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function checkoutNoticeMessage(message?: string | null): string | null {
|
|
10
|
+
return message?.trim() || null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function shouldShowCheckoutNotice(previous: string | null, next: string | null): boolean {
|
|
14
|
+
return Boolean(next && next !== previous)
|
|
15
|
+
}
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
asRecords,
|
|
12
12
|
isRecord,
|
|
13
|
-
shippingMethodIsCod,
|
|
14
13
|
stringValue,
|
|
15
14
|
} from "./commerce"
|
|
16
15
|
import type { CoreConfig } from "./types"
|
|
@@ -65,26 +64,26 @@ export function checkoutApi(config: CoreConfig) {
|
|
|
65
64
|
{ method: "POST", body: JSON.stringify({ provider_id: providerId }) },
|
|
66
65
|
)
|
|
67
66
|
|
|
68
|
-
const markPaymentMode = async (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
const markPaymentMode = async (
|
|
68
|
+
cartId: string, selectedProviderId: string,
|
|
69
|
+
choice: "cod" | "bank_transfer" | "online" = "online",
|
|
70
|
+
) => {
|
|
71
|
+
// Price authority is the backend. Never send a fee/amount from the browser.
|
|
72
|
+
const mode = selectedProviderId.toLowerCase().includes("system") ? choice : "online"
|
|
73
|
+
await medusaFetch<Record<string, unknown>>(
|
|
74
|
+
`/store/carts/${encodeURIComponent(cartId)}/cod`, {
|
|
75
|
+
method: "POST", body: JSON.stringify({ mode }),
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
if (mode === "bank_transfer" && config.payments.bank_transfer.enabled) {
|
|
79
|
+
const current = (await getCart(cartId)).cart
|
|
80
|
+
const metadata = isRecord(current.metadata) ? current.metadata : {}
|
|
77
81
|
const details = await bankTransferDetails()
|
|
78
82
|
const configured = isRecord(details.cart_metadata) ? details.cart_metadata : {}
|
|
79
|
-
await updateCart(cartId, {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
marker = "manual"
|
|
83
|
+
await updateCart(cartId, {
|
|
84
|
+
metadata: { ...metadata, ...configured, core_payment_method: "bank_transfer" },
|
|
85
|
+
})
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
await updateCart(cartId, {
|
|
86
|
-
metadata: { ...metadata, core_payment_method: marker },
|
|
87
|
-
})
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
const saveFoxpostSelection = (
|
|
@@ -177,6 +176,7 @@ export function checkoutApi(config: CoreConfig) {
|
|
|
177
176
|
},
|
|
178
177
|
|
|
179
178
|
updateCart,
|
|
179
|
+
markPaymentMode,
|
|
180
180
|
|
|
181
181
|
saveBillingTaxDetails: (cartId: string, data: {
|
|
182
182
|
is_company: boolean
|
|
@@ -346,7 +346,6 @@ export function checkoutApi(config: CoreConfig) {
|
|
|
346
346
|
paymentCollectionId: string,
|
|
347
347
|
selectedProviderId: string,
|
|
348
348
|
) => {
|
|
349
|
-
await markPaymentMode(cartId, selectedProviderId)
|
|
350
349
|
const result = await initializePaymentSession(paymentCollectionId, selectedProviderId)
|
|
351
350
|
const { cart } = await getCart(cartId)
|
|
352
351
|
trackPaymentInfo(config.analytics, cart, selectedProviderId)
|
|
@@ -22,6 +22,17 @@ export function stringValue(value: unknown) {
|
|
|
22
22
|
return typeof value === "string" ? value : value == null ? "" : String(value)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/** Product hero and card image: prefer thumbnail, then the first usable gallery image. */
|
|
26
|
+
export function productImageUrl(product: JsonRecord | null | undefined): string {
|
|
27
|
+
const thumbnail = stringValue(product?.thumbnail).trim()
|
|
28
|
+
if (thumbnail) return thumbnail
|
|
29
|
+
for (const image of asRecords(product?.images)) {
|
|
30
|
+
const url = stringValue(image.url).trim()
|
|
31
|
+
if (url) return url
|
|
32
|
+
}
|
|
33
|
+
return ""
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
export function numberValue(value: unknown, fallback = 0) {
|
|
26
37
|
const number = typeof value === "number" ? value : Number(value)
|
|
27
38
|
return Number.isFinite(number) ? number : fallback
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react"
|
|
4
|
+
import { useToast } from "@/components/toast-provider"
|
|
5
|
+
import {
|
|
6
|
+
checkoutErrorMessage,
|
|
7
|
+
checkoutNoticeMessage,
|
|
8
|
+
shouldShowCheckoutNotice,
|
|
9
|
+
} from "@/lib/core/checkout-feedback-state"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Common Core checkout notification bridge.
|
|
13
|
+
* Keep the existing inline field validation and payment retry UI; only
|
|
14
|
+
* transient checkout errors/success messages are mirrored into toast notices.
|
|
15
|
+
*/
|
|
16
|
+
export function useCheckoutFeedback(cartError?: string | null) {
|
|
17
|
+
const { showToast } = useToast()
|
|
18
|
+
const [error, setError] = useState<string | null>(null)
|
|
19
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
20
|
+
const lastError = useRef<string | null>(null)
|
|
21
|
+
const lastMessage = useRef<string | null>(null)
|
|
22
|
+
|
|
23
|
+
const activeError = checkoutErrorMessage(error, cartError)
|
|
24
|
+
const activeMessage = checkoutNoticeMessage(message)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!activeError) {
|
|
28
|
+
lastError.current = null
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
if (!shouldShowCheckoutNotice(lastError.current, activeError)) return
|
|
32
|
+
lastError.current = activeError
|
|
33
|
+
showToast({ tone: "error", message: activeError, durationMs: 7000 })
|
|
34
|
+
}, [activeError, showToast])
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!activeMessage) {
|
|
38
|
+
lastMessage.current = null
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (!shouldShowCheckoutNotice(lastMessage.current, activeMessage)) return
|
|
42
|
+
lastMessage.current = activeMessage
|
|
43
|
+
showToast({ tone: "success", message: activeMessage, durationMs: 7000 })
|
|
44
|
+
}, [activeMessage, showToast])
|
|
45
|
+
|
|
46
|
+
// Form-wide errors that do not need to persist as checkout state.
|
|
47
|
+
const notifyError = useCallback((text: string) => {
|
|
48
|
+
const next = checkoutNoticeMessage(text)
|
|
49
|
+
if (next) showToast({ tone: "error", message: next, durationMs: 7000 })
|
|
50
|
+
}, [showToast])
|
|
51
|
+
|
|
52
|
+
return { error, setError, message, setMessage, notifyError }
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import assert from "node:assert/strict"
|
|
2
|
+
import { readFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import test from "node:test"
|
|
5
|
+
import { fileURLToPath } from "node:url"
|
|
6
|
+
|
|
7
|
+
// Resolve relative to the test file, not process.cwd(): this test is copied
|
|
8
|
+
// into the create-commerce template and also runs from the generator root.
|
|
9
|
+
const srcDir = fileURLToPath(new URL("../src/", import.meta.url))
|
|
10
|
+
const read = (file) => readFileSync(join(srcDir, file), "utf8")
|
|
11
|
+
|
|
12
|
+
test("account requires verified email and retains one shared Core verification API", () => {
|
|
13
|
+
const account = read("lib/core/account.ts")
|
|
14
|
+
const dashboard = read("components/account-dashboard.tsx")
|
|
15
|
+
const gate = read("components/account-access-gate.tsx")
|
|
16
|
+
const panel = read("components/account-verification-panel.tsx")
|
|
17
|
+
|
|
18
|
+
assert.match(account, /isAccountEmailVerified/)
|
|
19
|
+
assert.match(account, /email_verified_address/)
|
|
20
|
+
assert.match(account, /emailVerificationStatus/)
|
|
21
|
+
assert.match(account, /requestEmailVerification/)
|
|
22
|
+
assert.match(account, /confirmEmailVerification/)
|
|
23
|
+
assert.match(dashboard, /if \(!isAccountEmailVerified\(customer\)\)/)
|
|
24
|
+
assert.match(dashboard, /AccountVerificationPanel/)
|
|
25
|
+
assert.match(gate, /router\.replace\("\/account"\)/)
|
|
26
|
+
assert.match(gate, /state === "unverified"/)
|
|
27
|
+
assert.match(panel, /retry_after_seconds/)
|
|
28
|
+
assert.match(panel, /resend_available_at/)
|
|
29
|
+
assert.match(panel, /retrySeconds > 0/)
|
|
30
|
+
assert.match(panel, /onLogout/)
|
|
31
|
+
assert.match(panel, /onVerified/)
|
|
32
|
+
assert.doesNotMatch(panel, /localStorage|sessionStorage/)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test("cart ownership is transferred only after email confirmation", () => {
|
|
36
|
+
const dashboard = read("components/account-dashboard.tsx")
|
|
37
|
+
assert.match(dashboard, /if \(registered\.customer && isAccountEmailVerified\(registered\.customer\)\)/)
|
|
38
|
+
assert.match(dashboard, /if \(signedIn && isAccountEmailVerified\(signedIn\)\)/)
|
|
39
|
+
assert.match(dashboard, /if \(updated && isAccountEmailVerified\(updated\)\)/)
|
|
40
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import test from "node:test"
|
|
2
|
+
import assert from "node:assert/strict"
|
|
3
|
+
import {
|
|
4
|
+
checkoutErrorMessage,
|
|
5
|
+
checkoutNoticeMessage,
|
|
6
|
+
shouldShowCheckoutNotice,
|
|
7
|
+
} from "../src/lib/core/checkout-feedback-state.ts"
|
|
8
|
+
|
|
9
|
+
test("checkout feedback prioritizes the local error over cart errors", () => {
|
|
10
|
+
assert.equal(checkoutErrorMessage("Form error", "Cart error"), "Form error")
|
|
11
|
+
assert.equal(checkoutErrorMessage(null, "Cart error"), "Cart error")
|
|
12
|
+
assert.equal(checkoutErrorMessage(" ", "Cart error"), "Cart error")
|
|
13
|
+
assert.equal(checkoutErrorMessage("", null), null)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test("checkout feedback ignores blank messages and normalizes whitespace", () => {
|
|
17
|
+
assert.equal(checkoutNoticeMessage(" Saved! "), "Saved!")
|
|
18
|
+
assert.equal(checkoutNoticeMessage(" "), null)
|
|
19
|
+
assert.equal(checkoutNoticeMessage(undefined), null)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test("checkout feedback does not repeat unchanged, empty notices", () => {
|
|
23
|
+
assert.equal(shouldShowCheckoutNotice(null, "Saved"), true)
|
|
24
|
+
assert.equal(shouldShowCheckoutNotice("Saved", "Saved"), false)
|
|
25
|
+
assert.equal(shouldShowCheckoutNotice("Saved", "Error"), true)
|
|
26
|
+
assert.equal(shouldShowCheckoutNotice(null, null), false)
|
|
27
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict"
|
|
2
|
+
import { readFileSync } from "node:fs"
|
|
3
|
+
import test from "node:test"
|
|
4
|
+
import { productImageUrl } from "../src/lib/core/commerce.ts"
|
|
5
|
+
|
|
6
|
+
test("a configured thumbnail takes precedence over gallery images", () => {
|
|
7
|
+
assert.equal(productImageUrl({
|
|
8
|
+
thumbnail: "https://example.com/primary.webp",
|
|
9
|
+
images: [{ url: "https://example.com/gallery.webp" }],
|
|
10
|
+
}), "https://example.com/primary.webp")
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("a product with no thumbnail uses its first usable gallery image", () => {
|
|
14
|
+
assert.equal(productImageUrl({
|
|
15
|
+
thumbnail: null,
|
|
16
|
+
images: [{ url: "" }, { url: " https://example.com/gallery.webp " }],
|
|
17
|
+
}), "https://example.com/gallery.webp")
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test("missing, empty or malformed image data stays an empty image", () => {
|
|
21
|
+
assert.equal(productImageUrl({ images: [{ invalid: "x" }] }), "")
|
|
22
|
+
assert.equal(productImageUrl({ thumbnail: " ", images: null }), "")
|
|
23
|
+
assert.equal(productImageUrl(null), "")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test("catalog cards and product details share the fallback resolver", () => {
|
|
27
|
+
const card = readFileSync(new URL("../src/components/product-card.tsx", import.meta.url), "utf8")
|
|
28
|
+
const detail = readFileSync(new URL("../src/app/[countryCode]/products/[handle]/page.tsx", import.meta.url), "utf8")
|
|
29
|
+
assert.match(card, /const thumbnail = productImageUrl\(product\)/)
|
|
30
|
+
assert.match(detail, /const thumbnail = productImageUrl\(product\)/)
|
|
31
|
+
})
|