@hszrdm/create-commerce 1.3.0 → 1.5.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/README.md +92 -1
- package/package.json +1 -1
- package/templates/backend/.env.example +271 -91
- package/templates/backend/README.md +4 -0
- package/templates/backend/package.json +6 -2
- package/templates/backend/scripts/core-backup.mjs +281 -0
- package/templates/backend/scripts/core-restore.mjs +179 -0
- package/templates/backend/scripts/lib/core-backup-common.mjs +237 -0
- package/templates/backend/scripts/materialize-production.mjs +37 -0
- package/templates/backend/scripts/production-assets/backup.sh +56 -0
- package/templates/backend/scripts/production-assets/deploy.sh +68 -0
- package/templates/backend/scripts/production-assets/ecosystem.config.cjs.tpl +24 -0
- package/templates/backend/scripts/production-assets/install.sh +201 -0
- package/templates/backend/scripts/production-assets/restore.sh +71 -0
- package/templates/backend/scripts/verify-env-contract.mjs +58 -0
- package/templates/backend/src/scripts/core-init.ts +3 -1
- package/templates/storefront/src/app/cart-recovery/page.tsx +35 -0
- package/templates/storefront/src/app/ertekeles/page.tsx +25 -0
- package/templates/storefront/src/app/fiok-aktivalas/page.tsx +35 -0
- package/templates/storefront/src/components/abandoned-cart-recovery.tsx +139 -0
- package/templates/storefront/src/components/account-activation-form.tsx +333 -0
- package/templates/storefront/src/components/add-to-cart.tsx +56 -0
- package/templates/storefront/src/components/analytics.tsx +15 -2
- package/templates/storefront/src/components/review-request-form.tsx +419 -0
- package/templates/storefront/src/lib/core/abandoned-cart.ts +47 -0
- package/templates/storefront/src/lib/core/account-activation.ts +75 -0
- package/templates/storefront/src/lib/core/back-in-stock.ts +25 -0
- package/templates/storefront/src/lib/core/reviews.ts +37 -5
- package/templates/storefront/src/lib/storefront-routes.ts +3 -0
- package/templates/storefront/src/proxy.ts +4 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from "react"
|
|
6
|
+
import { useCart } from "@/components/cart-provider"
|
|
7
|
+
import { abandonedCartApi } from "@/lib/core/abandoned-cart"
|
|
8
|
+
import { checkoutApi } from "@/lib/core/checkout"
|
|
9
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
10
|
+
import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
11
|
+
|
|
12
|
+
type RecoveryState = "checking" | "invalid" | "error"
|
|
13
|
+
|
|
14
|
+
export function AbandonedCartRecovery({ config }: { config: CoreConfig }) {
|
|
15
|
+
const pathname = usePathname()
|
|
16
|
+
const search = useSearchParams()
|
|
17
|
+
const router = useRouter()
|
|
18
|
+
const locale = localeFromPathname(pathname)
|
|
19
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
20
|
+
const recovery = useMemo(() => abandonedCartApi(config), [config])
|
|
21
|
+
const checkout = useMemo(() => checkoutApi(config), [config])
|
|
22
|
+
const { adoptCart, refresh } = useCart()
|
|
23
|
+
const started = useRef(false)
|
|
24
|
+
const [state, setState] = useState<RecoveryState>("checking")
|
|
25
|
+
const [reason, setReason] = useState<string | null>(null)
|
|
26
|
+
const [error, setError] = useState<string | null>(null)
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (started.current) return
|
|
30
|
+
started.current = true
|
|
31
|
+
|
|
32
|
+
const token = search.get("token")?.trim() || ""
|
|
33
|
+
if (!token) {
|
|
34
|
+
setReason("missing")
|
|
35
|
+
setState("invalid")
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void recovery
|
|
40
|
+
.recover(token)
|
|
41
|
+
.then(async (result) => {
|
|
42
|
+
if (!result.valid || !result.cart_id) {
|
|
43
|
+
setReason(result.reason || "invalid")
|
|
44
|
+
setState("invalid")
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const cartId = result.cart_id
|
|
49
|
+
const adopted = await adoptCart(cartId)
|
|
50
|
+
if (!adopted) throw new Error(copy(locale).cartUnavailable)
|
|
51
|
+
|
|
52
|
+
if (result.coupon_code) {
|
|
53
|
+
try {
|
|
54
|
+
await checkout.addPromotion(cartId, result.coupon_code)
|
|
55
|
+
await refresh(cartId)
|
|
56
|
+
} catch {
|
|
57
|
+
// The cart itself is still recoverable if a promotion was already
|
|
58
|
+
// used, disabled or otherwise no longer applicable.
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
router.replace(routes.cart)
|
|
63
|
+
})
|
|
64
|
+
.catch((cause) => {
|
|
65
|
+
setError(cause instanceof Error ? cause.message : copy(locale).failed)
|
|
66
|
+
setState("error")
|
|
67
|
+
})
|
|
68
|
+
}, [adoptCart, checkout, locale, recovery, refresh, router, routes.cart, search])
|
|
69
|
+
|
|
70
|
+
const text = copy(locale)
|
|
71
|
+
|
|
72
|
+
if (state === "checking") {
|
|
73
|
+
return <div className="empty-state">{text.checking}</div>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (state === "invalid") {
|
|
77
|
+
return (
|
|
78
|
+
<section className="panel stack narrow-card">
|
|
79
|
+
<div>
|
|
80
|
+
<p className="eyebrow">{text.eyebrow}</p>
|
|
81
|
+
<h1>{text.invalidTitle}</h1>
|
|
82
|
+
</div>
|
|
83
|
+
<p className="muted">{invalidReason(reason, locale)}</p>
|
|
84
|
+
<Link className="button button-large" href={routes.products}>
|
|
85
|
+
{text.shop}
|
|
86
|
+
</Link>
|
|
87
|
+
</section>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<section className="panel stack narrow-card">
|
|
93
|
+
<div>
|
|
94
|
+
<p className="eyebrow">{text.eyebrow}</p>
|
|
95
|
+
<h1>{text.errorTitle}</h1>
|
|
96
|
+
</div>
|
|
97
|
+
<p className="error">{error || text.failed}</p>
|
|
98
|
+
<Link className="button button-large" href={routes.products}>
|
|
99
|
+
{text.shop}
|
|
100
|
+
</Link>
|
|
101
|
+
</section>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function invalidReason(reason: string | null, locale: "hu" | "en") {
|
|
106
|
+
if (locale === "en") {
|
|
107
|
+
if (reason === "completed") return "This cart has already been checked out."
|
|
108
|
+
if (reason === "empty") return "This cart is empty and can no longer be restored."
|
|
109
|
+
if (reason === "missing") return "The recovery link is incomplete. Open the full link from the email."
|
|
110
|
+
return "This cart recovery link is invalid or has expired."
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (reason === "completed") return "Ebből a kosárból már rendelés készült."
|
|
114
|
+
if (reason === "empty") return "Ez a kosár már üres, ezért nem állítható vissza."
|
|
115
|
+
if (reason === "missing") return "A visszaállító link hiányos. Nyisd meg az e-mailben kapott teljes hivatkozást."
|
|
116
|
+
return "Ez a kosár-visszaállító link érvénytelen vagy lejárt."
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function copy(locale: "hu" | "en") {
|
|
120
|
+
return locale === "en"
|
|
121
|
+
? {
|
|
122
|
+
eyebrow: "Cart recovery",
|
|
123
|
+
checking: "Restoring your cart…",
|
|
124
|
+
invalidTitle: "This recovery link is no longer available",
|
|
125
|
+
errorTitle: "Your cart could not be restored",
|
|
126
|
+
failed: "Cart recovery failed.",
|
|
127
|
+
cartUnavailable: "The recovered cart is no longer available.",
|
|
128
|
+
shop: "Continue shopping",
|
|
129
|
+
}
|
|
130
|
+
: {
|
|
131
|
+
eyebrow: "Kosár visszaállítása",
|
|
132
|
+
checking: "A kosarad visszaállítása…",
|
|
133
|
+
invalidTitle: "Ez a visszaállító link már nem használható",
|
|
134
|
+
errorTitle: "A kosár visszaállítása nem sikerült",
|
|
135
|
+
failed: "A kosár visszaállítása nem sikerült.",
|
|
136
|
+
cartUnavailable: "A visszaállított kosár már nem érhető el.",
|
|
137
|
+
shop: "Vásárlás folytatása",
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname, useSearchParams } from "next/navigation"
|
|
5
|
+
import { useEffect, useMemo, useState, type FormEvent } from "react"
|
|
6
|
+
import {
|
|
7
|
+
customerActivationApi,
|
|
8
|
+
type CustomerActivationResult,
|
|
9
|
+
type CustomerActivationReward,
|
|
10
|
+
type CustomerActivationValidation,
|
|
11
|
+
} from "@/lib/core/account-activation"
|
|
12
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
13
|
+
import {
|
|
14
|
+
localeFromPathname,
|
|
15
|
+
STOREFRONT_ROUTES,
|
|
16
|
+
type StorefrontLocale,
|
|
17
|
+
} from "@/lib/storefront-routes"
|
|
18
|
+
|
|
19
|
+
type ActivationState = "checking" | "ready" | "invalid" | "success" | "error"
|
|
20
|
+
|
|
21
|
+
export function AccountActivationForm({ config }: { config: CoreConfig }) {
|
|
22
|
+
const pathname = usePathname()
|
|
23
|
+
const search = useSearchParams()
|
|
24
|
+
const locale = localeFromPathname(pathname)
|
|
25
|
+
const copy = activationCopy(locale)
|
|
26
|
+
const routes = STOREFRONT_ROUTES[locale]
|
|
27
|
+
const api = useMemo(() => customerActivationApi(config), [config])
|
|
28
|
+
const [credentials] = useState(() => ({
|
|
29
|
+
customerId: search.get("customer")?.trim() || "",
|
|
30
|
+
token: search.get("token")?.trim() || "",
|
|
31
|
+
}))
|
|
32
|
+
const [state, setState] = useState<ActivationState>("checking")
|
|
33
|
+
const [validation, setValidation] = useState<CustomerActivationValidation | null>(null)
|
|
34
|
+
const [result, setResult] = useState<CustomerActivationResult | null>(null)
|
|
35
|
+
const [reason, setReason] = useState<string | null>(null)
|
|
36
|
+
const [password, setPassword] = useState("")
|
|
37
|
+
const [confirmPassword, setConfirmPassword] = useState("")
|
|
38
|
+
const [busy, setBusy] = useState(false)
|
|
39
|
+
const [error, setError] = useState<string | null>(null)
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
let cancelled = false
|
|
43
|
+
|
|
44
|
+
if (!credentials.customerId || !credentials.token) {
|
|
45
|
+
setReason("missing")
|
|
46
|
+
setState("invalid")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setState("checking")
|
|
51
|
+
void api
|
|
52
|
+
.validate(credentials.customerId, credentials.token)
|
|
53
|
+
.then((payload) => {
|
|
54
|
+
if (cancelled) return
|
|
55
|
+
if (!payload.valid) {
|
|
56
|
+
setReason(payload.reason || "invalid")
|
|
57
|
+
setState("invalid")
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
setValidation(payload)
|
|
61
|
+
setState("ready")
|
|
62
|
+
})
|
|
63
|
+
.catch((cause) => {
|
|
64
|
+
if (cancelled) return
|
|
65
|
+
setError(cause instanceof Error ? cause.message : copy.validationFailed)
|
|
66
|
+
setState("error")
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true
|
|
71
|
+
}
|
|
72
|
+
}, [api, copy.validationFailed, credentials.customerId, credentials.token])
|
|
73
|
+
|
|
74
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
75
|
+
event.preventDefault()
|
|
76
|
+
setError(null)
|
|
77
|
+
|
|
78
|
+
if (password.length < 8) {
|
|
79
|
+
setError(copy.passwordTooShort)
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
if (password !== confirmPassword) {
|
|
83
|
+
setError(copy.passwordMismatch)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setBusy(true)
|
|
88
|
+
try {
|
|
89
|
+
const activation = await api.complete(
|
|
90
|
+
credentials.customerId,
|
|
91
|
+
credentials.token,
|
|
92
|
+
password,
|
|
93
|
+
)
|
|
94
|
+
if (typeof window !== "undefined" && window.location.search) {
|
|
95
|
+
window.history.replaceState(window.history.state, "", pathname)
|
|
96
|
+
}
|
|
97
|
+
setResult(activation)
|
|
98
|
+
setPassword("")
|
|
99
|
+
setConfirmPassword("")
|
|
100
|
+
setState("success")
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
setError(cause instanceof Error ? cause.message : copy.activationFailed)
|
|
103
|
+
} finally {
|
|
104
|
+
setBusy(false)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (state === "checking") {
|
|
109
|
+
return <div className="empty-state">{copy.checking}</div>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (state === "invalid") {
|
|
113
|
+
return (
|
|
114
|
+
<section className="panel stack narrow-card">
|
|
115
|
+
<div>
|
|
116
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
117
|
+
<h1>{copy.invalidTitle}</h1>
|
|
118
|
+
</div>
|
|
119
|
+
<p className="muted">{invalidMessage(reason, locale)}</p>
|
|
120
|
+
<Link className="button button-large" href={routes.account}>
|
|
121
|
+
{copy.goToAccount}
|
|
122
|
+
</Link>
|
|
123
|
+
</section>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (state === "error") {
|
|
128
|
+
return (
|
|
129
|
+
<section className="panel stack narrow-card">
|
|
130
|
+
<div>
|
|
131
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
132
|
+
<h1>{copy.errorTitle}</h1>
|
|
133
|
+
</div>
|
|
134
|
+
<p className="error">{error || copy.validationFailed}</p>
|
|
135
|
+
<Link className="button secondary" href={routes.account}>
|
|
136
|
+
{copy.goToAccount}
|
|
137
|
+
</Link>
|
|
138
|
+
</section>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (state === "success" && result) {
|
|
143
|
+
const reward = rewardText(result.reward, locale, config.store.default_currency)
|
|
144
|
+
return (
|
|
145
|
+
<section className="panel stack narrow-card">
|
|
146
|
+
<div>
|
|
147
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
148
|
+
<h1>{copy.successTitle}</h1>
|
|
149
|
+
</div>
|
|
150
|
+
<p className="success">{copy.successText}</p>
|
|
151
|
+
{result.coupon_code ? (
|
|
152
|
+
<div className="empty-state stack-sm">
|
|
153
|
+
<strong>{copy.couponTitle}</strong>
|
|
154
|
+
<code>{result.coupon_code}</code>
|
|
155
|
+
{reward ? <span className="muted small">{reward}</span> : null}
|
|
156
|
+
</div>
|
|
157
|
+
) : null}
|
|
158
|
+
<Link className="button button-large" href={routes.account}>
|
|
159
|
+
{copy.loginNow}
|
|
160
|
+
</Link>
|
|
161
|
+
</section>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const greeting = validation?.first_name?.trim()
|
|
166
|
+
? `${copy.greeting} ${validation.first_name.trim()}!`
|
|
167
|
+
: copy.title
|
|
168
|
+
const expiresAt = formatDateTime(validation?.expires_at, locale)
|
|
169
|
+
const reward = rewardText(validation?.reward, locale, config.store.default_currency)
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<section className="panel stack narrow-card">
|
|
173
|
+
<div>
|
|
174
|
+
<p className="eyebrow">{copy.eyebrow}</p>
|
|
175
|
+
<h1>{greeting}</h1>
|
|
176
|
+
</div>
|
|
177
|
+
<p className="muted">{copy.description}</p>
|
|
178
|
+
|
|
179
|
+
<div className="stack-sm">
|
|
180
|
+
{validation?.masked_email ? (
|
|
181
|
+
<p>
|
|
182
|
+
<strong>{copy.emailLabel}:</strong> {validation.masked_email}
|
|
183
|
+
</p>
|
|
184
|
+
) : null}
|
|
185
|
+
{expiresAt ? (
|
|
186
|
+
<p className="muted small">
|
|
187
|
+
{copy.expiresLabel}: {expiresAt}
|
|
188
|
+
</p>
|
|
189
|
+
) : null}
|
|
190
|
+
{reward ? (
|
|
191
|
+
<p className="muted small">
|
|
192
|
+
{copy.rewardLabel}: {reward}
|
|
193
|
+
</p>
|
|
194
|
+
) : null}
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<form className="stack-sm" onSubmit={submit}>
|
|
198
|
+
<label>
|
|
199
|
+
{copy.newPassword}
|
|
200
|
+
<input
|
|
201
|
+
autoComplete="new-password"
|
|
202
|
+
minLength={8}
|
|
203
|
+
required
|
|
204
|
+
type="password"
|
|
205
|
+
value={password}
|
|
206
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
207
|
+
/>
|
|
208
|
+
</label>
|
|
209
|
+
<label>
|
|
210
|
+
{copy.repeatPassword}
|
|
211
|
+
<input
|
|
212
|
+
autoComplete="new-password"
|
|
213
|
+
minLength={8}
|
|
214
|
+
required
|
|
215
|
+
type="password"
|
|
216
|
+
value={confirmPassword}
|
|
217
|
+
onChange={(event) => setConfirmPassword(event.target.value)}
|
|
218
|
+
/>
|
|
219
|
+
</label>
|
|
220
|
+
<p className="muted small">{copy.passwordHint}</p>
|
|
221
|
+
{error ? <p className="error">{error}</p> : null}
|
|
222
|
+
<button className="button button-large" disabled={busy} type="submit">
|
|
223
|
+
{busy ? copy.activating : copy.activate}
|
|
224
|
+
</button>
|
|
225
|
+
</form>
|
|
226
|
+
</section>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function invalidMessage(reason: string | null, locale: StorefrontLocale) {
|
|
231
|
+
if (locale === "en") {
|
|
232
|
+
if (reason === "expired") return "This activation link has expired. Request a new activation email from the store."
|
|
233
|
+
if (reason === "used") return "This activation link has already been used. You can sign in with your existing account."
|
|
234
|
+
if (reason === "missing") return "The activation link is incomplete. Open the full link from the email you received."
|
|
235
|
+
return "This activation link is invalid. Request a new activation email from the store."
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (reason === "expired") return "Ez az aktiváló link lejárt. Kérj új aktiváló e-mailt a webáruháztól."
|
|
239
|
+
if (reason === "used") return "Ezt az aktiváló linket már felhasználták. A meglévő fiókoddal már be tudsz jelentkezni."
|
|
240
|
+
if (reason === "missing") return "Az aktiváló link hiányos. Nyisd meg újra az e-mailben kapott teljes hivatkozást."
|
|
241
|
+
return "Ez az aktiváló link érvénytelen. Kérj új aktiváló e-mailt a webáruháztól."
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function rewardText(
|
|
245
|
+
reward: CustomerActivationReward | null | undefined,
|
|
246
|
+
locale: StorefrontLocale,
|
|
247
|
+
defaultCurrency: string,
|
|
248
|
+
) {
|
|
249
|
+
if (!reward?.enabled || !reward.value) return null
|
|
250
|
+
if (reward.type !== "fixed") {
|
|
251
|
+
return locale === "en"
|
|
252
|
+
? `${reward.value}% welcome discount after activation`
|
|
253
|
+
: `${reward.value}% üdvözlő kedvezmény az aktiválás után`
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const currency = (reward.currency_code || defaultCurrency || "huf").toUpperCase()
|
|
257
|
+
const amount = new Intl.NumberFormat(locale === "en" ? "en-GB" : "hu-HU", {
|
|
258
|
+
style: "currency",
|
|
259
|
+
currency,
|
|
260
|
+
maximumFractionDigits: 0,
|
|
261
|
+
}).format(reward.value)
|
|
262
|
+
return locale === "en"
|
|
263
|
+
? `${amount} welcome discount after activation`
|
|
264
|
+
: `${amount} üdvözlő kedvezmény az aktiválás után`
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function formatDateTime(value: string | null | undefined, locale: StorefrontLocale) {
|
|
268
|
+
if (!value) return null
|
|
269
|
+
const date = new Date(value)
|
|
270
|
+
if (Number.isNaN(date.getTime())) return null
|
|
271
|
+
return new Intl.DateTimeFormat(locale === "en" ? "en-GB" : "hu-HU", {
|
|
272
|
+
dateStyle: "medium",
|
|
273
|
+
timeStyle: "short",
|
|
274
|
+
}).format(date)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function activationCopy(locale: StorefrontLocale) {
|
|
278
|
+
if (locale === "en") {
|
|
279
|
+
return {
|
|
280
|
+
eyebrow: "Account activation",
|
|
281
|
+
title: "Activate your account",
|
|
282
|
+
greeting: "Welcome",
|
|
283
|
+
description: "Set a new password to activate the customer account created during migration.",
|
|
284
|
+
checking: "Checking activation link…",
|
|
285
|
+
invalidTitle: "Activation link unavailable",
|
|
286
|
+
errorTitle: "Activation could not be checked",
|
|
287
|
+
validationFailed: "We could not verify the activation link.",
|
|
288
|
+
activationFailed: "Account activation failed.",
|
|
289
|
+
emailLabel: "Account",
|
|
290
|
+
expiresLabel: "Link expires",
|
|
291
|
+
rewardLabel: "Activation reward",
|
|
292
|
+
newPassword: "New password",
|
|
293
|
+
repeatPassword: "Repeat password",
|
|
294
|
+
passwordHint: "Use at least 8 characters.",
|
|
295
|
+
passwordTooShort: "The password must be at least 8 characters long.",
|
|
296
|
+
passwordMismatch: "The two passwords do not match.",
|
|
297
|
+
activating: "Activating…",
|
|
298
|
+
activate: "Activate account",
|
|
299
|
+
successTitle: "Your account is active",
|
|
300
|
+
successText: "Your new password has been saved. You can now sign in to your account.",
|
|
301
|
+
couponTitle: "Your welcome coupon",
|
|
302
|
+
loginNow: "Sign in",
|
|
303
|
+
goToAccount: "Go to account",
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
eyebrow: "Fiókaktiválás",
|
|
309
|
+
title: "Aktiváld a fiókodat",
|
|
310
|
+
greeting: "Üdv",
|
|
311
|
+
description: "Adj meg egy új jelszót az átköltöztetett vásárlói fiókod aktiválásához.",
|
|
312
|
+
checking: "Aktiváló link ellenőrzése…",
|
|
313
|
+
invalidTitle: "Az aktiváló link nem használható",
|
|
314
|
+
errorTitle: "Az aktiváló linket nem sikerült ellenőrizni",
|
|
315
|
+
validationFailed: "Az aktiváló link ellenőrzése nem sikerült.",
|
|
316
|
+
activationFailed: "A fiók aktiválása nem sikerült.",
|
|
317
|
+
emailLabel: "Fiók",
|
|
318
|
+
expiresLabel: "A link lejár",
|
|
319
|
+
rewardLabel: "Aktiválási kedvezmény",
|
|
320
|
+
newPassword: "Új jelszó",
|
|
321
|
+
repeatPassword: "Új jelszó ismét",
|
|
322
|
+
passwordHint: "Legalább 8 karakteres jelszót adj meg.",
|
|
323
|
+
passwordTooShort: "A jelszó legalább 8 karakter legyen.",
|
|
324
|
+
passwordMismatch: "A két jelszó nem egyezik.",
|
|
325
|
+
activating: "Aktiválás…",
|
|
326
|
+
activate: "Fiók aktiválása",
|
|
327
|
+
successTitle: "A fiókod aktív",
|
|
328
|
+
successText: "Az új jelszavad mentve lett. Most már bejelentkezhetsz a fiókodba.",
|
|
329
|
+
couponTitle: "Az üdvözlő kuponod",
|
|
330
|
+
loginNow: "Bejelentkezés",
|
|
331
|
+
goToAccount: "Tovább a fiókhoz",
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -5,6 +5,7 @@ import { usePathname } from "next/navigation"
|
|
|
5
5
|
import { QuantityStepper } from "./quantity-stepper"
|
|
6
6
|
import { useToast } from "./toast-provider"
|
|
7
7
|
import { useCart } from "./cart-provider"
|
|
8
|
+
import { subscribeBackInStock } from "@/lib/core/back-in-stock"
|
|
8
9
|
import {
|
|
9
10
|
asRecords,
|
|
10
11
|
formatMoney,
|
|
@@ -28,6 +29,10 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
28
29
|
const [quantity, setQuantity] = useState(() => variantMinimum(variants[0], productMetadata))
|
|
29
30
|
const [message, setMessage] = useState<string | null>(null)
|
|
30
31
|
const [success, setSuccess] = useState(false)
|
|
32
|
+
const [alertEmail, setAlertEmail] = useState("")
|
|
33
|
+
const [alertBusy, setAlertBusy] = useState(false)
|
|
34
|
+
const [alertMessage, setAlertMessage] = useState<string | null>(null)
|
|
35
|
+
const [alertSuccess, setAlertSuccess] = useState(false)
|
|
31
36
|
const { addItem, mutating } = useCart()
|
|
32
37
|
const { showToast } = useToast()
|
|
33
38
|
const selected = variants.find((variant) => stringValue(variant.id) === variantId) || variants[0]
|
|
@@ -64,6 +69,8 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
64
69
|
setVariantId(nextId)
|
|
65
70
|
setQuantity(variantMinimum(next, productMetadata))
|
|
66
71
|
setMessage(null)
|
|
72
|
+
setAlertMessage(null)
|
|
73
|
+
setAlertSuccess(false)
|
|
67
74
|
if (typeof window !== "undefined") {
|
|
68
75
|
window.dispatchEvent(new CustomEvent("hszrdm:product-variant-change", {
|
|
69
76
|
detail: {
|
|
@@ -119,6 +126,55 @@ export function AddToCart({ product, config }: { product: Record<string, unknown
|
|
|
119
126
|
: (en ? "Currently unavailable" : "Jelenleg nem vásárolható")}
|
|
120
127
|
</div>
|
|
121
128
|
|
|
129
|
+
{!purchasable ? (
|
|
130
|
+
<div className="notice stack-sm">
|
|
131
|
+
<strong>{en ? "Notify me when available" : "Értesíts, ha újra elérhető"}</strong>
|
|
132
|
+
<label>
|
|
133
|
+
<span className="field-label">{en ? "Email address" : "E-mail-cím"}</span>
|
|
134
|
+
<input
|
|
135
|
+
type="email"
|
|
136
|
+
autoComplete="email"
|
|
137
|
+
value={alertEmail}
|
|
138
|
+
onChange={(event) => setAlertEmail(event.target.value)}
|
|
139
|
+
placeholder="email@example.com"
|
|
140
|
+
disabled={alertBusy}
|
|
141
|
+
/>
|
|
142
|
+
</label>
|
|
143
|
+
<button
|
|
144
|
+
type="button"
|
|
145
|
+
className="button button-secondary"
|
|
146
|
+
disabled={alertBusy || !variantId || !alertEmail.trim()}
|
|
147
|
+
aria-busy={alertBusy}
|
|
148
|
+
onClick={() => {
|
|
149
|
+
setAlertBusy(true)
|
|
150
|
+
setAlertMessage(null)
|
|
151
|
+
setAlertSuccess(false)
|
|
152
|
+
void subscribeBackInStock({ email: alertEmail.trim(), variantId, locale: formatLocale })
|
|
153
|
+
.then((result) => {
|
|
154
|
+
const next = result.already_available
|
|
155
|
+
? (en ? "This variant is already available. Refresh the page to order it." : "Ez a változat már újra elérhető. Frissítsd az oldalt a rendeléshez.")
|
|
156
|
+
: result.already_subscribed
|
|
157
|
+
? (en ? "You are already on the notification list for this variant." : "Erre a változatra már fel vagy iratkozva az értesítésre.")
|
|
158
|
+
: (en ? "Done. We will email you when this variant is available again." : "Kész. E-mailt küldünk, amikor ez a változat újra elérhető.")
|
|
159
|
+
setAlertSuccess(true)
|
|
160
|
+
setAlertMessage(next)
|
|
161
|
+
showToast({ message: next, tone: "success" })
|
|
162
|
+
})
|
|
163
|
+
.catch((error) => {
|
|
164
|
+
const next = humanizeStorefrontError(error, locale)
|
|
165
|
+
setAlertSuccess(false)
|
|
166
|
+
setAlertMessage(next)
|
|
167
|
+
showToast({ message: next, tone: "error" })
|
|
168
|
+
})
|
|
169
|
+
.finally(() => setAlertBusy(false))
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
{alertBusy ? (en ? "Saving…" : "Mentés…") : (en ? "Notify me" : "Kérek értesítést")}
|
|
173
|
+
</button>
|
|
174
|
+
{alertMessage ? <p className={alertSuccess ? "success" : "error"} aria-live="polite">{alertMessage}</p> : null}
|
|
175
|
+
</div>
|
|
176
|
+
) : null}
|
|
177
|
+
|
|
122
178
|
{sku ? (
|
|
123
179
|
<div className="sku-row">
|
|
124
180
|
<span><span className="muted">SKU:</span> <code>{sku}</code></span>
|
|
@@ -12,6 +12,17 @@ import {
|
|
|
12
12
|
import { analyticsTrackingMode, trackWebshopPageView } from "@/lib/core/tracking"
|
|
13
13
|
import type { CoreConfig } from "@/lib/core/types"
|
|
14
14
|
|
|
15
|
+
const SENSITIVE_ANALYTICS_PATHS = new Set([
|
|
16
|
+
"/fiok-aktivalas",
|
|
17
|
+
"/ertekeles",
|
|
18
|
+
"/reset-password",
|
|
19
|
+
"/newsletter/confirm",
|
|
20
|
+
"/newsletter/unsubscribe",
|
|
21
|
+
"/cart-recovery",
|
|
22
|
+
"/hu/kosar-visszaallitas",
|
|
23
|
+
"/en/cart-recovery",
|
|
24
|
+
])
|
|
25
|
+
|
|
15
26
|
export const GOOGLE_CONSENT_DEFAULT_SCRIPT = `
|
|
16
27
|
window.dataLayer=window.dataLayer||[];
|
|
17
28
|
function gtag(){dataLayer.push(arguments);}
|
|
@@ -28,6 +39,7 @@ export function AnalyticsGate({ analytics }: { analytics: CoreConfig["analytics"
|
|
|
28
39
|
const pathname = usePathname()
|
|
29
40
|
const [preferences, setPreferences] = useState<ConsentPreferences | null>(null)
|
|
30
41
|
const [ready, setReady] = useState(false)
|
|
42
|
+
const sensitivePath = SENSITIVE_ANALYTICS_PATHS.has(pathname)
|
|
31
43
|
|
|
32
44
|
useEffect(() => {
|
|
33
45
|
const stored = readConsentPreferences()
|
|
@@ -47,12 +59,13 @@ export function AnalyticsGate({ analytics }: { analytics: CoreConfig["analytics"
|
|
|
47
59
|
}, [])
|
|
48
60
|
|
|
49
61
|
useEffect(() => {
|
|
62
|
+
if (sensitivePath) return
|
|
50
63
|
// HSZRDM Webshop Analytics is first-party and independent from GA4/GTM.
|
|
51
64
|
// The tracker stores only pseudonymous identifiers and commerce context.
|
|
52
65
|
trackWebshopPageView()
|
|
53
|
-
}, [pathname])
|
|
66
|
+
}, [pathname, sensitivePath])
|
|
54
67
|
|
|
55
|
-
if (!ready) return null
|
|
68
|
+
if (!ready || sensitivePath) return null
|
|
56
69
|
|
|
57
70
|
const mode = analyticsTrackingMode(analytics)
|
|
58
71
|
const analyticsGranted = Boolean(preferences?.analytics)
|