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,148 @@
1
+ import type { ProductReview } from 'brainerce';
2
+ import { getServerClient } from '@/core/lib/brainerce';
3
+ <% if (i18nEnabled) { %>
4
+ import { getMessages, defaultLocale } from '@/i18n';
5
+ <% } else { %>
6
+ import { messages as staticMessages, defaultLocale } from '@/i18n';
7
+ <% } %>
8
+ import { ReviewForm } from './review-form';
9
+ import { IconStar } from '@/ui/shared/icons';
10
+
11
+ // Server component — it renders before any client i18n context exists, so the
12
+ // wrapper strings (title / empty state / verified badge) are read straight
13
+ // from the `reviews` namespace in messages/, keyed by the store locale.
14
+ type ReviewStrings = Record<string, string>;
15
+
16
+ async function getReviewStrings(locale: string): Promise<ReviewStrings> {
17
+ <% if (i18nEnabled) { %>
18
+ return ((await getMessages(locale)).reviews ?? {}) as ReviewStrings;
19
+ <% } else { %>
20
+ return (staticMessages.reviews ?? {}) as ReviewStrings;
21
+ <% } %>
22
+ }
23
+
24
+ interface ReviewsSectionProps {
25
+ productId: string;
26
+ initialReviews?: ProductReview[];
27
+ locale?: string;
28
+ /** Where to send users back to after submit (defaults to the current product URL). */
29
+ returnUrl?: string;
30
+ }
31
+
32
+ /**
33
+ * Renders the visible reviews for a product plus a submit form.
34
+ *
35
+ * Server component — fetches with the SDK on the server so reviews are in
36
+ * the initial HTML payload (good for SEO; JSON-LD on the same page already
37
+ * carries `aggregateRating` when reviewCount > 0).
38
+ */
39
+ export async function ReviewsSection({
40
+ productId,
41
+ initialReviews,
42
+ locale = defaultLocale,
43
+ }: ReviewsSectionProps) {
44
+ const t = await getReviewStrings(locale);
45
+ let reviews: ProductReview[] = initialReviews ?? [];
46
+
47
+ if (!initialReviews) {
48
+ try {
49
+ const result = await getServerClient().listProductReviews(productId, { page: 1, limit: 20 });
50
+ reviews = result.data;
51
+ } catch {
52
+ // Review listing disabled at store level or network error — render the form anyway.
53
+ reviews = [];
54
+ }
55
+ }
56
+
57
+ const avg =
58
+ reviews.length > 0
59
+ ? Math.round((reviews.reduce((s, r) => s + r.rating, 0) / reviews.length) * 10) / 10
60
+ : null;
61
+
62
+ return (
63
+ <section aria-labelledby="reviews-heading" className="border-t bg-secondary/40">
64
+ <div className="container-narrow grid gap-10 py-14 lg:grid-cols-3 lg:py-16">
65
+ {/* Summary column */}
66
+ <div>
67
+ <h2 id="reviews-heading" className="text-2xl sm:text-3xl">
68
+ {t.title}
69
+ </h2>
70
+ {avg !== null && (
71
+ <p className="mt-4 flex items-center gap-3">
72
+ <span className="font-display text-4xl text-foreground">{avg}</span>
73
+ <span className="inline-flex flex-col gap-1">
74
+ <Stars rating={Math.round(avg)} />
75
+ <span className="text-xs text-muted-foreground">
76
+ ({reviews.length})
77
+ </span>
78
+ </span>
79
+ </p>
80
+ )}
81
+
82
+ {/* Submit / edit form */}
83
+ <div className="card mt-6 p-5">
84
+ <ReviewForm productId={productId} />
85
+ </div>
86
+ </div>
87
+
88
+ {/* Review list */}
89
+ <div className="lg:col-span-2">
90
+ {reviews.length === 0 ? (
91
+ <div className="card flex h-full min-h-40 flex-col items-center justify-center gap-2 p-8 text-center">
92
+ <Stars rating={0} />
93
+ <p className="font-medium text-foreground">{t.beFirst ?? t.noReviews}</p>
94
+ <p className="text-sm text-muted-foreground">{t.noReviews}</p>
95
+ </div>
96
+ ) : (
97
+ <ul className="space-y-4">
98
+ {reviews.map((review) => (
99
+ <ReviewCard key={review.id} review={review} verifiedLabel={t.verifiedPurchase} />
100
+ ))}
101
+ </ul>
102
+ )}
103
+ </div>
104
+ </div>
105
+ </section>
106
+ );
107
+ }
108
+
109
+ function ReviewCard({ review, verifiedLabel }: { review: ProductReview; verifiedLabel: string }) {
110
+ return (
111
+ <li>
112
+ <article className="card p-5">
113
+ <header className="flex flex-wrap items-center gap-x-3 gap-y-1.5">
114
+ <Stars rating={review.rating} />
115
+ <span className="text-sm font-semibold text-foreground">{review.authorName}</span>
116
+ {review.verifiedPurchase && <span className="badge-soft">{verifiedLabel}</span>}
117
+ <time
118
+ dateTime={review.createdAt}
119
+ className="ms-auto text-xs text-muted-foreground"
120
+ >
121
+ {new Date(review.createdAt).toLocaleDateString()}
122
+ </time>
123
+ </header>
124
+ {review.body && (
125
+ <p className="mt-3 whitespace-pre-line break-words text-sm leading-6 text-foreground">
126
+ {review.body}
127
+ </p>
128
+ )}
129
+ </article>
130
+ </li>
131
+ );
132
+ }
133
+
134
+ function Stars({ rating }: { rating: number }) {
135
+ return (
136
+ <span aria-label={`${rating} of 5 stars`} className="inline-flex gap-0.5">
137
+ {[1, 2, 3, 4, 5].map((n) => (
138
+ <span
139
+ key={n}
140
+ aria-hidden="true"
141
+ className={n <= rating ? 'text-primary' : 'text-border'}
142
+ >
143
+ <IconStar size={16} filled={n <= rating} />
144
+ </span>
145
+ ))}
146
+ </span>
147
+ );
148
+ }
@@ -0,0 +1,66 @@
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
+ type StockState = 'in' | 'low' | 'out';
14
+
15
+ /**
16
+ * Stock status pill (in stock / low stock / out of stock) with a colored
17
+ * status dot; derives the label from the product/variant `inventory` prop.
18
+ */
19
+ export function StockBadge({ inventory, lowStockThreshold = 5, className }: StockBadgeProps) {
20
+ const t = useTranslations('productDetail');
21
+ const { label, state } = getStock(inventory, lowStockThreshold, t);
22
+
23
+ return (
24
+ <span
25
+ data-state={state}
26
+ className={cn(
27
+ 'inline-flex items-center gap-1.5 text-xs font-medium',
28
+ state === 'in' && 'text-primary',
29
+ state === 'low' && 'text-foreground',
30
+ state === 'out' && 'text-destructive',
31
+ className
32
+ )}
33
+ >
34
+ <span
35
+ aria-hidden="true"
36
+ className={cn(
37
+ 'inline-block h-1.5 w-1.5 rounded-full',
38
+ state === 'in' && 'bg-primary',
39
+ state === 'low' && 'bg-foreground/60',
40
+ state === 'out' && 'bg-destructive'
41
+ )}
42
+ />
43
+ {label}
44
+ </span>
45
+ );
46
+ }
47
+
48
+ function getStock(
49
+ inventory: InventoryInfo | null | undefined,
50
+ lowStockThreshold: number,
51
+ t: (key: string) => string
52
+ ): { label: string; state: StockState } {
53
+ if (!inventory) return { label: t('outOfStock'), state: 'out' };
54
+
55
+ const { trackingMode, inStock, available } = inventory;
56
+
57
+ if (trackingMode === 'DISABLED') return { label: t('unavailable'), state: 'out' };
58
+ if (!inStock) return { label: t('outOfStock'), state: 'out' };
59
+ if (trackingMode === 'UNLIMITED') return { label: t('inStock'), state: 'in' };
60
+
61
+ // TRACKED — show actual quantity
62
+ if (available <= lowStockThreshold) {
63
+ return { label: t('onlyLeft').replace('{available}', String(available)), state: 'low' };
64
+ }
65
+ return { label: t('availableInStock').replace('{available}', String(available)), state: 'in' };
66
+ }
@@ -0,0 +1,206 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from 'react';
4
+ import type { Product, ProductVariant } from 'brainerce';
5
+ import { getVariantOptions, getProductSwatches } from 'brainerce';
6
+ import { cn } from '@/core/lib/utils';
7
+
8
+ interface VariantSelectorProps {
9
+ product: Product;
10
+ selectedVariant: ProductVariant | null;
11
+ onVariantChange: (variant: ProductVariant) => void;
12
+ className?: string;
13
+ }
14
+
15
+ interface AttributeGroup {
16
+ name: string;
17
+ displayType: string;
18
+ values: Array<{
19
+ value: string;
20
+ swatchColor?: string | null;
21
+ swatchColor2?: string | null;
22
+ swatchImageUrl?: string | null;
23
+ variants: ProductVariant[];
24
+ }>;
25
+ }
26
+
27
+ /**
28
+ * Variant selector on the product page: one group per attribute (Size,
29
+ * Color, …) rendered as pill buttons; merchant swatch metadata
30
+ * (`swatchColor`, `swatchColor2`, `swatchImageUrl`) renders as a color/image
31
+ * dot inside the pill. Selection state + matching logic are the contract.
32
+ */
33
+ export function VariantSelector({
34
+ product,
35
+ selectedVariant,
36
+ onVariantChange,
37
+ className,
38
+ }: VariantSelectorProps) {
39
+ const variants = useMemo(() => product.variants || [], [product.variants]);
40
+
41
+ // Get swatch metadata from product attribute options
42
+ const swatchData = useMemo(() => getProductSwatches(product), [product]);
43
+ const swatchMap = useMemo(() => {
44
+ const map = new Map<
45
+ string,
46
+ {
47
+ displayType: string;
48
+ options: Map<
49
+ string,
50
+ {
51
+ swatchColor?: string | null;
52
+ swatchColor2?: string | null;
53
+ swatchImageUrl?: string | null;
54
+ }
55
+ >;
56
+ }
57
+ >();
58
+ for (const attr of swatchData) {
59
+ const optMap = new Map<
60
+ string,
61
+ {
62
+ swatchColor?: string | null;
63
+ swatchColor2?: string | null;
64
+ swatchImageUrl?: string | null;
65
+ }
66
+ >();
67
+ for (const opt of attr.options) {
68
+ optMap.set(opt.name, {
69
+ swatchColor: opt.swatchColor,
70
+ swatchColor2: opt.swatchColor2,
71
+ swatchImageUrl: opt.swatchImageUrl,
72
+ });
73
+ }
74
+ map.set(attr.attributeName, { displayType: attr.displayType, options: optMap });
75
+ }
76
+ return map;
77
+ }, [swatchData]);
78
+
79
+ // Build attribute groups from variant data, enriched with swatch info
80
+ const attributeGroups = useMemo<AttributeGroup[]>(() => {
81
+ const groups = new Map<string, Map<string, ProductVariant[]>>();
82
+
83
+ for (const variant of variants) {
84
+ const options = getVariantOptions(variant);
85
+ for (const { name, value } of options) {
86
+ if (!groups.has(name)) {
87
+ groups.set(name, new Map());
88
+ }
89
+ const valuesMap = groups.get(name)!;
90
+ if (!valuesMap.has(value)) {
91
+ valuesMap.set(value, []);
92
+ }
93
+ valuesMap.get(value)!.push(variant);
94
+ }
95
+ }
96
+
97
+ return Array.from(groups.entries()).map(([name, valuesMap]) => {
98
+ const attrSwatch = swatchMap.get(name);
99
+ return {
100
+ name,
101
+ displayType: attrSwatch?.displayType || 'DROPDOWN',
102
+ values: Array.from(valuesMap.entries()).map(([value, variantList]) => {
103
+ const optSwatch = attrSwatch?.options.get(value);
104
+ return {
105
+ value,
106
+ swatchColor: optSwatch?.swatchColor,
107
+ swatchColor2: optSwatch?.swatchColor2,
108
+ swatchImageUrl: optSwatch?.swatchImageUrl,
109
+ variants: variantList,
110
+ };
111
+ }),
112
+ };
113
+ });
114
+ }, [variants, swatchMap]);
115
+
116
+ // Get currently selected attribute values
117
+ const selectedOptions = useMemo(() => {
118
+ if (!selectedVariant) return new Map<string, string>();
119
+ const opts = getVariantOptions(selectedVariant);
120
+ return new Map(opts.map(({ name, value }) => [name, value]));
121
+ }, [selectedVariant]);
122
+
123
+ // Find the variant that matches all selected attributes
124
+ function findMatchingVariant(
125
+ attributeName: string,
126
+ newValue: string
127
+ ): ProductVariant | undefined {
128
+ const nextSelection = new Map(selectedOptions);
129
+ nextSelection.set(attributeName, newValue);
130
+
131
+ return variants.find((v) => {
132
+ const opts = getVariantOptions(v);
133
+ return Array.from(nextSelection.entries()).every(([name, value]) =>
134
+ opts.some((o) => o.name === name && o.value === value)
135
+ );
136
+ });
137
+ }
138
+
139
+ if (attributeGroups.length === 0) return null;
140
+
141
+ return (
142
+ <div className={cn('space-y-5', className)}>
143
+ {attributeGroups.map((group) => (
144
+ <fieldset key={group.name} data-display-type={group.displayType}>
145
+ <legend className="mb-2.5 text-sm font-semibold text-foreground">
146
+ {group.name}
147
+ {selectedOptions.get(group.name) && (
148
+ <span className="font-normal text-muted-foreground">
149
+ : {selectedOptions.get(group.name)}
150
+ </span>
151
+ )}
152
+ </legend>
153
+ <div className="flex flex-wrap gap-2">
154
+ {group.values.map(({ value, swatchColor, swatchColor2, swatchImageUrl, variants: matchingVariants }) => {
155
+ const isSelected = selectedOptions.get(group.name) === value;
156
+ const matchedVariant = findMatchingVariant(group.name, value);
157
+ const isAvailable = matchedVariant?.inventory?.canPurchase !== false;
158
+ const hasSwatch = Boolean(swatchColor || swatchImageUrl);
159
+
160
+ return (
161
+ <button
162
+ key={value}
163
+ type="button"
164
+ disabled={!isAvailable}
165
+ aria-pressed={isSelected}
166
+ onClick={() => {
167
+ const variant = matchedVariant || matchingVariants[0];
168
+ if (variant) onVariantChange(variant);
169
+ }}
170
+ className={cn(
171
+ 'inline-flex min-h-10 items-center gap-2 rounded-full border px-4 py-1.5 text-sm font-medium transition-colors',
172
+ isSelected
173
+ ? 'border-primary bg-primary text-primary-foreground'
174
+ : 'border-border bg-background text-foreground hover:border-foreground',
175
+ !isAvailable && 'opacity-40 line-through'
176
+ )}
177
+ >
178
+ {hasSwatch && (
179
+ <span
180
+ aria-hidden="true"
181
+ className="inline-block h-5 w-5 shrink-0 rounded-full border border-foreground/15 bg-cover bg-center"
182
+ style={
183
+ swatchImageUrl
184
+ ? { backgroundImage: `url(${swatchImageUrl})` }
185
+ : swatchColor2
186
+ ? {
187
+ background: `linear-gradient(135deg, ${swatchColor} 50%, ${swatchColor2} 50%)`,
188
+ }
189
+ : { backgroundColor: swatchColor ?? undefined }
190
+ }
191
+ />
192
+ )}
193
+ {value}
194
+ </button>
195
+ );
196
+ })}
197
+ </div>
198
+ </fieldset>
199
+ ))}
200
+
201
+ {/* Variant-specific price + stock intentionally NOT repeated here — the
202
+ buy box's PriceDisplay and StockBadge react to the selected variant
203
+ via useProductPage(), so a strip here would duplicate them. */}
204
+ </div>
205
+ );
206
+ }
@@ -0,0 +1,29 @@
1
+ import Image, { type ImageProps } from 'next/image';
2
+ import { OPTIMIZED_IMAGE_HOSTS } from '@/core/lib/image-hosts';
3
+
4
+ const OPTIMIZED_HOSTS = new Set(OPTIMIZED_IMAGE_HOSTS);
5
+
6
+ function isOptimizedHost(src: ImageProps['src']): boolean {
7
+ if (typeof src !== 'string') return true; // StaticImageData — always local
8
+ try {
9
+ return OPTIMIZED_HOSTS.has(new URL(src).hostname);
10
+ } catch {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Drop-in `next/image` replacement for Brainerce-sourced images (product
17
+ * photos, blog covers). Uploaded images get re-hosted onto cdn.brainerce.com
18
+ * by the backend's async image-import pipeline, but a product/variant can
19
+ * still carry a raw upstream-merchant URL while mid-import, or if that job
20
+ * failed. next/image throws if `src`'s host isn't in `images.remotePatterns`,
21
+ * so any host outside our known CDN falls back to `unoptimized` — an
22
+ * unresized, direct-from-origin fetch — instead of crashing the page.
23
+ *
24
+ * DESIGN ME — shared image wrapper; render ALL catalog images through this
25
+ * component (not raw next/image) so unknown hosts never crash the page.
26
+ */
27
+ export function CdnImage({ unoptimized, ...props }: ImageProps) {
28
+ return <Image {...props} unoptimized={unoptimized ?? !isOptimizedHost(props.src)} />;
29
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * "Fly to cart" — a small round thumbnail of the product lifts off the image
3
+ * and drifts into the header cart icon, which then bumps.
4
+ *
5
+ * RTL gotcha (learned the hard way): next/image renders its <img> with
6
+ * `inset: 0`; a naive clone keeps that, and in an RTL document an
7
+ * over-constrained left+right resolves to RIGHT — pinning the clone to the
8
+ * wrong edge. `inset: 'auto'` must be set BEFORE top/left.
9
+ *
10
+ * Pure presentation; no-ops under prefers-reduced-motion or when either end
11
+ * of the flight is missing.
12
+ */
13
+ export function flyToCart(source: HTMLElement | null) {
14
+ if (!source || typeof document === 'undefined') return;
15
+ if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
16
+
17
+ const target = document.getElementById('cart-anchor');
18
+ if (!target) return;
19
+
20
+ const img = source.querySelector('img') ?? source;
21
+ const from = img.getBoundingClientRect();
22
+ const to = target.getBoundingClientRect();
23
+ if (from.width === 0 || to.width === 0) return;
24
+
25
+ const SIZE = 64;
26
+ const startX = from.left + from.width / 2 - SIZE / 2;
27
+ const startY = from.top + from.height / 2 - SIZE / 2;
28
+
29
+ const clone = img.cloneNode(true) as HTMLElement;
30
+ Object.assign(clone.style, {
31
+ inset: 'auto', // kill next/image's inset:0 BEFORE top/left (RTL right-wins)
32
+ position: 'fixed',
33
+ top: `${startY}px`,
34
+ left: `${startX}px`,
35
+ width: `${SIZE}px`,
36
+ height: `${SIZE}px`,
37
+ borderRadius: '9999px',
38
+ objectFit: 'cover',
39
+ zIndex: '9999',
40
+ pointerEvents: 'none',
41
+ margin: '0',
42
+ border: '2px solid hsl(var(--background))',
43
+ boxShadow: '0 10px 24px -10px hsl(var(--primary) / 0.5)',
44
+ background: 'hsl(var(--background))',
45
+ });
46
+ document.body.appendChild(clone);
47
+
48
+ const dx = to.left + to.width / 2 - (startX + SIZE / 2);
49
+ const dy = to.top + to.height / 2 - (startY + SIZE / 2);
50
+
51
+ const flight = clone.animate(
52
+ [
53
+ { transform: 'translate(0, 0) scale(0.6)', opacity: 0 },
54
+ { transform: 'translate(0, -14px) scale(1)', opacity: 1, offset: 0.18 },
55
+ {
56
+ transform: `translate(${dx * 0.55}px, ${dy * 0.55 - 56}px) scale(0.75)`,
57
+ opacity: 1,
58
+ offset: 0.62,
59
+ },
60
+ { transform: `translate(${dx}px, ${dy}px) scale(0.15)`, opacity: 0.4 },
61
+ ],
62
+ { duration: 750, easing: 'cubic-bezier(0.22, 1, 0.36, 1)' }
63
+ );
64
+
65
+ const land = () => {
66
+ clone.remove();
67
+ target.classList.add('cart-bump');
68
+ window.setTimeout(() => target.classList.remove('cart-bump'), 450);
69
+ };
70
+ flight.onfinish = land;
71
+ // Failsafe — never leave a stray clone in the DOM (tab switch, WAAPI hiccup)
72
+ window.setTimeout(() => {
73
+ if (clone.isConnected) land();
74
+ }, 1100);
75
+ }
76
+
77
+ /** Picks the first visible element matching the selector — for pages that
78
+ * render separate mobile/desktop galleries. */
79
+ export function firstVisible(selector: string): HTMLElement | null {
80
+ if (typeof document === 'undefined') return null;
81
+ for (const el of document.querySelectorAll<HTMLElement>(selector)) {
82
+ const rect = el.getBoundingClientRect();
83
+ if (rect.width > 0 && rect.height > 0) return el;
84
+ }
85
+ return null;
86
+ }