@hszrdm/create-commerce 0.0.0-stage → 1.0.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.
Files changed (68) hide show
  1. package/README.md +50 -2
  2. package/bin/create-commerce.mjs +51 -0
  3. package/package.json +23 -4
  4. package/src/cli.mjs +585 -0
  5. package/templates/backend/.env.example +113 -0
  6. package/templates/backend/README.md +7 -0
  7. package/templates/backend/instrumentation.ts +24 -0
  8. package/templates/backend/medusa-config.ts +11 -0
  9. package/templates/backend/package.json +42 -0
  10. package/templates/backend/scripts/prepare-project.mjs +49 -0
  11. package/templates/backend/src/project/README.md +13 -0
  12. package/templates/backend/src/project/api/.gitkeep +0 -0
  13. package/templates/backend/src/project/jobs/.gitkeep +0 -0
  14. package/templates/backend/src/project/modules/.gitkeep +0 -0
  15. package/templates/backend/src/project/subscribers/.gitkeep +0 -0
  16. package/templates/backend/src/project/workflows/.gitkeep +0 -0
  17. package/templates/backend/src/scripts/core-init.ts +21 -0
  18. package/templates/backend/src/scripts/create-storefront-key.ts +12 -0
  19. package/templates/backend/src/scripts/verify-bootstrap.ts +1 -0
  20. package/templates/backend/tsconfig.json +33 -0
  21. package/templates/storefront/.env.example +5 -0
  22. package/templates/storefront/README.md +108 -0
  23. package/templates/storefront/next-env.d.ts +4 -0
  24. package/templates/storefront/next.config.ts +8 -0
  25. package/templates/storefront/package.json +24 -0
  26. package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +38 -0
  27. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +51 -0
  28. package/templates/storefront/src/app/[countryCode]/products/page.tsx +47 -0
  29. package/templates/storefront/src/app/account/orders/[id]/page.tsx +8 -0
  30. package/templates/storefront/src/app/account/page.tsx +11 -0
  31. package/templates/storefront/src/app/cart/page.tsx +12 -0
  32. package/templates/storefront/src/app/checkout/page.tsx +15 -0
  33. package/templates/storefront/src/app/checkout/success/page.tsx +72 -0
  34. package/templates/storefront/src/app/error.tsx +14 -0
  35. package/templates/storefront/src/app/globals.css +250 -0
  36. package/templates/storefront/src/app/layout.tsx +59 -0
  37. package/templates/storefront/src/app/legal/page.tsx +26 -0
  38. package/templates/storefront/src/app/loading.tsx +3 -0
  39. package/templates/storefront/src/app/not-found.tsx +14 -0
  40. package/templates/storefront/src/app/page.tsx +47 -0
  41. package/templates/storefront/src/app/reset-password/page.tsx +14 -0
  42. package/templates/storefront/src/app/robots.txt/route.ts +13 -0
  43. package/templates/storefront/src/app/sitemap.xml/route.ts +13 -0
  44. package/templates/storefront/src/components/account-dashboard.tsx +325 -0
  45. package/templates/storefront/src/components/add-to-cart.tsx +71 -0
  46. package/templates/storefront/src/components/analytics.tsx +90 -0
  47. package/templates/storefront/src/components/cart-provider.tsx +236 -0
  48. package/templates/storefront/src/components/cart-view.tsx +135 -0
  49. package/templates/storefront/src/components/checkout-flow.tsx +534 -0
  50. package/templates/storefront/src/components/consent-banner.tsx +131 -0
  51. package/templates/storefront/src/components/order-detail.tsx +273 -0
  52. package/templates/storefront/src/components/product-card.tsx +38 -0
  53. package/templates/storefront/src/components/product-view-tracker.tsx +37 -0
  54. package/templates/storefront/src/components/reset-password-form.tsx +65 -0
  55. package/templates/storefront/src/components/storefront-header.tsx +42 -0
  56. package/templates/storefront/src/components/stripe-payment.tsx +90 -0
  57. package/templates/storefront/src/lib/core/account.ts +170 -0
  58. package/templates/storefront/src/lib/core/after-sales.ts +50 -0
  59. package/templates/storefront/src/lib/core/catalog.ts +56 -0
  60. package/templates/storefront/src/lib/core/checkout.ts +330 -0
  61. package/templates/storefront/src/lib/core/client.ts +107 -0
  62. package/templates/storefront/src/lib/core/commerce.ts +148 -0
  63. package/templates/storefront/src/lib/core/consent.ts +111 -0
  64. package/templates/storefront/src/lib/core/legal.ts +33 -0
  65. package/templates/storefront/src/lib/core/seo.ts +88 -0
  66. package/templates/storefront/src/lib/core/tracking.ts +584 -0
  67. package/templates/storefront/src/lib/core/types.ts +123 -0
  68. package/templates/storefront/tsconfig.json +23 -0
@@ -0,0 +1,273 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { useCallback, useEffect, useMemo, useState } from "react"
5
+ import { accountApi } from "@/lib/core/account"
6
+ import { afterSalesApi, type AfterSalesCaseType } from "@/lib/core/after-sales"
7
+ import { medusaFetch } from "@/lib/core/client"
8
+ import {
9
+ asRecords,
10
+ formatMoney,
11
+ isRecord,
12
+ numberValue,
13
+ orderDisplayId,
14
+ stringValue,
15
+ type JsonRecord,
16
+ } from "@/lib/core/commerce"
17
+ import type { CoreConfig } from "@/lib/core/types"
18
+
19
+ type CaseMode = "return" | "exchange" | "claim"
20
+ type VisibleCase = JsonRecord & { __case_type: AfterSalesCaseType }
21
+
22
+ export function OrderDetail({ config, orderId }: { config: CoreConfig; orderId: string }) {
23
+ const account = useMemo(() => accountApi(config), [config])
24
+ const afterSales = useMemo(() => afterSalesApi(config), [config])
25
+ const [order, setOrder] = useState<JsonRecord | null>(null)
26
+ const [after, setAfter] = useState<JsonRecord | null>(null)
27
+ const [reasons, setReasons] = useState<JsonRecord[]>([])
28
+ const [variants, setVariants] = useState<JsonRecord[]>([])
29
+ const [loading, setLoading] = useState(true)
30
+ const [error, setError] = useState<string | null>(null)
31
+ const [message, setMessage] = useState<string | null>(null)
32
+ const [mode, setMode] = useState<CaseMode>("return")
33
+ const [itemId, setItemId] = useState("")
34
+ const [quantity, setQuantity] = useState(1)
35
+ const [reasonId, setReasonId] = useState("")
36
+ const [claimReason, setClaimReason] = useState("other")
37
+ const [claimType, setClaimType] = useState("refund")
38
+ const [newVariantId, setNewVariantId] = useState("")
39
+ const [description, setDescription] = useState("")
40
+ const [busy, setBusy] = useState(false)
41
+
42
+ const load = useCallback(async () => {
43
+ setLoading(true)
44
+ setError(null)
45
+ try {
46
+ const [orderResult, afterResult] = await Promise.all([
47
+ account.order(orderId),
48
+ config.after_sales.enabled
49
+ ? afterSales.status(orderId)
50
+ : Promise.resolve(null),
51
+ ])
52
+ setOrder(orderResult.order)
53
+ setAfter(afterResult && isRecord(afterResult.after_sales) ? afterResult.after_sales : null)
54
+ const first = asRecords(orderResult.order.items)[0]
55
+ if (first && !itemId) setItemId(stringValue(first.id))
56
+ } catch (cause) {
57
+ setError(cause instanceof Error ? cause.message : "A rendelés nem tölthető be.")
58
+ } finally {
59
+ setLoading(false)
60
+ }
61
+ }, [account, afterSales, config.after_sales.enabled, itemId, orderId])
62
+
63
+ useEffect(() => { void load() }, [load])
64
+
65
+ useEffect(() => {
66
+ if (!config.after_sales.enabled) return
67
+ void afterSales.returnReasons()
68
+ .then((result) => setReasons(result.return_reasons))
69
+ .catch(() => setReasons([]))
70
+ }, [afterSales, config.after_sales.enabled])
71
+
72
+ useEffect(() => {
73
+ if (mode !== "exchange" || variants.length) return
74
+ void medusaFetch<{ products: JsonRecord[] }>(
75
+ "/store/products?limit=100&fields=+variants",
76
+ { cache: "no-store" },
77
+ )
78
+ .then((result) => setVariants(
79
+ result.products.flatMap((product) =>
80
+ asRecords(product.variants).map((variant) => ({
81
+ ...variant,
82
+ product_title: product.title,
83
+ })),
84
+ ),
85
+ ))
86
+ .catch(() => setVariants([]))
87
+ }, [mode, variants.length])
88
+
89
+ if (loading) return <div className="empty-state">Rendelés betöltése…</div>
90
+ if (error || !order) return <div className="notice error-box">{error || "A rendelés nem található."}</div>
91
+
92
+ const items = asRecords(order.items)
93
+ const selectedItem = items.find((item) => stringValue(item.id) === itemId) || items[0]
94
+ const currency = stringValue(order.currency_code || config.store.default_currency).toUpperCase()
95
+ const afterConfig = after && isRecord(after.config) ? after.config : {}
96
+ const returns = asRecords(after?.returns)
97
+ const exchanges = asRecords(after?.exchanges)
98
+ const claims = asRecords(after?.claims)
99
+ const cases: VisibleCase[] = [
100
+ ...returns.map((entry) => ({ ...entry, __case_type: "return" as const })),
101
+ ...exchanges.map((entry) => ({ ...entry, __case_type: "exchange" as const })),
102
+ ...claims.map((entry) => ({ ...entry, __case_type: "claim" as const })),
103
+ ].sort((a: VisibleCase, b: VisibleCase) => stringValue(b.created_at).localeCompare(stringValue(a.created_at)))
104
+
105
+ const submit = async () => {
106
+ if (!selectedItem) throw new Error("Válassz rendelési tételt.")
107
+ setBusy(true)
108
+ setError(null)
109
+ setMessage(null)
110
+ try {
111
+ const baseItem = {
112
+ id: stringValue(selectedItem.id),
113
+ quantity,
114
+ note: description || undefined,
115
+ }
116
+ if (mode === "return") {
117
+ await afterSales.createReturn(orderId, {
118
+ items: [{ ...baseItem, reason_id: reasonId || undefined }],
119
+ description: description || undefined,
120
+ locale: config.store.locale,
121
+ })
122
+ } else if (mode === "exchange") {
123
+ if (!newVariantId) throw new Error("Válassz csereterméket.")
124
+ await afterSales.createExchange(orderId, {
125
+ return_items: [{ ...baseItem, reason_id: reasonId || undefined }],
126
+ new_items: [{ variant_id: newVariantId, quantity }],
127
+ description: description || undefined,
128
+ locale: config.store.locale,
129
+ })
130
+ } else {
131
+ await afterSales.createClaim(orderId, {
132
+ type: claimType,
133
+ items: [{ ...baseItem, reason: claimReason }],
134
+ description: description || undefined,
135
+ locale: config.store.locale,
136
+ })
137
+ }
138
+ setMessage("A kérelem elküldve.")
139
+ setDescription("")
140
+ await load()
141
+ } catch (cause) {
142
+ setError(cause instanceof Error ? cause.message : "A kérelem nem küldhető el.")
143
+ } finally {
144
+ setBusy(false)
145
+ }
146
+ }
147
+
148
+ const canReturn = config.after_sales.enabled && config.after_sales.returns && afterConfig.returnsEnabled !== false
149
+ const canExchange = config.after_sales.enabled && config.after_sales.exchanges && afterConfig.exchangesEnabled !== false
150
+ const canClaim = config.after_sales.enabled && config.after_sales.claims && afterConfig.claimsEnabled !== false
151
+
152
+ return (
153
+ <div className="stack">
154
+ <div className="page-heading">
155
+ <div>
156
+ <p className="eyebrow">Rendelés</p>
157
+ <h1>#{orderDisplayId(order)}</h1>
158
+ <p className="muted">{formatDate(order.created_at, config.store.locale)} · {stringValue(order.status)}</p>
159
+ </div>
160
+ <Link className="button secondary" href="/account">Vissza a fiókhoz</Link>
161
+ </div>
162
+
163
+ <div className="order-detail-grid">
164
+ <section className="panel stack">
165
+ <h2>Termékek</h2>
166
+ {items.map((item) => (
167
+ <div className="order-item" key={stringValue(item.id)}>
168
+ {stringValue(item.thumbnail)
169
+ ? <img src={stringValue(item.thumbnail)} alt="" />
170
+ : <div className="media-placeholder" />}
171
+ <div>
172
+ <strong>{stringValue(item.product_title || item.title)}</strong>
173
+ <span className="muted">{stringValue(item.variant_title)}</span>
174
+ <span>{numberValue(item.quantity, 1)} db</span>
175
+ </div>
176
+ <strong>{typeof item.total === "number" ? formatMoney(item.total, currency, config.store.locale) : ""}</strong>
177
+ </div>
178
+ ))}
179
+ {typeof order.total === "number"
180
+ ? <div className="summary-total"><span>Összesen</span><strong>{formatMoney(order.total, currency, config.store.locale)}</strong></div>
181
+ : null}
182
+ </section>
183
+
184
+ <aside className="panel stack-sm">
185
+ <h2>Rendelési adatok</h2>
186
+ <Info label="Státusz" value={stringValue(order.status)} />
187
+ <Info label="Fizetés" value={stringValue(order.payment_status)} />
188
+ <Info label="Teljesítés" value={stringValue(order.fulfillment_status)} />
189
+ <Info label="E-mail" value={stringValue(order.email)} />
190
+ {isRecord(order.shipping_address)
191
+ ? <Info label="Szállítási cím" value={formatAddress(order.shipping_address)} />
192
+ : null}
193
+ {asRecords(order.fulfillments)
194
+ .flatMap((fulfillment) => asRecords(fulfillment.labels))
195
+ .map((label) => stringValue(label.tracking_url))
196
+ .filter(Boolean)
197
+ .map((url) => <a className="text-link" href={url} target="_blank" rel="noreferrer" key={url}>Csomagkövetés</a>)}
198
+ </aside>
199
+ </div>
200
+
201
+ {config.after_sales.enabled ? (
202
+ <section className="panel stack">
203
+ <div><p className="eyebrow">After-sales</p><h2>Visszaküldés, csere vagy reklamáció</h2></div>
204
+ <div className="segmented">
205
+ {canReturn ? <button type="button" className={mode === "return" ? "active" : ""} onClick={() => setMode("return")}>Visszaküldés</button> : null}
206
+ {canExchange ? <button type="button" className={mode === "exchange" ? "active" : ""} onClick={() => setMode("exchange")}>Csere</button> : null}
207
+ {canClaim ? <button type="button" className={mode === "claim" ? "active" : ""} onClick={() => setMode("claim")}>Reklamáció</button> : null}
208
+ </div>
209
+
210
+ <div className="form-grid two-col">
211
+ <label>
212
+ Rendelési tétel
213
+ <select value={itemId} onChange={(event) => setItemId(event.target.value)}>
214
+ {items.map((item) => <option key={stringValue(item.id)} value={stringValue(item.id)}>{stringValue(item.product_title || item.title)} · {stringValue(item.variant_title)}</option>)}
215
+ </select>
216
+ </label>
217
+ <label>Mennyiség<input type="number" min={1} max={Math.max(1, numberValue(selectedItem?.quantity, 1))} value={quantity} onChange={(event) => setQuantity(Math.max(1, Number(event.target.value) || 1))} /></label>
218
+ {mode !== "claim" ? (
219
+ <label>Ok<select value={reasonId} onChange={(event) => setReasonId(event.target.value)}><option value="">Nincs megadva</option>{reasons.map((reason) => <option key={stringValue(reason.id)} value={stringValue(reason.id)}>{stringValue(reason.label || reason.value)}</option>)}</select></label>
220
+ ) : null}
221
+ {mode === "claim" ? (
222
+ <>
223
+ <label>Reklamáció típusa<select value={claimType} onChange={(event) => setClaimType(event.target.value)}><option value="refund">Visszatérítés</option><option value="replace">Cserepótlás</option></select></label>
224
+ <label>Hiba oka<select value={claimReason} onChange={(event) => setClaimReason(event.target.value)}><option value="production_failure">Gyártási hiba</option><option value="wrong_item">Rossz termék</option><option value="missing_item">Hiányzó termék</option><option value="other">Egyéb</option></select></label>
225
+ </>
226
+ ) : null}
227
+ {mode === "exchange" ? (
228
+ <label>Cseretermék<select value={newVariantId} onChange={(event) => setNewVariantId(event.target.value)}><option value="">Válassz variánst</option>{variants.map((variant) => <option value={stringValue(variant.id)} key={stringValue(variant.id)}>{stringValue(variant.product_title)} · {stringValue(variant.title || variant.sku)}</option>)}</select></label>
229
+ ) : null}
230
+ </div>
231
+ <label>Leírás<textarea value={description} rows={4} onChange={(event) => setDescription(event.target.value)} placeholder="Írd le röviden a kérést vagy problémát." /></label>
232
+ <button className="button" type="button" disabled={busy} onClick={() => void submit()}>{busy ? "Küldés…" : "Kérelem elküldése"}</button>
233
+ {message ? <p className="success">{message}</p> : null}
234
+ {error ? <p className="error">{error}</p> : null}
235
+ </section>
236
+ ) : null}
237
+
238
+ {cases.length ? (
239
+ <section className="panel stack">
240
+ <h2>Korábbi kérelmek</h2>
241
+ {cases.map((entry) => (
242
+ <div className="case-row" key={`${entry.__case_type}:${stringValue(entry.id)}`}>
243
+ <div>
244
+ <strong>{caseLabel(entry.__case_type)}</strong>
245
+ <span className="muted">#{stringValue(entry.display_id || entry.id)}</span>
246
+ </div>
247
+ <div>
248
+ <span className="status-pill">{stringValue(entry.request_status || entry.status || entry.change_status || "—")}</span>
249
+ {stringValue(entry.request_status) === "submitted"
250
+ ? <button className="text-button danger" type="button" onClick={() => void afterSales.cancel(orderId, entry.__case_type, stringValue(entry.id)).then(load)}>Visszavonás</button>
251
+ : null}
252
+ </div>
253
+ </div>
254
+ ))}
255
+ </section>
256
+ ) : null}
257
+ </div>
258
+ )
259
+ }
260
+
261
+ function Info({ label, value }: { label: string; value: string }) {
262
+ return <div className="info-row"><span className="muted">{label}</span><strong>{value || "—"}</strong></div>
263
+ }
264
+ function formatDate(value: unknown, locale: string) {
265
+ const date = new Date(stringValue(value))
266
+ return Number.isNaN(date.valueOf()) ? "" : date.toLocaleString(locale)
267
+ }
268
+ function formatAddress(address: JsonRecord) {
269
+ return [stringValue(address.postal_code), stringValue(address.city), stringValue(address.address_1), stringValue(address.address_2)].filter(Boolean).join(" ")
270
+ }
271
+ function caseLabel(type: AfterSalesCaseType) {
272
+ return type === "return" ? "Visszaküldés" : type === "exchange" ? "Csere" : "Reklamáció"
273
+ }
@@ -0,0 +1,38 @@
1
+ import Link from "next/link"
2
+ import {
3
+ asRecords,
4
+ formatMoney,
5
+ isRecord,
6
+ productVariantCurrency,
7
+ productVariantPrice,
8
+ stringValue,
9
+ } from "@/lib/core/commerce"
10
+ import { renderPathTemplate } from "@/lib/core/client"
11
+ import type { CoreConfig } from "@/lib/core/types"
12
+
13
+ export function ProductCard({ product, config }: { product: Record<string, unknown>; config: CoreConfig }) {
14
+ const variants = asRecords(product.variants)
15
+ const variant = variants[0] || null
16
+ const price = productVariantPrice(variant)
17
+ const currency = productVariantCurrency(variant, config.store.default_currency)
18
+ const handle = stringValue(product.handle)
19
+ const href = renderPathTemplate(config.seo.product_path_template, {
20
+ country_code: config.seo.default_country_code,
21
+ handle,
22
+ })
23
+ const thumbnail = stringValue(product.thumbnail)
24
+ const categories = asRecords(product.categories)
25
+
26
+ return (
27
+ <article className="product-card">
28
+ <Link href={href} className="product-media">
29
+ {thumbnail ? <img src={thumbnail} alt={stringValue(product.title)} /> : <span className="media-placeholder">Nincs kép</span>}
30
+ </Link>
31
+ <div className="product-card-body">
32
+ {categories[0] && isRecord(categories[0]) ? <span className="eyebrow">{stringValue(categories[0].name)}</span> : null}
33
+ <Link href={href}><h2>{stringValue(product.title)}</h2></Link>
34
+ {Number.isFinite(price) ? <strong>{formatMoney(price, currency, config.store.locale)}</strong> : <span className="muted">Ár a termékoldalon</span>}
35
+ </div>
36
+ </article>
37
+ )
38
+ }
@@ -0,0 +1,37 @@
1
+ "use client"
2
+
3
+ import { useEffect } from "react"
4
+ import { COOKIE_CONSENT_EVENT } from "@/lib/core/consent"
5
+ import {
6
+ trackViewItem,
7
+ type EcommerceItem,
8
+ } from "@/lib/core/tracking"
9
+ import type { CoreConfig } from "@/lib/core/types"
10
+
11
+ export function ProductViewTracker({
12
+ analytics,
13
+ item,
14
+ currency,
15
+ value,
16
+ }: {
17
+ analytics: CoreConfig["analytics"]
18
+ item: EcommerceItem
19
+ currency: string
20
+ value?: number
21
+ }) {
22
+ useEffect(() => {
23
+ const send = () =>
24
+ trackViewItem(analytics, {
25
+ item,
26
+ currency,
27
+ value,
28
+ dedupeKey: `${item.item_id}:${window.location.pathname}`,
29
+ })
30
+
31
+ send()
32
+ window.addEventListener(COOKIE_CONSENT_EVENT, send)
33
+ return () => window.removeEventListener(COOKIE_CONSENT_EVENT, send)
34
+ }, [analytics, currency, item, value])
35
+
36
+ return null
37
+ }
@@ -0,0 +1,65 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { useSearchParams } from "next/navigation"
5
+ import { useMemo, useState } from "react"
6
+ import { accountApi } from "@/lib/core/account"
7
+ import type { CoreConfig } from "@/lib/core/types"
8
+
9
+ export function ResetPasswordForm({ config }: { config: CoreConfig }) {
10
+ const api = useMemo(() => accountApi(config), [config])
11
+ const search = useSearchParams()
12
+ const token = search.get("token") || ""
13
+ const initialEmail = search.get("email") || ""
14
+ const [email, setEmail] = useState(initialEmail)
15
+ const [password, setPassword] = useState("")
16
+ const [confirm, setConfirm] = useState("")
17
+ const [busy, setBusy] = useState(false)
18
+ const [message, setMessage] = useState<string | null>(null)
19
+ const [error, setError] = useState<string | null>(null)
20
+
21
+ const submit = async () => {
22
+ setError(null)
23
+ setMessage(null)
24
+ if (!token) {
25
+ setError("Hiányzik a jelszó-visszaállítási token. Kérj új visszaállító e-mailt.")
26
+ return
27
+ }
28
+ if (!email.trim()) {
29
+ setError("Add meg az e-mail címedet.")
30
+ return
31
+ }
32
+ if (password.length < 8) {
33
+ setError("Az új jelszó legalább 8 karakter legyen.")
34
+ return
35
+ }
36
+ if (password !== confirm) {
37
+ setError("A két jelszó nem egyezik.")
38
+ return
39
+ }
40
+ setBusy(true)
41
+ try {
42
+ await api.completePasswordReset(token, email, password)
43
+ setMessage("A jelszó sikeresen módosult. Most már bejelentkezhetsz.")
44
+ setPassword("")
45
+ setConfirm("")
46
+ } catch (cause) {
47
+ setError(cause instanceof Error ? cause.message : "A jelszó-visszaállítás nem sikerült.")
48
+ } finally {
49
+ setBusy(false)
50
+ }
51
+ }
52
+
53
+ return (
54
+ <section className="panel stack narrow-card">
55
+ <div><p className="eyebrow">Fiók biztonság</p><h1>Új jelszó beállítása</h1></div>
56
+ <label>E-mail<input type="email" value={email} onChange={(event) => setEmail(event.target.value)} /></label>
57
+ <label>Új jelszó<input type="password" value={password} onChange={(event) => setPassword(event.target.value)} /></label>
58
+ <label>Új jelszó újra<input type="password" value={confirm} onChange={(event) => setConfirm(event.target.value)} /></label>
59
+ {error ? <p className="error">{error}</p> : null}
60
+ {message ? <p className="success">{message}</p> : null}
61
+ <button className="button button-large" type="button" disabled={busy} onClick={() => void submit()}>{busy ? "Mentés…" : "Jelszó mentése"}</button>
62
+ <Link className="text-link" href="/account">Vissza a belépéshez</Link>
63
+ </section>
64
+ )
65
+ }
@@ -0,0 +1,42 @@
1
+ "use client"
2
+
3
+ import Link from "next/link"
4
+ import { useCart } from "./cart-provider"
5
+ import { CartView } from "./cart-view"
6
+ import type { CoreConfig } from "@/lib/core/types"
7
+
8
+ export function StorefrontHeader({ config }: { config: CoreConfig }) {
9
+ const { count, drawerOpen, setDrawerOpen } = useCart()
10
+ const country = config.seo.default_country_code
11
+
12
+ return (
13
+ <>
14
+ <header className="shell header">
15
+ <Link className="brand" href="/">{config.store.name}</Link>
16
+ <nav className="nav" aria-label="Fő navigáció">
17
+ <Link href={`/${country}/products`}>Termékek</Link>
18
+ <Link href="/legal">Jogi dokumentumok</Link>
19
+ {config.features.account ? <Link href="/account">Fiókom</Link> : null}
20
+ <button className="nav-cart" type="button" onClick={() => setDrawerOpen(true)}>
21
+ Kosár <span className="cart-count">{count}</span>
22
+ </button>
23
+ </nav>
24
+ </header>
25
+
26
+ {drawerOpen ? (
27
+ <div className="drawer-backdrop" onMouseDown={() => setDrawerOpen(false)}>
28
+ <aside className="drawer" onMouseDown={(event) => event.stopPropagation()} aria-label="Kosár">
29
+ <div className="drawer-head">
30
+ <div>
31
+ <p className="eyebrow">Kosár</p>
32
+ <h2>{count} termék</h2>
33
+ </div>
34
+ <button className="icon-button" type="button" aria-label="Bezárás" onClick={() => setDrawerOpen(false)}>×</button>
35
+ </div>
36
+ <CartView config={config} compact />
37
+ </aside>
38
+ </div>
39
+ ) : null}
40
+ </>
41
+ )
42
+ }
@@ -0,0 +1,90 @@
1
+ "use client"
2
+
3
+ import { useMemo, useState } from "react"
4
+ import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js"
5
+ import { loadStripe } from "@stripe/stripe-js/pure"
6
+
7
+ export function StripePayment({
8
+ publishableKey,
9
+ clientSecret,
10
+ cartId,
11
+ disabled = false,
12
+ beforeConfirm,
13
+ onConfirmed,
14
+ }: {
15
+ publishableKey: string
16
+ clientSecret: string
17
+ cartId: string
18
+ disabled?: boolean
19
+ beforeConfirm?: () => Promise<void>
20
+ onConfirmed: () => Promise<void>
21
+ }) {
22
+ const stripePromise = useMemo(() => loadStripe(publishableKey), [publishableKey])
23
+ return (
24
+ <Elements stripe={stripePromise} options={{ clientSecret }}>
25
+ <StripePaymentForm
26
+ cartId={cartId}
27
+ disabled={disabled}
28
+ beforeConfirm={beforeConfirm}
29
+ onConfirmed={onConfirmed}
30
+ />
31
+ </Elements>
32
+ )
33
+ }
34
+
35
+ function StripePaymentForm({
36
+ cartId,
37
+ disabled,
38
+ beforeConfirm,
39
+ onConfirmed,
40
+ }: {
41
+ cartId: string
42
+ disabled: boolean
43
+ beforeConfirm?: () => Promise<void>
44
+ onConfirmed: () => Promise<void>
45
+ }) {
46
+ const stripe = useStripe()
47
+ const elements = useElements()
48
+ const [busy, setBusy] = useState(false)
49
+ const [error, setError] = useState<string | null>(null)
50
+
51
+ const submit = async () => {
52
+ if (!stripe || !elements || disabled) return
53
+ setBusy(true)
54
+ setError(null)
55
+ try {
56
+ if (beforeConfirm) await beforeConfirm()
57
+ const returnUrl = new URL("/checkout", window.location.origin)
58
+ returnUrl.searchParams.set("cart_id", cartId)
59
+ returnUrl.searchParams.set("stripe_return", "1")
60
+ const result = await stripe.confirmPayment({
61
+ elements,
62
+ redirect: "if_required",
63
+ confirmParams: { return_url: returnUrl.toString() },
64
+ })
65
+ if (result.error) {
66
+ throw new Error(result.error.message || "A bankkártyás fizetés nem sikerült.")
67
+ }
68
+ await onConfirmed()
69
+ } catch (cause) {
70
+ setError(cause instanceof Error ? cause.message : "A bankkártyás fizetés nem sikerült.")
71
+ } finally {
72
+ setBusy(false)
73
+ }
74
+ }
75
+
76
+ return (
77
+ <div className="stack-sm">
78
+ <div className="stripe-element"><PaymentElement /></div>
79
+ {error ? <p className="error">{error}</p> : null}
80
+ <button
81
+ className="button button-large"
82
+ type="button"
83
+ disabled={!stripe || !elements || disabled || busy}
84
+ onClick={() => void submit()}
85
+ >
86
+ {busy ? "Fizetés feldolgozása…" : "Fizetés bankkártyával"}
87
+ </button>
88
+ </div>
89
+ )
90
+ }