create-brainerce-store 1.50.5 → 1.51.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 +171 -66
- package/messages/en.json +4 -1
- package/messages/he.json +4 -1
- package/package.json +1 -1
- package/templates/nextjs/base/.claude/commands/design.md +51 -0
- package/templates/nextjs/base/.env.local.ejs +5 -0
- package/templates/nextjs/base/.eslintrc.json +57 -3
- package/templates/nextjs/base/AGENTS.md +41 -0
- package/templates/nextjs/base/AI-GUIDE.md +94 -0
- package/templates/nextjs/base/CLAUDE.md +42 -0
- package/templates/nextjs/base/TRANSLATIONS.md +1 -1
- package/templates/nextjs/base/next.config.ts +2 -2
- package/templates/nextjs/base/src/app/account/page.tsx +5 -5
- package/templates/nextjs/base/src/app/api/auth/logout/route.ts +1 -1
- package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +2 -2
- package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +1 -1
- package/templates/nextjs/base/src/app/auth/callback/page.tsx +4 -4
- package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +4 -4
- package/templates/nextjs/base/src/app/blog/page.tsx.ejs +2 -2
- package/templates/nextjs/base/src/app/cart/page.tsx +2 -173
- package/templates/nextjs/base/src/app/checkout/page.tsx +12 -11
- package/templates/nextjs/base/src/app/contact/page.tsx +3 -3
- package/templates/nextjs/base/src/app/faq/page.tsx.ejs +2 -2
- package/templates/nextjs/base/src/app/forgot-password/page.tsx +4 -4
- package/templates/nextjs/base/src/app/layout.tsx.ejs +12 -12
- package/templates/nextjs/base/src/app/login/page.tsx +4 -4
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +19 -12
- package/templates/nextjs/base/src/app/page.tsx +4 -4
- package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +3 -3
- package/templates/nextjs/base/src/app/payment-complete/page.tsx +1 -1
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -6
- package/templates/nextjs/base/src/app/products/page.tsx +4 -623
- package/templates/nextjs/base/src/app/register/page.tsx +4 -4
- package/templates/nextjs/base/src/app/reset-password/page.tsx +5 -5
- package/templates/nextjs/base/src/app/sitemap.ts +1 -1
- package/templates/nextjs/base/src/app/verify-email/page.tsx +5 -5
- package/templates/nextjs/base/src/components/account/address-book.tsx +3 -3
- package/templates/nextjs/base/src/components/account/order-customizations.tsx +3 -3
- package/templates/nextjs/base/src/components/account/order-history.tsx +13 -5
- package/templates/nextjs/base/src/components/account/order-payment-block.tsx +2 -2
- package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +2 -2
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +2 -2
- package/templates/nextjs/base/src/components/account/profile-section.tsx +3 -3
- package/templates/nextjs/base/src/components/auth/login-form.tsx +4 -4
- package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +4 -4
- package/templates/nextjs/base/src/components/auth/register-form.tsx +4 -4
- package/templates/nextjs/base/src/components/brainerce-bot.tsx +2 -2
- package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +24 -3
- package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +2 -2
- package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +2 -2
- package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +4 -4
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +6 -6
- package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +3 -3
- package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +3 -3
- package/templates/nextjs/base/src/components/checkout/tax-display.tsx +3 -3
- package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +2 -2
- package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +3 -3
- package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +58 -0
- package/templates/nextjs/base/src/core/hooks/use-home-data.ts +51 -0
- package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +295 -0
- package/templates/nextjs/base/src/core/hooks/use-product-page.ts +278 -0
- package/templates/nextjs/base/src/{hooks → core/hooks}/use-search.ts +1 -1
- package/templates/nextjs/base/src/{lib → core/lib}/brainerce.ts.ejs +1 -1
- package/templates/nextjs/base/src/core/lib/product-options.ts +121 -0
- package/templates/nextjs/base/src/{lib → core/lib}/resolve-currency.ts +1 -1
- package/templates/nextjs/base/src/{lib → core/lib}/safe-redirect.ts +1 -1
- package/templates/nextjs/base/src/{lib → core/lib}/sanitize.ts.ejs +1 -1
- package/templates/nextjs/base/src/{lib → core/lib}/use-currency.ts +1 -1
- package/templates/nextjs/base/src/{providers → core/providers}/store-provider.tsx.ejs +4 -4
- package/templates/nextjs/base/src/{components → ui}/cart/cart-bundle-offer.tsx +5 -5
- package/templates/nextjs/base/src/{components → ui}/cart/cart-item.tsx +6 -6
- package/templates/nextjs/base/src/{components → ui}/cart/cart-nudges.tsx +1 -1
- package/templates/nextjs/base/src/{components → ui}/cart/cart-summary.tsx +4 -4
- package/templates/nextjs/base/src/{components → ui}/cart/cart-upgrade-banner.tsx +5 -5
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +149 -0
- package/templates/nextjs/base/src/{components → ui}/cart/coupon-input.tsx +4 -4
- package/templates/nextjs/base/src/{components → ui}/cart/free-shipping-bar.tsx +4 -4
- package/templates/nextjs/base/src/{components → ui}/cart/reservation-countdown.tsx +2 -2
- package/templates/nextjs/base/src/ui/home/discount-banner-strip.tsx +20 -0
- package/templates/nextjs/base/src/ui/home/featured-products-section.tsx +24 -0
- package/templates/nextjs/base/src/ui/home/hero-section.tsx +29 -0
- package/templates/nextjs/base/src/ui/home/home-client.tsx +29 -0
- package/templates/nextjs/base/src/{components/content → ui/layout}/faq-section.tsx.ejs +2 -2
- package/templates/nextjs/base/src/{components/content → ui/layout}/header-account.tsx +3 -3
- package/templates/nextjs/base/src/{components/content → ui/layout}/rich-text-block.tsx.ejs +1 -1
- package/templates/nextjs/base/src/{components/content → ui/layout}/site-header.tsx.ejs +1 -1
- package/templates/nextjs/base/src/{components/products → ui/product}/customization-fields.tsx +18 -51
- package/templates/nextjs/base/src/{components/products → ui/product}/discount-badge.tsx +1 -1
- package/templates/nextjs/base/src/{components/products → ui/product}/frequently-bought-together.tsx +6 -6
- package/templates/nextjs/base/src/{components/products → ui/product}/modifier-group-selector.tsx +10 -73
- package/templates/nextjs/base/src/{components/shared → ui/product}/price-display.tsx +2 -2
- package/templates/nextjs/base/src/{components/products → ui/product}/product-card.tsx +10 -10
- package/templates/nextjs/base/src/{app/products/[slug] → ui/product}/product-client-section.tsx +45 -206
- package/templates/nextjs/base/src/{components/products → ui/product}/product-grid.tsx +3 -3
- package/templates/nextjs/base/src/ui/product/product-listing.tsx +429 -0
- package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx +4 -4
- package/templates/nextjs/base/src/{components/reviews → ui/product}/review-form.tsx +2 -2
- package/templates/nextjs/base/src/{components/reviews → ui/product}/reviews-section.tsx +1 -1
- package/templates/nextjs/base/src/{components/products → ui/product}/stock-badge.tsx +2 -2
- package/templates/nextjs/base/src/{components/products → ui/product}/variant-selector.tsx +3 -3
- package/templates/nextjs/base/src/{components → ui}/shared/cdn-image.tsx +1 -1
- package/templates/nextjs/base/src/{components → ui}/shared/loading-spinner.tsx +2 -2
- package/templates/nextjs/base/tailwind.config.ts +12 -0
- package/templates/nextjs/designs/passepartout/app-overlay/layout.tsx.ejs +253 -0
- package/templates/nextjs/designs/passepartout/globals.css +412 -0
- package/templates/nextjs/designs/passepartout/messages-patch/en.json +87 -0
- package/templates/nextjs/designs/passepartout/messages-patch/he.json +87 -0
- package/templates/nextjs/designs/passepartout/ui/cart/cart-bundle-offer.tsx +111 -0
- package/templates/nextjs/designs/passepartout/ui/cart/cart-nudges.tsx +39 -0
- package/templates/nextjs/designs/passepartout/ui/cart/cart-upgrade-banner.tsx +141 -0
- package/templates/nextjs/designs/passepartout/ui/cart/cart-view.tsx +149 -0
- package/templates/nextjs/designs/passepartout/ui/cart/free-shipping-bar.tsx +62 -0
- package/templates/nextjs/designs/passepartout/ui/cart/reservation-countdown.tsx +103 -0
- package/templates/nextjs/designs/passepartout/ui/home/home-client.tsx +401 -0
- package/templates/nextjs/designs/passepartout/ui/layout/announcement-bar.tsx +139 -0
- package/templates/nextjs/designs/passepartout/ui/layout/cart-link.tsx +45 -0
- package/templates/nextjs/designs/passepartout/ui/layout/faq-section.tsx +103 -0
- package/templates/nextjs/designs/passepartout/ui/layout/site-footer.tsx +159 -0
- package/templates/nextjs/designs/passepartout/ui/layout/site-header.tsx.ejs +155 -0
- package/templates/nextjs/designs/passepartout/ui/layout/trust-icons.tsx +60 -0
- package/templates/nextjs/designs/passepartout/ui/layout/whatsapp-button.tsx +34 -0
- package/templates/nextjs/designs/passepartout/ui/product/discount-badge.tsx +22 -0
- package/templates/nextjs/designs/passepartout/ui/product/frequently-bought-together.tsx +205 -0
- package/templates/nextjs/designs/passepartout/ui/product/price-display.tsx +111 -0
- package/templates/nextjs/designs/passepartout/ui/product/product-card.tsx +265 -0
- package/templates/nextjs/designs/passepartout/ui/product/product-client-section.tsx +667 -0
- package/templates/nextjs/designs/passepartout/ui/product/product-grid.tsx +35 -0
- package/templates/nextjs/designs/passepartout/ui/product/product-listing.tsx +427 -0
- package/templates/nextjs/designs/passepartout/ui/product/recommendation-section.tsx +113 -0
- package/templates/nextjs/designs/passepartout/ui/product/review-form.tsx +294 -0
- package/templates/nextjs/designs/passepartout/ui/product/reviews-section.tsx.ejs +96 -0
- package/templates/nextjs/designs/passepartout/ui/product/stock-badge.tsx +52 -0
- package/templates/nextjs/designs/passepartout/ui/product/variant-selector.tsx +307 -0
- package/templates/nextjs/designs/passepartout/ui/shared/fly-to-cart.ts +85 -0
- package/templates/nextjs/designs/passepartout/ui/shared/loading-spinner.tsx +33 -0
- package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +87 -0
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +121 -0
- package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +25 -0
- package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +97 -0
- package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +103 -0
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +106 -0
- package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +117 -0
- package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +52 -0
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +79 -0
- package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +19 -0
- package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +23 -0
- package/templates/nextjs/ui-canvas/home/hero-section.tsx +21 -0
- package/templates/nextjs/ui-canvas/home/home-client.tsx +26 -0
- package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +101 -0
- package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +71 -0
- package/templates/nextjs/ui-canvas/layout/header-account.tsx +31 -0
- package/templates/nextjs/ui-canvas/layout/language-switcher.tsx.ejs +74 -0
- package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +34 -0
- package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +82 -0
- package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +119 -0
- package/templates/nextjs/ui-canvas/product/customization-fields.tsx +443 -0
- package/templates/nextjs/ui-canvas/product/discount-badge.tsx +17 -0
- package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +166 -0
- package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +163 -0
- package/templates/nextjs/ui-canvas/product/price-display.tsx +50 -0
- package/templates/nextjs/ui-canvas/product/product-card.tsx +197 -0
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +352 -0
- package/templates/nextjs/ui-canvas/product/product-grid.tsx +27 -0
- package/templates/nextjs/ui-canvas/product/product-listing.tsx +224 -0
- package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +95 -0
- package/templates/nextjs/ui-canvas/product/review-form.tsx +269 -0
- package/templates/nextjs/ui-canvas/product/reviews-section.tsx +78 -0
- package/templates/nextjs/ui-canvas/product/stock-badge.tsx +43 -0
- package/templates/nextjs/ui-canvas/product/variant-selector.tsx +210 -0
- package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +29 -0
- package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +25 -0
- package/templates/nextjs/base/src/app/home-client.tsx +0 -98
- /package/templates/nextjs/base/src/{lib → core/lib}/auth.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/csrf.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/image-hosts.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/navigation.tsx.ejs +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/nonce.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/sanitize-html.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/seo.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/store-info.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/translations.ts.ejs +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/utils.ts +0 -0
- /package/templates/nextjs/base/src/{lib → core/lib}/validation.ts +0 -0
- /package/templates/nextjs/base/src/{components/content → ui/layout}/announcement-bar.tsx.ejs +0 -0
- /package/templates/nextjs/base/src/{components → ui}/layout/language-switcher.tsx.ejs +0 -0
- /package/templates/nextjs/base/src/{components/content → ui/layout}/site-footer.tsx.ejs +0 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, useRef } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
useProductListing,
|
|
6
|
+
sortOptions,
|
|
7
|
+
isActiveInTree,
|
|
8
|
+
type CategoryNode,
|
|
9
|
+
} from '@/core/hooks/use-product-listing';
|
|
10
|
+
import { ProductGrid } from '@/ui/product/product-grid';
|
|
11
|
+
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
12
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
13
|
+
import { cn } from '@/core/lib/utils';
|
|
14
|
+
|
|
15
|
+
/** Chevron down SVG */
|
|
16
|
+
function ChevronDown({ className }: { className?: string }) {
|
|
17
|
+
return (
|
|
18
|
+
<svg
|
|
19
|
+
className={className}
|
|
20
|
+
width="12"
|
|
21
|
+
height="12"
|
|
22
|
+
viewBox="0 0 12 12"
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
strokeWidth="2"
|
|
26
|
+
strokeLinecap="round"
|
|
27
|
+
strokeLinejoin="round"
|
|
28
|
+
>
|
|
29
|
+
<path d="M3 4.5L6 7.5L9 4.5" />
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Recursive dropdown items for nested categories */
|
|
35
|
+
function CategoryDropdownItems({
|
|
36
|
+
items,
|
|
37
|
+
depth,
|
|
38
|
+
selectedId,
|
|
39
|
+
onSelect,
|
|
40
|
+
}: {
|
|
41
|
+
items: CategoryNode[];
|
|
42
|
+
depth: number;
|
|
43
|
+
selectedId: string;
|
|
44
|
+
onSelect: (id: string) => void;
|
|
45
|
+
}) {
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
{items.map((child) => (
|
|
49
|
+
<div key={child.id}>
|
|
50
|
+
<button
|
|
51
|
+
onClick={() => onSelect(child.id)}
|
|
52
|
+
className={cn(
|
|
53
|
+
'hover:bg-muted w-full px-4 py-2 text-start text-sm transition-colors',
|
|
54
|
+
selectedId === child.id && 'bg-primary/10 text-primary font-medium'
|
|
55
|
+
)}
|
|
56
|
+
style={{ paddingInlineStart: `${(depth + 1) * 16}px` }}
|
|
57
|
+
>
|
|
58
|
+
{child.name}
|
|
59
|
+
</button>
|
|
60
|
+
{child.children.length > 0 && (
|
|
61
|
+
<CategoryDropdownItems
|
|
62
|
+
items={child.children}
|
|
63
|
+
depth={depth + 1}
|
|
64
|
+
selectedId={selectedId}
|
|
65
|
+
onSelect={onSelect}
|
|
66
|
+
/>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
))}
|
|
70
|
+
</>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Category chip with dropdown for subcategories */
|
|
75
|
+
function CategoryChip({
|
|
76
|
+
category,
|
|
77
|
+
selectedId,
|
|
78
|
+
onSelect,
|
|
79
|
+
tc,
|
|
80
|
+
}: {
|
|
81
|
+
category: CategoryNode;
|
|
82
|
+
selectedId: string;
|
|
83
|
+
onSelect: (id: string) => void;
|
|
84
|
+
tc: (key: string) => string;
|
|
85
|
+
}) {
|
|
86
|
+
const [open, setOpen] = useState(false);
|
|
87
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
88
|
+
const hasChildren = category.children.length > 0;
|
|
89
|
+
const isActive = isActiveInTree(category, selectedId);
|
|
90
|
+
|
|
91
|
+
// Find the display name for the selected subcategory
|
|
92
|
+
function findName(nodes: CategoryNode[], id: string): string | null {
|
|
93
|
+
for (const n of nodes) {
|
|
94
|
+
if (n.id === id) return n.name;
|
|
95
|
+
const found = findName(n.children, id);
|
|
96
|
+
if (found) return found;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const selectedChildName =
|
|
102
|
+
isActive && selectedId !== category.id ? findName(category.children, selectedId) : null;
|
|
103
|
+
|
|
104
|
+
// Close dropdown on outside click
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!open) return;
|
|
107
|
+
function handleClick(e: MouseEvent) {
|
|
108
|
+
if (ref.current && !ref.current.contains(e.target as Node)) {
|
|
109
|
+
setOpen(false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
document.addEventListener('mousedown', handleClick);
|
|
113
|
+
return () => document.removeEventListener('mousedown', handleClick);
|
|
114
|
+
}, [open]);
|
|
115
|
+
|
|
116
|
+
if (!hasChildren) {
|
|
117
|
+
return (
|
|
118
|
+
<button
|
|
119
|
+
onClick={() => onSelect(category.id)}
|
|
120
|
+
className={cn(
|
|
121
|
+
'rounded-full border px-3 py-1.5 text-sm transition-colors',
|
|
122
|
+
selectedId === category.id
|
|
123
|
+
? 'bg-primary text-primary-foreground border-primary'
|
|
124
|
+
: 'border-border text-muted-foreground hover:border-primary hover:text-foreground'
|
|
125
|
+
)}
|
|
126
|
+
>
|
|
127
|
+
{category.name}
|
|
128
|
+
</button>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<div ref={ref} className="relative">
|
|
134
|
+
<button
|
|
135
|
+
onClick={() => setOpen((prev) => !prev)}
|
|
136
|
+
className={cn(
|
|
137
|
+
'inline-flex items-center gap-1 rounded-full border px-3 py-1.5 text-sm transition-colors',
|
|
138
|
+
isActive
|
|
139
|
+
? 'bg-primary text-primary-foreground border-primary'
|
|
140
|
+
: 'border-border text-muted-foreground hover:border-primary hover:text-foreground'
|
|
141
|
+
)}
|
|
142
|
+
>
|
|
143
|
+
{category.name}
|
|
144
|
+
{selectedChildName && (
|
|
145
|
+
<span className="opacity-80">
|
|
146
|
+
{'·'} {selectedChildName}
|
|
147
|
+
</span>
|
|
148
|
+
)}
|
|
149
|
+
<ChevronDown className={cn('ms-0.5 transition-transform', open && 'rotate-180')} />
|
|
150
|
+
</button>
|
|
151
|
+
|
|
152
|
+
{open && (
|
|
153
|
+
<div className="bg-background border-border absolute start-0 top-full z-50 mt-1 min-w-[180px] overflow-hidden rounded-lg border shadow-lg">
|
|
154
|
+
{/* "All in [category]" option */}
|
|
155
|
+
<button
|
|
156
|
+
onClick={() => {
|
|
157
|
+
onSelect(category.id);
|
|
158
|
+
setOpen(false);
|
|
159
|
+
}}
|
|
160
|
+
className={cn(
|
|
161
|
+
'hover:bg-muted w-full px-4 py-2 text-start text-sm font-medium transition-colors',
|
|
162
|
+
selectedId === category.id && 'bg-primary/10 text-primary'
|
|
163
|
+
)}
|
|
164
|
+
>
|
|
165
|
+
{tc('all')} {category.name}
|
|
166
|
+
</button>
|
|
167
|
+
<div className="bg-border mx-2 h-px" />
|
|
168
|
+
{/* Recursive children */}
|
|
169
|
+
<div onClick={() => setOpen(false)}>
|
|
170
|
+
<CategoryDropdownItems
|
|
171
|
+
items={category.children}
|
|
172
|
+
depth={0}
|
|
173
|
+
selectedId={selectedId}
|
|
174
|
+
onSelect={onSelect}
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Product listing page (filters + sort + grid + load-more). All data and
|
|
185
|
+
* URL-state behavior comes from `useProductListing`; this component is
|
|
186
|
+
* presentation only. Must be rendered inside `<Suspense>` (URL params).
|
|
187
|
+
*/
|
|
188
|
+
export function ProductListing() {
|
|
189
|
+
const t = useTranslations('products');
|
|
190
|
+
const tc = useTranslations('common');
|
|
191
|
+
|
|
192
|
+
const {
|
|
193
|
+
products,
|
|
194
|
+
loading,
|
|
195
|
+
loadingMore,
|
|
196
|
+
page,
|
|
197
|
+
totalPages,
|
|
198
|
+
total,
|
|
199
|
+
categories,
|
|
200
|
+
brands,
|
|
201
|
+
tags,
|
|
202
|
+
metafieldDefs,
|
|
203
|
+
searchQuery,
|
|
204
|
+
categoryId,
|
|
205
|
+
brandId,
|
|
206
|
+
tagId,
|
|
207
|
+
sortIndex,
|
|
208
|
+
handleLoadMore,
|
|
209
|
+
updateParam,
|
|
210
|
+
handleCategorySelect,
|
|
211
|
+
getSelectedMetafieldValues,
|
|
212
|
+
setMetafieldValue,
|
|
213
|
+
} = useProductListing();
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
|
217
|
+
{/* Page Header */}
|
|
218
|
+
<div className="mb-8">
|
|
219
|
+
<h1 className="text-foreground text-3xl font-bold">
|
|
220
|
+
{searchQuery ? `${t('searchPrefix')} "${searchQuery}"` : t('allProducts')}
|
|
221
|
+
</h1>
|
|
222
|
+
{!loading && (
|
|
223
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
224
|
+
{total} {total === 1 ? tc('product') : tc('products')} {tc('found')}
|
|
225
|
+
</p>
|
|
226
|
+
)}
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
{/* Filters and Sort */}
|
|
230
|
+
<div className="mb-6 flex flex-col gap-4">
|
|
231
|
+
{/* Category Filter */}
|
|
232
|
+
{categories.length > 0 && (
|
|
233
|
+
<div className="flex flex-wrap gap-2">
|
|
234
|
+
<button
|
|
235
|
+
onClick={() => updateParam('category', '')}
|
|
236
|
+
className={cn(
|
|
237
|
+
'rounded-full border px-3 py-1.5 text-sm transition-colors',
|
|
238
|
+
!categoryId
|
|
239
|
+
? 'bg-primary text-primary-foreground border-primary'
|
|
240
|
+
: 'border-border text-muted-foreground hover:border-primary hover:text-foreground'
|
|
241
|
+
)}
|
|
242
|
+
>
|
|
243
|
+
{tc('all')}
|
|
244
|
+
</button>
|
|
245
|
+
{categories.map((cat) => (
|
|
246
|
+
<CategoryChip
|
|
247
|
+
key={cat.id}
|
|
248
|
+
category={cat}
|
|
249
|
+
selectedId={categoryId}
|
|
250
|
+
onSelect={handleCategorySelect}
|
|
251
|
+
tc={tc as (key: string) => string}
|
|
252
|
+
/>
|
|
253
|
+
))}
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
|
|
257
|
+
{/* Brand, Tag & Sort row */}
|
|
258
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
259
|
+
{/* Brand Filter */}
|
|
260
|
+
{brands.length > 0 && (
|
|
261
|
+
<select
|
|
262
|
+
value={brandId}
|
|
263
|
+
onChange={(e) => updateParam('brand', e.target.value)}
|
|
264
|
+
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"
|
|
265
|
+
>
|
|
266
|
+
<option value="">{t('allBrands')}</option>
|
|
267
|
+
{brands.map((b) => (
|
|
268
|
+
<option key={b.id} value={b.id}>
|
|
269
|
+
{b.name}
|
|
270
|
+
</option>
|
|
271
|
+
))}
|
|
272
|
+
</select>
|
|
273
|
+
)}
|
|
274
|
+
|
|
275
|
+
{/* Tag Filter */}
|
|
276
|
+
{tags.length > 0 && (
|
|
277
|
+
<select
|
|
278
|
+
value={tagId}
|
|
279
|
+
onChange={(e) => updateParam('tag', e.target.value)}
|
|
280
|
+
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"
|
|
281
|
+
>
|
|
282
|
+
<option value="">{t('allTags')}</option>
|
|
283
|
+
{tags.map((tg) => (
|
|
284
|
+
<option key={tg.id} value={tg.id}>
|
|
285
|
+
{tg.name}
|
|
286
|
+
</option>
|
|
287
|
+
))}
|
|
288
|
+
</select>
|
|
289
|
+
)}
|
|
290
|
+
|
|
291
|
+
{/* Custom-field (metafield) facets — rendered per definition type.
|
|
292
|
+
Only definitions flagged `filterable: true` and published to
|
|
293
|
+
this sales channel reach this list (see `metafieldDefs` filter
|
|
294
|
+
in the hook). The merchant's display name (`def.name`) is shown
|
|
295
|
+
as-is — `enumValues` come from the merchant's dashboard config. */}
|
|
296
|
+
{metafieldDefs.map((def) => {
|
|
297
|
+
const selected = getSelectedMetafieldValues(def.key);
|
|
298
|
+
|
|
299
|
+
if (def.type === 'BOOLEAN') {
|
|
300
|
+
const isOn = selected.includes('true');
|
|
301
|
+
return (
|
|
302
|
+
<label
|
|
303
|
+
key={def.id}
|
|
304
|
+
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"
|
|
305
|
+
>
|
|
306
|
+
<input
|
|
307
|
+
type="checkbox"
|
|
308
|
+
checked={isOn}
|
|
309
|
+
onChange={(e) => setMetafieldValue(def.key, e.target.checked ? ['true'] : [])}
|
|
310
|
+
className="accent-primary h-4 w-4"
|
|
311
|
+
/>
|
|
312
|
+
{def.name}
|
|
313
|
+
</label>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (def.type === 'SELECT') {
|
|
318
|
+
return (
|
|
319
|
+
<select
|
|
320
|
+
key={def.id}
|
|
321
|
+
value={selected[0] || ''}
|
|
322
|
+
onChange={(e) =>
|
|
323
|
+
setMetafieldValue(def.key, e.target.value ? [e.target.value] : [])
|
|
324
|
+
}
|
|
325
|
+
aria-label={def.name}
|
|
326
|
+
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"
|
|
327
|
+
>
|
|
328
|
+
<option value="">{`${tc('all')} ${def.name}`}</option>
|
|
329
|
+
{(def.enumValues || []).map((v) => (
|
|
330
|
+
<option key={v.value} value={v.value}>
|
|
331
|
+
{v.label || v.value}
|
|
332
|
+
</option>
|
|
333
|
+
))}
|
|
334
|
+
</select>
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// MULTI_SELECT — chip toggles. Each click adds/removes one value.
|
|
339
|
+
return (
|
|
340
|
+
<div
|
|
341
|
+
key={def.id}
|
|
342
|
+
className="border-border inline-flex items-center gap-1 rounded border px-2 py-1"
|
|
343
|
+
aria-label={def.name}
|
|
344
|
+
>
|
|
345
|
+
<span className="text-muted-foreground px-1 text-xs">{def.name}:</span>
|
|
346
|
+
{(def.enumValues || []).map((v) => {
|
|
347
|
+
const active = selected.includes(v.value);
|
|
348
|
+
return (
|
|
349
|
+
<button
|
|
350
|
+
key={v.value}
|
|
351
|
+
type="button"
|
|
352
|
+
onClick={() =>
|
|
353
|
+
setMetafieldValue(
|
|
354
|
+
def.key,
|
|
355
|
+
active ? selected.filter((s) => s !== v.value) : [...selected, v.value]
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
className={cn(
|
|
359
|
+
'rounded-full border px-2 py-0.5 text-xs transition-colors',
|
|
360
|
+
active
|
|
361
|
+
? 'bg-primary text-primary-foreground border-primary'
|
|
362
|
+
: 'border-border text-muted-foreground hover:border-primary hover:text-foreground'
|
|
363
|
+
)}
|
|
364
|
+
>
|
|
365
|
+
{v.label || v.value}
|
|
366
|
+
</button>
|
|
367
|
+
);
|
|
368
|
+
})}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
})}
|
|
372
|
+
|
|
373
|
+
{/* Sort */}
|
|
374
|
+
<div className="flex items-center gap-2 sm:ms-auto">
|
|
375
|
+
<label htmlFor="sort" className="text-muted-foreground whitespace-nowrap text-sm">
|
|
376
|
+
{tc('sortBy')}
|
|
377
|
+
</label>
|
|
378
|
+
<select
|
|
379
|
+
id="sort"
|
|
380
|
+
value={sortIndex}
|
|
381
|
+
onChange={(e) => updateParam('sort', e.target.value)}
|
|
382
|
+
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"
|
|
383
|
+
>
|
|
384
|
+
{sortOptions.map((opt, idx) => (
|
|
385
|
+
<option key={idx} value={idx}>
|
|
386
|
+
{t(opt.labelKey)}
|
|
387
|
+
</option>
|
|
388
|
+
))}
|
|
389
|
+
</select>
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
</div>
|
|
393
|
+
|
|
394
|
+
{/* Products Grid */}
|
|
395
|
+
{loading ? (
|
|
396
|
+
<div className="flex items-center justify-center py-20">
|
|
397
|
+
<LoadingSpinner size="lg" />
|
|
398
|
+
</div>
|
|
399
|
+
) : (
|
|
400
|
+
<>
|
|
401
|
+
<ProductGrid products={products} />
|
|
402
|
+
|
|
403
|
+
{/* Load More */}
|
|
404
|
+
{page < totalPages && (
|
|
405
|
+
<div className="mt-10 flex justify-center">
|
|
406
|
+
<button
|
|
407
|
+
onClick={handleLoadMore}
|
|
408
|
+
disabled={loadingMore}
|
|
409
|
+
className="bg-primary text-primary-foreground inline-flex items-center gap-2 rounded px-6 py-2.5 font-medium transition-opacity hover:opacity-90 disabled:opacity-50"
|
|
410
|
+
>
|
|
411
|
+
{loadingMore ? (
|
|
412
|
+
<>
|
|
413
|
+
<LoadingSpinner
|
|
414
|
+
size="sm"
|
|
415
|
+
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
416
|
+
/>
|
|
417
|
+
{tc('loading')}
|
|
418
|
+
</>
|
|
419
|
+
) : (
|
|
420
|
+
t('loadMore')
|
|
421
|
+
)}
|
|
422
|
+
</button>
|
|
423
|
+
</div>
|
|
424
|
+
)}
|
|
425
|
+
</>
|
|
426
|
+
)}
|
|
427
|
+
</div>
|
|
428
|
+
);
|
|
429
|
+
}
|
package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
|
-
import { Link } from '@/lib/navigation';
|
|
5
|
-
import { CdnImage as Image } from '@/
|
|
4
|
+
import { Link } from '@/core/lib/navigation';
|
|
5
|
+
import { CdnImage as Image } from '@/ui/shared/cdn-image';
|
|
6
6
|
import type { ProductRecommendation } from 'brainerce';
|
|
7
|
-
import { PriceDisplay } from '@/
|
|
8
|
-
import { cn } from '@/lib/utils';
|
|
7
|
+
import { PriceDisplay } from '@/ui/product/price-display';
|
|
8
|
+
import { cn } from '@/core/lib/utils';
|
|
9
9
|
|
|
10
10
|
interface RecommendationCardProps {
|
|
11
11
|
item: ProductRecommendation;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
|
-
import { getClient } from '@/lib/brainerce';
|
|
5
|
-
import { checkAuthStatus } from '@/lib/auth';
|
|
4
|
+
import { getClient } from '@/core/lib/brainerce';
|
|
5
|
+
import { checkAuthStatus } from '@/core/lib/auth';
|
|
6
6
|
import type { MyProductReview, ProductReview } from 'brainerce';
|
|
7
7
|
|
|
8
8
|
interface ReviewFormProps {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { InventoryInfo } from 'brainerce';
|
|
4
|
-
import { cn } from '@/lib/utils';
|
|
5
|
-
import { useTranslations } from '@/lib/translations';
|
|
4
|
+
import { cn } from '@/core/lib/utils';
|
|
5
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
6
6
|
|
|
7
7
|
interface StockBadgeProps {
|
|
8
8
|
inventory: InventoryInfo | null | undefined;
|
|
@@ -4,9 +4,9 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import type { Product, ProductVariant } from 'brainerce';
|
|
5
5
|
import { getVariantOptions, getProductSwatches, formatPrice } from 'brainerce';
|
|
6
6
|
import type { InventoryInfo } from 'brainerce';
|
|
7
|
-
import { useCurrency } from '@/lib/use-currency';
|
|
8
|
-
import { useTranslations } from '@/lib/translations';
|
|
9
|
-
import { cn } from '@/lib/utils';
|
|
7
|
+
import { useCurrency } from '@/core/lib/use-currency';
|
|
8
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
9
|
+
import { cn } from '@/core/lib/utils';
|
|
10
10
|
|
|
11
11
|
interface VariantSelectorProps {
|
|
12
12
|
product: Product;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useTranslations } from '@/lib/translations';
|
|
4
|
-
import { cn } from '@/lib/utils';
|
|
3
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
4
|
+
import { cn } from '@/core/lib/utils';
|
|
5
5
|
|
|
6
6
|
interface LoadingSpinnerProps {
|
|
7
7
|
size?: 'sm' | 'md' | 'lg';
|
|
@@ -18,6 +18,18 @@ const config: Config = {
|
|
|
18
18
|
'destructive-foreground': 'hsl(var(--destructive-foreground))',
|
|
19
19
|
accent: 'hsl(var(--accent))',
|
|
20
20
|
'accent-foreground': 'hsl(var(--accent-foreground))',
|
|
21
|
+
// Extended tokens used by design packs (defined in their globals.css).
|
|
22
|
+
// Harmless when a design doesn't set the CSS variables — the classes
|
|
23
|
+
// simply aren't used by the base ui.
|
|
24
|
+
surface: 'hsl(var(--surface))',
|
|
25
|
+
plinth: 'hsl(var(--plinth))',
|
|
26
|
+
},
|
|
27
|
+
fontFamily: {
|
|
28
|
+
// Design packs set --font-sans / --font-serif via next/font variables
|
|
29
|
+
// in app/layout.tsx; the fallbacks keep font-sans/font-serif usable
|
|
30
|
+
// even when a layout doesn't define them.
|
|
31
|
+
sans: ['var(--font-sans)', 'ui-sans-serif', 'system-ui', 'sans-serif'],
|
|
32
|
+
serif: ['var(--font-serif)', 'ui-serif', 'Georgia', 'serif'],
|
|
21
33
|
},
|
|
22
34
|
borderRadius: {
|
|
23
35
|
DEFAULT: 'var(--radius)',
|