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
|
@@ -1,260 +1,332 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useProductListing,
|
|
5
|
-
sortOptions,
|
|
6
|
-
type CategoryNode,
|
|
7
|
-
} from '@/core/hooks/use-product-listing';
|
|
8
|
-
import { ProductGrid } from '@/ui/product/product-grid';
|
|
9
|
-
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
10
|
-
import { SelectMenu, type SelectMenuOption } from '@/ui/shared/select-menu';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<div className="
|
|
36
|
-
|
|
37
|
-
<div className="h-4 w-
|
|
38
|
-
<div className="
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useProductListing,
|
|
5
|
+
sortOptions,
|
|
6
|
+
type CategoryNode,
|
|
7
|
+
} from '@/core/hooks/use-product-listing';
|
|
8
|
+
import { ProductGrid } from '@/ui/product/product-grid';
|
|
9
|
+
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
10
|
+
import { SelectMenu, type SelectMenuOption } from '@/ui/shared/select-menu';
|
|
11
|
+
import { useState } from 'react';
|
|
12
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Flatten the category tree into indented options so nested categories stay
|
|
16
|
+
* selectable in the styled dropdown.
|
|
17
|
+
*/
|
|
18
|
+
function flattenCategories(items: CategoryNode[], depth = 0): SelectMenuOption[] {
|
|
19
|
+
return items.flatMap((node) => [
|
|
20
|
+
{ value: node.id, label: `${'— '.repeat(depth)}${node.name}` },
|
|
21
|
+
...flattenCategories(node.children, depth + 1),
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Shimmer skeleton card shown while the grid loads — no layout jump. */
|
|
26
|
+
function SkeletonGrid() {
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
className="grid grid-cols-2 gap-3 sm:gap-5 lg:grid-cols-4 lg:gap-6"
|
|
30
|
+
role="status"
|
|
31
|
+
aria-label="Loading"
|
|
32
|
+
>
|
|
33
|
+
{Array.from({ length: 8 }).map((_, i) => (
|
|
34
|
+
<div key={i} className="card overflow-hidden">
|
|
35
|
+
<div className="aspect-square animate-pulse bg-secondary" />
|
|
36
|
+
<div className="space-y-2.5 p-4">
|
|
37
|
+
<div className="h-4 w-3/4 animate-pulse rounded bg-secondary" />
|
|
38
|
+
<div className="h-4 w-1/3 animate-pulse rounded bg-secondary" />
|
|
39
|
+
<div className="mt-2 h-9 w-full animate-pulse rounded-full bg-secondary" />
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
))}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Append a product count to a facet value label when one is known.
|
|
49
|
+
*
|
|
50
|
+
* `metafieldCounts` comes from `getMetafieldFilters()`, which not every mode
|
|
51
|
+
* or store can answer — a missing entry means "no count available", NOT zero,
|
|
52
|
+
* so the bare label is returned unchanged rather than showing "(0)" on a facet
|
|
53
|
+
* that may well have products behind it.
|
|
54
|
+
*/
|
|
55
|
+
function withCount(label: string, count: number | undefined): string {
|
|
56
|
+
return typeof count === 'number' ? `${label} (${count})` : label;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Product listing page: page header band, filter/sort toolbar, grid,
|
|
61
|
+
* load-more. All data and URL-state behavior comes from `useProductListing`;
|
|
62
|
+
* this component is presentation only. Must be rendered inside `<Suspense>`
|
|
63
|
+
* (URL params).
|
|
64
|
+
*/
|
|
65
|
+
export function ProductListing() {
|
|
66
|
+
const t = useTranslations('products');
|
|
67
|
+
const tc = useTranslations('common');
|
|
68
|
+
|
|
69
|
+
const {
|
|
70
|
+
products,
|
|
71
|
+
loading,
|
|
72
|
+
loadingMore,
|
|
73
|
+
page,
|
|
74
|
+
totalPages,
|
|
75
|
+
total,
|
|
76
|
+
categories,
|
|
77
|
+
brands,
|
|
78
|
+
tags,
|
|
79
|
+
metafieldDefs,
|
|
80
|
+
metafieldCounts,
|
|
81
|
+
searchQuery,
|
|
82
|
+
categoryId,
|
|
83
|
+
brandId,
|
|
84
|
+
tagId,
|
|
85
|
+
minPrice,
|
|
86
|
+
maxPrice,
|
|
87
|
+
setPriceRange,
|
|
88
|
+
sortIndex,
|
|
89
|
+
handleLoadMore,
|
|
90
|
+
updateParam,
|
|
91
|
+
handleCategorySelect,
|
|
92
|
+
getSelectedMetafieldValues,
|
|
93
|
+
setMetafieldValue,
|
|
94
|
+
} = useProductListing();
|
|
95
|
+
|
|
96
|
+
// Draft bounds. Held locally so typing does not refetch on every keystroke;
|
|
97
|
+
// `setPriceRange` pushes both to the URL in one navigation on submit. Seeded
|
|
98
|
+
// from the URL and re-seeded whenever it changes (including a back button or
|
|
99
|
+
// a "clear filters" that wipes the params).
|
|
100
|
+
const [priceDraft, setPriceDraft] = useState({ min: minPrice, max: maxPrice });
|
|
101
|
+
const [priceDraftKey, setPriceDraftKey] = useState(`${minPrice}|${maxPrice}`);
|
|
102
|
+
if (priceDraftKey !== `${minPrice}|${maxPrice}`) {
|
|
103
|
+
setPriceDraftKey(`${minPrice}|${maxPrice}`);
|
|
104
|
+
setPriceDraft({ min: minPrice, max: maxPrice });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<section>
|
|
109
|
+
{/* Page header band */}
|
|
110
|
+
<header className="wash-hero relative overflow-hidden">
|
|
111
|
+
<div className="container-page py-10 text-center lg:py-14">
|
|
112
|
+
<h1 className="text-4xl sm:text-5xl">
|
|
113
|
+
{searchQuery ? `${t('searchPrefix')} "${searchQuery}"` : t('allProducts')}
|
|
114
|
+
</h1>
|
|
115
|
+
<p className="mx-auto mt-3 max-w-xl text-muted-foreground">
|
|
116
|
+
{searchQuery ? (
|
|
117
|
+
!loading && (
|
|
118
|
+
<>
|
|
119
|
+
{total} {total === 1 ? tc('product') : tc('products')} {tc('found')}
|
|
120
|
+
</>
|
|
121
|
+
)
|
|
122
|
+
) : (
|
|
123
|
+
t('listingSubtitle')
|
|
124
|
+
)}
|
|
125
|
+
</p>
|
|
126
|
+
</div>
|
|
127
|
+
</header>
|
|
128
|
+
|
|
129
|
+
<div className="container-page pb-16 pt-8 lg:pb-20">
|
|
130
|
+
{/* Filters + sort toolbar */}
|
|
131
|
+
<div className="mb-8 flex flex-wrap items-center gap-3">
|
|
132
|
+
{/* Category filter — nested tree flattened into a select */}
|
|
133
|
+
{categories.length > 0 && (
|
|
134
|
+
<SelectMenu
|
|
135
|
+
value={categoryId}
|
|
136
|
+
options={[{ value: '', label: tc('all') }, ...flattenCategories(categories)]}
|
|
137
|
+
onChange={(v) => (v ? handleCategorySelect(v) : updateParam('category', ''))}
|
|
138
|
+
ariaLabel={t('filtersLabel')}
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
|
|
142
|
+
{/* Price range. `minPrice` / `maxPrice` are discrete top-level keys
|
|
143
|
+
on getProducts — there is no `filters` object, and an unknown key
|
|
144
|
+
is dropped by the SDK's whitelist before the request goes out.
|
|
145
|
+
Always rendered: unlike brands/tags there is no list to be empty,
|
|
146
|
+
and an empty pair of bounds simply filters nothing. */}
|
|
147
|
+
<form
|
|
148
|
+
className="flex items-center gap-2 rounded-full border bg-background px-3 py-1.5"
|
|
149
|
+
onSubmit={(event) => {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
setPriceRange(priceDraft.min, priceDraft.max);
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
<span className="text-muted-foreground text-sm font-medium">{t('priceLabel')}</span>
|
|
155
|
+
<input
|
|
156
|
+
type="number"
|
|
157
|
+
inputMode="decimal"
|
|
158
|
+
min={0}
|
|
159
|
+
step="any"
|
|
160
|
+
value={priceDraft.min}
|
|
161
|
+
onChange={(event) => setPriceDraft((d) => ({ ...d, min: event.target.value }))}
|
|
162
|
+
aria-label={t('priceMin')}
|
|
163
|
+
placeholder={t('priceMin')}
|
|
164
|
+
className="h-8 w-20 rounded-full border-0 bg-transparent px-2 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
|
|
165
|
+
/>
|
|
166
|
+
<span aria-hidden="true" className="text-muted-foreground">
|
|
167
|
+
–
|
|
168
|
+
</span>
|
|
169
|
+
<input
|
|
170
|
+
type="number"
|
|
171
|
+
inputMode="decimal"
|
|
172
|
+
min={0}
|
|
173
|
+
step="any"
|
|
174
|
+
value={priceDraft.max}
|
|
175
|
+
onChange={(event) => setPriceDraft((d) => ({ ...d, max: event.target.value }))}
|
|
176
|
+
aria-label={t('priceMax')}
|
|
177
|
+
placeholder={t('priceMax')}
|
|
178
|
+
className="h-8 w-20 rounded-full border-0 bg-transparent px-2 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
|
|
179
|
+
/>
|
|
180
|
+
<button type="submit" className="btn-outline btn-sm h-8 rounded-full px-3">
|
|
181
|
+
{tc('apply')}
|
|
182
|
+
</button>
|
|
183
|
+
</form>
|
|
184
|
+
|
|
185
|
+
{/* Brand Filter */}
|
|
186
|
+
{brands.length > 0 && (
|
|
187
|
+
<SelectMenu
|
|
188
|
+
value={brandId}
|
|
189
|
+
options={[
|
|
190
|
+
{ value: '', label: t('allBrands') },
|
|
191
|
+
...brands.map((b) => ({ value: b.id, label: b.name })),
|
|
192
|
+
]}
|
|
193
|
+
onChange={(v) => updateParam('brand', v)}
|
|
194
|
+
ariaLabel={t('allBrands')}
|
|
195
|
+
/>
|
|
196
|
+
)}
|
|
197
|
+
|
|
198
|
+
{/* Tag Filter */}
|
|
199
|
+
{tags.length > 0 && (
|
|
200
|
+
<SelectMenu
|
|
201
|
+
value={tagId}
|
|
202
|
+
options={[
|
|
203
|
+
{ value: '', label: t('allTags') },
|
|
204
|
+
...tags.map((tg) => ({ value: tg.id, label: tg.name })),
|
|
205
|
+
]}
|
|
206
|
+
onChange={(v) => updateParam('tag', v)}
|
|
207
|
+
ariaLabel={t('allTags')}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
{/* Custom-field (metafield) facets — rendered per definition type.
|
|
212
|
+
Only definitions flagged `filterable: true` and published to
|
|
213
|
+
this sales channel reach this list. */}
|
|
214
|
+
{metafieldDefs.map((def) => {
|
|
215
|
+
const selected = getSelectedMetafieldValues(def.key);
|
|
216
|
+
const counts = metafieldCounts[def.key];
|
|
217
|
+
|
|
218
|
+
if (def.type === 'BOOLEAN') {
|
|
219
|
+
const isOn = selected.includes('true');
|
|
220
|
+
return (
|
|
221
|
+
<label
|
|
222
|
+
key={def.id}
|
|
223
|
+
className="inline-flex h-10 cursor-pointer items-center gap-2 rounded-full border bg-background px-4 text-sm font-medium"
|
|
224
|
+
>
|
|
225
|
+
<input
|
|
226
|
+
type="checkbox"
|
|
227
|
+
checked={isOn}
|
|
228
|
+
onChange={(e) => setMetafieldValue(def.key, e.target.checked ? ['true'] : [])}
|
|
229
|
+
className="h-4 w-4 accent-primary"
|
|
230
|
+
/>
|
|
231
|
+
{def.name}
|
|
232
|
+
</label>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (def.type === 'SELECT') {
|
|
237
|
+
return (
|
|
238
|
+
<SelectMenu
|
|
239
|
+
key={def.id}
|
|
240
|
+
value={selected[0] || ''}
|
|
241
|
+
options={[
|
|
242
|
+
{ value: '', label: `${tc('all')} ${def.name}` },
|
|
243
|
+
...(def.enumValues || []).map((v) => ({
|
|
244
|
+
value: v.value,
|
|
245
|
+
label: withCount(v.label || v.value, counts?.[v.value]),
|
|
246
|
+
})),
|
|
247
|
+
]}
|
|
248
|
+
onChange={(v) => setMetafieldValue(def.key, v ? [v] : [])}
|
|
249
|
+
ariaLabel={def.name}
|
|
250
|
+
/>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// MULTI_SELECT — checkbox toggles. Each click adds/removes one value.
|
|
255
|
+
return (
|
|
256
|
+
<fieldset
|
|
257
|
+
key={def.id}
|
|
258
|
+
className="inline-flex flex-wrap items-center gap-2 rounded-full border bg-background px-4 py-2"
|
|
259
|
+
>
|
|
260
|
+
<legend className="sr-only">{def.name}</legend>
|
|
261
|
+
<span className="text-sm font-medium text-muted-foreground">{def.name}:</span>
|
|
262
|
+
{(def.enumValues || []).map((v) => {
|
|
263
|
+
const active = selected.includes(v.value);
|
|
264
|
+
return (
|
|
265
|
+
<label
|
|
266
|
+
key={v.value}
|
|
267
|
+
className="inline-flex cursor-pointer items-center gap-1.5 text-sm"
|
|
268
|
+
>
|
|
269
|
+
<input
|
|
270
|
+
type="checkbox"
|
|
271
|
+
checked={active}
|
|
272
|
+
onChange={() =>
|
|
273
|
+
setMetafieldValue(
|
|
274
|
+
def.key,
|
|
275
|
+
active ? selected.filter((s) => s !== v.value) : [...selected, v.value]
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
className="h-4 w-4 accent-primary"
|
|
279
|
+
/>
|
|
280
|
+
{withCount(v.label || v.value, counts?.[v.value])}
|
|
281
|
+
</label>
|
|
282
|
+
);
|
|
283
|
+
})}
|
|
284
|
+
</fieldset>
|
|
285
|
+
);
|
|
286
|
+
})}
|
|
287
|
+
|
|
288
|
+
{/* Result count + sort — pushed to the end of the toolbar */}
|
|
289
|
+
<div className="ms-auto flex items-center gap-3">
|
|
290
|
+
{!loading && (
|
|
291
|
+
<p className="hidden text-sm text-muted-foreground sm:block">
|
|
292
|
+
{total} {total === 1 ? tc('product') : tc('products')}
|
|
293
|
+
</p>
|
|
294
|
+
)}
|
|
295
|
+
<SelectMenu
|
|
296
|
+
value={String(sortIndex)}
|
|
297
|
+
options={sortOptions.map((opt, idx) => ({
|
|
298
|
+
value: String(idx),
|
|
299
|
+
label: t(opt.labelKey),
|
|
300
|
+
}))}
|
|
301
|
+
onChange={(v) => updateParam('sort', v)}
|
|
302
|
+
ariaLabel={tc('sortBy')}
|
|
303
|
+
/>
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
{/* Products Grid */}
|
|
308
|
+
{loading ? (
|
|
309
|
+
<SkeletonGrid />
|
|
310
|
+
) : (
|
|
311
|
+
<>
|
|
312
|
+
<ProductGrid products={products} />
|
|
313
|
+
|
|
314
|
+
{/* Load More */}
|
|
315
|
+
{page < totalPages && (
|
|
316
|
+
<div className="mt-10 flex justify-center">
|
|
317
|
+
<button
|
|
318
|
+
type="button"
|
|
319
|
+
onClick={handleLoadMore}
|
|
320
|
+
disabled={loadingMore}
|
|
321
|
+
className="btn-outline btn-md min-w-44"
|
|
322
|
+
>
|
|
323
|
+
{loadingMore ? <LoadingSpinner size="sm" /> : t('loadMore')}
|
|
324
|
+
</button>
|
|
325
|
+
</div>
|
|
326
|
+
)}
|
|
327
|
+
</>
|
|
328
|
+
)}
|
|
329
|
+
</div>
|
|
330
|
+
</section>
|
|
331
|
+
);
|
|
332
|
+
}
|