create-brainerce-store 1.50.5 → 1.52.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 (230) hide show
  1. package/README.md +72 -0
  2. package/dist/index.js +146 -100
  3. package/messages/en.json +36 -1
  4. package/messages/he.json +36 -1
  5. package/package.json +1 -1
  6. package/templates/nextjs/base/.claude/commands/design.md +60 -0
  7. package/templates/nextjs/base/.env.local.ejs +5 -0
  8. package/templates/nextjs/base/.eslintrc.json +57 -3
  9. package/templates/nextjs/base/AGENTS.md +41 -0
  10. package/templates/nextjs/base/AI-GUIDE.md +143 -0
  11. package/templates/nextjs/base/CLAUDE.md +52 -0
  12. package/templates/nextjs/base/TRANSLATIONS.md +1 -1
  13. package/templates/nextjs/base/next.config.ts +2 -2
  14. package/templates/nextjs/base/package.json.ejs +52 -39
  15. package/templates/nextjs/base/src/app/account/page.tsx +5 -5
  16. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +1 -1
  17. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +2 -2
  18. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +1 -1
  19. package/templates/nextjs/base/src/app/auth/callback/page.tsx +4 -4
  20. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +4 -4
  21. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +2 -2
  22. package/templates/nextjs/base/src/app/cart/page.tsx +2 -173
  23. package/templates/nextjs/base/src/app/checkout/page.tsx +12 -11
  24. package/templates/nextjs/base/src/app/contact/page.tsx +3 -3
  25. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +2 -2
  26. package/templates/nextjs/base/src/app/forgot-password/page.tsx +4 -4
  27. package/templates/nextjs/base/src/app/globals.css +36 -30
  28. package/templates/nextjs/base/src/app/layout.tsx.ejs +12 -12
  29. package/templates/nextjs/base/src/app/login/page.tsx +4 -4
  30. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +19 -12
  31. package/templates/nextjs/base/src/app/page.tsx +4 -4
  32. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +3 -3
  33. package/templates/nextjs/base/src/app/payment-complete/page.tsx +1 -1
  34. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -6
  35. package/templates/nextjs/base/src/app/products/page.tsx +4 -623
  36. package/templates/nextjs/base/src/app/register/page.tsx +4 -4
  37. package/templates/nextjs/base/src/app/reset-password/page.tsx +5 -5
  38. package/templates/nextjs/base/src/app/sitemap.ts +1 -1
  39. package/templates/nextjs/base/src/app/verify-email/page.tsx +5 -5
  40. package/templates/nextjs/base/src/components/account/address-book.tsx +3 -3
  41. package/templates/nextjs/base/src/components/account/order-customizations.tsx +3 -3
  42. package/templates/nextjs/base/src/components/account/order-history.tsx +13 -5
  43. package/templates/nextjs/base/src/components/account/order-payment-block.tsx +2 -2
  44. package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +2 -2
  45. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +2 -2
  46. package/templates/nextjs/base/src/components/account/profile-section.tsx +3 -3
  47. package/templates/nextjs/base/src/components/auth/login-form.tsx +4 -4
  48. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +4 -4
  49. package/templates/nextjs/base/src/components/auth/register-form.tsx +4 -4
  50. package/templates/nextjs/base/src/components/brainerce-bot.tsx +2 -2
  51. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +24 -3
  52. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +2 -2
  53. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +2 -2
  54. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +4 -4
  55. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +20 -16
  56. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +3 -3
  57. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +3 -3
  58. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +3 -3
  59. package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +2 -2
  60. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +3 -3
  61. package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
  62. package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
  63. package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
  64. package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
  65. package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
  66. package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
  67. package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
  68. package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
  69. package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
  70. package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
  71. package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
  72. package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
  73. package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
  74. package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
  75. package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
  76. package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
  77. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +58 -0
  78. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +51 -0
  79. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +295 -0
  80. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +278 -0
  81. package/templates/nextjs/base/src/{hooks → core/hooks}/use-search.ts +1 -1
  82. package/templates/nextjs/base/src/{lib → core/lib}/brainerce.ts.ejs +1 -1
  83. package/templates/nextjs/base/src/core/lib/product-options.ts +121 -0
  84. package/templates/nextjs/base/src/{lib → core/lib}/resolve-currency.ts +1 -1
  85. package/templates/nextjs/base/src/{lib → core/lib}/safe-redirect.ts +1 -1
  86. package/templates/nextjs/base/src/{lib → core/lib}/sanitize.ts.ejs +1 -1
  87. package/templates/nextjs/base/src/{lib → core/lib}/use-currency.ts +1 -1
  88. package/templates/nextjs/base/src/{providers → core/providers}/store-provider.tsx.ejs +4 -4
  89. package/templates/nextjs/base/src/{components → ui}/cart/cart-bundle-offer.tsx +22 -16
  90. package/templates/nextjs/base/src/{components → ui}/cart/cart-item.tsx +8 -14
  91. package/templates/nextjs/base/src/{components → ui}/cart/cart-nudges.tsx +28 -39
  92. package/templates/nextjs/base/src/{components → ui}/cart/cart-summary.tsx +7 -5
  93. package/templates/nextjs/base/src/{components → ui}/cart/cart-upgrade-banner.tsx +13 -28
  94. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +140 -0
  95. package/templates/nextjs/base/src/{components → ui}/cart/coupon-input.tsx +14 -25
  96. package/templates/nextjs/base/src/{components → ui}/cart/free-shipping-bar.tsx +6 -7
  97. package/templates/nextjs/base/src/{components → ui}/cart/reservation-countdown.tsx +95 -103
  98. package/templates/nextjs/base/src/ui/home/discount-banner-strip.tsx +20 -0
  99. package/templates/nextjs/base/src/ui/home/featured-products-section.tsx +24 -0
  100. package/templates/nextjs/base/src/ui/home/hero-section.tsx +27 -0
  101. package/templates/nextjs/base/src/ui/home/home-client.tsx +29 -0
  102. package/templates/nextjs/base/src/{components/content → ui/layout}/announcement-bar.tsx.ejs +116 -125
  103. package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -0
  104. package/templates/nextjs/base/src/{components/content → ui/layout}/header-account.tsx +5 -20
  105. package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -0
  106. package/templates/nextjs/base/src/{components/content → ui/layout}/rich-text-block.tsx.ejs +1 -1
  107. package/templates/nextjs/base/src/{components/content → ui/layout}/site-footer.tsx.ejs +144 -164
  108. package/templates/nextjs/base/src/{components/content → ui/layout}/site-header.tsx.ejs +152 -182
  109. package/templates/nextjs/base/src/{components/products → ui/product}/customization-fields.tsx +457 -478
  110. package/templates/nextjs/base/src/{components/products → ui/product}/discount-badge.tsx +18 -22
  111. package/templates/nextjs/base/src/{components/products → ui/product}/frequently-bought-together.tsx +21 -33
  112. package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -0
  113. package/templates/nextjs/base/src/{components/shared → ui/product}/price-display.tsx +5 -4
  114. package/templates/nextjs/base/src/{components/products → ui/product}/product-card.tsx +238 -271
  115. package/templates/nextjs/base/src/{app/products/[slug] → ui/product}/product-client-section.tsx +455 -631
  116. package/templates/nextjs/base/src/{components/products → ui/product}/product-grid.tsx +3 -3
  117. package/templates/nextjs/base/src/ui/product/product-listing.tsx +446 -0
  118. package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx +102 -107
  119. package/templates/nextjs/base/src/{components/reviews → ui/product}/review-form.tsx +46 -45
  120. package/templates/nextjs/base/src/{components/reviews/reviews-section.tsx → ui/product/reviews-section.tsx.ejs} +38 -15
  121. package/templates/nextjs/base/src/{components/products → ui/product}/stock-badge.tsx +61 -63
  122. package/templates/nextjs/base/src/{components/products → ui/product}/variant-selector.tsx +3 -3
  123. package/templates/nextjs/base/src/{components → ui}/shared/cdn-image.tsx +1 -1
  124. package/templates/nextjs/base/src/{components → ui}/shared/loading-spinner.tsx +2 -2
  125. package/templates/nextjs/base/tailwind.config.ts +69 -30
  126. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +251 -0
  127. package/templates/nextjs/designs/atelier/globals.css +396 -0
  128. package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
  129. package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
  130. package/templates/nextjs/designs/atelier/ui/cart/cart-bundle-offer.tsx +110 -0
  131. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
  132. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
  133. package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
  134. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
  135. package/templates/nextjs/designs/atelier/ui/cart/cart-upgrade-banner.tsx +123 -0
  136. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
  137. package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
  138. package/templates/nextjs/designs/atelier/ui/cart/free-shipping-bar.tsx +77 -0
  139. package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +89 -0
  140. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
  141. package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
  142. package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
  143. package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
  144. package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
  145. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
  146. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
  147. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
  148. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
  149. package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
  150. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
  151. package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
  152. package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
  153. package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
  154. package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
  155. package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
  156. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
  157. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
  158. package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
  159. package/templates/nextjs/designs/atelier/ui/product/discount-badge.tsx +17 -0
  160. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +196 -0
  161. package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
  162. package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
  163. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
  164. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
  165. package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
  166. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
  167. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
  168. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +267 -0
  169. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
  170. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
  171. package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
  172. package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
  173. package/templates/nextjs/designs/atelier/ui/shared/fly-to-cart.ts +86 -0
  174. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
  175. package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
  176. package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
  177. package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
  178. package/templates/nextjs/themes/luxury/globals.css +405 -399
  179. package/templates/nextjs/themes/minimal/globals.css +36 -30
  180. package/templates/nextjs/themes/playful/globals.css +406 -400
  181. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +89 -0
  182. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +123 -0
  183. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +27 -0
  184. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +99 -0
  185. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +105 -0
  186. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +106 -0
  187. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +119 -0
  188. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +54 -0
  189. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +81 -0
  190. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +19 -0
  191. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +23 -0
  192. package/templates/nextjs/ui-canvas/home/hero-section.tsx +21 -0
  193. package/templates/nextjs/ui-canvas/home/home-client.tsx +26 -0
  194. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +101 -0
  195. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +71 -0
  196. package/templates/nextjs/ui-canvas/layout/header-account.tsx +31 -0
  197. package/templates/nextjs/{base/src/components → ui-canvas}/layout/language-switcher.tsx.ejs +76 -70
  198. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +36 -0
  199. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +82 -0
  200. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +119 -0
  201. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +445 -0
  202. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +19 -0
  203. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +168 -0
  204. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +165 -0
  205. package/templates/nextjs/ui-canvas/product/price-display.tsx +52 -0
  206. package/templates/nextjs/ui-canvas/product/product-card.tsx +197 -0
  207. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +352 -0
  208. package/templates/nextjs/ui-canvas/product/product-grid.tsx +27 -0
  209. package/templates/nextjs/ui-canvas/product/product-listing.tsx +224 -0
  210. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +99 -0
  211. package/templates/nextjs/ui-canvas/product/review-form.tsx +266 -0
  212. package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -0
  213. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +45 -0
  214. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +212 -0
  215. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +31 -0
  216. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +27 -0
  217. package/templates/nextjs/base/src/app/home-client.tsx +0 -98
  218. package/templates/nextjs/base/src/components/content/faq-section.tsx.ejs +0 -103
  219. package/templates/nextjs/base/src/components/products/modifier-group-selector.tsx +0 -238
  220. /package/templates/nextjs/base/src/{lib → core/lib}/auth.ts +0 -0
  221. /package/templates/nextjs/base/src/{lib → core/lib}/csrf.ts +0 -0
  222. /package/templates/nextjs/base/src/{lib → core/lib}/image-hosts.ts +0 -0
  223. /package/templates/nextjs/base/src/{lib → core/lib}/navigation.tsx.ejs +0 -0
  224. /package/templates/nextjs/base/src/{lib → core/lib}/nonce.ts +0 -0
  225. /package/templates/nextjs/base/src/{lib → core/lib}/sanitize-html.ts +0 -0
  226. /package/templates/nextjs/base/src/{lib → core/lib}/seo.ts +0 -0
  227. /package/templates/nextjs/base/src/{lib → core/lib}/store-info.ts +0 -0
  228. /package/templates/nextjs/base/src/{lib → core/lib}/translations.ts.ejs +0 -0
  229. /package/templates/nextjs/base/src/{lib → core/lib}/utils.ts +0 -0
  230. /package/templates/nextjs/base/src/{lib → core/lib}/validation.ts +0 -0
@@ -0,0 +1,99 @@
1
+ 'use client';
2
+
3
+ import { Link } from '@/core/lib/navigation';
4
+ import { CdnImage as Image } from '@/ui/shared/cdn-image';
5
+ import type { ProductRecommendation } from 'brainerce';
6
+ import { PriceDisplay } from '@/ui/product/price-display';
7
+ import { cn } from '@/core/lib/utils';
8
+
9
+ interface RecommendationCardProps {
10
+ item: ProductRecommendation;
11
+ className?: string;
12
+ }
13
+
14
+ function RecommendationCard({ item, className }: RecommendationCardProps) {
15
+ const firstImage = item.images?.[0];
16
+ const imageUrl = typeof firstImage === 'string' ? firstImage : firstImage?.url || null;
17
+ const slug = item.slug || item.id;
18
+ const basePrice = parseFloat(item.basePrice);
19
+ const salePrice = item.salePrice ? parseFloat(item.salePrice) : undefined;
20
+ const isOnSale = salePrice != null && salePrice < basePrice;
21
+
22
+ return (
23
+ <Link href={`/products/${slug}`} className={cn(className)}>
24
+ {/* `relative` + `aspect-square` are layout-critical for next/image fill */}
25
+ <span className="relative block aspect-square">
26
+ {imageUrl ? (
27
+ <Image
28
+ src={imageUrl}
29
+ alt={item.name}
30
+ fill
31
+ sizes="(max-width: 640px) 50vw, (max-width: 1024px) 33vw, 20vw"
32
+ />
33
+ ) : null}
34
+ </span>
35
+ <span className="block">
36
+ <span className="block">{item.name}</span>
37
+ <PriceDisplay price={basePrice} salePrice={isOnSale ? salePrice : undefined} size="sm" />
38
+ </span>
39
+ </Link>
40
+ );
41
+ }
42
+
43
+ interface RecommendationSectionProps {
44
+ title: string;
45
+ items: ProductRecommendation[];
46
+ className?: string;
47
+ }
48
+
49
+ /**
50
+ * DESIGN ME — recommendation strip on the product page (upsells / related);
51
+ * items come from useProductPage().recommendations, title is passed in.
52
+ *
53
+ * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
54
+ */
55
+ export function RecommendationSection({ title, items, className }: RecommendationSectionProps) {
56
+ if (items.length === 0) return null;
57
+
58
+ return (
59
+ <section className={cn(className)}>
60
+ <h2>{title}</h2>
61
+ <div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
62
+ {items.map((item) => (
63
+ <RecommendationCard key={item.id} item={item} />
64
+ ))}
65
+ </div>
66
+ </section>
67
+ );
68
+ }
69
+
70
+ interface CartRecommendationSectionProps {
71
+ title: string;
72
+ items: ProductRecommendation[];
73
+ className?: string;
74
+ }
75
+
76
+ /**
77
+ * DESIGN ME — cross-sell strip on the cart page ("you might also need");
78
+ * items come from useCartPage().cartRecs.
79
+ *
80
+ * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
81
+ */
82
+ export function CartRecommendationSection({
83
+ title,
84
+ items,
85
+ className,
86
+ }: CartRecommendationSectionProps) {
87
+ if (items.length === 0) return null;
88
+
89
+ return (
90
+ <section className={cn(className)}>
91
+ <h2>{title}</h2>
92
+ <div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
93
+ {items.map((item) => (
94
+ <RecommendationCard key={item.id} item={item} />
95
+ ))}
96
+ </div>
97
+ </section>
98
+ );
99
+ }
@@ -0,0 +1,266 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { getClient } from '@/core/lib/brainerce';
5
+ import { checkAuthStatus } from '@/core/lib/auth';
6
+ import { useTranslations } from '@/core/lib/translations';
7
+ import type { MyProductReview, ProductReview } from 'brainerce';
8
+
9
+ interface ReviewFormProps {
10
+ productId: string;
11
+ }
12
+
13
+ type Stage =
14
+ | { kind: 'loading' }
15
+ | { kind: 'signed_out' }
16
+ | { kind: 'not_eligible'; reason: MyProductReview['reason'] }
17
+ | { kind: 'submit' }
18
+ | { kind: 'edit'; review: ProductReview };
19
+
20
+ /**
21
+ * Single component that decides which UI to render for a customer on a PDP:
22
+ * - Loading while we check auth state and eligibility
23
+ * - Signed out -> sign-in CTA
24
+ * - Signed in but not eligible -> "purchase this product to review"
25
+ * - Eligible without review -> submit form
26
+ * - Eligible with existing review -> edit/delete form (rating + body prefilled)
27
+ *
28
+ * DESIGN ME — review submit/edit form; auth via checkAuthStatus(), eligibility
29
+ * + existing review via getClient().getMyProductReview(productId).
30
+ *
31
+ * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
32
+ */
33
+ export function ReviewForm({ productId }: ReviewFormProps) {
34
+ const [stage, setStage] = useState<Stage>({ kind: 'loading' });
35
+ const t = useTranslations('reviews');
36
+
37
+ useEffect(() => {
38
+ let cancelled = false;
39
+ async function load() {
40
+ const auth = await checkAuthStatus();
41
+ if (cancelled) return;
42
+ if (!auth.isLoggedIn) {
43
+ setStage({ kind: 'signed_out' });
44
+ return;
45
+ }
46
+ try {
47
+ const me = await getClient().getMyProductReview(productId);
48
+ if (cancelled) return;
49
+ if (!me.eligible) {
50
+ setStage({ kind: 'not_eligible', reason: me.reason });
51
+ return;
52
+ }
53
+ if (me.myReview) {
54
+ setStage({ kind: 'edit', review: me.myReview });
55
+ return;
56
+ }
57
+ setStage({ kind: 'submit' });
58
+ } catch {
59
+ if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
60
+ }
61
+ }
62
+ void load();
63
+ return () => {
64
+ cancelled = true;
65
+ };
66
+ }, [productId]);
67
+
68
+ if (stage.kind === 'loading') {
69
+ return <p role="status">{t('loading')}</p>;
70
+ }
71
+
72
+ if (stage.kind === 'signed_out') {
73
+ return (
74
+ <p>
75
+ <a href="/account/login">{t('signIn')}</a> {t('signInSuffix')}
76
+ </p>
77
+ );
78
+ }
79
+
80
+ if (stage.kind === 'not_eligible') {
81
+ return <NotEligibleMessage reason={stage.reason} />;
82
+ }
83
+
84
+ if (stage.kind === 'edit') {
85
+ return (
86
+ <EditReviewBlock
87
+ productId={productId}
88
+ initial={stage.review}
89
+ onDeleted={() => setStage({ kind: 'submit' })}
90
+ />
91
+ );
92
+ }
93
+
94
+ return <SubmitReviewBlock productId={productId} />;
95
+ }
96
+
97
+ function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
98
+ const t = useTranslations('reviews');
99
+ let message: string;
100
+ switch (reason) {
101
+ case 'no_eligible_order':
102
+ message = t('onlyPurchasers');
103
+ break;
104
+ case 'reviews_disabled':
105
+ message = t('reviewsDisabled');
106
+ break;
107
+ default:
108
+ message = t('cannotReview');
109
+ }
110
+ return <p>{message}</p>;
111
+ }
112
+
113
+ function SubmitReviewBlock({ productId }: { productId: string }) {
114
+ return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
115
+ }
116
+
117
+ function EditReviewBlock({
118
+ productId,
119
+ initial,
120
+ onDeleted,
121
+ }: {
122
+ productId: string;
123
+ initial: ProductReview;
124
+ onDeleted: () => void;
125
+ }) {
126
+ const [deleting, setDeleting] = useState(false);
127
+ const t = useTranslations('reviews');
128
+ const [deleteError, setDeleteError] = useState<string | null>(null);
129
+
130
+ async function handleDelete() {
131
+ if (!window.confirm(t('confirmDelete'))) return;
132
+ setDeleting(true);
133
+ setDeleteError(null);
134
+ try {
135
+ await getClient().deleteMyProductReview(productId);
136
+ onDeleted();
137
+ window.location.reload();
138
+ } catch {
139
+ setDeleteError(t('deleteFailed'));
140
+ } finally {
141
+ setDeleting(false);
142
+ }
143
+ }
144
+
145
+ return (
146
+ <div>
147
+ <ReviewEditor
148
+ productId={productId}
149
+ mode="edit"
150
+ initialRating={initial.rating}
151
+ initialBody={initial.body ?? ''}
152
+ />
153
+ <div className="flex items-center gap-2">
154
+ <p>{t('startOver')}</p>
155
+ <button type="button" onClick={handleDelete} disabled={deleting}>
156
+ {deleting ? t('deleting') : t('deleteReview')}
157
+ </button>
158
+ </div>
159
+ {deleteError && <p role="alert">{deleteError}</p>}
160
+ </div>
161
+ );
162
+ }
163
+
164
+ /**
165
+ * The actual form. Same shape for create and edit — only the API method
166
+ * and the heading differ. Optimistic UX: success state + page reload to
167
+ * let the server-rendered reviews list pick up the change.
168
+ */
169
+ function ReviewEditor({
170
+ productId,
171
+ mode,
172
+ initialRating,
173
+ initialBody,
174
+ }: {
175
+ productId: string;
176
+ mode: 'create' | 'edit';
177
+ initialRating: number;
178
+ initialBody: string;
179
+ }) {
180
+ const [rating, setRating] = useState(initialRating);
181
+ const t = useTranslations('reviews');
182
+ const [body, setBody] = useState(initialBody);
183
+ const [submitting, setSubmitting] = useState(false);
184
+ const [error, setError] = useState<string | null>(null);
185
+ const [success, setSuccess] = useState(false);
186
+
187
+ async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
188
+ event.preventDefault();
189
+ setError(null);
190
+ setSubmitting(true);
191
+ try {
192
+ const client = getClient();
193
+ const input = { rating, body: body.trim() || undefined };
194
+ if (mode === 'edit') {
195
+ await client.updateMyProductReview(productId, input);
196
+ } else {
197
+ await client.submitProductReview(productId, input);
198
+ }
199
+ setSuccess(true);
200
+ setTimeout(() => window.location.reload(), 1200);
201
+ } catch (err) {
202
+ const status = (err as { status?: number })?.status;
203
+ if (status === 409) {
204
+ setError(t('alreadySubmitted'));
205
+ } else if (status === 403) {
206
+ setError(t('onlyPurchasers'));
207
+ } else if (status === 429) {
208
+ setError(t('tooMany'));
209
+ } else {
210
+ setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
211
+ }
212
+ } finally {
213
+ setSubmitting(false);
214
+ }
215
+ }
216
+
217
+ if (success) {
218
+ return <p role="status">{mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}</p>;
219
+ }
220
+
221
+ return (
222
+ <form onSubmit={handleSubmit}>
223
+ <h3>{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
224
+
225
+ <fieldset>
226
+ <legend>{t('yourRating')}</legend>
227
+ <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
228
+ {[1, 2, 3, 4, 5].map((n) => (
229
+ <button
230
+ key={n}
231
+ type="button"
232
+ role="radio"
233
+ aria-checked={rating === n}
234
+ onClick={() => setRating(n)}
235
+ >
236
+ {n <= rating ? '★' : '☆'}
237
+ </button>
238
+ ))}
239
+ </div>
240
+ </fieldset>
241
+
242
+ <label className="block">
243
+ {t('yourReview')} <span>({t('optionalField')})</span>
244
+ <textarea
245
+ value={body}
246
+ onChange={(event) => setBody(event.target.value)}
247
+ maxLength={5000}
248
+ rows={4}
249
+ className="block w-full"
250
+ />
251
+ </label>
252
+
253
+ {error && <p role="alert">{error}</p>}
254
+
255
+ <button type="submit" disabled={submitting}>
256
+ {submitting
257
+ ? mode === 'edit'
258
+ ? t('saving')
259
+ : t('submittingBtn')
260
+ : mode === 'edit'
261
+ ? t('saveChanges')
262
+ : t('submitReview')}
263
+ </button>
264
+ </form>
265
+ );
266
+ }
@@ -0,0 +1,96 @@
1
+ import type { ProductReview } from 'brainerce';
2
+ import { getServerClient } from '@/core/lib/brainerce';
3
+ <% if (i18nEnabled) { %>import { getMessages, defaultLocale } from '@/i18n';<% } else { %>import { defaultLocale, messages } from '@/i18n';<% } %>
4
+ import { ReviewForm } from './review-form';
5
+
6
+ // Server component — it renders before any client i18n context exists, so the
7
+ // wrapper strings (title / empty state / verified badge) are read straight
8
+ // from the `reviews` namespace in messages/, keyed by the store locale.
9
+ type ReviewStrings = Record<string, string>;
10
+
11
+ <% if (i18nEnabled) { %>async function getReviewStrings(locale: string): Promise<ReviewStrings> {
12
+ return ((await getMessages(locale)).reviews ?? {}) as ReviewStrings;
13
+ }<% } else { %>async function getReviewStrings(_locale: string): Promise<ReviewStrings> {
14
+ return messages.reviews as ReviewStrings;
15
+ }<% } %>
16
+
17
+ interface ReviewsSectionProps {
18
+ productId: string;
19
+ initialReviews?: ProductReview[];
20
+ locale?: string;
21
+ /** Where to send users back to after submit (defaults to the current product URL). */
22
+ returnUrl?: string;
23
+ }
24
+
25
+ /**
26
+ * Renders the visible reviews for a product plus a submit form.
27
+ *
28
+ * Server component — fetches with the SDK on the server so reviews are in
29
+ * the initial HTML payload (good for SEO; JSON-LD on the same page already
30
+ * carries `aggregateRating` when reviewCount > 0).
31
+ */
32
+ export async function ReviewsSection({
33
+ productId,
34
+ initialReviews,
35
+ locale = defaultLocale,
36
+ }: ReviewsSectionProps) {
37
+ const t = await getReviewStrings(locale);
38
+ let reviews: ProductReview[] = initialReviews ?? [];
39
+
40
+ if (!initialReviews) {
41
+ try {
42
+ const result = await getServerClient().listProductReviews(productId, { page: 1, limit: 20 });
43
+ reviews = result.data;
44
+ } catch {
45
+ // Review listing disabled at store level or network error — render the form anyway.
46
+ reviews = [];
47
+ }
48
+ }
49
+
50
+ return (
51
+ <section aria-labelledby="reviews-heading">
52
+ {/* DESIGN ME — product reviews: server-fetched review list (SDK listProductReviews) + eligibility-aware submit form. Compose with the shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons. */}
53
+ <h2 id="reviews-heading">{t.title}</h2>
54
+
55
+ {reviews.length === 0 ? (
56
+ <p>{t.noReviews}</p>
57
+ ) : (
58
+ <ul>
59
+ {reviews.map((review) => (
60
+ <ReviewCard key={review.id} review={review} verifiedLabel={t.verifiedPurchase} />
61
+ ))}
62
+ </ul>
63
+ )}
64
+
65
+ <ReviewForm productId={productId} />
66
+ </section>
67
+ );
68
+ }
69
+
70
+ function ReviewCard({ review, verifiedLabel }: { review: ProductReview; verifiedLabel: string }) {
71
+ return (
72
+ <li>
73
+ <article>
74
+ <header className="flex flex-wrap items-center gap-2">
75
+ <Stars rating={review.rating} />
76
+ <span>{review.authorName}</span>
77
+ {review.verifiedPurchase && <span>{verifiedLabel}</span>}
78
+ <time dateTime={review.createdAt}>{new Date(review.createdAt).toLocaleDateString()}</time>
79
+ </header>
80
+ {review.body && <p className="whitespace-pre-line break-words">{review.body}</p>}
81
+ </article>
82
+ </li>
83
+ );
84
+ }
85
+
86
+ function Stars({ rating }: { rating: number }) {
87
+ return (
88
+ <span aria-label={`${rating} of 5 stars`}>
89
+ {[1, 2, 3, 4, 5].map((n) => (
90
+ <span key={n} aria-hidden="true">
91
+ {n <= rating ? '★' : '☆'}
92
+ </span>
93
+ ))}
94
+ </span>
95
+ );
96
+ }
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+
3
+ import type { InventoryInfo } from 'brainerce';
4
+ import { cn } from '@/core/lib/utils';
5
+ import { useTranslations } from '@/core/lib/translations';
6
+
7
+ interface StockBadgeProps {
8
+ inventory: InventoryInfo | null | undefined;
9
+ lowStockThreshold?: number;
10
+ className?: string;
11
+ }
12
+
13
+ /**
14
+ * DESIGN ME — stock status badge (in stock / low stock / out of stock);
15
+ * derives the label from the product/variant `inventory` prop. Keep the
16
+ * label logic; add your own tones per state.
17
+ *
18
+ * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with.
19
+ */
20
+ export function StockBadge({ inventory, lowStockThreshold = 5, className }: StockBadgeProps) {
21
+ const t = useTranslations('productDetail');
22
+ const label = getStockLabel(inventory, lowStockThreshold, t);
23
+
24
+ return <span className={cn(className)}>{label}</span>;
25
+ }
26
+
27
+ function getStockLabel(
28
+ inventory: InventoryInfo | null | undefined,
29
+ lowStockThreshold: number,
30
+ t: (key: string) => string
31
+ ): string {
32
+ if (!inventory) return t('outOfStock');
33
+
34
+ const { trackingMode, inStock, available } = inventory;
35
+
36
+ if (trackingMode === 'DISABLED') return t('unavailable');
37
+ if (!inStock) return t('outOfStock');
38
+ if (trackingMode === 'UNLIMITED') return t('inStock');
39
+
40
+ // TRACKED — show actual quantity
41
+ if (available <= lowStockThreshold) {
42
+ return t('onlyLeft').replace('{available}', String(available));
43
+ }
44
+ return t('availableInStock').replace('{available}', String(available));
45
+ }