@hszrdm/create-commerce 1.2.0 → 1.4.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 (30) hide show
  1. package/README.md +92 -1
  2. package/package.json +2 -2
  3. package/templates/backend/.env.example +288 -76
  4. package/templates/backend/package.json +5 -3
  5. package/templates/backend/scripts/materialize-production.mjs +37 -0
  6. package/templates/backend/scripts/production-assets/backup.sh +56 -0
  7. package/templates/backend/scripts/production-assets/deploy.sh +67 -0
  8. package/templates/backend/scripts/production-assets/ecosystem.config.cjs.tpl +24 -0
  9. package/templates/backend/scripts/production-assets/install.sh +200 -0
  10. package/templates/backend/scripts/production-assets/restore.sh +68 -0
  11. package/templates/backend/scripts/verify-env-contract.mjs +58 -0
  12. package/templates/storefront/README.md +14 -1
  13. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +2 -0
  14. package/templates/storefront/src/app/blog/[slug]/page.tsx +36 -0
  15. package/templates/storefront/src/app/blog/page.tsx +25 -0
  16. package/templates/storefront/src/app/contact/page.tsx +25 -0
  17. package/templates/storefront/src/app/customer-capabilities.css +60 -0
  18. package/templates/storefront/src/app/knowledge-base/[slug]/page.tsx +35 -0
  19. package/templates/storefront/src/app/knowledge-base/page.tsx +25 -0
  20. package/templates/storefront/src/app/layout.tsx +11 -2
  21. package/templates/storefront/src/app/pages/[slug]/page.tsx +35 -0
  22. package/templates/storefront/src/app/quote-request/page.tsx +20 -0
  23. package/templates/storefront/src/components/cms-content.tsx +75 -0
  24. package/templates/storefront/src/components/lead-form.tsx +203 -0
  25. package/templates/storefront/src/components/newsletter-signup.tsx +107 -0
  26. package/templates/storefront/src/components/product-reviews.tsx +150 -0
  27. package/templates/storefront/src/components/quote-request-form.tsx +212 -0
  28. package/templates/storefront/src/lib/core/cms.ts +5 -4
  29. package/templates/storefront/src/lib/storefront-routes.ts +30 -0
  30. package/templates/storefront/src/proxy.ts +22 -28
@@ -0,0 +1,60 @@
1
+ /* Customer-facing Core capability reference UI. Brand tokens remain storefront-owned. */
2
+
3
+ .cms-grid,
4
+ .review-list {
5
+ display: grid;
6
+ gap: 18px;
7
+ }
8
+ .cms-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
9
+ .cms-card { overflow: hidden; }
10
+ .cms-card-image,
11
+ .cms-hero-image {
12
+ width: 100%;
13
+ border-radius: 14px;
14
+ object-fit: cover;
15
+ }
16
+ .cms-card-image { aspect-ratio: 16 / 9; }
17
+ .cms-hero-image { max-height: 520px; }
18
+ .cms-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; }
19
+ .cms-body { max-width: 78ch; line-height: 1.75; }
20
+ .cms-body img { max-width: 100%; height: auto; border-radius: 12px; }
21
+ .cms-body blockquote { margin: 0; border-left: 4px solid var(--line); padding-left: 18px; color: var(--muted); }
22
+ .cms-detail { max-width: 900px; margin-inline: auto; }
23
+
24
+ .product-reviews { border-top: 1px solid var(--line); padding-top: 28px; }
25
+ .review-summary { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
26
+ .review-summary strong { font-size: 1.35rem; }
27
+ .review-card { display: grid; gap: 10px; }
28
+ .review-card-heading { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
29
+ .review-card-heading > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
30
+ .verified-badge { border-radius: 999px; background: var(--surface-soft); padding: 4px 8px; font-size: .75rem; font-weight: 800; }
31
+ .review-form select,
32
+ .review-form textarea,
33
+ .newsletter-form input,
34
+ .quote-request-form input,
35
+ .quote-request-form select,
36
+ .quote-request-form textarea,
37
+ .lead-form input,
38
+ .lead-form select,
39
+ .lead-form textarea {
40
+ width: 100%;
41
+ }
42
+
43
+ .footer-newsletter-shell { padding-top: 28px; }
44
+ .footer-newsletter { border-bottom: 1px solid var(--line); padding-bottom: 28px; }
45
+ .newsletter-form { display: grid; gap: 10px; max-width: 760px; }
46
+ .newsletter-form-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
47
+ .checkbox-row { display: flex; gap: 10px; align-items: flex-start; }
48
+ .checkbox-row input { width: auto; margin-top: 3px; }
49
+
50
+ .narrow-page { max-width: 920px; margin-inline: auto; }
51
+ .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
52
+ .form-fieldset { margin: 0; border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
53
+ .form-fieldset legend { padding-inline: 6px; font-weight: 850; }
54
+ .honeypot-field { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; }
55
+
56
+ @media (max-width: 760px) {
57
+ .form-grid,
58
+ .newsletter-form-row { grid-template-columns: 1fr; }
59
+ .review-summary { align-items: flex-start; }
60
+ }
@@ -0,0 +1,35 @@
1
+ import type { Metadata } from "next"
2
+ import { notFound } from "next/navigation"
3
+ import { Breadcrumbs } from "@/components/breadcrumbs"
4
+ import { CmsEntryBody, CmsEntryMeta } from "@/components/cms-content"
5
+ import { cmsEntrySeo, getKnowledgeBaseEntry } from "@/lib/core/cms"
6
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
7
+ import { STOREFRONT_ROUTES, medusaLocale } from "@/lib/storefront-routes"
8
+
9
+ export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
10
+ const { slug } = await params
11
+ const locale = await requestStorefrontLocale()
12
+ const result = await getKnowledgeBaseEntry(slug, { locale: medusaLocale(locale) }).catch(() => null)
13
+ return result ? cmsEntrySeo(result.entry) : {}
14
+ }
15
+
16
+ export default async function KnowledgeBaseEntryPage({ params }: { params: Promise<{ slug: string }> }) {
17
+ const { slug } = await params
18
+ const locale = await requestStorefrontLocale()
19
+ const english = locale === "en"
20
+ const result = await getKnowledgeBaseEntry(slug, { locale: medusaLocale(locale) }).catch(() => null)
21
+ if (!result) notFound()
22
+ const entry = result.entry
23
+
24
+ return (
25
+ <article className="stack page-section cms-detail">
26
+ <Breadcrumbs items={[{ label: english ? "Knowledge base" : "Tudástár", href: STOREFRONT_ROUTES[locale].knowledgeBase }, { label: entry.title }]} label={english ? "Breadcrumb" : "Morzsanavigáció"} />
27
+ <header className="stack-sm">
28
+ <CmsEntryMeta entry={entry} locale={locale} />
29
+ <h1>{entry.title}</h1>
30
+ {entry.excerpt ? <p className="lead">{entry.excerpt}</p> : null}
31
+ </header>
32
+ <CmsEntryBody entry={entry} />
33
+ </article>
34
+ )
35
+ }
@@ -0,0 +1,25 @@
1
+ import { CmsEntryCard } from "@/components/cms-content"
2
+ import { listKnowledgeBaseEntries } from "@/lib/core/cms"
3
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
4
+ import { knowledgeBasePath, medusaLocale } from "@/lib/storefront-routes"
5
+
6
+ export default async function KnowledgeBasePage() {
7
+ const locale = await requestStorefrontLocale()
8
+ const english = locale === "en"
9
+ const { entries } = await listKnowledgeBaseEntries({ locale: medusaLocale(locale), limit: 100 }).catch(() => ({ entries: [] }))
10
+
11
+ return (
12
+ <div className="stack page-section">
13
+ <header className="stack-sm">
14
+ <p className="eyebrow">{english ? "Help center" : "Segítség"}</p>
15
+ <h1>{english ? "Knowledge base" : "Tudástár"}</h1>
16
+ <p className="muted">{english ? "Answers, guides and practical information." : "Válaszok, útmutatók és gyakorlati információk."}</p>
17
+ </header>
18
+ {entries.length ? (
19
+ <div className="cms-grid">
20
+ {entries.map((entry) => <CmsEntryCard key={entry.id} entry={entry} href={knowledgeBasePath(locale, entry.slug)} locale={locale} />)}
21
+ </div>
22
+ ) : <div className="empty-state">{english ? "No knowledge-base entries yet." : "Még nincs publikált tudástár-bejegyzés."}</div>}
23
+ </div>
24
+ )
25
+ }
@@ -1,11 +1,13 @@
1
1
  import "./globals.css"
2
2
  import "./core-ux.css"
3
+ import "./customer-capabilities.css"
3
4
  import type { Metadata } from "next"
4
5
  import Link from "next/link"
5
6
  import { AccessibilityPreferencesControl, AccessibilityPreferencesProvider } from "@/components/accessibility-preferences"
6
7
  import { AnalyticsGate } from "@/components/analytics"
7
8
  import { CartProvider } from "@/components/cart-provider"
8
9
  import { ConsentBanner } from "@/components/consent-banner"
10
+ import { NewsletterSignup } from "@/components/newsletter-signup"
9
11
  import { StorefrontHeader } from "@/components/storefront-header"
10
12
  import { ToastProvider } from "@/components/toast-provider"
11
13
  import { getCoreConfig } from "@/lib/core/client"
@@ -61,15 +63,22 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
61
63
  <StorefrontHeader config={config} />
62
64
  <main id="main-content" className="shell main" tabIndex={-1}>{children}</main>
63
65
  <footer className="footer">
66
+ <div className="shell footer-newsletter-shell">
67
+ <NewsletterSignup locale={locale} />
68
+ </div>
64
69
  <div className="shell footer-inner">
65
70
  <div>
66
71
  <strong>{config.store.name}</strong>
67
72
  <p className="muted small">Powered by HSZRDM Commerce</p>
68
73
  </div>
69
74
  <nav className="footer-nav" aria-label={en ? "Footer navigation" : "Lábléc navigáció"}>
70
- <Link href={routes.legal}>{en ? "Legal documents" : "Jogi dokumentumok"}</Link>
71
- <Link href={routes.account}>{en ? "Account" : "Fiókom"}</Link>
72
75
  <Link href={routes.products}>{en ? "Products" : "Termékek"}</Link>
76
+ <Link href={routes.blog}>{en ? "Blog" : "Blog"}</Link>
77
+ <Link href={routes.knowledgeBase}>{en ? "Knowledge base" : "Tudástár"}</Link>
78
+ <Link href={routes.quoteRequest}>{en ? "Request a quote" : "Ajánlatkérés"}</Link>
79
+ <Link href={routes.contact}>{en ? "Contact" : "Kapcsolat"}</Link>
80
+ <Link href={routes.account}>{en ? "Account" : "Fiókom"}</Link>
81
+ <Link href={routes.legal}>{en ? "Legal documents" : "Jogi dokumentumok"}</Link>
73
82
  </nav>
74
83
  <AccessibilityPreferencesControl locale={locale} />
75
84
  </div>
@@ -0,0 +1,35 @@
1
+ import type { Metadata } from "next"
2
+ import { notFound } from "next/navigation"
3
+ import { Breadcrumbs } from "@/components/breadcrumbs"
4
+ import { CmsEntryBody } from "@/components/cms-content"
5
+ import { cmsEntrySeo, getCmsPage } from "@/lib/core/cms"
6
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
7
+ import { STOREFRONT_ROUTES, medusaLocale } from "@/lib/storefront-routes"
8
+
9
+ export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
10
+ const { slug } = await params
11
+ const locale = await requestStorefrontLocale()
12
+ const result = await getCmsPage(slug, { locale: medusaLocale(locale) }).catch(() => null)
13
+ return result ? cmsEntrySeo(result.entry) : {}
14
+ }
15
+
16
+ export default async function CmsPage({ params }: { params: Promise<{ slug: string }> }) {
17
+ const { slug } = await params
18
+ const locale = await requestStorefrontLocale()
19
+ const english = locale === "en"
20
+ const result = await getCmsPage(slug, { locale: medusaLocale(locale) }).catch(() => null)
21
+ if (!result) notFound()
22
+ const entry = result.entry
23
+
24
+ return (
25
+ <article className="stack page-section cms-detail">
26
+ <Breadcrumbs items={[{ label: english ? "Pages" : "Oldalak", href: STOREFRONT_ROUTES[locale].home }, { label: entry.title }]} label={english ? "Breadcrumb" : "Morzsanavigáció"} />
27
+ <header className="stack-sm">
28
+ <h1>{entry.title}</h1>
29
+ {entry.excerpt ? <p className="lead">{entry.excerpt}</p> : null}
30
+ {entry.featured_image_url ? <img className="cms-hero-image" src={entry.featured_image_url} alt={entry.featured_image_alt || entry.title} /> : null}
31
+ </header>
32
+ <CmsEntryBody entry={entry} />
33
+ </article>
34
+ )
35
+ }
@@ -0,0 +1,20 @@
1
+ import { QuoteRequestForm } from "@/components/quote-request-form"
2
+ import { quoteRequestConfig } from "@/lib/core/quotes"
3
+ import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
4
+
5
+ export default async function QuoteRequestPage() {
6
+ const locale = await requestStorefrontLocale()
7
+ const english = locale === "en"
8
+ const config = await quoteRequestConfig().catch(() => ({ enabled: false, order_types: [], extra_fields: [] }))
9
+
10
+ return (
11
+ <div className="stack page-section narrow-page">
12
+ <header className="stack-sm">
13
+ <p className="eyebrow">{english ? "Business request" : "Üzleti megkeresés"}</p>
14
+ <h1>{english ? "Request a quote" : "Ajánlatkérés"}</h1>
15
+ <p className="muted">{english ? "Describe what you need and we will prepare a tailored offer." : "Írd le, mire van szükséged, és személyre szabott ajánlatot készítünk."}</p>
16
+ </header>
17
+ <QuoteRequestForm locale={locale} config={config} />
18
+ </div>
19
+ )
20
+ }
@@ -0,0 +1,75 @@
1
+ import Link from "next/link"
2
+ import type { CmsEntry } from "@/lib/core/cms"
3
+
4
+ type Locale = "hu" | "en"
5
+
6
+ export function CmsEntryCard({ entry, href, locale }: { entry: CmsEntry; href: string; locale: Locale }) {
7
+ const english = locale === "en"
8
+ return (
9
+ <article className="panel cms-card stack-sm">
10
+ {entry.featured_image_url ? (
11
+ <img className="cms-card-image" src={entry.featured_image_url} alt={entry.featured_image_alt || entry.title} />
12
+ ) : null}
13
+ <div className="stack-sm">
14
+ <CmsEntryMeta entry={entry} locale={locale} />
15
+ <h2><Link href={href}>{entry.title}</Link></h2>
16
+ {entry.excerpt ? <p>{entry.excerpt}</p> : null}
17
+ <Link className="text-link" href={href}>{english ? "Read more" : "Tovább olvasom"}</Link>
18
+ </div>
19
+ </article>
20
+ )
21
+ }
22
+
23
+ export function CmsEntryMeta({ entry, locale }: { entry: CmsEntry; locale: Locale }) {
24
+ const english = locale === "en"
25
+ const date = entry.published_at || entry.created_at
26
+ return (
27
+ <div className="cms-meta muted small">
28
+ {entry.author_name ? <span>{entry.author_name}</span> : null}
29
+ {date ? (
30
+ <time dateTime={date}>
31
+ {new Intl.DateTimeFormat(english ? "en-US" : "hu-HU", { dateStyle: "medium" }).format(new Date(date))}
32
+ </time>
33
+ ) : null}
34
+ {entry.terms?.length ? <span>{entry.terms.map((term) => term.name).join(" · ")}</span> : null}
35
+ </div>
36
+ )
37
+ }
38
+
39
+ export function CmsEntryBody({ entry }: { entry: CmsEntry }) {
40
+ if (entry.body_format === "html" && entry.body) {
41
+ return <div className="cms-body" dangerouslySetInnerHTML={{ __html: entry.body }} />
42
+ }
43
+
44
+ if (entry.body_format === "blocks" && Array.isArray(entry.blocks)) {
45
+ return (
46
+ <div className="cms-body stack-sm">
47
+ {entry.blocks.map((block, index) => <CmsBlock block={block} index={index} key={index} />)}
48
+ </div>
49
+ )
50
+ }
51
+
52
+ const paragraphs = String(entry.body || "")
53
+ .split(/\n\s*\n/)
54
+ .map((paragraph) => paragraph.trim())
55
+ .filter(Boolean)
56
+
57
+ return (
58
+ <div className="cms-body stack-sm">
59
+ {paragraphs.map((paragraph, index) => <p key={index}>{paragraph}</p>)}
60
+ </div>
61
+ )
62
+ }
63
+
64
+ function CmsBlock({ block, index }: { block: unknown; index: number }) {
65
+ if (typeof block === "string") return <p>{block}</p>
66
+ if (!block || typeof block !== "object" || Array.isArray(block)) return null
67
+ const row = block as Record<string, unknown>
68
+ const type = typeof row.type === "string" ? row.type : ""
69
+ const raw = row.text ?? row.content ?? row.value ?? (row.data && typeof row.data === "object" && !Array.isArray(row.data) ? (row.data as Record<string, unknown>).text : null)
70
+ const text = typeof raw === "string" ? raw : ""
71
+ if (!text) return null
72
+ if (type === "heading" || type === "h2" || type === "h3") return <h3>{text}</h3>
73
+ if (type === "quote") return <blockquote>{text}</blockquote>
74
+ return <p data-block-index={index}>{text}</p>
75
+ }
@@ -0,0 +1,203 @@
1
+ "use client"
2
+
3
+ import { FormEvent, useEffect, useState } from "react"
4
+ import { submitLead, type LeadFieldDefinition, type LeadFormDefinition } from "@/lib/core/leads"
5
+ import { useToast } from "@/components/toast-provider"
6
+
7
+ type Props = {
8
+ locale: "hu" | "en"
9
+ form: LeadFormDefinition
10
+ spamProtection: {
11
+ honeypot_field: string
12
+ turnstile: { enabled: boolean; site_key?: string | null }
13
+ }
14
+ }
15
+
16
+ export function LeadForm({ locale, form, spamProtection }: Props) {
17
+ const english = locale === "en"
18
+ const { showToast } = useToast()
19
+ const [submitting, setSubmitting] = useState(false)
20
+ const [turnstileToken, setTurnstileToken] = useState("")
21
+ const [startedAt] = useState(() => new Date().toISOString())
22
+ const turnstileCallback = "hszrdmLeadTurnstileSuccess"
23
+ const turnstileExpiredCallback = "hszrdmLeadTurnstileExpired"
24
+
25
+ useEffect(() => {
26
+ if (!spamProtection.turnstile.enabled || !spamProtection.turnstile.site_key) return
27
+ const target = window as unknown as Record<string, unknown>
28
+ target[turnstileCallback] = (token: string) => setTurnstileToken(token)
29
+ target[turnstileExpiredCallback] = () => setTurnstileToken("")
30
+ if (!document.querySelector('script[data-hszrdm-turnstile="true"]')) {
31
+ const script = document.createElement("script")
32
+ script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js"
33
+ script.async = true
34
+ script.defer = true
35
+ script.dataset.hszrdmTurnstile = "true"
36
+ document.head.appendChild(script)
37
+ }
38
+ return () => {
39
+ delete target[turnstileCallback]
40
+ delete target[turnstileExpiredCallback]
41
+ }
42
+ }, [spamProtection.turnstile.enabled, spamProtection.turnstile.site_key])
43
+
44
+ async function onSubmit(event: FormEvent<HTMLFormElement>) {
45
+ event.preventDefault()
46
+ if (submitting) return
47
+ const element = event.currentTarget
48
+ const data = new FormData(element)
49
+ const fields: Record<string, unknown> = {}
50
+
51
+ for (const field of form.fields) {
52
+ const raw = data.get(`field_${field.key}`)
53
+ if (field.type === "boolean") fields[field.key] = raw === "on"
54
+ else if (field.type === "number" && raw !== null && String(raw).trim()) fields[field.key] = Number(raw)
55
+ else if (raw !== null && String(raw).trim()) fields[field.key] = String(raw).trim()
56
+ }
57
+
58
+ setSubmitting(true)
59
+ try {
60
+ const pageUrl = typeof window !== "undefined" ? window.location.href : undefined
61
+ const referrer = typeof document !== "undefined" ? document.referrer || undefined : undefined
62
+ await submitLead({
63
+ form_key: form.key,
64
+ name: value(data, "name"),
65
+ email: value(data, "email"),
66
+ phone: value(data, "phone"),
67
+ company: value(data, "company"),
68
+ message: value(data, "message"),
69
+ fields,
70
+ source: "storefront_contact",
71
+ page_url: pageUrl,
72
+ referrer,
73
+ privacy_consent: data.get("privacy_consent") === "on",
74
+ form_started_at: startedAt,
75
+ turnstile_token: turnstileToken || undefined,
76
+ [spamProtection.honeypot_field]: value(data, spamProtection.honeypot_field) || "",
77
+ })
78
+ element.reset()
79
+ setTurnstileToken("")
80
+ showToast({
81
+ tone: "success",
82
+ message: english ? "Your message has been sent." : "Az üzenetedet elküldtük.",
83
+ })
84
+ } catch (cause) {
85
+ showToast({
86
+ tone: "error",
87
+ message: cause instanceof Error
88
+ ? cause.message
89
+ : (english ? "The message could not be sent." : "Az üzenetet nem sikerült elküldeni."),
90
+ })
91
+ } finally {
92
+ setSubmitting(false)
93
+ }
94
+ }
95
+
96
+ const required = new Set(form.required_standard_fields)
97
+ const turnstileRequired = spamProtection.turnstile.enabled && Boolean(spamProtection.turnstile.site_key)
98
+
99
+ return (
100
+ <form className="panel stack lead-form" onSubmit={onSubmit}>
101
+ <div className="form-grid">
102
+ <StandardField name="name" label={english ? "Name" : "Név"} required={required.has("name")} />
103
+ <StandardField name="email" label={english ? "Email address" : "E-mail-cím"} type="email" required={required.has("email")} />
104
+ <StandardField name="phone" label={english ? "Phone" : "Telefonszám"} type="tel" required={required.has("phone")} />
105
+ <StandardField name="company" label={english ? "Company" : "Cég"} required={required.has("company")} />
106
+ </div>
107
+
108
+ <div>
109
+ <label className="field-label" htmlFor="lead-message">{english ? "Message" : "Üzenet"}{required.has("message") ? <span className="required-mark">*</span> : null}</label>
110
+ <textarea id="lead-message" name="message" rows={6} required={required.has("message")} />
111
+ </div>
112
+
113
+ {form.fields.length ? (
114
+ <div className="form-grid">
115
+ {form.fields.map((field) => <LeadFieldControl field={field} key={field.key} />)}
116
+ </div>
117
+ ) : null}
118
+
119
+ <div className="honeypot-field" aria-hidden="true">
120
+ <label htmlFor={`lead-${spamProtection.honeypot_field}`}>Website</label>
121
+ <input id={`lead-${spamProtection.honeypot_field}`} name={spamProtection.honeypot_field} type="text" tabIndex={-1} autoComplete="off" />
122
+ </div>
123
+
124
+ {form.privacy.required ? (
125
+ <label className="checkbox-row">
126
+ <input name="privacy_consent" type="checkbox" required />
127
+ <span>
128
+ {form.privacy.label}
129
+ {form.privacy.url ? <> <a href={form.privacy.url} target="_blank" rel="noreferrer">{english ? "Details" : "Részletek"}</a>.</> : null}
130
+ </span>
131
+ </label>
132
+ ) : null}
133
+
134
+ {turnstileRequired ? (
135
+ <div
136
+ className="cf-turnstile"
137
+ data-sitekey={spamProtection.turnstile.site_key || undefined}
138
+ data-callback={turnstileCallback}
139
+ data-expired-callback={turnstileExpiredCallback}
140
+ />
141
+ ) : null}
142
+
143
+ <button className="button button-large" type="submit" disabled={submitting || (turnstileRequired && !turnstileToken)}>
144
+ {submitting ? (english ? "Sending…" : "Küldés…") : (english ? "Send message" : "Üzenet küldése")}
145
+ </button>
146
+ </form>
147
+ )
148
+ }
149
+
150
+ function StandardField({ name, label, type = "text", required = false }: { name: string; label: string; type?: string; required?: boolean }) {
151
+ const id = `lead-${name}`
152
+ return (
153
+ <div>
154
+ <label className="field-label" htmlFor={id}>{label}{required ? <span className="required-mark">*</span> : null}</label>
155
+ <input id={id} name={name} type={type} required={required} />
156
+ </div>
157
+ )
158
+ }
159
+
160
+ function LeadFieldControl({ field }: { field: LeadFieldDefinition }) {
161
+ const id = `lead-field-${field.key}`
162
+ const name = `field_${field.key}`
163
+ if (field.type === "boolean") {
164
+ return (
165
+ <label className="checkbox-row" htmlFor={id}>
166
+ <input id={id} name={name} type="checkbox" required={field.required} />
167
+ <span>{field.label}</span>
168
+ </label>
169
+ )
170
+ }
171
+ if (field.type === "textarea") {
172
+ return (
173
+ <div>
174
+ <label className="field-label" htmlFor={id}>{field.label}{field.required ? <span className="required-mark">*</span> : null}</label>
175
+ <textarea id={id} name={name} rows={4} required={field.required} />
176
+ </div>
177
+ )
178
+ }
179
+ if (field.type === "select") {
180
+ return (
181
+ <div>
182
+ <label className="field-label" htmlFor={id}>{field.label}{field.required ? <span className="required-mark">*</span> : null}</label>
183
+ <select id={id} name={name} required={field.required} defaultValue="">
184
+ <option value="" disabled={field.required}>—</option>
185
+ {(field.options || []).map((option) => <option value={option} key={option}>{option}</option>)}
186
+ </select>
187
+ </div>
188
+ )
189
+ }
190
+ const type = field.type === "phone" ? "tel" : field.type
191
+ return (
192
+ <div>
193
+ <label className="field-label" htmlFor={id}>{field.label}{field.required ? <span className="required-mark">*</span> : null}</label>
194
+ <input id={id} name={name} type={type} required={field.required} />
195
+ </div>
196
+ )
197
+ }
198
+
199
+ function value(data: FormData, key: string) {
200
+ const raw = data.get(key)
201
+ const result = typeof raw === "string" ? raw.trim() : ""
202
+ return result || undefined
203
+ }
@@ -0,0 +1,107 @@
1
+ "use client"
2
+
3
+ import { FormEvent, useEffect, useState } from "react"
4
+ import { newsletterConfig, subscribeNewsletter, type NewsletterConfig } from "@/lib/core/newsletter"
5
+ import { useToast } from "@/components/toast-provider"
6
+
7
+ type Props = {
8
+ locale: "hu" | "en"
9
+ }
10
+
11
+ export function NewsletterSignup({ locale }: Props) {
12
+ const english = locale === "en"
13
+ const { showToast } = useToast()
14
+ const [config, setConfig] = useState<NewsletterConfig | null>(null)
15
+ const [email, setEmail] = useState("")
16
+ const [consent, setConsent] = useState(false)
17
+ const [submitting, setSubmitting] = useState(false)
18
+
19
+ useEffect(() => {
20
+ let active = true
21
+ void newsletterConfig()
22
+ .then((value) => {
23
+ if (active) setConfig(value)
24
+ })
25
+ .catch(() => {
26
+ if (active) setConfig(null)
27
+ })
28
+ return () => {
29
+ active = false
30
+ }
31
+ }, [])
32
+
33
+ if (!config?.enabled) return null
34
+
35
+ async function onSubmit(event: FormEvent<HTMLFormElement>) {
36
+ event.preventDefault()
37
+ if (!email.trim() || !consent || submitting) return
38
+ setSubmitting(true)
39
+ try {
40
+ const url = typeof window !== "undefined" ? new URL(window.location.href) : null
41
+ const utm = url
42
+ ? Object.fromEntries(
43
+ ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"]
44
+ .map((key) => [key, url.searchParams.get(key) || ""])
45
+ .filter(([, value]) => value),
46
+ )
47
+ : undefined
48
+ const response = await subscribeNewsletter({
49
+ email: email.trim(),
50
+ consent: true,
51
+ source: "storefront_footer",
52
+ page_url: url?.toString(),
53
+ utm,
54
+ })
55
+ setEmail("")
56
+ setConsent(false)
57
+ showToast({ tone: "success", message: response.message })
58
+ } catch (cause) {
59
+ showToast({
60
+ tone: "error",
61
+ message: cause instanceof Error
62
+ ? cause.message
63
+ : (english ? "Subscription failed." : "A feliratkozás nem sikerült."),
64
+ })
65
+ } finally {
66
+ setSubmitting(false)
67
+ }
68
+ }
69
+
70
+ return (
71
+ <section className="footer-newsletter stack-sm" aria-labelledby="newsletter-title">
72
+ <div>
73
+ <p className="eyebrow">{english ? "Newsletter" : "Hírlevél"}</p>
74
+ <h2 id="newsletter-title">{english ? "Stay in the loop" : "Maradj képben"}</h2>
75
+ <p className="muted small">
76
+ {config.double_opt_in
77
+ ? (english ? "We will send a confirmation link before subscribing you." : "Feliratkozás előtt megerősítő linket küldünk.")
78
+ : (english ? "Get updates and useful offers by email." : "Kérj e-mailes híreket és hasznos ajánlatokat.")}
79
+ </p>
80
+ </div>
81
+ <form className="newsletter-form" onSubmit={onSubmit}>
82
+ <label className="field-label" htmlFor="newsletter-email">{english ? "Email address" : "E-mail-cím"}</label>
83
+ <div className="newsletter-form-row">
84
+ <input
85
+ id="newsletter-email"
86
+ type="email"
87
+ autoComplete="email"
88
+ required
89
+ value={email}
90
+ onChange={(event) => setEmail(event.target.value)}
91
+ placeholder="email@example.com"
92
+ />
93
+ <button className="button" type="submit" disabled={submitting || !consent || !email.trim()}>
94
+ {submitting ? (english ? "Sending…" : "Küldés…") : (english ? "Subscribe" : "Feliratkozom")}
95
+ </button>
96
+ </div>
97
+ <label className="checkbox-row">
98
+ <input type="checkbox" checked={consent} onChange={(event) => setConsent(event.target.checked)} required />
99
+ <span>
100
+ {english ? "I consent to receiving newsletter emails." : "Hozzájárulok a hírlevél e-mailek fogadásához."}
101
+ {config.consent_url ? <> <a href={config.consent_url} target="_blank" rel="noreferrer">{english ? "Privacy information" : "Adatkezelési tájékoztató"}</a>.</> : null}
102
+ </span>
103
+ </label>
104
+ </form>
105
+ </section>
106
+ )
107
+ }