create-brainerce-store 1.73.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.
Files changed (77) hide show
  1. package/dist/index.js +35 -2
  2. package/messages/en.json +27 -1
  3. package/messages/he.json +27 -1
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/AGENTS.md.ejs +63 -16
  6. package/templates/nextjs/base/AI-GUIDE.md +17 -4
  7. package/templates/nextjs/base/CLAUDE.md.ejs +67 -20
  8. package/templates/nextjs/base/src/app/account/page.tsx +168 -122
  9. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +10 -1
  10. package/templates/nextjs/base/src/app/checkout/page.tsx +145 -40
  11. package/templates/nextjs/base/src/app/layout.tsx.ejs +48 -4
  12. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +98 -3
  13. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +14 -2
  14. package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +226 -0
  15. package/templates/nextjs/base/src/components/account/order-history.tsx +58 -7
  16. package/templates/nextjs/base/src/components/account/saved-payment-methods.tsx +104 -0
  17. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +618 -612
  18. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +354 -306
  19. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +141 -74
  20. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +97 -6
  21. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +63 -51
  22. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +379 -295
  23. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +33 -1
  24. package/templates/nextjs/base/src/core/lib/capabilities.ts +65 -0
  25. package/templates/nextjs/base/src/core/lib/display-price.ts +139 -0
  26. package/templates/nextjs/base/src/core/lib/region.server.ts +112 -0
  27. package/templates/nextjs/base/src/core/lib/region.ts +112 -0
  28. package/templates/nextjs/base/src/core/lib/store-info.ts +19 -0
  29. package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +423 -243
  30. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +10 -0
  31. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +109 -110
  32. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +45 -2
  33. package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +191 -0
  34. package/templates/nextjs/base/src/ui/cart/tax-estimate-line.tsx +108 -0
  35. package/templates/nextjs/base/src/ui/home/home-client.tsx +27 -29
  36. package/templates/nextjs/base/src/ui/layout/header-search.tsx +249 -0
  37. package/templates/nextjs/base/src/ui/layout/region-switcher.tsx +59 -0
  38. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +171 -152
  39. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +197 -191
  40. package/templates/nextjs/base/src/ui/product/product-card.tsx +25 -52
  41. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +12 -3
  42. package/templates/nextjs/base/src/ui/product/product-listing.tsx +460 -446
  43. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +108 -102
  44. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +15 -3
  45. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +48 -4
  46. package/templates/nextjs/designs/atelier/messages-patch/en.json +21 -25
  47. package/templates/nextjs/designs/atelier/messages-patch/he.json +21 -25
  48. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +10 -0
  49. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +106 -107
  50. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +56 -11
  51. package/templates/nextjs/designs/atelier/ui/cart/tax-estimate-line.tsx +108 -0
  52. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +10 -1
  53. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +178 -174
  54. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +4 -6
  55. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +150 -78
  56. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +79 -46
  57. package/templates/nextjs/designs/atelier/ui/layout/header-search.tsx +264 -0
  58. package/templates/nextjs/designs/atelier/ui/layout/region-switcher.tsx +44 -0
  59. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +5 -0
  60. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +202 -196
  61. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +27 -52
  62. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +12 -3
  63. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +332 -260
  64. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +101 -95
  65. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +17 -2
  66. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +9 -0
  67. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +98 -99
  68. package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +142 -0
  69. package/templates/nextjs/ui-canvas/cart/tax-estimate-line.tsx +104 -0
  70. package/templates/nextjs/ui-canvas/home/home-client.tsx +24 -26
  71. package/templates/nextjs/ui-canvas/layout/region-switcher.tsx +51 -0
  72. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +3 -0
  73. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +174 -168
  74. package/templates/nextjs/ui-canvas/product/product-card.tsx +9 -51
  75. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +5 -3
  76. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +105 -99
  77. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +17 -2
@@ -1,29 +1,27 @@
1
- 'use client';
2
-
3
- import { useStoreInfo } from '@/core/providers/store-provider';
4
- import { useHomeData } from '@/core/hooks/use-home-data';
5
- import { LoadingSpinner } from '@/ui/shared/loading-spinner';
6
- import { DiscountBannerStrip } from './discount-banner-strip';
7
- import { HeroSection } from './hero-section';
8
- import { FeaturedProductsSection } from './featured-products-section';
9
-
10
- export function HomeClient() {
11
- const { storeInfo, loading: storeLoading } = useStoreInfo();
12
- const { products, banners, loading } = useHomeData();
13
-
14
- if (storeLoading || loading) {
15
- return (
16
- <div className="flex min-h-[60vh] items-center justify-center">
17
- <LoadingSpinner size="lg" />
18
- </div>
19
- );
20
- }
21
-
22
- return (
23
- <div>
24
- <DiscountBannerStrip banners={banners} />
25
- <HeroSection storeName={storeInfo?.name} />
26
- <FeaturedProductsSection products={products} />
27
- </div>
28
- );
29
- }
1
+ 'use client';
2
+
3
+ import { useStoreInfo } from '@/core/providers/store-provider';
4
+ import { useHomeData } from '@/core/hooks/use-home-data';
5
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
6
+ import { HeroSection } from './hero-section';
7
+ import { FeaturedProductsSection } from './featured-products-section';
8
+
9
+ export function HomeClient() {
10
+ const { storeInfo, loading: storeLoading } = useStoreInfo();
11
+ const { products, loading } = useHomeData();
12
+
13
+ if (storeLoading || loading) {
14
+ return (
15
+ <div className="flex min-h-[60vh] items-center justify-center">
16
+ <LoadingSpinner size="lg" />
17
+ </div>
18
+ );
19
+ }
20
+
21
+ return (
22
+ <div>
23
+ <HeroSection storeName={storeInfo?.name} />
24
+ <FeaturedProductsSection products={products} />
25
+ </div>
26
+ );
27
+ }
@@ -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
+ }