@hszrdm/create-commerce 0.0.0-stage → 1.0.1
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 +50 -2
- package/bin/create-commerce.mjs +51 -0
- package/package.json +23 -4
- package/src/cli.mjs +585 -0
- package/templates/backend/.env.example +113 -0
- package/templates/backend/README.md +7 -0
- package/templates/backend/instrumentation.ts +24 -0
- package/templates/backend/medusa-config.ts +11 -0
- package/templates/backend/package.json +42 -0
- package/templates/backend/scripts/prepare-project.mjs +49 -0
- package/templates/backend/src/project/README.md +13 -0
- package/templates/backend/src/project/api/.gitkeep +0 -0
- package/templates/backend/src/project/jobs/.gitkeep +0 -0
- package/templates/backend/src/project/modules/.gitkeep +0 -0
- package/templates/backend/src/project/subscribers/.gitkeep +0 -0
- package/templates/backend/src/project/workflows/.gitkeep +0 -0
- package/templates/backend/src/scripts/core-init.ts +21 -0
- package/templates/backend/src/scripts/create-storefront-key.ts +12 -0
- package/templates/backend/src/scripts/verify-bootstrap.ts +1 -0
- package/templates/backend/tsconfig.json +33 -0
- package/templates/storefront/.env.example +5 -0
- package/templates/storefront/README.md +108 -0
- package/templates/storefront/next-env.d.ts +4 -0
- package/templates/storefront/next.config.ts +8 -0
- package/templates/storefront/package.json +24 -0
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +38 -0
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +51 -0
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +47 -0
- package/templates/storefront/src/app/account/orders/[id]/page.tsx +8 -0
- package/templates/storefront/src/app/account/page.tsx +11 -0
- package/templates/storefront/src/app/cart/page.tsx +12 -0
- package/templates/storefront/src/app/checkout/page.tsx +15 -0
- package/templates/storefront/src/app/checkout/success/page.tsx +72 -0
- package/templates/storefront/src/app/error.tsx +14 -0
- package/templates/storefront/src/app/globals.css +250 -0
- package/templates/storefront/src/app/layout.tsx +59 -0
- package/templates/storefront/src/app/legal/page.tsx +26 -0
- package/templates/storefront/src/app/loading.tsx +3 -0
- package/templates/storefront/src/app/not-found.tsx +14 -0
- package/templates/storefront/src/app/page.tsx +47 -0
- package/templates/storefront/src/app/reset-password/page.tsx +14 -0
- package/templates/storefront/src/app/robots.txt/route.ts +13 -0
- package/templates/storefront/src/app/sitemap.xml/route.ts +13 -0
- package/templates/storefront/src/components/account-dashboard.tsx +325 -0
- package/templates/storefront/src/components/add-to-cart.tsx +71 -0
- package/templates/storefront/src/components/analytics.tsx +90 -0
- package/templates/storefront/src/components/cart-provider.tsx +236 -0
- package/templates/storefront/src/components/cart-view.tsx +135 -0
- package/templates/storefront/src/components/checkout-flow.tsx +534 -0
- package/templates/storefront/src/components/consent-banner.tsx +131 -0
- package/templates/storefront/src/components/order-detail.tsx +273 -0
- package/templates/storefront/src/components/product-card.tsx +38 -0
- package/templates/storefront/src/components/product-view-tracker.tsx +37 -0
- package/templates/storefront/src/components/reset-password-form.tsx +65 -0
- package/templates/storefront/src/components/storefront-header.tsx +42 -0
- package/templates/storefront/src/components/stripe-payment.tsx +90 -0
- package/templates/storefront/src/lib/core/account.ts +170 -0
- package/templates/storefront/src/lib/core/after-sales.ts +50 -0
- package/templates/storefront/src/lib/core/catalog.ts +56 -0
- package/templates/storefront/src/lib/core/checkout.ts +330 -0
- package/templates/storefront/src/lib/core/client.ts +107 -0
- package/templates/storefront/src/lib/core/commerce.ts +148 -0
- package/templates/storefront/src/lib/core/consent.ts +111 -0
- package/templates/storefront/src/lib/core/legal.ts +33 -0
- package/templates/storefront/src/lib/core/seo.ts +88 -0
- package/templates/storefront/src/lib/core/tracking.ts +584 -0
- package/templates/storefront/src/lib/core/types.ts +123 -0
- package/templates/storefront/tsconfig.json +23 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState, type FormEvent } from "react"
|
|
5
|
+
import { accountApi } from "@/lib/core/account"
|
|
6
|
+
import { asRecords, stringValue, type JsonRecord } from "@/lib/core/commerce"
|
|
7
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
8
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
9
|
+
import { useCart } from "./cart-provider"
|
|
10
|
+
|
|
11
|
+
type AuthMode = "login" | "register" | "forgot"
|
|
12
|
+
type AccountTab = "profile" | "addresses" | "orders" | "security"
|
|
13
|
+
|
|
14
|
+
type AddressForm = {
|
|
15
|
+
id: string
|
|
16
|
+
address_name: string
|
|
17
|
+
first_name: string
|
|
18
|
+
last_name: string
|
|
19
|
+
company: string
|
|
20
|
+
phone: string
|
|
21
|
+
country_code: string
|
|
22
|
+
postal_code: string
|
|
23
|
+
city: string
|
|
24
|
+
province: string
|
|
25
|
+
address_1: string
|
|
26
|
+
address_2: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function AccountDashboard({ config }: { config: CoreConfig }) {
|
|
30
|
+
const api = useMemo(() => accountApi(config), [config])
|
|
31
|
+
const { transferToCustomer } = useCart()
|
|
32
|
+
const [customer, setCustomer] = useState<JsonRecord | null>(null)
|
|
33
|
+
const [loading, setLoading] = useState(true)
|
|
34
|
+
const [busy, setBusy] = useState<string | null>(null)
|
|
35
|
+
const [error, setError] = useState<string | null>(null)
|
|
36
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
37
|
+
const [mode, setMode] = useState<AuthMode>("login")
|
|
38
|
+
const [tab, setTab] = useState<AccountTab>("profile")
|
|
39
|
+
const [email, setEmail] = useState("")
|
|
40
|
+
const [password, setPassword] = useState("")
|
|
41
|
+
const [firstName, setFirstName] = useState("")
|
|
42
|
+
const [lastName, setLastName] = useState("")
|
|
43
|
+
|
|
44
|
+
const refresh = useCallback(async () => {
|
|
45
|
+
try {
|
|
46
|
+
const result = await api.profile()
|
|
47
|
+
setCustomer(result.customer)
|
|
48
|
+
return result.customer
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
if (cause instanceof CoreApiError && cause.status === 401) {
|
|
51
|
+
setCustomer(null)
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
throw cause
|
|
55
|
+
}
|
|
56
|
+
}, [api])
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
void refresh().catch(() => setCustomer(null)).finally(() => setLoading(false))
|
|
60
|
+
}, [refresh])
|
|
61
|
+
|
|
62
|
+
const authSubmit = async (event: FormEvent) => {
|
|
63
|
+
event.preventDefault()
|
|
64
|
+
setBusy("auth")
|
|
65
|
+
setError(null)
|
|
66
|
+
setMessage(null)
|
|
67
|
+
try {
|
|
68
|
+
if (mode === "forgot") {
|
|
69
|
+
await api.requestPasswordReset(email)
|
|
70
|
+
setMessage("Ha az e-mail címhez tartozik fiók, elküldtük a jelszó-visszaállítási levelet.")
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if (mode === "register") {
|
|
74
|
+
await api.register({ email, password, first_name: firstName, last_name: lastName })
|
|
75
|
+
await transferToCustomer().catch(() => undefined)
|
|
76
|
+
await refresh()
|
|
77
|
+
setMessage("A fiók létrejött. Az e-mail megerősítéséhez kövesd a kapott kódot.")
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
await api.login(email, password)
|
|
81
|
+
await transferToCustomer().catch(() => undefined)
|
|
82
|
+
await refresh()
|
|
83
|
+
setPassword("")
|
|
84
|
+
} catch (cause) {
|
|
85
|
+
setError(cause instanceof Error ? cause.message : "A művelet nem sikerült.")
|
|
86
|
+
} finally {
|
|
87
|
+
setBusy(null)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (loading) return <div className="empty-state">Fiók betöltése…</div>
|
|
92
|
+
|
|
93
|
+
if (!customer) {
|
|
94
|
+
return (
|
|
95
|
+
<div className="account-auth-grid">
|
|
96
|
+
<section className="panel stack">
|
|
97
|
+
<div>
|
|
98
|
+
<p className="eyebrow">Customer account</p>
|
|
99
|
+
<h1>{mode === "register" ? "Regisztráció" : mode === "forgot" ? "Elfelejtett jelszó" : "Belépés"}</h1>
|
|
100
|
+
</div>
|
|
101
|
+
<div className="segmented">
|
|
102
|
+
<button type="button" className={mode === "login" ? "active" : ""} onClick={() => setMode("login")}>Belépés</button>
|
|
103
|
+
<button type="button" className={mode === "register" ? "active" : ""} onClick={() => setMode("register")}>Regisztráció</button>
|
|
104
|
+
<button type="button" className={mode === "forgot" ? "active" : ""} onClick={() => setMode("forgot")}>Jelszó</button>
|
|
105
|
+
</div>
|
|
106
|
+
<form className="stack-sm" onSubmit={authSubmit}>
|
|
107
|
+
{mode === "register" ? (
|
|
108
|
+
<div className="form-grid two-col">
|
|
109
|
+
<Field label="Keresztnév" value={firstName} onChange={setFirstName} required />
|
|
110
|
+
<Field label="Vezetéknév" value={lastName} onChange={setLastName} required />
|
|
111
|
+
</div>
|
|
112
|
+
) : null}
|
|
113
|
+
<Field label="E-mail" type="email" value={email} onChange={setEmail} required />
|
|
114
|
+
{mode !== "forgot" ? <Field label="Jelszó" type="password" value={password} onChange={setPassword} required /> : null}
|
|
115
|
+
{error ? <p className="error">{error}</p> : null}
|
|
116
|
+
{message ? <p className="success">{message}</p> : null}
|
|
117
|
+
<button className="button button-large" type="submit" disabled={busy === "auth"}>
|
|
118
|
+
{busy === "auth" ? "Feldolgozás…" : mode === "register" ? "Fiók létrehozása" : mode === "forgot" ? "Visszaállító e-mail kérése" : "Belépés"}
|
|
119
|
+
</button>
|
|
120
|
+
</form>
|
|
121
|
+
</section>
|
|
122
|
+
<aside className="panel stack-sm account-benefits">
|
|
123
|
+
<p className="eyebrow">Fiók előnyei</p>
|
|
124
|
+
<h2>Rendeléseid egy helyen</h2>
|
|
125
|
+
<p className="muted">Mentett címek, rendelési előzmények, jelszó- és e-mail-kezelés, valamint visszaküldés, csere és reklamáció a Core-on keresztül.</p>
|
|
126
|
+
</aside>
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<div className="account-layout">
|
|
133
|
+
<aside className="account-sidebar panel">
|
|
134
|
+
<p className="eyebrow">Bejelentkezve</p>
|
|
135
|
+
<h2>{stringValue(customer.first_name || customer.email)}</h2>
|
|
136
|
+
<p className="muted small">{stringValue(customer.email)}</p>
|
|
137
|
+
<nav className="account-nav">
|
|
138
|
+
<TabButton active={tab === "profile"} onClick={() => setTab("profile")}>Profil</TabButton>
|
|
139
|
+
<TabButton active={tab === "addresses"} onClick={() => setTab("addresses")}>Címek</TabButton>
|
|
140
|
+
<TabButton active={tab === "orders"} onClick={() => setTab("orders")}>Rendelések</TabButton>
|
|
141
|
+
<TabButton active={tab === "security"} onClick={() => setTab("security")}>Biztonság</TabButton>
|
|
142
|
+
</nav>
|
|
143
|
+
<button className="button secondary" type="button" disabled={busy === "logout"} onClick={() => {
|
|
144
|
+
setBusy("logout")
|
|
145
|
+
void api.logout().finally(() => { setCustomer(null); setBusy(null) })
|
|
146
|
+
}}>Kijelentkezés</button>
|
|
147
|
+
</aside>
|
|
148
|
+
|
|
149
|
+
<main className="stack">
|
|
150
|
+
{tab === "profile" ? <ProfileSection customer={customer} api={api} refresh={refresh} setBusy={setBusy} busy={busy} /> : null}
|
|
151
|
+
{tab === "addresses" ? <AddressesSection config={config} api={api} /> : null}
|
|
152
|
+
{tab === "orders" ? <OrdersSection config={config} api={api} /> : null}
|
|
153
|
+
{tab === "security" ? <SecuritySection customer={customer} api={api} refresh={refresh} onDeleted={() => setCustomer(null)} /> : null}
|
|
154
|
+
</main>
|
|
155
|
+
</div>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function ProfileSection({ customer, api, refresh, busy, setBusy }: { customer: JsonRecord; api: ReturnType<typeof accountApi>; refresh: () => Promise<JsonRecord | null>; busy: string | null; setBusy: (value: string | null) => void }) {
|
|
160
|
+
const [first, setFirst] = useState(stringValue(customer.first_name))
|
|
161
|
+
const [last, setLast] = useState(stringValue(customer.last_name))
|
|
162
|
+
const [phone, setPhone] = useState(stringValue(customer.phone))
|
|
163
|
+
const [code, setCode] = useState("")
|
|
164
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
165
|
+
const metadata = isRecordSafe(customer.metadata) ? customer.metadata : {}
|
|
166
|
+
const verified = metadata.email_verified === true
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
<section className="panel stack">
|
|
171
|
+
<div><p className="eyebrow">Profil</p><h1>Személyes adatok</h1></div>
|
|
172
|
+
<div className="form-grid two-col">
|
|
173
|
+
<Field label="Keresztnév" value={first} onChange={setFirst} />
|
|
174
|
+
<Field label="Vezetéknév" value={last} onChange={setLast} />
|
|
175
|
+
<Field label="Telefon" value={phone} onChange={setPhone} />
|
|
176
|
+
<label>E-mail<input value={stringValue(customer.email)} readOnly /></label>
|
|
177
|
+
</div>
|
|
178
|
+
<button className="button" type="button" disabled={busy === "profile"} onClick={() => {
|
|
179
|
+
setBusy("profile")
|
|
180
|
+
void api.updateProfile({ first_name: first, last_name: last, phone }).then(refresh).then(() => setMessage("Profil mentve.")).catch((e) => setMessage(e instanceof Error ? e.message : "Mentési hiba.")).finally(() => setBusy(null))
|
|
181
|
+
}}>Profil mentése</button>
|
|
182
|
+
{message ? <p className={message.includes("mentve") ? "success" : "error"}>{message}</p> : null}
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<section className="panel stack-sm">
|
|
186
|
+
<div className="section-title-row"><div><p className="eyebrow">E-mail</p><h2>{verified ? "Megerősítve" : "Megerősítés szükséges"}</h2></div><span className={`status-pill ${verified ? "success-pill" : "warning-pill"}`}>{verified ? "Ellenőrizve" : "Függőben"}</span></div>
|
|
187
|
+
{!verified ? (
|
|
188
|
+
<>
|
|
189
|
+
<button className="button secondary" type="button" onClick={() => void api.requestEmailVerification().then(() => setMessage("Megerősítő kód elküldve."))}>Kód újraküldése</button>
|
|
190
|
+
<div className="inline-form"><input value={code} onChange={(e) => setCode(e.target.value)} placeholder="Megerősítő kód" /><button className="button" type="button" disabled={!code.trim()} onClick={() => void api.confirmEmailVerification(code).then(refresh).then(() => setMessage("E-mail megerősítve."))}>Megerősítés</button></div>
|
|
191
|
+
</>
|
|
192
|
+
) : null}
|
|
193
|
+
</section>
|
|
194
|
+
</>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function AddressesSection({ config, api }: { config: CoreConfig; api: ReturnType<typeof accountApi> }) {
|
|
199
|
+
const [addresses, setAddresses] = useState<JsonRecord[]>([])
|
|
200
|
+
const [form, setForm] = useState<AddressForm>(() => emptyAddressForm(config.store.default_country))
|
|
201
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
202
|
+
const load = useCallback(() => api.addresses().then((r) => setAddresses(r.addresses)), [api])
|
|
203
|
+
useEffect(() => { void load() }, [load])
|
|
204
|
+
|
|
205
|
+
const save = async () => {
|
|
206
|
+
const body = { ...form, id: undefined, country_code: form.country_code.toLowerCase() }
|
|
207
|
+
if (form.id) await api.updateAddress(form.id, body)
|
|
208
|
+
else await api.createAddress(body)
|
|
209
|
+
setForm(emptyAddressForm(config.store.default_country))
|
|
210
|
+
setMessage("Cím mentve.")
|
|
211
|
+
await load()
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<section className="panel stack">
|
|
216
|
+
<div><p className="eyebrow">Címjegyzék</p><h1>Mentett címek</h1></div>
|
|
217
|
+
{addresses.length ? <div className="address-grid">{addresses.map((address) => (
|
|
218
|
+
<div className="address-card" key={stringValue(address.id)}>
|
|
219
|
+
<strong>{stringValue(address.address_name || `${stringValue(address.first_name)} ${stringValue(address.last_name)}`)}</strong>
|
|
220
|
+
<span>{stringValue(address.postal_code)} {stringValue(address.city)}</span>
|
|
221
|
+
<span>{stringValue(address.address_1)} {stringValue(address.address_2)}</span>
|
|
222
|
+
<div className="button-row"><button className="text-button" type="button" onClick={() => setForm(addressToForm(address, config.store.default_country))}>Szerkesztés</button><button className="text-button danger" type="button" onClick={() => void api.deleteAddress(stringValue(address.id)).then(load)}>Törlés</button></div>
|
|
223
|
+
</div>
|
|
224
|
+
))}</div> : <div className="empty-state">Még nincs mentett címed.</div>}
|
|
225
|
+
|
|
226
|
+
<div className="divider" />
|
|
227
|
+
<h2>{form.id ? "Cím szerkesztése" : "Új cím"}</h2>
|
|
228
|
+
<div className="form-grid two-col">
|
|
229
|
+
{(["address_name", "first_name", "last_name", "company", "phone", "country_code", "postal_code", "city", "province", "address_1", "address_2"] as const).map((key) => (
|
|
230
|
+
<Field key={key} label={addressLabel(key)} value={form[key]} onChange={(value) => setForm((current) => ({ ...current, [key]: value }))} />
|
|
231
|
+
))}
|
|
232
|
+
</div>
|
|
233
|
+
<div className="button-row"><button className="button" type="button" onClick={() => void save().catch((e) => setMessage(e instanceof Error ? e.message : "Mentési hiba."))}>{form.id ? "Cím frissítése" : "Cím hozzáadása"}</button>{form.id ? <button className="button secondary" type="button" onClick={() => setForm(emptyAddressForm(config.store.default_country))}>Mégse</button> : null}</div>
|
|
234
|
+
{message ? <p className={message.includes("mentve") ? "success" : "error"}>{message}</p> : null}
|
|
235
|
+
</section>
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function OrdersSection({ config, api }: { config: CoreConfig; api: ReturnType<typeof accountApi> }) {
|
|
240
|
+
const [orders, setOrders] = useState<JsonRecord[]>([])
|
|
241
|
+
const [loading, setLoading] = useState(true)
|
|
242
|
+
useEffect(() => { void api.orders().then((r) => setOrders(r.orders)).finally(() => setLoading(false)) }, [api])
|
|
243
|
+
if (loading) return <section className="panel">Rendelések betöltése…</section>
|
|
244
|
+
return (
|
|
245
|
+
<section className="panel stack">
|
|
246
|
+
<div><p className="eyebrow">Előzmények</p><h1>Rendeléseim</h1></div>
|
|
247
|
+
{!orders.length ? <div className="empty-state">Még nincs rendelésed.</div> : <div className="order-list">{orders.map((order) => (
|
|
248
|
+
<Link className="order-row" href={`/account/orders/${encodeURIComponent(stringValue(order.id))}`} key={stringValue(order.id)}>
|
|
249
|
+
<div><strong>#{stringValue(order.display_id || order.id)}</strong><span className="muted">{formatDate(order.created_at, config.store.locale)}</span></div>
|
|
250
|
+
<div className="order-row-right"><span>{stringValue(order.status || "—")}</span><strong>{typeof order.total === "number" ? new Intl.NumberFormat(config.store.locale, { style: "currency", currency: stringValue(order.currency_code || config.store.default_currency).toUpperCase() }).format(order.total) : ""}</strong></div>
|
|
251
|
+
</Link>
|
|
252
|
+
))}</div>}
|
|
253
|
+
</section>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function SecuritySection({ customer, api, refresh, onDeleted }: { customer: JsonRecord; api: ReturnType<typeof accountApi>; refresh: () => Promise<JsonRecord | null>; onDeleted: () => void }) {
|
|
258
|
+
const [currentPassword, setCurrentPassword] = useState("")
|
|
259
|
+
const [newPassword, setNewPassword] = useState("")
|
|
260
|
+
const [newEmail, setNewEmail] = useState("")
|
|
261
|
+
const [emailCode, setEmailCode] = useState("")
|
|
262
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<>
|
|
266
|
+
<section className="panel stack-sm">
|
|
267
|
+
<div><p className="eyebrow">Jelszó</p><h2>Jelszó módosítása</h2></div>
|
|
268
|
+
<Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
|
|
269
|
+
<Field label="Új jelszó" type="password" value={newPassword} onChange={setNewPassword} />
|
|
270
|
+
<button className="button" type="button" onClick={() => void api.changePassword(currentPassword, newPassword).then(() => { setCurrentPassword(""); setNewPassword(""); setMessage("Jelszó módosítva.") }).catch((e) => setMessage(e instanceof Error ? e.message : "Hiba."))}>Jelszó módosítása</button>
|
|
271
|
+
</section>
|
|
272
|
+
|
|
273
|
+
<section className="panel stack-sm">
|
|
274
|
+
<div><p className="eyebrow">E-mail</p><h2>E-mail cím módosítása</h2></div>
|
|
275
|
+
<p className="muted">Jelenlegi cím: {stringValue(customer.email)}</p>
|
|
276
|
+
<Field label="Új e-mail" type="email" value={newEmail} onChange={setNewEmail} />
|
|
277
|
+
<Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
|
|
278
|
+
<button className="button secondary" type="button" onClick={() => void api.requestEmailChange(currentPassword, newEmail).then(() => setMessage("Megerősítő kód elküldve az új címhez."))}>E-mail módosítás kérése</button>
|
|
279
|
+
<div className="inline-form"><input value={emailCode} onChange={(e) => setEmailCode(e.target.value)} placeholder="Megerősítő kód" /><button className="button" type="button" onClick={() => void api.confirmEmailChange(emailCode).then(refresh).then(() => setMessage("E-mail cím módosítva."))}>Megerősítés</button></div>
|
|
280
|
+
</section>
|
|
281
|
+
|
|
282
|
+
<section className="panel stack-sm danger-zone">
|
|
283
|
+
<div><p className="eyebrow">Veszélyes művelet</p><h2>Fiók törlése</h2></div>
|
|
284
|
+
<p className="muted">A törléshez add meg a jelenlegi jelszavad. A rendelési bizonylatok és jogszabály szerint megőrzendő adatok kezelése a backend szabályai szerint történik.</p>
|
|
285
|
+
<Field label="Jelenlegi jelszó" type="password" value={currentPassword} onChange={setCurrentPassword} />
|
|
286
|
+
<button className="button danger-button" type="button" onClick={() => {
|
|
287
|
+
if (!confirm("Biztosan törlöd a fiókodat?")) return
|
|
288
|
+
void api.deleteAccount(currentPassword).then(onDeleted).catch((e) => setMessage(e instanceof Error ? e.message : "A törlés nem sikerült."))
|
|
289
|
+
}}>Fiók végleges törlése</button>
|
|
290
|
+
</section>
|
|
291
|
+
{message ? <p className={message.toLowerCase().includes("hiba") ? "error" : "success"}>{message}</p> : null}
|
|
292
|
+
</>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function TabButton({ active, onClick, children }: { active: boolean; onClick: () => void; children: React.ReactNode }) {
|
|
297
|
+
return <button className={active ? "active" : ""} type="button" onClick={onClick}>{children}</button>
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function Field({ label, value, onChange, type = "text", required = false }: { label: string; value: string; onChange: (value: string) => void; type?: string; required?: boolean }) {
|
|
301
|
+
return <label>{label}<input type={type} value={value} required={required} onChange={(event) => onChange(event.target.value)} /></label>
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function emptyAddressForm(country: string): AddressForm {
|
|
305
|
+
return { id: "", address_name: "", first_name: "", last_name: "", company: "", phone: "", country_code: country.toUpperCase(), postal_code: "", city: "", province: "", address_1: "", address_2: "" }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function addressToForm(address: JsonRecord, country: string): AddressForm {
|
|
309
|
+
const base = emptyAddressForm(country)
|
|
310
|
+
return Object.fromEntries(Object.keys(base).map((key) => [key, stringValue(address[key]) || base[key as keyof AddressForm]])) as unknown as AddressForm
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function addressLabel(key: keyof Omit<AddressForm, "id">) {
|
|
314
|
+
const labels: Record<string, string> = { address_name: "Cím neve", first_name: "Keresztnév", last_name: "Vezetéknév", company: "Cég", phone: "Telefon", country_code: "Ország", postal_code: "Irányítószám", city: "Város", province: "Megye / régió", address_1: "Utca, házszám", address_2: "Cím kiegészítés" }
|
|
315
|
+
return labels[key] || key
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function formatDate(value: unknown, locale: string) {
|
|
319
|
+
const date = new Date(stringValue(value))
|
|
320
|
+
return Number.isNaN(date.valueOf()) ? "" : date.toLocaleDateString(locale)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function isRecordSafe(value: unknown): value is JsonRecord {
|
|
324
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value))
|
|
325
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react"
|
|
4
|
+
import { useCart } from "./cart-provider"
|
|
5
|
+
import {
|
|
6
|
+
asRecords,
|
|
7
|
+
formatMoney,
|
|
8
|
+
productVariantCurrency,
|
|
9
|
+
productVariantPrice,
|
|
10
|
+
stringValue,
|
|
11
|
+
} from "@/lib/core/commerce"
|
|
12
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
13
|
+
|
|
14
|
+
export function AddToCart({ product, config }: { product: Record<string, unknown>; config: CoreConfig }) {
|
|
15
|
+
const variants = useMemo(() => asRecords(product.variants), [product])
|
|
16
|
+
const [variantId, setVariantId] = useState(() => stringValue(variants[0]?.id))
|
|
17
|
+
const [quantity, setQuantity] = useState(1)
|
|
18
|
+
const [message, setMessage] = useState<string | null>(null)
|
|
19
|
+
const { addItem, mutating } = useCart()
|
|
20
|
+
const selected = variants.find((variant) => stringValue(variant.id) === variantId) || variants[0]
|
|
21
|
+
const price = productVariantPrice(selected)
|
|
22
|
+
const currency = productVariantCurrency(selected, config.store.default_currency)
|
|
23
|
+
|
|
24
|
+
if (!variants.length) {
|
|
25
|
+
return <div className="notice warning">Ehhez a termékhez nincs megvásárolható variáns.</div>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="buy-box stack-sm">
|
|
30
|
+
{variants.length > 1 ? (
|
|
31
|
+
<label>
|
|
32
|
+
Változat
|
|
33
|
+
<select value={variantId} onChange={(event) => setVariantId(event.target.value)}>
|
|
34
|
+
{variants.map((variant) => (
|
|
35
|
+
<option key={stringValue(variant.id)} value={stringValue(variant.id)}>
|
|
36
|
+
{stringValue(variant.title || variant.sku || variant.id)}
|
|
37
|
+
{Number.isFinite(productVariantPrice(variant))
|
|
38
|
+
? ` – ${formatMoney(productVariantPrice(variant), productVariantCurrency(variant, currency), config.store.locale)}`
|
|
39
|
+
: ""}
|
|
40
|
+
</option>
|
|
41
|
+
))}
|
|
42
|
+
</select>
|
|
43
|
+
</label>
|
|
44
|
+
) : null}
|
|
45
|
+
<div className="buy-row">
|
|
46
|
+
<label className="quantity-field">
|
|
47
|
+
Mennyiség
|
|
48
|
+
<input min={1} max={99} type="number" value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} />
|
|
49
|
+
</label>
|
|
50
|
+
<div className="buy-price">
|
|
51
|
+
<span className="muted">Ár</span>
|
|
52
|
+
<strong>{Number.isFinite(price) ? formatMoney(price, currency, config.store.locale) : "—"}</strong>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
<button
|
|
56
|
+
className="button button-large"
|
|
57
|
+
type="button"
|
|
58
|
+
disabled={mutating || !variantId}
|
|
59
|
+
onClick={() => {
|
|
60
|
+
setMessage(null)
|
|
61
|
+
void addItem(variantId, quantity)
|
|
62
|
+
.then(() => setMessage("A termék bekerült a kosárba."))
|
|
63
|
+
.catch((error) => setMessage(error instanceof Error ? error.message : "Nem sikerült kosárba tenni."))
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
{mutating ? "Kosár frissítése…" : "Kosárba"}
|
|
67
|
+
</button>
|
|
68
|
+
{message ? <p className={message.includes("bekerült") ? "success" : "error"}>{message}</p> : null}
|
|
69
|
+
</div>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Script from "next/script"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
5
|
+
import { useEffect, useState } from "react"
|
|
6
|
+
import {
|
|
7
|
+
COOKIE_CONSENT_EVENT,
|
|
8
|
+
applyGoogleConsent,
|
|
9
|
+
readConsentPreferences,
|
|
10
|
+
type ConsentPreferences,
|
|
11
|
+
} from "@/lib/core/consent"
|
|
12
|
+
import { analyticsTrackingMode, trackWebshopPageView } from "@/lib/core/tracking"
|
|
13
|
+
import type { CoreConfig } from "@/lib/core/types"
|
|
14
|
+
|
|
15
|
+
export const GOOGLE_CONSENT_DEFAULT_SCRIPT = `
|
|
16
|
+
window.dataLayer=window.dataLayer||[];
|
|
17
|
+
function gtag(){dataLayer.push(arguments);}
|
|
18
|
+
gtag('consent','default',{
|
|
19
|
+
analytics_storage:'denied',
|
|
20
|
+
ad_storage:'denied',
|
|
21
|
+
ad_user_data:'denied',
|
|
22
|
+
ad_personalization:'denied',
|
|
23
|
+
wait_for_update:500
|
|
24
|
+
});
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
export function AnalyticsGate({ analytics }: { analytics: CoreConfig["analytics"] }) {
|
|
28
|
+
const pathname = usePathname()
|
|
29
|
+
const [preferences, setPreferences] = useState<ConsentPreferences | null>(null)
|
|
30
|
+
const [ready, setReady] = useState(false)
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const stored = readConsentPreferences()
|
|
34
|
+
if (stored) applyGoogleConsent(stored)
|
|
35
|
+
setPreferences(stored)
|
|
36
|
+
setReady(true)
|
|
37
|
+
|
|
38
|
+
const onConsent = (event: Event) => {
|
|
39
|
+
const next = (event as CustomEvent<ConsentPreferences>).detail
|
|
40
|
+
if (!next) return
|
|
41
|
+
applyGoogleConsent(next)
|
|
42
|
+
setPreferences(next)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
window.addEventListener(COOKIE_CONSENT_EVENT, onConsent)
|
|
46
|
+
return () => window.removeEventListener(COOKIE_CONSENT_EVENT, onConsent)
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
// HSZRDM Webshop Analytics is first-party and independent from GA4/GTM.
|
|
51
|
+
// The tracker stores only pseudonymous identifiers and commerce context.
|
|
52
|
+
trackWebshopPageView()
|
|
53
|
+
}, [pathname])
|
|
54
|
+
|
|
55
|
+
if (!ready) return null
|
|
56
|
+
|
|
57
|
+
const mode = analyticsTrackingMode(analytics)
|
|
58
|
+
const analyticsGranted = Boolean(preferences?.analytics)
|
|
59
|
+
const marketingGranted = Boolean(preferences?.marketing)
|
|
60
|
+
|
|
61
|
+
// GTM is the single loader whenever a container is configured. This prevents
|
|
62
|
+
// a direct GA4 snippet and a GA4 tag inside GTM from double-counting events.
|
|
63
|
+
const loadGtm = mode === "gtm" && (analyticsGranted || marketingGranted)
|
|
64
|
+
const loadGa4 = mode === "ga4" && analyticsGranted
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
{loadGa4 && analytics.google_analytics.measurement_id ? (
|
|
69
|
+
<>
|
|
70
|
+
<Script
|
|
71
|
+
id="core-ga4-loader"
|
|
72
|
+
src={`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(
|
|
73
|
+
analytics.google_analytics.measurement_id,
|
|
74
|
+
)}`}
|
|
75
|
+
strategy="afterInteractive"
|
|
76
|
+
/>
|
|
77
|
+
<Script id="core-ga4-config" strategy="afterInteractive">
|
|
78
|
+
{`gtag('js',new Date());gtag('config','${analytics.google_analytics.measurement_id}');`}
|
|
79
|
+
</Script>
|
|
80
|
+
</>
|
|
81
|
+
) : null}
|
|
82
|
+
|
|
83
|
+
{loadGtm && analytics.google_tag_manager.container_id ? (
|
|
84
|
+
<Script id="core-gtm" strategy="afterInteractive">
|
|
85
|
+
{`(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${analytics.google_tag_manager.container_id}');`}
|
|
86
|
+
</Script>
|
|
87
|
+
) : null}
|
|
88
|
+
</>
|
|
89
|
+
)
|
|
90
|
+
}
|