create-brainerce-store 1.72.0 → 1.74.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/dist/index.js +37 -4
- package/messages/en.json +30 -1
- package/messages/he.json +30 -1
- package/package.json +1 -1
- package/templates/nextjs/base/AGENTS.md.ejs +63 -16
- package/templates/nextjs/base/AI-GUIDE.md +17 -4
- package/templates/nextjs/base/CLAUDE.md.ejs +67 -20
- package/templates/nextjs/base/TRANSLATIONS.md +207 -207
- package/templates/nextjs/base/src/app/account/page.tsx +168 -122
- package/templates/nextjs/base/src/app/category/[slug]/page.tsx +10 -1
- package/templates/nextjs/base/src/app/checkout/page.tsx +1179 -1074
- package/templates/nextjs/base/src/app/layout.tsx.ejs +48 -4
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +98 -3
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +14 -2
- package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +226 -0
- package/templates/nextjs/base/src/components/account/order-history.tsx +422 -371
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +85 -85
- package/templates/nextjs/base/src/components/account/saved-payment-methods.tsx +104 -0
- package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +618 -612
- package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +354 -306
- package/templates/nextjs/base/src/components/checkout/tax-display.tsx +141 -74
- package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +218 -127
- package/templates/nextjs/base/src/core/hooks/use-home-data.ts +63 -51
- package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +379 -295
- package/templates/nextjs/base/src/core/hooks/use-product-page.ts +33 -1
- package/templates/nextjs/base/src/core/lib/capabilities.ts +65 -0
- package/templates/nextjs/base/src/core/lib/display-price.ts +139 -0
- package/templates/nextjs/base/src/core/lib/region.server.ts +112 -0
- package/templates/nextjs/base/src/core/lib/region.ts +112 -0
- package/templates/nextjs/base/src/core/lib/store-info.ts +19 -0
- package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +423 -243
- package/templates/nextjs/base/src/ui/cart/cart-item.tsx +174 -164
- package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +109 -110
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +219 -176
- package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +191 -0
- package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +137 -137
- package/templates/nextjs/base/src/ui/cart/tax-estimate-line.tsx +108 -0
- package/templates/nextjs/base/src/ui/home/home-client.tsx +27 -29
- package/templates/nextjs/base/src/ui/layout/header-search.tsx +249 -0
- package/templates/nextjs/base/src/ui/layout/region-switcher.tsx +59 -0
- package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +171 -152
- package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +197 -191
- package/templates/nextjs/base/src/ui/product/product-card.tsx +25 -52
- package/templates/nextjs/base/src/ui/product/product-client-section.tsx +12 -3
- package/templates/nextjs/base/src/ui/product/product-listing.tsx +460 -446
- package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +108 -102
- package/templates/nextjs/base/src/ui/product/review-form.tsx +33 -11
- package/templates/nextjs/base/src/ui/product/stock-badge.tsx +15 -3
- package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +48 -4
- package/templates/nextjs/designs/atelier/messages-patch/en.json +21 -25
- package/templates/nextjs/designs/atelier/messages-patch/he.json +21 -25
- package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +177 -181
- package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +168 -158
- package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +106 -107
- package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +229 -184
- package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +131 -131
- package/templates/nextjs/designs/atelier/ui/cart/tax-estimate-line.tsx +108 -0
- package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +10 -1
- package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +178 -174
- package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +4 -6
- package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +150 -78
- package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +79 -46
- package/templates/nextjs/designs/atelier/ui/layout/header-search.tsx +264 -0
- package/templates/nextjs/designs/atelier/ui/layout/region-switcher.tsx +44 -0
- package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +5 -0
- package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +202 -196
- package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +27 -52
- package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +12 -3
- package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +332 -260
- package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +101 -95
- package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +30 -10
- package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +17 -2
- package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +9 -0
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +137 -137
- package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +98 -99
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +140 -140
- package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +142 -0
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +124 -124
- package/templates/nextjs/ui-canvas/cart/tax-estimate-line.tsx +104 -0
- package/templates/nextjs/ui-canvas/home/home-client.tsx +24 -26
- package/templates/nextjs/ui-canvas/layout/region-switcher.tsx +51 -0
- package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +3 -0
- package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +174 -168
- package/templates/nextjs/ui-canvas/product/product-card.tsx +9 -51
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +5 -3
- package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +105 -99
- package/templates/nextjs/ui-canvas/product/review-form.tsx +9 -1
- package/templates/nextjs/ui-canvas/product/stock-badge.tsx +17 -2
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Header search with autocomplete.
|
|
5
|
+
*
|
|
6
|
+
* The header itself is a server component (merchant-configured Content), so
|
|
7
|
+
* the search box is a client island — the same bridge `HeaderAccount` uses.
|
|
8
|
+
*
|
|
9
|
+
* Behaviour:
|
|
10
|
+
* - `useSearch()` supplies the suggestions (300ms debounce, 2-char minimum,
|
|
11
|
+
* abort on re-query). This component owns only the input + dropdown.
|
|
12
|
+
* - Submitting navigates to `/products?search=<query>`, which is exactly
|
|
13
|
+
* what `use-product-listing` reads back off the URL. The listing side
|
|
14
|
+
* already works; this is the surface that writes the param.
|
|
15
|
+
* - Picking a product suggestion goes straight to its PDP; picking a
|
|
16
|
+
* category goes to the listing filtered by `?category=<id>`, because a
|
|
17
|
+
* CategorySuggestion carries `id` + `name` + `productCount` and no slug.
|
|
18
|
+
*
|
|
19
|
+
* The dropdown auto-hides: `suggestions` is `null` until a query clears the
|
|
20
|
+
* 2-char minimum, and an empty store answers `{ products: [], categories: [] }`
|
|
21
|
+
* which renders the "no results" line rather than an empty box.
|
|
22
|
+
*
|
|
23
|
+
* Keyboard: ArrowDown / ArrowUp move the active option, Enter opens it (or
|
|
24
|
+
* submits the raw query when nothing is active), Escape closes the panel and
|
|
25
|
+
* keeps focus in the field. A blur that lands outside the widget closes it.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import * as React from 'react';
|
|
29
|
+
import { Search } from 'lucide-react';
|
|
30
|
+
import { useRouter } from '@/core/lib/navigation';
|
|
31
|
+
import { useSearch } from '@/core/hooks/use-search';
|
|
32
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
33
|
+
import { cn } from '@/core/lib/utils';
|
|
34
|
+
|
|
35
|
+
interface HeaderSearchProps {
|
|
36
|
+
className?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One flattened dropdown row — products first, then categories. */
|
|
40
|
+
type Option =
|
|
41
|
+
| { kind: 'product'; id: string; label: string; href: string }
|
|
42
|
+
| { kind: 'category'; id: string; label: string; href: string };
|
|
43
|
+
|
|
44
|
+
export function HeaderSearch({ className }: HeaderSearchProps) {
|
|
45
|
+
const router = useRouter();
|
|
46
|
+
const t = useTranslations('nav');
|
|
47
|
+
const tc = useTranslations('common');
|
|
48
|
+
const tp = useTranslations('products');
|
|
49
|
+
|
|
50
|
+
const [query, setQuery] = React.useState('');
|
|
51
|
+
const [open, setOpen] = React.useState(false);
|
|
52
|
+
const [activeIndex, setActiveIndex] = React.useState(-1);
|
|
53
|
+
const { suggestions, loading } = useSearch(query);
|
|
54
|
+
|
|
55
|
+
const rootRef = React.useRef<HTMLDivElement>(null);
|
|
56
|
+
const listboxId = React.useId();
|
|
57
|
+
|
|
58
|
+
// Products first, then categories — one flat list so the arrow keys can walk
|
|
59
|
+
// the whole panel without caring which section a row came from.
|
|
60
|
+
const options: Option[] = React.useMemo(() => {
|
|
61
|
+
if (!suggestions) return [];
|
|
62
|
+
const rows: Option[] = [];
|
|
63
|
+
for (const product of suggestions.products) {
|
|
64
|
+
rows.push({
|
|
65
|
+
kind: 'product',
|
|
66
|
+
id: product.id,
|
|
67
|
+
label: product.name,
|
|
68
|
+
// `slug` is nullable on a ProductSuggestion — fall back to the id,
|
|
69
|
+
// the same way the product cards do.
|
|
70
|
+
href: `/products/${product.slug || product.id}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
for (const category of suggestions.categories) {
|
|
74
|
+
rows.push({
|
|
75
|
+
kind: 'category',
|
|
76
|
+
id: category.id,
|
|
77
|
+
label: category.name,
|
|
78
|
+
// CategorySuggestion carries no slug, so filter the listing by id.
|
|
79
|
+
href: `/products?category=${encodeURIComponent(category.id)}`,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return rows;
|
|
83
|
+
}, [suggestions]);
|
|
84
|
+
|
|
85
|
+
// A fresh result set invalidates whatever row was highlighted.
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
setActiveIndex(-1);
|
|
88
|
+
}, [options]);
|
|
89
|
+
|
|
90
|
+
// Close when the click lands outside the widget. Pointerdown rather than
|
|
91
|
+
// click so the panel is gone before a link underneath activates.
|
|
92
|
+
React.useEffect(() => {
|
|
93
|
+
if (!open) return;
|
|
94
|
+
function onPointerDown(event: PointerEvent) {
|
|
95
|
+
if (!rootRef.current) return;
|
|
96
|
+
if (!rootRef.current.contains(event.target as Node)) setOpen(false);
|
|
97
|
+
}
|
|
98
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
99
|
+
return () => document.removeEventListener('pointerdown', onPointerDown);
|
|
100
|
+
}, [open]);
|
|
101
|
+
|
|
102
|
+
function go(href: string) {
|
|
103
|
+
setOpen(false);
|
|
104
|
+
setActiveIndex(-1);
|
|
105
|
+
router.push(href);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function submit() {
|
|
109
|
+
const trimmed = query.trim();
|
|
110
|
+
if (!trimmed) return;
|
|
111
|
+
go(`/products?search=${encodeURIComponent(trimmed)}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
|
|
115
|
+
if (event.key === 'Escape') {
|
|
116
|
+
setOpen(false);
|
|
117
|
+
setActiveIndex(-1);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
122
|
+
if (options.length === 0) return;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
setOpen(true);
|
|
125
|
+
setActiveIndex((prev) => {
|
|
126
|
+
const step = event.key === 'ArrowDown' ? 1 : -1;
|
|
127
|
+
const next = prev + step;
|
|
128
|
+
if (next < 0) return options.length - 1;
|
|
129
|
+
if (next >= options.length) return 0;
|
|
130
|
+
return next;
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (event.key === 'Enter') {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
const active = activeIndex >= 0 ? options[activeIndex] : undefined;
|
|
138
|
+
if (active) {
|
|
139
|
+
go(active.href);
|
|
140
|
+
} else {
|
|
141
|
+
submit();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// The panel is only worth showing once the hook has something to say —
|
|
147
|
+
// either rows, a spinner, or an explicit "nothing matched".
|
|
148
|
+
const showPanel = open && (loading || suggestions !== null);
|
|
149
|
+
const activeOptionId = activeIndex >= 0 ? `${listboxId}-${activeIndex}` : undefined;
|
|
150
|
+
const productCount = suggestions?.products.length ?? 0;
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<div ref={rootRef} className={cn('relative', className)}>
|
|
154
|
+
<form
|
|
155
|
+
role="search"
|
|
156
|
+
onSubmit={(event) => {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
submit();
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<label htmlFor={`${listboxId}-input`} className="sr-only">
|
|
162
|
+
{t('search')}
|
|
163
|
+
</label>
|
|
164
|
+
<div className="relative">
|
|
165
|
+
<Search
|
|
166
|
+
className="text-muted-foreground pointer-events-none absolute start-2.5 top-1/2 h-4 w-4 -translate-y-1/2"
|
|
167
|
+
aria-hidden="true"
|
|
168
|
+
/>
|
|
169
|
+
<input
|
|
170
|
+
id={`${listboxId}-input`}
|
|
171
|
+
type="search"
|
|
172
|
+
role="combobox"
|
|
173
|
+
autoComplete="off"
|
|
174
|
+
aria-expanded={showPanel}
|
|
175
|
+
aria-controls={listboxId}
|
|
176
|
+
aria-activedescendant={activeOptionId}
|
|
177
|
+
placeholder={t('searchPlaceholder')}
|
|
178
|
+
value={query}
|
|
179
|
+
onChange={(event) => {
|
|
180
|
+
setQuery(event.target.value);
|
|
181
|
+
setOpen(true);
|
|
182
|
+
}}
|
|
183
|
+
onFocus={() => setOpen(true)}
|
|
184
|
+
onKeyDown={handleKeyDown}
|
|
185
|
+
className="border-border bg-background text-foreground placeholder:text-muted-foreground focus-visible:ring-primary h-9 w-full rounded-md border pe-3 ps-8 text-sm focus-visible:outline-none focus-visible:ring-2"
|
|
186
|
+
/>
|
|
187
|
+
</div>
|
|
188
|
+
</form>
|
|
189
|
+
|
|
190
|
+
{showPanel && (
|
|
191
|
+
<div className="border-border bg-background absolute inset-x-0 top-full z-50 mt-2 overflow-hidden rounded-lg border shadow-lg">
|
|
192
|
+
{loading && options.length === 0 ? (
|
|
193
|
+
<p className="text-muted-foreground px-4 py-3 text-sm">{tc('loading')}</p>
|
|
194
|
+
) : options.length === 0 ? (
|
|
195
|
+
<p className="text-muted-foreground px-4 py-3 text-sm">{tc('noResults')}</p>
|
|
196
|
+
) : (
|
|
197
|
+
<ul
|
|
198
|
+
id={listboxId}
|
|
199
|
+
role="listbox"
|
|
200
|
+
aria-label={t('search')}
|
|
201
|
+
className="max-h-80 overflow-y-auto py-1"
|
|
202
|
+
>
|
|
203
|
+
{options.map((option, index) => (
|
|
204
|
+
<React.Fragment key={`${option.kind}-${option.id}`}>
|
|
205
|
+
{index === 0 && productCount > 0 && (
|
|
206
|
+
<li
|
|
207
|
+
role="presentation"
|
|
208
|
+
className="text-muted-foreground px-4 pb-1 pt-2 text-[11px] font-semibold uppercase tracking-wide"
|
|
209
|
+
>
|
|
210
|
+
{tp('pageTitle')}
|
|
211
|
+
</li>
|
|
212
|
+
)}
|
|
213
|
+
{index === productCount && option.kind === 'category' && (
|
|
214
|
+
<li
|
|
215
|
+
role="presentation"
|
|
216
|
+
className="text-muted-foreground px-4 pb-1 pt-2 text-[11px] font-semibold uppercase tracking-wide"
|
|
217
|
+
>
|
|
218
|
+
{t('categories')}
|
|
219
|
+
</li>
|
|
220
|
+
)}
|
|
221
|
+
<li
|
|
222
|
+
id={`${listboxId}-${index}`}
|
|
223
|
+
role="option"
|
|
224
|
+
aria-selected={index === activeIndex}
|
|
225
|
+
className={cn(
|
|
226
|
+
'cursor-pointer px-4 py-2 text-sm transition-colors',
|
|
227
|
+
index === activeIndex
|
|
228
|
+
? 'bg-muted text-foreground'
|
|
229
|
+
: 'text-foreground/80 hover:bg-muted/60'
|
|
230
|
+
)}
|
|
231
|
+
onPointerDown={(event) => {
|
|
232
|
+
// Keep focus in the input so the blur handler cannot
|
|
233
|
+
// close the panel before the navigation runs.
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
go(option.href);
|
|
236
|
+
}}
|
|
237
|
+
onMouseEnter={() => setActiveIndex(index)}
|
|
238
|
+
>
|
|
239
|
+
{option.label}
|
|
240
|
+
</li>
|
|
241
|
+
</React.Fragment>
|
|
242
|
+
))}
|
|
243
|
+
</ul>
|
|
244
|
+
)}
|
|
245
|
+
</div>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Region / currency switcher.
|
|
5
|
+
*
|
|
6
|
+
* ⛔ RENDERS NOTHING on a single-region store, which is almost every store.
|
|
7
|
+
* `regions.length <= 1` returns null before any markup: an empty or
|
|
8
|
+
* one-option dropdown in the header is worse than no switcher at all, and the
|
|
9
|
+
* whole regions feature is meant to be invisible until a merchant actually
|
|
10
|
+
* adds a second region.
|
|
11
|
+
*
|
|
12
|
+
* ⛔ It also renders nothing when the regions call FAILED. A brand-new store
|
|
13
|
+
* is empty and the call can fail (channel not live yet, backend hiccup); the
|
|
14
|
+
* provider swallows that and leaves `regions` at `[]`, which lands in the same
|
|
15
|
+
* early return. There is no error box and no skeleton, because a shopper has
|
|
16
|
+
* no idea what a region is and nothing here is worth interrupting them for.
|
|
17
|
+
*
|
|
18
|
+
* Why a manual switcher exists at all when the edge already guesses: the guess
|
|
19
|
+
* is an IP, and an IP is wrong for travellers, expats, VPNs and anyone behind
|
|
20
|
+
* a corporate egress. The shopper is the authority on where they are, and
|
|
21
|
+
* their choice is stored in a cookie so the SERVER renders the same prices on
|
|
22
|
+
* the next navigation instead of the client re-pricing after hydration.
|
|
23
|
+
*
|
|
24
|
+
* The labels are store data (`region.name`, `region.currency`), not UI copy,
|
|
25
|
+
* so this component needs no translation keys in any locale.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useRegion } from '@/core/providers/store-provider';
|
|
29
|
+
import {
|
|
30
|
+
Select,
|
|
31
|
+
SelectContent,
|
|
32
|
+
SelectItem,
|
|
33
|
+
SelectTrigger,
|
|
34
|
+
SelectValue,
|
|
35
|
+
} from '@/components/ui/select';
|
|
36
|
+
|
|
37
|
+
export function RegionSwitcher() {
|
|
38
|
+
const { regions, region, setRegion } = useRegion();
|
|
39
|
+
|
|
40
|
+
if (regions.length <= 1 || !region) return null;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Select value={region.id} onValueChange={setRegion}>
|
|
44
|
+
<SelectTrigger
|
|
45
|
+
className="h-8 w-auto gap-1 rounded border bg-transparent px-2 py-1 text-sm"
|
|
46
|
+
aria-label="Select region and currency"
|
|
47
|
+
>
|
|
48
|
+
<SelectValue />
|
|
49
|
+
</SelectTrigger>
|
|
50
|
+
<SelectContent>
|
|
51
|
+
{regions.map((r) => (
|
|
52
|
+
<SelectItem key={r.id} value={r.id}>
|
|
53
|
+
{r.name} ({r.currency})
|
|
54
|
+
</SelectItem>
|
|
55
|
+
))}
|
|
56
|
+
</SelectContent>
|
|
57
|
+
</Select>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -1,152 +1,171 @@
|
|
|
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 brand (logo or store-name fallback) + nav items + CTA + cart link,
|
|
8
|
-
* with a `<details>` mobile menu that works without client-side JS. Everything
|
|
9
|
-
* is generic — do NOT hardcode nav labels or logo paths here; the merchant
|
|
10
|
-
* edits them in the dashboard and the change propagates within ~5 minutes.
|
|
11
|
-
*
|
|
12
|
-
* If `header` is null (404 from the API, or the merchant deleted the row),
|
|
13
|
-
* we render a minimal static fallback with just the brand label and cart link
|
|
14
|
-
* so the layout never collapses. New stores ship with a seeded HEADER row
|
|
15
|
-
* from the backend (StoresService.seedDefaultContent), so the populated
|
|
16
|
-
* branch is the common case.
|
|
17
|
-
*/
|
|
18
|
-
import * as React from 'react';
|
|
19
|
-
import { Menu, ShoppingCart } from 'lucide-react';
|
|
20
|
-
import type { Content } from 'brainerce';
|
|
21
|
-
import { Button } from '@/components/ui/button';
|
|
22
|
-
// Locale-aware Link (client component — fine to render from this server
|
|
23
|
-
// component). Used for the static internal links (brand → /, cart) so the
|
|
24
|
-
// current locale prefix is preserved; merchant-configured nav items keep
|
|
25
|
-
// plain <a> since their URLs are arbitrary (may be external).
|
|
26
|
-
import { Link } from '@/core/lib/navigation';
|
|
27
|
-
import { HeaderAccount } from './header-account';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
// the
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
</
|
|
145
|
-
</
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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 brand (logo or store-name fallback) + nav items + CTA + cart link,
|
|
8
|
+
* with a `<details>` mobile menu that works without client-side JS. Everything
|
|
9
|
+
* is generic — do NOT hardcode nav labels or logo paths here; the merchant
|
|
10
|
+
* edits them in the dashboard and the change propagates within ~5 minutes.
|
|
11
|
+
*
|
|
12
|
+
* If `header` is null (404 from the API, or the merchant deleted the row),
|
|
13
|
+
* we render a minimal static fallback with just the brand label and cart link
|
|
14
|
+
* so the layout never collapses. New stores ship with a seeded HEADER row
|
|
15
|
+
* from the backend (StoresService.seedDefaultContent), so the populated
|
|
16
|
+
* branch is the common case.
|
|
17
|
+
*/
|
|
18
|
+
import * as React from 'react';
|
|
19
|
+
import { Menu, ShoppingCart } from 'lucide-react';
|
|
20
|
+
import type { Content } from 'brainerce';
|
|
21
|
+
import { Button } from '@/components/ui/button';
|
|
22
|
+
// Locale-aware Link (client component — fine to render from this server
|
|
23
|
+
// component). Used for the static internal links (brand → /, cart) so the
|
|
24
|
+
// current locale prefix is preserved; merchant-configured nav items keep
|
|
25
|
+
// plain <a> since their URLs are arbitrary (may be external).
|
|
26
|
+
import { Link } from '@/core/lib/navigation';
|
|
27
|
+
import { HeaderAccount } from './header-account';
|
|
28
|
+
import { HeaderSearch } from './header-search';
|
|
29
|
+
<% if (i18nEnabled) { %>
|
|
30
|
+
import { LanguageSwitcher } from '@/ui/layout/language-switcher';
|
|
31
|
+
<% } %>
|
|
32
|
+
import { RegionSwitcher } from '@/ui/layout/region-switcher';
|
|
33
|
+
|
|
34
|
+
interface SiteHeaderProps {
|
|
35
|
+
/** Pre-fetched header payload (server-side). `null` triggers static fallback. */
|
|
36
|
+
header: Content<'HEADER'> | null;
|
|
37
|
+
/** Fallback brand label when the merchant hasn't uploaded a logo yet. */
|
|
38
|
+
storeName?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function SiteHeader({ header, storeName }: SiteHeaderProps) {
|
|
42
|
+
const data = header?.data;
|
|
43
|
+
const logo = data?.logo;
|
|
44
|
+
const navItems = data?.navItems ?? [];
|
|
45
|
+
const cta = data?.cta;
|
|
46
|
+
const brandLabel = logo?.alt || storeName || 'Store';
|
|
47
|
+
|
|
48
|
+
// Static fallback — runs when the Content API returned null (no HEADER row
|
|
49
|
+
// for this store yet, or fetch failed). Keep the brand + cart so the page
|
|
50
|
+
// always has a clickable home link and entry to checkout, but no nav since
|
|
51
|
+
// the merchant hasn't defined any items.
|
|
52
|
+
if (!header) {
|
|
53
|
+
return (
|
|
54
|
+
<header className="border-border bg-background/95 supports-[backdrop-filter]:bg-background/70 sticky top-0 z-40 border-b backdrop-blur">
|
|
55
|
+
<div className="mx-auto flex h-16 max-w-7xl items-center justify-between gap-4 px-4 sm:px-6 lg:px-8">
|
|
56
|
+
<Link href="/" className="text-lg font-semibold tracking-tight" aria-label={brandLabel}>
|
|
57
|
+
{brandLabel}
|
|
58
|
+
</Link>
|
|
59
|
+
{/* Search lives in the fallback branch too — a store whose merchant
|
|
60
|
+
has not seeded a HEADER row still needs to be searchable. */}
|
|
61
|
+
<HeaderSearch className="hidden max-w-xs flex-1 sm:block" />
|
|
62
|
+
<div className="flex items-center gap-2">
|
|
63
|
+
<% if (i18nEnabled) { %>
|
|
64
|
+
<LanguageSwitcher />
|
|
65
|
+
<% } %>
|
|
66
|
+
<RegionSwitcher />
|
|
67
|
+
<HeaderAccount />
|
|
68
|
+
<Link
|
|
69
|
+
href="/cart"
|
|
70
|
+
aria-label="Cart"
|
|
71
|
+
className="text-foreground/80 hover:text-foreground hover:bg-muted/60 inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors"
|
|
72
|
+
>
|
|
73
|
+
<ShoppingCart className="h-5 w-5" aria-hidden="true" />
|
|
74
|
+
</Link>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
{/* Narrow screens get the field on its own row rather than a cramped
|
|
78
|
+
icon: the bar above is already three controls wide. */}
|
|
79
|
+
<div className="mx-auto max-w-7xl px-4 pb-3 sm:hidden">
|
|
80
|
+
<HeaderSearch />
|
|
81
|
+
</div>
|
|
82
|
+
</header>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<header className="border-border bg-background/95 supports-[backdrop-filter]:bg-background/70 sticky top-0 z-40 border-b backdrop-blur">
|
|
88
|
+
<div className="mx-auto flex h-16 max-w-7xl items-center justify-between gap-4 px-4 sm:px-6 lg:px-8">
|
|
89
|
+
<Link
|
|
90
|
+
href="/"
|
|
91
|
+
className="flex items-center gap-2 font-semibold tracking-tight"
|
|
92
|
+
aria-label={brandLabel}
|
|
93
|
+
>
|
|
94
|
+
{logo ? (
|
|
95
|
+
// eslint-disable-next-line @next/next/no-img-element -- merchant-supplied URL, dynamic optimization handled by CDN
|
|
96
|
+
<img src={logo.src} alt={logo.alt} className="h-8 w-auto" />
|
|
97
|
+
) : (
|
|
98
|
+
<span className="text-lg">{brandLabel}</span>
|
|
99
|
+
)}
|
|
100
|
+
</Link>
|
|
101
|
+
|
|
102
|
+
{navItems.length > 0 ? (
|
|
103
|
+
<nav className="hidden items-center gap-8 md:flex">
|
|
104
|
+
{navItems.map((item, idx) => (
|
|
105
|
+
<a
|
|
106
|
+
key={`${item.url}-${idx}`}
|
|
107
|
+
href={item.url}
|
|
108
|
+
className="text-foreground/80 hover:text-foreground text-sm font-medium transition-colors"
|
|
109
|
+
>
|
|
110
|
+
{item.label}
|
|
111
|
+
</a>
|
|
112
|
+
))}
|
|
113
|
+
</nav>
|
|
114
|
+
) : null}
|
|
115
|
+
|
|
116
|
+
<HeaderSearch className="hidden max-w-xs flex-1 sm:block" />
|
|
117
|
+
|
|
118
|
+
<div className="flex items-center gap-2">
|
|
119
|
+
{cta ? (
|
|
120
|
+
<Button asChild className="hidden sm:inline-flex">
|
|
121
|
+
<a href={cta.url}>{cta.label}</a>
|
|
122
|
+
</Button>
|
|
123
|
+
) : null}
|
|
124
|
+
|
|
125
|
+
<% if (i18nEnabled) { %>
|
|
126
|
+
<LanguageSwitcher />
|
|
127
|
+
<% } %>
|
|
128
|
+
<RegionSwitcher />
|
|
129
|
+
|
|
130
|
+
<HeaderAccount />
|
|
131
|
+
|
|
132
|
+
<Link
|
|
133
|
+
href="/cart"
|
|
134
|
+
aria-label="Cart"
|
|
135
|
+
className="text-foreground/80 hover:text-foreground hover:bg-muted/60 inline-flex h-9 w-9 items-center justify-center rounded-md transition-colors"
|
|
136
|
+
>
|
|
137
|
+
<ShoppingCart className="h-5 w-5" aria-hidden="true" />
|
|
138
|
+
</Link>
|
|
139
|
+
|
|
140
|
+
{navItems.length > 0 ? (
|
|
141
|
+
<details className="group relative md:hidden">
|
|
142
|
+
<summary className="text-foreground/80 hover:text-foreground hover:bg-muted/60 inline-flex h-9 w-9 cursor-pointer list-none items-center justify-center rounded-md transition-colors [&::-webkit-details-marker]:hidden">
|
|
143
|
+
<Menu className="h-5 w-5" aria-hidden="true" />
|
|
144
|
+
<span className="sr-only">Menu</span>
|
|
145
|
+
</summary>
|
|
146
|
+
<nav className="border-border bg-background absolute end-0 top-full z-50 mt-2 w-56 overflow-hidden rounded-lg border shadow-lg">
|
|
147
|
+
<ul className="py-1">
|
|
148
|
+
{navItems.map((item, idx) => (
|
|
149
|
+
<li key={`m-${item.url}-${idx}`}>
|
|
150
|
+
<a
|
|
151
|
+
href={item.url}
|
|
152
|
+
className="text-foreground/80 hover:text-foreground hover:bg-muted block px-4 py-2 text-sm transition-colors"
|
|
153
|
+
>
|
|
154
|
+
{item.label}
|
|
155
|
+
</a>
|
|
156
|
+
</li>
|
|
157
|
+
))}
|
|
158
|
+
</ul>
|
|
159
|
+
</nav>
|
|
160
|
+
</details>
|
|
161
|
+
) : null}
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
{/* Narrow screens get the field on its own row rather than a cramped
|
|
165
|
+
icon: the bar above is already three controls wide. */}
|
|
166
|
+
<div className="mx-auto max-w-7xl px-4 pb-3 sm:hidden">
|
|
167
|
+
<HeaderSearch />
|
|
168
|
+
</div>
|
|
169
|
+
</header>
|
|
170
|
+
);
|
|
171
|
+
}
|