@hszrdm/create-commerce 1.1.0 → 1.3.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 +2 -2
- package/src/cli.mjs +5 -2
- package/templates/backend/.env.example +45 -0
- package/templates/backend/package.json +1 -1
- package/templates/storefront/README.md +14 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +43 -9
- package/templates/storefront/src/app/account/page.tsx +12 -1
- package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
- package/templates/storefront/src/app/blog/[slug]/page.tsx +36 -0
- package/templates/storefront/src/app/blog/page.tsx +25 -0
- package/templates/storefront/src/app/contact/page.tsx +25 -0
- package/templates/storefront/src/app/core-ux.css +244 -0
- package/templates/storefront/src/app/customer-capabilities.css +60 -0
- package/templates/storefront/src/app/knowledge-base/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/knowledge-base/page.tsx +25 -0
- package/templates/storefront/src/app/layout.tsx +40 -12
- package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
- package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
- package/templates/storefront/src/app/pages/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/quote-request/page.tsx +20 -0
- package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
- package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
- package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
- package/templates/storefront/src/components/account-wishlist.tsx +95 -0
- package/templates/storefront/src/components/add-to-cart.tsx +110 -15
- package/templates/storefront/src/components/back-to-top.tsx +26 -0
- package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
- package/templates/storefront/src/components/cart-view.tsx +72 -16
- package/templates/storefront/src/components/cms-content.tsx +75 -0
- package/templates/storefront/src/components/form-ux.tsx +47 -0
- package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
- package/templates/storefront/src/components/lead-form.tsx +203 -0
- package/templates/storefront/src/components/newsletter-action.tsx +66 -0
- package/templates/storefront/src/components/newsletter-signup.tsx +107 -0
- package/templates/storefront/src/components/product-gallery.tsx +64 -0
- package/templates/storefront/src/components/product-reviews.tsx +150 -0
- package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
- package/templates/storefront/src/components/quote-request-form.tsx +212 -0
- package/templates/storefront/src/components/share-button.tsx +63 -0
- package/templates/storefront/src/components/storefront-header.tsx +72 -18
- package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
- package/templates/storefront/src/components/toast-provider.tsx +92 -0
- package/templates/storefront/src/components/variant-price-display.tsx +31 -0
- package/templates/storefront/src/components/wishlist-button.tsx +88 -0
- package/templates/storefront/src/lib/core/account.ts +3 -0
- package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
- package/templates/storefront/src/lib/core/cms.ts +71 -11
- package/templates/storefront/src/lib/core/form-ux.ts +57 -0
- package/templates/storefront/src/lib/core/newsletter.ts +53 -0
- package/templates/storefront/src/lib/core/reviews.ts +40 -0
- package/templates/storefront/src/lib/core/share.ts +57 -0
- package/templates/storefront/src/lib/core/wishlist.ts +88 -0
- package/templates/storefront/src/lib/storefront-routes.ts +33 -0
- package/templates/storefront/src/proxy.ts +25 -28
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { FormEvent, useState } from "react"
|
|
4
|
+
import { submitQuoteRequest } from "@/lib/core/quotes"
|
|
5
|
+
import { useToast } from "@/components/toast-provider"
|
|
6
|
+
|
|
7
|
+
type ExtraField = {
|
|
8
|
+
key: string
|
|
9
|
+
label: string
|
|
10
|
+
type: "text" | "textarea" | "number" | "boolean" | "select"
|
|
11
|
+
required: boolean
|
|
12
|
+
options?: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
locale: "hu" | "en"
|
|
17
|
+
config: {
|
|
18
|
+
enabled: boolean
|
|
19
|
+
order_types: string[]
|
|
20
|
+
extra_fields: Array<Record<string, unknown>>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function QuoteRequestForm({ locale, config }: Props) {
|
|
25
|
+
const english = locale === "en"
|
|
26
|
+
const { showToast } = useToast()
|
|
27
|
+
const [submitting, setSubmitting] = useState(false)
|
|
28
|
+
const extraFields = config.extra_fields.map(normalizeExtraField).filter((field): field is ExtraField => Boolean(field))
|
|
29
|
+
|
|
30
|
+
if (!config.enabled) {
|
|
31
|
+
return <div className="empty-state">{english ? "Quote requests are currently unavailable." : "Az ajánlatkérés jelenleg nem elérhető."}</div>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function onSubmit(event: FormEvent<HTMLFormElement>) {
|
|
35
|
+
event.preventDefault()
|
|
36
|
+
if (submitting) return
|
|
37
|
+
const form = event.currentTarget
|
|
38
|
+
const data = new FormData(form)
|
|
39
|
+
const orderType = String(data.get("order_type") || "one_time") === "recurring" ? "recurring" : "one_time"
|
|
40
|
+
const itemTitle = String(data.get("item_title") || "").trim()
|
|
41
|
+
const itemQuantity = Number(data.get("item_quantity") || 1)
|
|
42
|
+
const extra_fields: Record<string, unknown> = {}
|
|
43
|
+
|
|
44
|
+
for (const field of extraFields) {
|
|
45
|
+
const raw = data.get(`extra_${field.key}`)
|
|
46
|
+
if (field.type === "boolean") extra_fields[field.key] = raw === "on"
|
|
47
|
+
else if (field.type === "number" && raw !== null && String(raw).trim()) extra_fields[field.key] = Number(raw)
|
|
48
|
+
else if (raw !== null && String(raw).trim()) extra_fields[field.key] = String(raw).trim()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setSubmitting(true)
|
|
52
|
+
try {
|
|
53
|
+
await submitQuoteRequest({
|
|
54
|
+
company_name: text(data.get("company_name")),
|
|
55
|
+
tax_number: text(data.get("tax_number")),
|
|
56
|
+
company_address: text(data.get("company_address")),
|
|
57
|
+
contact_name: String(data.get("contact_name") || "").trim(),
|
|
58
|
+
contact_email: String(data.get("contact_email") || "").trim(),
|
|
59
|
+
contact_phone: text(data.get("contact_phone")),
|
|
60
|
+
order_type: orderType,
|
|
61
|
+
recurrence: orderType === "recurring" ? text(data.get("recurrence")) : undefined,
|
|
62
|
+
note: text(data.get("note")),
|
|
63
|
+
extra_fields,
|
|
64
|
+
items: [{
|
|
65
|
+
title: itemTitle,
|
|
66
|
+
quantity: Number.isInteger(itemQuantity) && itemQuantity > 0 ? itemQuantity : 1,
|
|
67
|
+
unit_label: text(data.get("item_unit")),
|
|
68
|
+
custom_request: text(data.get("item_request")),
|
|
69
|
+
is_custom: true,
|
|
70
|
+
}],
|
|
71
|
+
})
|
|
72
|
+
form.reset()
|
|
73
|
+
showToast({
|
|
74
|
+
tone: "success",
|
|
75
|
+
message: english ? "Your quote request has been sent." : "Az ajánlatkérésedet elküldtük.",
|
|
76
|
+
})
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
showToast({
|
|
79
|
+
tone: "error",
|
|
80
|
+
message: cause instanceof Error
|
|
81
|
+
? cause.message
|
|
82
|
+
: (english ? "The quote request could not be sent." : "Az ajánlatkérést nem sikerült elküldeni."),
|
|
83
|
+
})
|
|
84
|
+
} finally {
|
|
85
|
+
setSubmitting(false)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<form className="panel stack quote-request-form" onSubmit={onSubmit}>
|
|
91
|
+
<div className="form-grid">
|
|
92
|
+
<Field name="contact_name" label={english ? "Contact name" : "Kapcsolattartó neve"} required />
|
|
93
|
+
<Field name="contact_email" label={english ? "Email address" : "E-mail-cím"} type="email" required />
|
|
94
|
+
<Field name="contact_phone" label={english ? "Phone" : "Telefonszám"} type="tel" />
|
|
95
|
+
<Field name="company_name" label={english ? "Company" : "Cégnév"} />
|
|
96
|
+
<Field name="tax_number" label={english ? "Tax number" : "Adószám"} />
|
|
97
|
+
<Field name="company_address" label={english ? "Company address" : "Cég címe"} />
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div className="form-grid">
|
|
101
|
+
<div>
|
|
102
|
+
<label className="field-label" htmlFor="quote-order-type">{english ? "Order type" : "Rendelés típusa"}</label>
|
|
103
|
+
<select id="quote-order-type" name="order_type" defaultValue="one_time">
|
|
104
|
+
<option value="one_time">{english ? "One-time" : "Egyszeri"}</option>
|
|
105
|
+
<option value="recurring">{english ? "Recurring" : "Rendszeres"}</option>
|
|
106
|
+
</select>
|
|
107
|
+
</div>
|
|
108
|
+
<Field name="recurrence" label={english ? "Recurrence, if applicable" : "Gyakoriság, ha rendszeres"} placeholder={english ? "e.g. monthly" : "pl. havonta"} />
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<fieldset className="form-fieldset stack-sm">
|
|
112
|
+
<legend>{english ? "Requested item" : "Ajánlatkérési tétel"}</legend>
|
|
113
|
+
<div className="form-grid">
|
|
114
|
+
<Field name="item_title" label={english ? "Item / service" : "Termék / szolgáltatás"} required />
|
|
115
|
+
<Field name="item_quantity" label={english ? "Quantity" : "Mennyiség"} type="number" min="1" defaultValue="1" required />
|
|
116
|
+
<Field name="item_unit" label={english ? "Unit" : "Egység"} placeholder={english ? "pcs, m, kg…" : "db, m, kg…"} />
|
|
117
|
+
</div>
|
|
118
|
+
<div>
|
|
119
|
+
<label className="field-label" htmlFor="quote-item-request">{english ? "Custom request" : "Egyedi igény"}</label>
|
|
120
|
+
<textarea id="quote-item-request" name="item_request" rows={4} />
|
|
121
|
+
</div>
|
|
122
|
+
</fieldset>
|
|
123
|
+
|
|
124
|
+
{extraFields.length ? (
|
|
125
|
+
<fieldset className="form-fieldset stack-sm">
|
|
126
|
+
<legend>{english ? "Additional details" : "További adatok"}</legend>
|
|
127
|
+
<div className="form-grid">
|
|
128
|
+
{extraFields.map((field) => <ExtraFieldControl field={field} key={field.key} />)}
|
|
129
|
+
</div>
|
|
130
|
+
</fieldset>
|
|
131
|
+
) : null}
|
|
132
|
+
|
|
133
|
+
<div>
|
|
134
|
+
<label className="field-label" htmlFor="quote-note">{english ? "Message" : "Megjegyzés"}</label>
|
|
135
|
+
<textarea id="quote-note" name="note" rows={5} />
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<button className="button button-large" type="submit" disabled={submitting}>
|
|
139
|
+
{submitting ? (english ? "Sending…" : "Küldés…") : (english ? "Request a quote" : "Ajánlatot kérek")}
|
|
140
|
+
</button>
|
|
141
|
+
</form>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function Field(props: {
|
|
146
|
+
name: string
|
|
147
|
+
label: string
|
|
148
|
+
type?: string
|
|
149
|
+
required?: boolean
|
|
150
|
+
placeholder?: string
|
|
151
|
+
min?: string
|
|
152
|
+
defaultValue?: string
|
|
153
|
+
}) {
|
|
154
|
+
const id = `quote-${props.name}`
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<label className="field-label" htmlFor={id}>{props.label}{props.required ? <span className="required-mark">*</span> : null}</label>
|
|
158
|
+
<input id={id} name={props.name} type={props.type || "text"} required={props.required} placeholder={props.placeholder} min={props.min} defaultValue={props.defaultValue} />
|
|
159
|
+
</div>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function ExtraFieldControl({ field }: { field: ExtraField }) {
|
|
164
|
+
const id = `quote-extra-${field.key}`
|
|
165
|
+
if (field.type === "boolean") {
|
|
166
|
+
return (
|
|
167
|
+
<label className="checkbox-row" htmlFor={id}>
|
|
168
|
+
<input id={id} name={`extra_${field.key}`} type="checkbox" required={field.required} />
|
|
169
|
+
<span>{field.label}</span>
|
|
170
|
+
</label>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
if (field.type === "textarea") {
|
|
174
|
+
return (
|
|
175
|
+
<div>
|
|
176
|
+
<label className="field-label" htmlFor={id}>{field.label}{field.required ? <span className="required-mark">*</span> : null}</label>
|
|
177
|
+
<textarea id={id} name={`extra_${field.key}`} rows={4} required={field.required} />
|
|
178
|
+
</div>
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
if (field.type === "select") {
|
|
182
|
+
return (
|
|
183
|
+
<div>
|
|
184
|
+
<label className="field-label" htmlFor={id}>{field.label}{field.required ? <span className="required-mark">*</span> : null}</label>
|
|
185
|
+
<select id={id} name={`extra_${field.key}`} required={field.required} defaultValue="">
|
|
186
|
+
<option value="" disabled={field.required}>—</option>
|
|
187
|
+
{(field.options || []).map((option) => <option value={option} key={option}>{option}</option>)}
|
|
188
|
+
</select>
|
|
189
|
+
</div>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
return <Field name={`extra_${field.key}`} label={field.label} type={field.type === "number" ? "number" : "text"} required={field.required} />
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function normalizeExtraField(value: Record<string, unknown>): ExtraField | null {
|
|
196
|
+
const key = typeof value.key === "string" ? value.key : ""
|
|
197
|
+
const label = typeof value.label === "string" ? value.label : key
|
|
198
|
+
const type = typeof value.type === "string" ? value.type : "text"
|
|
199
|
+
if (!key || !["text", "textarea", "number", "boolean", "select"].includes(type)) return null
|
|
200
|
+
return {
|
|
201
|
+
key,
|
|
202
|
+
label,
|
|
203
|
+
type: type as ExtraField["type"],
|
|
204
|
+
required: value.required === true,
|
|
205
|
+
options: Array.isArray(value.options) ? value.options.filter((item): item is string => typeof item === "string") : undefined,
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function text(value: FormDataEntryValue | null) {
|
|
210
|
+
const result = typeof value === "string" ? value.trim() : ""
|
|
211
|
+
return result || undefined
|
|
212
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { usePathname } from "next/navigation"
|
|
4
|
+
import { useMemo, useState } from "react"
|
|
5
|
+
import { copyText, shareContent, shareFallbackLinks } from "@/lib/core/share"
|
|
6
|
+
import { localeFromPathname } from "@/lib/storefront-routes"
|
|
7
|
+
import { useToast } from "./toast-provider"
|
|
8
|
+
|
|
9
|
+
export function ShareButton({
|
|
10
|
+
title,
|
|
11
|
+
text,
|
|
12
|
+
url,
|
|
13
|
+
showFallbackLinks = false,
|
|
14
|
+
}: {
|
|
15
|
+
title?: string
|
|
16
|
+
text?: string
|
|
17
|
+
url?: string
|
|
18
|
+
showFallbackLinks?: boolean
|
|
19
|
+
}) {
|
|
20
|
+
const pathname = usePathname()
|
|
21
|
+
const locale = localeFromPathname(pathname)
|
|
22
|
+
const en = locale === "en"
|
|
23
|
+
const { showToast } = useToast()
|
|
24
|
+
const [expanded, setExpanded] = useState(false)
|
|
25
|
+
const resolvedUrl = useMemo(() => {
|
|
26
|
+
if (url) return url
|
|
27
|
+
if (typeof window === "undefined") return pathname
|
|
28
|
+
return window.location.href
|
|
29
|
+
}, [pathname, url])
|
|
30
|
+
const links = shareFallbackLinks({ title, text, url: resolvedUrl })
|
|
31
|
+
|
|
32
|
+
const share = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const result = await shareContent({ title, text, url: resolvedUrl })
|
|
35
|
+
if (result === "copied") showToast({ message: en ? "Link copied" : "Link másolva", tone: "success" })
|
|
36
|
+
} catch {
|
|
37
|
+
setExpanded(true)
|
|
38
|
+
showToast({ message: en ? "Sharing is not available. You can copy the link instead." : "A megosztás nem érhető el. A linket külön kimásolhatod.", tone: "error" })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="share-control">
|
|
44
|
+
<button type="button" className="button secondary" onClick={() => void share()}>
|
|
45
|
+
{en ? "Share" : "Megosztás"}
|
|
46
|
+
</button>
|
|
47
|
+
<button
|
|
48
|
+
type="button"
|
|
49
|
+
className="text-button"
|
|
50
|
+
onClick={() => void copyText(resolvedUrl).then(() => showToast({ message: en ? "Link copied" : "Link másolva", tone: "success" }))}
|
|
51
|
+
>
|
|
52
|
+
{en ? "Copy link" : "Link másolása"}
|
|
53
|
+
</button>
|
|
54
|
+
{showFallbackLinks || expanded ? (
|
|
55
|
+
<div className="share-links" aria-label={en ? "Share options" : "Megosztási lehetőségek"}>
|
|
56
|
+
<a href={links.facebook} target="_blank" rel="noreferrer">Facebook</a>
|
|
57
|
+
<a href={links.linkedin} target="_blank" rel="noreferrer">LinkedIn</a>
|
|
58
|
+
<a href={links.email}>{en ? "Email" : "E-mail"}</a>
|
|
59
|
+
</div>
|
|
60
|
+
) : null}
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import Link from "next/link"
|
|
4
4
|
import { usePathname } from "next/navigation"
|
|
5
|
+
import { useCallback, useEffect, useState } from "react"
|
|
6
|
+
import { AccessibleDialog } from "./accessible-dialog"
|
|
5
7
|
import { useCart } from "./cart-provider"
|
|
6
8
|
import { CartView } from "./cart-view"
|
|
7
9
|
import type { CoreConfig } from "@/lib/core/types"
|
|
@@ -14,43 +16,95 @@ import {
|
|
|
14
16
|
|
|
15
17
|
export function StorefrontHeader({ config }: { config: CoreConfig }) {
|
|
16
18
|
const { count, drawerOpen, setDrawerOpen } = useCart()
|
|
19
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
17
20
|
const pathname = usePathname()
|
|
18
21
|
const locale = localeFromPathname(pathname)
|
|
19
22
|
const routes = STOREFRONT_ROUTES[locale]
|
|
20
23
|
const copy = storefrontCopy(locale)
|
|
24
|
+
const closeDrawer = useCallback(() => setDrawerOpen(false), [setDrawerOpen])
|
|
25
|
+
const closeMenu = useCallback(() => setMenuOpen(false), [])
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
closeDrawer()
|
|
29
|
+
closeMenu()
|
|
30
|
+
}, [closeDrawer, closeMenu, pathname])
|
|
31
|
+
|
|
32
|
+
const primaryLinks = [
|
|
33
|
+
{ href: routes.products, label: copy.products },
|
|
34
|
+
{ href: routes.legal, label: copy.legalDocuments },
|
|
35
|
+
...(config.features.account ? [{ href: routes.account, label: copy.account }] : []),
|
|
36
|
+
]
|
|
21
37
|
|
|
22
38
|
return (
|
|
23
39
|
<>
|
|
24
40
|
<header className="shell header">
|
|
25
|
-
<Link className="brand" href={routes.home}>{config.store.name}</Link>
|
|
41
|
+
<Link className="brand" href={routes.home} aria-current={pathname === routes.home ? "page" : undefined}>{config.store.name}</Link>
|
|
26
42
|
<nav className="nav" aria-label={locale === "en" ? "Main navigation" : "Fő navigáció"}>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
{primaryLinks.map((item) => (
|
|
44
|
+
<Link key={item.href} href={item.href} aria-current={isActive(pathname, item.href) ? "page" : undefined}>{item.label}</Link>
|
|
45
|
+
))}
|
|
30
46
|
<span className="locale-switch" aria-label={locale === "en" ? "Language" : "Nyelv"}>
|
|
31
47
|
<Link aria-current={locale === "hu" ? "page" : undefined} href={equivalentLocalePath(pathname, "hu")}>HU</Link>
|
|
32
48
|
<Link aria-current={locale === "en" ? "page" : undefined} href={equivalentLocalePath(pathname, "en")}>EN</Link>
|
|
33
49
|
</span>
|
|
34
|
-
<button
|
|
35
|
-
|
|
50
|
+
<button
|
|
51
|
+
className="mobile-menu-trigger icon-button"
|
|
52
|
+
type="button"
|
|
53
|
+
aria-label={locale === "en" ? "Open menu" : "Menü megnyitása"}
|
|
54
|
+
aria-haspopup="dialog"
|
|
55
|
+
aria-expanded={menuOpen}
|
|
56
|
+
aria-controls="mobile-navigation"
|
|
57
|
+
onClick={() => setMenuOpen(true)}
|
|
58
|
+
>
|
|
59
|
+
☰
|
|
60
|
+
</button>
|
|
61
|
+
<button
|
|
62
|
+
className="nav-cart"
|
|
63
|
+
type="button"
|
|
64
|
+
aria-haspopup="dialog"
|
|
65
|
+
aria-expanded={drawerOpen}
|
|
66
|
+
aria-controls="cart-drawer"
|
|
67
|
+
onClick={() => setDrawerOpen(true)}
|
|
68
|
+
>
|
|
69
|
+
{copy.cart} <span className="cart-count" aria-label={`${count} ${copy.productCountSuffix}`}>{count}</span>
|
|
36
70
|
</button>
|
|
37
71
|
</nav>
|
|
38
72
|
</header>
|
|
39
73
|
|
|
40
|
-
{
|
|
41
|
-
<div
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<
|
|
74
|
+
<AccessibleDialog open={menuOpen} onClose={closeMenu} labelledBy="mobile-menu-title" className="mobile-menu-drawer">
|
|
75
|
+
<div id="mobile-navigation" className="stack">
|
|
76
|
+
<div className="drawer-head">
|
|
77
|
+
<h2 id="mobile-menu-title">{locale === "en" ? "Menu" : "Menü"}</h2>
|
|
78
|
+
<button className="icon-button" type="button" aria-label={copy.close} onClick={closeMenu}>×</button>
|
|
79
|
+
</div>
|
|
80
|
+
<nav className="mobile-nav-links" aria-label={locale === "en" ? "Mobile navigation" : "Mobil navigáció"}>
|
|
81
|
+
{primaryLinks.map((item) => (
|
|
82
|
+
<Link key={item.href} href={item.href} aria-current={isActive(pathname, item.href) ? "page" : undefined}>{item.label}</Link>
|
|
83
|
+
))}
|
|
84
|
+
</nav>
|
|
85
|
+
<div className="mobile-locale-switch" aria-label={locale === "en" ? "Language" : "Nyelv"}>
|
|
86
|
+
<Link aria-current={locale === "hu" ? "page" : undefined} href={equivalentLocalePath(pathname, "hu")}>Magyar</Link>
|
|
87
|
+
<Link aria-current={locale === "en" ? "page" : undefined} href={equivalentLocalePath(pathname, "en")}>English</Link>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</AccessibleDialog>
|
|
91
|
+
|
|
92
|
+
<AccessibleDialog open={drawerOpen} onClose={closeDrawer} labelledBy="cart-drawer-title">
|
|
93
|
+
<div id="cart-drawer">
|
|
94
|
+
<div className="drawer-head">
|
|
95
|
+
<div>
|
|
96
|
+
<p className="eyebrow">{copy.cart}</p>
|
|
97
|
+
<h2 id="cart-drawer-title">{count} {copy.productCountSuffix}</h2>
|
|
49
98
|
</div>
|
|
50
|
-
<
|
|
51
|
-
</
|
|
99
|
+
<button className="icon-button" type="button" aria-label={copy.close} onClick={closeDrawer}>×</button>
|
|
100
|
+
</div>
|
|
101
|
+
<CartView config={config} compact />
|
|
52
102
|
</div>
|
|
53
|
-
|
|
103
|
+
</AccessibleDialog>
|
|
54
104
|
</>
|
|
55
105
|
)
|
|
56
106
|
}
|
|
107
|
+
|
|
108
|
+
function isActive(pathname: string, href: string) {
|
|
109
|
+
return pathname === href || pathname.startsWith(`${href}/`)
|
|
110
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type QuantityPriceTier = {
|
|
2
|
+
minQuantity: number
|
|
3
|
+
unitPrice?: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function unitsUntilNextPriceTier(quantity: number, tiers: QuantityPriceTier[]) {
|
|
7
|
+
const sorted = [...tiers]
|
|
8
|
+
.filter((tier) => Number.isFinite(tier.minQuantity) && tier.minQuantity > 0)
|
|
9
|
+
.sort((a, b) => a.minQuantity - b.minQuantity)
|
|
10
|
+
const next = sorted.find((tier) => tier.minQuantity > quantity)
|
|
11
|
+
return next ? { remaining: next.minQuantity - quantity, tier: next } : null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function TierProgressHint({
|
|
15
|
+
quantity,
|
|
16
|
+
tiers,
|
|
17
|
+
locale = "hu",
|
|
18
|
+
}: {
|
|
19
|
+
quantity: number
|
|
20
|
+
tiers: QuantityPriceTier[]
|
|
21
|
+
locale?: "hu" | "en"
|
|
22
|
+
}) {
|
|
23
|
+
const next = unitsUntilNextPriceTier(quantity, tiers)
|
|
24
|
+
if (!next) return null
|
|
25
|
+
return (
|
|
26
|
+
<p className="tier-progress-hint" role="status" aria-live="polite">
|
|
27
|
+
{locale === "en"
|
|
28
|
+
? `${next.remaining} more to reach the next price tier.`
|
|
29
|
+
: `Még ${next.remaining} db a következő árszintig.`}
|
|
30
|
+
</p>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from "react"
|
|
12
|
+
|
|
13
|
+
type ToastTone = "success" | "error" | "info"
|
|
14
|
+
|
|
15
|
+
type ToastInput = {
|
|
16
|
+
message: string
|
|
17
|
+
tone?: ToastTone
|
|
18
|
+
actionLabel?: string
|
|
19
|
+
onAction?: () => void | Promise<void>
|
|
20
|
+
durationMs?: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type ToastItem = ToastInput & { id: number }
|
|
24
|
+
|
|
25
|
+
type ToastContextValue = {
|
|
26
|
+
showToast: (input: ToastInput | string) => number
|
|
27
|
+
dismissToast: (id: number) => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ToastContext = createContext<ToastContextValue | null>(null)
|
|
31
|
+
|
|
32
|
+
export function ToastProvider({ children, locale = "hu" }: { children: ReactNode; locale?: "hu" | "en" }) {
|
|
33
|
+
const [items, setItems] = useState<ToastItem[]>([])
|
|
34
|
+
const sequence = useRef(0)
|
|
35
|
+
const timers = useRef(new Map<number, ReturnType<typeof setTimeout>>())
|
|
36
|
+
const closeLabel = locale === "en" ? "Close notification" : "Értesítés bezárása"
|
|
37
|
+
|
|
38
|
+
const dismissToast = useCallback((id: number) => {
|
|
39
|
+
const timer = timers.current.get(id)
|
|
40
|
+
if (timer) clearTimeout(timer)
|
|
41
|
+
timers.current.delete(id)
|
|
42
|
+
setItems((current) => current.filter((item) => item.id !== id))
|
|
43
|
+
}, [])
|
|
44
|
+
|
|
45
|
+
const showToast = useCallback((input: ToastInput | string) => {
|
|
46
|
+
const normalized: ToastInput = typeof input === "string" ? { message: input } : input
|
|
47
|
+
const id = ++sequence.current
|
|
48
|
+
const item: ToastItem = {
|
|
49
|
+
id,
|
|
50
|
+
tone: normalized.tone || "info",
|
|
51
|
+
durationMs: normalized.durationMs ?? (normalized.actionLabel ? 7000 : 4200),
|
|
52
|
+
...normalized,
|
|
53
|
+
}
|
|
54
|
+
setItems((current) => [...current.slice(-3), item])
|
|
55
|
+
const timer = setTimeout(() => dismissToast(id), item.durationMs)
|
|
56
|
+
timers.current.set(id, timer)
|
|
57
|
+
return id
|
|
58
|
+
}, [dismissToast])
|
|
59
|
+
|
|
60
|
+
const value = useMemo(() => ({ showToast, dismissToast }), [dismissToast, showToast])
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ToastContext.Provider value={value}>
|
|
64
|
+
{children}
|
|
65
|
+
<div className="toast-region" aria-live="polite" aria-atomic="false">
|
|
66
|
+
{items.map((item) => (
|
|
67
|
+
<div className={`toast toast-${item.tone}`} role={item.tone === "error" ? "alert" : "status"} key={item.id}>
|
|
68
|
+
<span>{item.message}</span>
|
|
69
|
+
{item.actionLabel && item.onAction ? (
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
className="toast-action"
|
|
73
|
+
onClick={() => {
|
|
74
|
+
void Promise.resolve(item.onAction?.()).finally(() => dismissToast(item.id))
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{item.actionLabel}
|
|
78
|
+
</button>
|
|
79
|
+
) : null}
|
|
80
|
+
<button type="button" className="toast-close" aria-label={closeLabel} onClick={() => dismissToast(item.id)}>×</button>
|
|
81
|
+
</div>
|
|
82
|
+
))}
|
|
83
|
+
</div>
|
|
84
|
+
</ToastContext.Provider>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function useToast() {
|
|
89
|
+
const context = useContext(ToastContext)
|
|
90
|
+
if (!context) throw new Error("useToast csak ToastProvider alatt használható.")
|
|
91
|
+
return context
|
|
92
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react"
|
|
4
|
+
import { formatMoney } from "@/lib/core/commerce"
|
|
5
|
+
|
|
6
|
+
export function VariantPriceDisplay({
|
|
7
|
+
initialPrice,
|
|
8
|
+
initialCurrency,
|
|
9
|
+
locale,
|
|
10
|
+
}: {
|
|
11
|
+
initialPrice: number
|
|
12
|
+
initialCurrency: string
|
|
13
|
+
locale: string
|
|
14
|
+
}) {
|
|
15
|
+
const [price, setPrice] = useState(initialPrice)
|
|
16
|
+
const [currency, setCurrency] = useState(initialCurrency)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const listener = (event: Event) => {
|
|
20
|
+
const detail = (event as CustomEvent<{ price?: number; currency?: string }>).detail
|
|
21
|
+
const nextPrice = Number(detail?.price)
|
|
22
|
+
if (Number.isFinite(nextPrice)) setPrice(nextPrice)
|
|
23
|
+
if (detail?.currency) setCurrency(detail.currency)
|
|
24
|
+
}
|
|
25
|
+
window.addEventListener("hszrdm:product-variant-change", listener)
|
|
26
|
+
return () => window.removeEventListener("hszrdm:product-variant-change", listener)
|
|
27
|
+
}, [])
|
|
28
|
+
|
|
29
|
+
if (!Number.isFinite(price)) return null
|
|
30
|
+
return <div className="product-price" aria-live="polite">{formatMoney(price, currency, locale)}</div>
|
|
31
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
5
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
6
|
+
import { humanizeStorefrontError } from "@/lib/core/form-ux"
|
|
7
|
+
import {
|
|
8
|
+
addGuestWishlistProduct,
|
|
9
|
+
addWishlistProduct,
|
|
10
|
+
getGuestWishlistProductIds,
|
|
11
|
+
listWishlist,
|
|
12
|
+
removeGuestWishlistProduct,
|
|
13
|
+
removeWishlistProduct,
|
|
14
|
+
} from "@/lib/core/wishlist"
|
|
15
|
+
import { localeFromPathname } from "@/lib/storefront-routes"
|
|
16
|
+
import { useToast } from "./toast-provider"
|
|
17
|
+
|
|
18
|
+
type WishlistMode = "loading" | "account" | "guest"
|
|
19
|
+
|
|
20
|
+
export function WishlistButton({ productId }: { productId: string }) {
|
|
21
|
+
const pathname = usePathname()
|
|
22
|
+
const locale = localeFromPathname(pathname)
|
|
23
|
+
const en = locale === "en"
|
|
24
|
+
const { showToast } = useToast()
|
|
25
|
+
const [mode, setMode] = useState<WishlistMode>("loading")
|
|
26
|
+
const [saved, setSaved] = useState(false)
|
|
27
|
+
const [busy, setBusy] = useState(false)
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
let active = true
|
|
31
|
+
void listWishlist()
|
|
32
|
+
.then((response) => {
|
|
33
|
+
if (!active) return
|
|
34
|
+
setMode("account")
|
|
35
|
+
setSaved(response.items.some((item) => item.product_id === productId))
|
|
36
|
+
})
|
|
37
|
+
.catch((error) => {
|
|
38
|
+
if (!active) return
|
|
39
|
+
if (error instanceof CoreApiError && error.status !== 401) {
|
|
40
|
+
setMode("guest")
|
|
41
|
+
} else {
|
|
42
|
+
setMode("guest")
|
|
43
|
+
}
|
|
44
|
+
setSaved(getGuestWishlistProductIds().includes(productId))
|
|
45
|
+
})
|
|
46
|
+
return () => { active = false }
|
|
47
|
+
}, [productId])
|
|
48
|
+
|
|
49
|
+
const toggle = async () => {
|
|
50
|
+
if (busy || mode === "loading") return
|
|
51
|
+
setBusy(true)
|
|
52
|
+
try {
|
|
53
|
+
if (mode === "account") {
|
|
54
|
+
if (saved) await removeWishlistProduct(productId)
|
|
55
|
+
else await addWishlistProduct(productId)
|
|
56
|
+
} else if (saved) {
|
|
57
|
+
removeGuestWishlistProduct(productId)
|
|
58
|
+
} else {
|
|
59
|
+
addGuestWishlistProduct(productId)
|
|
60
|
+
}
|
|
61
|
+
setSaved((current) => !current)
|
|
62
|
+
showToast({
|
|
63
|
+
message: saved
|
|
64
|
+
? (en ? "Removed from wishlist." : "Eltávolítva a kedvencekből.")
|
|
65
|
+
: (en ? "Added to wishlist." : "Hozzáadva a kedvencekhez."),
|
|
66
|
+
tone: "success",
|
|
67
|
+
})
|
|
68
|
+
} catch (error) {
|
|
69
|
+
showToast({ message: humanizeStorefrontError(error, locale), tone: "error" })
|
|
70
|
+
} finally {
|
|
71
|
+
setBusy(false)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
className={`button secondary wishlist-button${saved ? " is-saved" : ""}`}
|
|
79
|
+
aria-pressed={saved}
|
|
80
|
+
aria-busy={busy || mode === "loading"}
|
|
81
|
+
disabled={busy || mode === "loading"}
|
|
82
|
+
onClick={() => void toggle()}
|
|
83
|
+
>
|
|
84
|
+
<span aria-hidden="true">{saved ? "♥" : "♡"}</span>
|
|
85
|
+
{saved ? (en ? "Saved" : "Kedvenc") : (en ? "Add to wishlist" : "Kedvencekhez")}
|
|
86
|
+
</button>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { endpoint, medusaFetch } from "./client"
|
|
2
2
|
import type { CoreConfig } from "./types"
|
|
3
|
+
import { mergeGuestWishlistAfterLogin } from "./wishlist"
|
|
3
4
|
|
|
4
5
|
export function accountApi(config: CoreConfig) {
|
|
5
6
|
const paths = config.account.endpoints
|
|
@@ -52,6 +53,7 @@ export function accountApi(config: CoreConfig) {
|
|
|
52
53
|
method: "POST",
|
|
53
54
|
headers: { Authorization: `Bearer ${login.token}` },
|
|
54
55
|
})
|
|
56
|
+
await mergeGuestWishlistAfterLogin().catch(() => undefined)
|
|
55
57
|
return profile()
|
|
56
58
|
},
|
|
57
59
|
|
|
@@ -64,6 +66,7 @@ export function accountApi(config: CoreConfig) {
|
|
|
64
66
|
method: "POST",
|
|
65
67
|
headers: { Authorization: `Bearer ${result.token}` },
|
|
66
68
|
})
|
|
69
|
+
await mergeGuestWishlistAfterLogin().catch(() => undefined)
|
|
67
70
|
return result
|
|
68
71
|
},
|
|
69
72
|
|