create-brainerce-store 1.36.0 → 1.39.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.
@@ -1,10 +1,9 @@
1
1
  'use client';
2
2
 
3
- import { Suspense, useEffect, useState, useCallback, useRef } from 'react';
3
+ import { Suspense, useEffect, useMemo, useState, useCallback, useRef } from 'react';
4
4
  import { useSearchParams } from 'next/navigation';
5
5
  import { useRouter } from '@/lib/navigation';
6
- import type { Product } from 'brainerce';
7
- import type { ProductQueryParams } from 'brainerce';
6
+ import type { Product, ProductQueryParams, PublicMetafieldDefinition } from 'brainerce';
8
7
  import { getClient } from '@/lib/brainerce';
9
8
  import { ProductGrid } from '@/components/products/product-grid';
10
9
  import { LoadingSpinner } from '@/components/shared/loading-spinner';
@@ -13,6 +12,18 @@ import { cn } from '@/lib/utils';
13
12
 
14
13
  const PAGE_SIZE = 20;
15
14
 
15
+ /**
16
+ * Metafield (custom-field) values are passed in the URL as `mf_<key>=v1,v2`
17
+ * for readability (no JSON encoding). The SDK assembles them back into
18
+ * `{ [key]: string[] }` before calling `client.getProducts`.
19
+ *
20
+ * Only definitions with `filterable: true` of type SELECT / MULTI_SELECT /
21
+ * BOOLEAN are honored server-side — the storefront renders facets only for
22
+ * those.
23
+ */
24
+ const METAFIELD_URL_PREFIX = 'mf_';
25
+ const FILTERABLE_TYPES = new Set(['SELECT', 'MULTI_SELECT', 'BOOLEAN']);
26
+
16
27
  type SortOption = {
17
28
  labelKey: 'sortNewest' | 'sortNameAZ' | 'sortNameZA' | 'sortPriceLow' | 'sortPriceHigh';
18
29
  sortBy: ProductQueryParams['sortBy'];
@@ -239,26 +250,52 @@ function ProductsContent() {
239
250
  const [categories, setCategories] = useState<CategoryNode[]>([]);
240
251
  const [brands, setBrands] = useState<Array<{ id: string; name: string }>>([]);
241
252
  const [tags, setTags] = useState<Array<{ id: string; name: string }>>([]);
253
+ const [metafieldDefs, setMetafieldDefs] = useState<PublicMetafieldDefinition[]>([]);
242
254
 
243
255
  const sortIndex = parseInt(sortParam, 10) || 0;
244
256
  const currentSort = sortOptions[sortIndex] || sortOptions[0];
245
257
 
246
- // Load categories, brands, and tags
258
+ // Load categories, brands, tags, and metafield definitions (for custom-field facets).
259
+ // The metafield-definitions endpoint already returns only definitions
260
+ // published to this sales channel; we filter client-side to the ones flagged
261
+ // `filterable: true` and of a UI-renderable type.
247
262
  useEffect(() => {
248
263
  async function loadFilters() {
249
264
  const client = getClient();
250
- const [catRes, brandRes, tagRes] = await Promise.allSettled([
265
+ const [catRes, brandRes, tagRes, mfRes] = await Promise.allSettled([
251
266
  client.getCategories(),
252
267
  client.getBrands(),
253
268
  client.getTags(),
269
+ client.getPublicMetafieldDefinitions(),
254
270
  ]);
255
271
  if (catRes.status === 'fulfilled') setCategories(catRes.value.categories as CategoryNode[]);
256
272
  if (brandRes.status === 'fulfilled') setBrands(brandRes.value.brands);
257
273
  if (tagRes.status === 'fulfilled') setTags(tagRes.value.tags);
274
+ if (mfRes.status === 'fulfilled') {
275
+ setMetafieldDefs(
276
+ mfRes.value.definitions.filter(
277
+ (d) => d.filterable === true && FILTERABLE_TYPES.has(d.type)
278
+ )
279
+ );
280
+ }
258
281
  }
259
282
  loadFilters();
260
283
  }, []);
261
284
 
285
+ // Stable serialized signature of the selected metafield facets — used as
286
+ // the `loadProducts` dependency (and to derive the SDK shape). When no
287
+ // facets are selected, this is `''` so the SDK call omits `metafields`
288
+ // entirely and the backend short-circuits the filter branch.
289
+ const metafieldsKey = useMemo(() => {
290
+ if (metafieldDefs.length === 0) return '';
291
+ const parts: string[] = [];
292
+ for (const def of metafieldDefs) {
293
+ const raw = searchParams.get(`${METAFIELD_URL_PREFIX}${def.key}`);
294
+ if (raw) parts.push(`${def.key}=${raw}`);
295
+ }
296
+ return parts.sort().join('&');
297
+ }, [metafieldDefs, searchParams]);
298
+
262
299
  // Load products when filters change
263
300
  const loadProducts = useCallback(
264
301
  async (pageNum: number, append: boolean) => {
@@ -281,6 +318,24 @@ function ProductsContent() {
281
318
  if (categoryId) params.categories = categoryId;
282
319
  if (brandId) params.brands = brandId;
283
320
  if (tagId) params.tags = tagId;
321
+ // Build the `metafields` shape from `metafieldsKey` (each segment is
322
+ // `key=v1,v2`). Equivalent to reading the URL params directly but
323
+ // tied to the stable signature already in this callback's deps.
324
+ if (metafieldsKey) {
325
+ const mf: Record<string, string[]> = {};
326
+ for (const segment of metafieldsKey.split('&')) {
327
+ const eq = segment.indexOf('=');
328
+ if (eq < 0) continue;
329
+ const k = segment.slice(0, eq);
330
+ const v = segment
331
+ .slice(eq + 1)
332
+ .split(',')
333
+ .map((s) => s.trim())
334
+ .filter(Boolean);
335
+ if (v.length > 0) mf[k] = v;
336
+ }
337
+ if (Object.keys(mf).length > 0) params.metafields = mf;
338
+ }
284
339
 
285
340
  const result = await client.getProducts(params);
286
341
 
@@ -299,7 +354,15 @@ function ProductsContent() {
299
354
  setLoadingMore(false);
300
355
  }
301
356
  },
302
- [searchQuery, categoryId, brandId, tagId, currentSort.sortBy, currentSort.sortOrder]
357
+ [
358
+ searchQuery,
359
+ categoryId,
360
+ brandId,
361
+ tagId,
362
+ currentSort.sortBy,
363
+ currentSort.sortOrder,
364
+ metafieldsKey,
365
+ ]
303
366
  );
304
367
 
305
368
  useEffect(() => {
@@ -326,6 +389,24 @@ function ProductsContent() {
326
389
  updateParam('category', id);
327
390
  }
328
391
 
392
+ /** Read the currently-selected values for a given metafield definition. */
393
+ function getSelectedMetafieldValues(key: string): string[] {
394
+ const raw = searchParams.get(`${METAFIELD_URL_PREFIX}${key}`);
395
+ if (!raw) return [];
396
+ return raw
397
+ .split(',')
398
+ .map((v) => v.trim())
399
+ .filter(Boolean);
400
+ }
401
+
402
+ /**
403
+ * Toggle one value on/off in a metafield facet's URL param. Multi-select
404
+ * adds/removes from the list; single-select / boolean replace the value.
405
+ */
406
+ function setMetafieldValue(key: string, values: string[]) {
407
+ updateParam(`${METAFIELD_URL_PREFIX}${key}`, values.join(','));
408
+ }
409
+
329
410
  return (
330
411
  <div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
331
412
  {/* Page Header */}
@@ -402,6 +483,88 @@ function ProductsContent() {
402
483
  </select>
403
484
  )}
404
485
 
486
+ {/* Custom-field (metafield) facets — rendered per definition type.
487
+ Only definitions flagged `filterable: true` and published to
488
+ this sales channel reach this list (see `metafieldDefs` filter
489
+ above). The merchant's display name (`def.name`) is shown as-is
490
+ — `enumValues` come from the merchant's dashboard config. */}
491
+ {metafieldDefs.map((def) => {
492
+ const selected = getSelectedMetafieldValues(def.key);
493
+
494
+ if (def.type === 'BOOLEAN') {
495
+ const isOn = selected.includes('true');
496
+ return (
497
+ <label
498
+ key={def.id}
499
+ className="border-border text-foreground hover:border-primary inline-flex h-9 cursor-pointer items-center gap-2 rounded border px-3 text-sm transition-colors"
500
+ >
501
+ <input
502
+ type="checkbox"
503
+ checked={isOn}
504
+ onChange={(e) => setMetafieldValue(def.key, e.target.checked ? ['true'] : [])}
505
+ className="accent-primary h-4 w-4"
506
+ />
507
+ {def.name}
508
+ </label>
509
+ );
510
+ }
511
+
512
+ if (def.type === 'SELECT') {
513
+ return (
514
+ <select
515
+ key={def.id}
516
+ value={selected[0] || ''}
517
+ onChange={(e) =>
518
+ setMetafieldValue(def.key, e.target.value ? [e.target.value] : [])
519
+ }
520
+ aria-label={def.name}
521
+ className="border-border bg-background text-foreground focus:ring-primary/20 focus:border-primary h-9 rounded border px-3 text-sm focus:outline-none focus:ring-2"
522
+ >
523
+ <option value="">{`${tc('all')} ${def.name}`}</option>
524
+ {(def.enumValues || []).map((v) => (
525
+ <option key={v} value={v}>
526
+ {v}
527
+ </option>
528
+ ))}
529
+ </select>
530
+ );
531
+ }
532
+
533
+ // MULTI_SELECT — chip toggles. Each click adds/removes one value.
534
+ return (
535
+ <div
536
+ key={def.id}
537
+ className="border-border inline-flex items-center gap-1 rounded border px-2 py-1"
538
+ aria-label={def.name}
539
+ >
540
+ <span className="text-muted-foreground px-1 text-xs">{def.name}:</span>
541
+ {(def.enumValues || []).map((v) => {
542
+ const active = selected.includes(v);
543
+ return (
544
+ <button
545
+ key={v}
546
+ type="button"
547
+ onClick={() =>
548
+ setMetafieldValue(
549
+ def.key,
550
+ active ? selected.filter((s) => s !== v) : [...selected, v]
551
+ )
552
+ }
553
+ className={cn(
554
+ 'rounded-full border px-2 py-0.5 text-xs transition-colors',
555
+ active
556
+ ? 'bg-primary text-primary-foreground border-primary'
557
+ : 'border-border text-muted-foreground hover:border-primary hover:text-foreground'
558
+ )}
559
+ >
560
+ {v}
561
+ </button>
562
+ );
563
+ })}
564
+ </div>
565
+ );
566
+ })}
567
+
405
568
  {/* Sort */}
406
569
  <div className="flex items-center gap-2 sm:ms-auto">
407
570
  <label htmlFor="sort" className="text-muted-foreground whitespace-nowrap text-sm">
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Storefront announcement bar — fully driven by the merchant's dashboard.
3
+ *
4
+ * The merchant configures announcements in the Brainerce dashboard under
5
+ * Sell → Content → Announcement
6
+ *
7
+ * Everything below is generic rendering logic — it adapts automatically to
8
+ * any announcement shape returned by the API, so **you should not hardcode
9
+ * the message or severity here**.
10
+ *
11
+ * API contract:
12
+ * GET → client.content.announcement.list(locale) → Content<'ANNOUNCEMENT'>[]
13
+ * Empty array → renders nothing (page layout stays intact).
14
+ *
15
+ * Time-bounded: each announcement may have `startsAt` / `endsAt` ISO
16
+ * timestamps. We filter client-side so the cached server response can be
17
+ * shared across visitors regardless of the current time.
18
+ */
19
+ 'use client';
20
+
21
+ import * as React from 'react';
22
+ import type { Content } from 'brainerce';
23
+
24
+ interface AnnouncementBarProps {
25
+ /** Pre-fetched list from the server. Pass `[]` to render nothing. */
26
+ announcements: Content<'ANNOUNCEMENT'>[];
27
+ }
28
+
29
+ const SEVERITY_STYLES: Record<'info' | 'warning' | 'success', string> = {
30
+ info: 'bg-blue-600 text-white',
31
+ warning: 'bg-amber-500 text-amber-950',
32
+ success: 'bg-emerald-600 text-white',
33
+ };
34
+
35
+ const STORAGE_KEY = 'brainerce_dismissed_announcements';
36
+
37
+ export function AnnouncementBar({ announcements }: AnnouncementBarProps) {
38
+ const [dismissed, setDismissed] = React.useState<Set<string>>(() => new Set());
39
+
40
+ // Hydrate dismissals from localStorage on mount (avoids SSR/CSR mismatch).
41
+ React.useEffect(() => {
42
+ if (typeof window === 'undefined') return;
43
+ try {
44
+ const raw = window.localStorage.getItem(STORAGE_KEY);
45
+ if (raw) setDismissed(new Set(JSON.parse(raw) as string[]));
46
+ } catch {
47
+ // ignore malformed storage
48
+ }
49
+ }, []);
50
+
51
+ const dismiss = (id: string) => {
52
+ setDismissed((prev) => {
53
+ const next = new Set(prev);
54
+ next.add(id);
55
+ if (typeof window !== 'undefined') {
56
+ try {
57
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify([...next]));
58
+ } catch {
59
+ // ignore quota errors
60
+ }
61
+ }
62
+ return next;
63
+ });
64
+ };
65
+
66
+ const now = Date.now();
67
+ const visible = announcements.filter((a) => {
68
+ if (dismissed.has(a.id)) return false;
69
+ const startOk = !a.data.startsAt || new Date(a.data.startsAt).getTime() <= now;
70
+ const endOk = !a.data.endsAt || new Date(a.data.endsAt).getTime() >= now;
71
+ return startOk && endOk;
72
+ });
73
+
74
+ if (visible.length === 0) return null;
75
+
76
+ return (
77
+ <div role="region" aria-label="Site announcements">
78
+ {visible.map((announcement) => {
79
+ const severity = announcement.data.severity;
80
+ const tone = SEVERITY_STYLES[severity] ?? SEVERITY_STYLES.info;
81
+ return (
82
+ <div
83
+ key={announcement.id}
84
+ className={`flex items-center justify-center gap-3 px-4 py-2 text-sm ${tone}`}
85
+ >
86
+ <span className="flex-1 text-center">
87
+ {announcement.data.message}
88
+ {announcement.data.ctaHref && announcement.data.ctaLabel ? (
89
+ <>
90
+ {' '}
91
+ <a
92
+ href={announcement.data.ctaHref}
93
+ className="underline underline-offset-2"
94
+ >
95
+ {announcement.data.ctaLabel}
96
+ </a>
97
+ </>
98
+ ) : null}
99
+ </span>
100
+ {announcement.data.dismissible ? (
101
+ <button
102
+ type="button"
103
+ onClick={() => dismiss(announcement.id)}
104
+ aria-label="Dismiss announcement"
105
+ className="text-current opacity-80 transition-opacity hover:opacity-100"
106
+ >
107
+ <svg
108
+ xmlns="http://www.w3.org/2000/svg"
109
+ viewBox="0 0 24 24"
110
+ fill="none"
111
+ stroke="currentColor"
112
+ strokeWidth="2"
113
+ className="h-4 w-4"
114
+ aria-hidden="true"
115
+ >
116
+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
117
+ </svg>
118
+ </button>
119
+ ) : null}
120
+ </div>
121
+ );
122
+ })}
123
+ </div>
124
+ );
125
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * FAQ accordion — fully driven by the merchant's dashboard configuration.
3
+ *
4
+ * The merchant configures FAQs in the Brainerce dashboard under
5
+ * Sell → Content → FAQ
6
+ *
7
+ * Each FAQ row has a `key` (e.g. 'main', 'shipping', 'returns'). Pass the
8
+ * pre-fetched payload as `faq`; this component knows nothing about which
9
+ * key it came from.
10
+ *
11
+ * Security: FAQ answers may contain merchant-authored HTML — we sanitize
12
+ * via `sanitizeHtml` before injecting via dangerouslySetInnerHTML.
13
+ */
14
+ 'use client';
15
+
16
+ import * as React from 'react';
17
+ import type { Content } from 'brainerce';
18
+ import { sanitizeHtml } from '@/lib/sanitize';
19
+
20
+ interface FaqSectionProps {
21
+ /** Pre-fetched FAQ row. `null` triggers a minimal empty-state message. */
22
+ faq: Content<'FAQ'> | null;
23
+ }
24
+
25
+ export function FaqSection({ faq }: FaqSectionProps) {
26
+ const [openIdx, setOpenIdx] = React.useState<number | null>(0);
27
+
28
+ if (!faq || !faq.data.items?.length) {
29
+ return null;
30
+ }
31
+
32
+ return (
33
+ <section className="mx-auto max-w-3xl px-4 py-10 sm:px-6 lg:px-8">
34
+ <h1 className="text-foreground mb-6 text-2xl font-semibold sm:text-3xl">{faq.name}</h1>
35
+ <ul className="border-border divide-border divide-y rounded-lg border">
36
+ {faq.data.items.map((item, idx) => {
37
+ const open = openIdx === idx;
38
+ return (
39
+ <li key={idx}>
40
+ <button
41
+ type="button"
42
+ onClick={() => setOpenIdx(open ? null : idx)}
43
+ aria-expanded={open}
44
+ className="hover:bg-muted/40 flex w-full items-center justify-between gap-4 p-4 text-start transition-colors"
45
+ >
46
+ <span className="text-foreground text-sm font-medium sm:text-base">
47
+ {item.question}
48
+ </span>
49
+ <svg
50
+ xmlns="http://www.w3.org/2000/svg"
51
+ viewBox="0 0 24 24"
52
+ fill="none"
53
+ stroke="currentColor"
54
+ strokeWidth="2"
55
+ className={`text-muted-foreground h-4 w-4 transition-transform ${
56
+ open ? 'rotate-180' : ''
57
+ }`}
58
+ aria-hidden="true"
59
+ >
60
+ <path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
61
+ </svg>
62
+ </button>
63
+ {open ? (
64
+ <div
65
+ className="text-muted-foreground prose prose-sm dark:prose-invert max-w-none px-4 pb-4 text-sm leading-relaxed"
66
+ dangerouslySetInnerHTML={{ __html: sanitizeHtml(item.answer) }}
67
+ />
68
+ ) : null}
69
+ </li>
70
+ );
71
+ })}
72
+ </ul>
73
+ </section>
74
+ );
75
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Inline rich-text block — fully driven by the merchant's dashboard.
3
+ *
4
+ * The merchant configures rich-text blocks in the Brainerce dashboard
5
+ * under Sell → Content → Rich Text. Use this component anywhere on a page
6
+ * to drop a merchant-editable HTML block (intro copy, banner descriptions,
7
+ * inline announcements that aren't tied to the top-of-page Announcement
8
+ * bar, etc.).
9
+ *
10
+ * Security: HTML is sanitized via `sanitizeHtml` (isomorphic-dompurify)
11
+ * before injecting via dangerouslySetInnerHTML.
12
+ */
13
+ import * as React from 'react';
14
+ import type { Content } from 'brainerce';
15
+ import { sanitizeHtml } from '@/lib/sanitize';
16
+
17
+ interface RichTextBlockProps {
18
+ /** Pre-fetched RICH_TEXT row, e.g. via `client.content.richText.get(key, locale)`. */
19
+ block: Content<'RICH_TEXT'> | null;
20
+ /** Optional wrapper className for layout positioning. */
21
+ className?: string;
22
+ }
23
+
24
+ export function RichTextBlock({ block, className }: RichTextBlockProps) {
25
+ if (!block?.data?.html) return null;
26
+ return (
27
+ <div
28
+ className={className ?? 'prose prose-sm dark:prose-invert max-w-none'}
29
+ dangerouslySetInnerHTML={{ __html: sanitizeHtml(block.data.html) }}
30
+ />
31
+ );
32
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Storefront footer — fully driven by the merchant's dashboard configuration.
3
+ *
4
+ * The merchant configures the footer in the Brainerce dashboard under
5
+ * Sell → Content → Footer
6
+ *
7
+ * Everything below is generic rendering logic — it adapts automatically to
8
+ * any footer shape returned by the API, so **you should not hardcode column
9
+ * titles or link labels here**.
10
+ *
11
+ * API contract:
12
+ * GET → client.content.footer.get('main', locale) → Content<'FOOTER'> | null
13
+ * Returns null on 404 — we render a minimal fallback so the layout never
14
+ * crashes when the merchant hasn't seeded the footer yet.
15
+ *
16
+ * Security: this component renders text only. For RichText/Page HTML, use
17
+ * <RichTextBlock> which sanitizes via isomorphic-dompurify.
18
+ */
19
+ import * as React from 'react';
20
+ import type { Content } from 'brainerce';
21
+
22
+ interface SiteFooterProps {
23
+ /** Pre-fetched footer payload (server-side). `null` triggers fallback rendering. */
24
+ footer: Content<'FOOTER'> | null;
25
+ /** Store name shown in the fallback copyright when no footer is configured. */
26
+ storeName?: string;
27
+ }
28
+
29
+ export function SiteFooter({ footer, storeName }: SiteFooterProps) {
30
+ const data = footer?.data;
31
+ const columns = data?.columns ?? [];
32
+ const social = data?.social ?? [];
33
+
34
+ // Fallback when the merchant hasn't seeded a footer yet — keeps the layout
35
+ // visually complete without exposing "missing content" to shoppers.
36
+ if (!data || (columns.length === 0 && !data.copyright && social.length === 0)) {
37
+ const year = new Date().getFullYear();
38
+ return (
39
+ <footer className="border-border bg-muted/30 text-muted-foreground mt-12 border-t py-8 text-sm">
40
+ <div className="mx-auto max-w-7xl px-4 text-center sm:px-6 lg:px-8">
41
+ © {year} {storeName ?? 'Store'}
42
+ </div>
43
+ </footer>
44
+ );
45
+ }
46
+
47
+ return (
48
+ <footer className="border-border bg-muted/30 text-foreground mt-12 border-t">
49
+ <div className="mx-auto max-w-7xl px-4 py-10 sm:px-6 lg:px-8">
50
+ {columns.length > 0 ? (
51
+ <div className="grid grid-cols-1 gap-8 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4">
52
+ {columns.map((col, idx) => (
53
+ <div key={`${col.title}-${idx}`}>
54
+ <h3 className="text-foreground mb-3 text-sm font-semibold">{col.title}</h3>
55
+ <ul className="space-y-2">
56
+ {col.links.map((link, linkIdx) => (
57
+ <li key={`${link.url}-${linkIdx}`}>
58
+ <a
59
+ href={link.url}
60
+ className="text-muted-foreground hover:text-foreground text-sm transition-colors"
61
+ >
62
+ {link.label}
63
+ </a>
64
+ </li>
65
+ ))}
66
+ </ul>
67
+ </div>
68
+ ))}
69
+ </div>
70
+ ) : null}
71
+
72
+ {social.length > 0 ? (
73
+ <div className="border-border mt-8 flex flex-wrap items-center gap-4 border-t pt-6">
74
+ {social.map((entry, idx) => (
75
+ <a
76
+ key={`${entry.platform}-${idx}`}
77
+ href={entry.url}
78
+ target="_blank"
79
+ rel="noopener noreferrer"
80
+ className="text-muted-foreground hover:text-foreground text-sm capitalize transition-colors"
81
+ >
82
+ {entry.platform}
83
+ </a>
84
+ ))}
85
+ </div>
86
+ ) : null}
87
+
88
+ {data.copyright ? (
89
+ <div className="border-border text-muted-foreground mt-6 border-t pt-4 text-center text-xs">
90
+ {data.copyright}
91
+ </div>
92
+ ) : null}
93
+ </div>
94
+ </footer>
95
+ );
96
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Merchant-controlled site header.
3
+ *
4
+ * The merchant configures the header in the Brainerce dashboard under
5
+ * Sell → Content → Header
6
+ *
7
+ * Renders logo (when set) + nav items + CTA. Everything is generic — you
8
+ * should NOT hardcode nav labels or logo paths here; the merchant edits
9
+ * them in the dashboard and the change propagates within ~5 minutes.
10
+ *
11
+ * Returns null on 404 — new stores are seeded with a default HEADER row
12
+ * by the backend (StoresService.seedDefaultContent) so this should be
13
+ * populated out of the box.
14
+ */
15
+ import * as React from 'react';
16
+ import type { Content } from 'brainerce';
17
+
18
+ interface SiteHeaderProps {
19
+ /** Pre-fetched header payload (server-side). `null` renders nothing. */
20
+ header: Content<'HEADER'> | null;
21
+ }
22
+
23
+ export function SiteHeader({ header }: SiteHeaderProps) {
24
+ if (!header) return null;
25
+ const data = header.data;
26
+ const logo = data.logo;
27
+ const navItems = data.navItems ?? [];
28
+ const cta = data.cta;
29
+
30
+ return (
31
+ <div className="border-border bg-background border-b">
32
+ <div className="mx-auto flex h-14 max-w-7xl items-center justify-between gap-4 px-4 sm:px-6 lg:px-8">
33
+ <a href="/" className="flex items-center gap-2">
34
+ {logo ? (
35
+ // eslint-disable-next-line @next/next/no-img-element -- merchant-supplied URL, dynamic optimization handled by CDN
36
+ <img src={logo.src} alt={logo.alt} className="h-8 w-auto" />
37
+ ) : null}
38
+ </a>
39
+
40
+ {navItems.length > 0 ? (
41
+ <nav className="hidden items-center gap-6 md:flex">
42
+ {navItems.map((item, idx) => (
43
+ <a
44
+ key={`${item.url}-${idx}`}
45
+ href={item.url}
46
+ className="text-muted-foreground hover:text-foreground text-sm transition-colors"
47
+ >
48
+ {item.label}
49
+ </a>
50
+ ))}
51
+ </nav>
52
+ ) : null}
53
+
54
+ {cta ? (
55
+ <a
56
+ href={cta.url}
57
+ className="bg-primary text-primary-foreground inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium transition-colors hover:opacity-90"
58
+ >
59
+ {cta.label}
60
+ </a>
61
+ ) : null}
62
+ </div>
63
+ </div>
64
+ );
65
+ }