create-brainerce-store 1.50.1 → 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.
Files changed (189) hide show
  1. package/dist/index.js +171 -66
  2. package/messages/en.json +4 -1
  3. package/messages/he.json +4 -1
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/.claude/commands/design.md +51 -0
  6. package/templates/nextjs/base/.env.local.ejs +5 -0
  7. package/templates/nextjs/base/.eslintrc.json +57 -3
  8. package/templates/nextjs/base/AGENTS.md +41 -0
  9. package/templates/nextjs/base/AI-GUIDE.md +94 -0
  10. package/templates/nextjs/base/CLAUDE.md +42 -0
  11. package/templates/nextjs/base/TRANSLATIONS.md +1 -1
  12. package/templates/nextjs/base/next.config.ts +18 -10
  13. package/templates/nextjs/base/package.json.ejs +5 -1
  14. package/templates/nextjs/base/src/app/account/page.tsx +5 -5
  15. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +1 -1
  16. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +2 -2
  17. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +1 -1
  18. package/templates/nextjs/base/src/app/auth/callback/page.tsx +4 -4
  19. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +4 -4
  20. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +2 -2
  21. package/templates/nextjs/base/src/app/cart/page.tsx +2 -173
  22. package/templates/nextjs/base/src/app/checkout/page.tsx +12 -11
  23. package/templates/nextjs/base/src/app/contact/page.tsx +3 -3
  24. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +2 -2
  25. package/templates/nextjs/base/src/app/forgot-password/page.tsx +4 -4
  26. package/templates/nextjs/base/src/app/layout.tsx.ejs +16 -14
  27. package/templates/nextjs/base/src/app/login/page.tsx +4 -4
  28. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +19 -12
  29. package/templates/nextjs/base/src/app/page.tsx +4 -4
  30. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +3 -3
  31. package/templates/nextjs/base/src/app/payment-complete/page.tsx +1 -1
  32. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -6
  33. package/templates/nextjs/base/src/app/products/page.tsx +4 -623
  34. package/templates/nextjs/base/src/app/register/page.tsx +4 -4
  35. package/templates/nextjs/base/src/app/reset-password/page.tsx +5 -5
  36. package/templates/nextjs/base/src/app/sitemap.ts +1 -1
  37. package/templates/nextjs/base/src/app/verify-email/page.tsx +5 -5
  38. package/templates/nextjs/base/src/components/account/address-book.tsx +3 -3
  39. package/templates/nextjs/base/src/components/account/order-customizations.tsx +3 -3
  40. package/templates/nextjs/base/src/components/account/order-history.tsx +13 -5
  41. package/templates/nextjs/base/src/components/account/order-payment-block.tsx +2 -2
  42. package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +2 -2
  43. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +2 -2
  44. package/templates/nextjs/base/src/components/account/profile-section.tsx +3 -3
  45. package/templates/nextjs/base/src/components/auth/login-form.tsx +4 -4
  46. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +4 -4
  47. package/templates/nextjs/base/src/components/auth/register-form.tsx +4 -4
  48. package/templates/nextjs/base/src/components/brainerce-bot.tsx +2 -2
  49. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +24 -3
  50. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +2 -2
  51. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +2 -2
  52. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +4 -4
  53. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +6 -6
  54. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +3 -3
  55. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +3 -3
  56. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +3 -3
  57. package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +2 -2
  58. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +3 -3
  59. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +58 -0
  60. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +51 -0
  61. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +295 -0
  62. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +278 -0
  63. package/templates/nextjs/base/src/{hooks → core/hooks}/use-search.ts +1 -1
  64. package/templates/nextjs/base/src/{lib → core/lib}/brainerce.ts.ejs +1 -1
  65. package/templates/nextjs/base/src/core/lib/image-hosts.ts +7 -0
  66. package/templates/nextjs/base/src/core/lib/product-options.ts +121 -0
  67. package/templates/nextjs/base/src/{lib → core/lib}/resolve-currency.ts +1 -1
  68. package/templates/nextjs/base/src/{lib → core/lib}/safe-redirect.ts +1 -1
  69. package/templates/nextjs/base/src/{lib → core/lib}/sanitize-html.ts +12 -0
  70. package/templates/nextjs/base/src/{lib → core/lib}/sanitize.ts.ejs +1 -1
  71. package/templates/nextjs/base/src/{lib → core/lib}/use-currency.ts +1 -1
  72. package/templates/nextjs/base/src/{providers → core/providers}/store-provider.tsx.ejs +4 -4
  73. package/templates/nextjs/base/src/middleware.ts.ejs +2 -2
  74. package/templates/nextjs/base/src/{components → ui}/cart/cart-bundle-offer.tsx +5 -5
  75. package/templates/nextjs/base/src/{components → ui}/cart/cart-item.tsx +6 -6
  76. package/templates/nextjs/base/src/{components → ui}/cart/cart-nudges.tsx +1 -1
  77. package/templates/nextjs/base/src/{components → ui}/cart/cart-summary.tsx +4 -4
  78. package/templates/nextjs/base/src/{components → ui}/cart/cart-upgrade-banner.tsx +5 -5
  79. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +149 -0
  80. package/templates/nextjs/base/src/{components → ui}/cart/coupon-input.tsx +4 -4
  81. package/templates/nextjs/base/src/{components → ui}/cart/free-shipping-bar.tsx +4 -4
  82. package/templates/nextjs/base/src/{components → ui}/cart/reservation-countdown.tsx +2 -2
  83. package/templates/nextjs/base/src/ui/home/discount-banner-strip.tsx +20 -0
  84. package/templates/nextjs/base/src/ui/home/featured-products-section.tsx +24 -0
  85. package/templates/nextjs/base/src/ui/home/hero-section.tsx +29 -0
  86. package/templates/nextjs/base/src/ui/home/home-client.tsx +29 -0
  87. package/templates/nextjs/base/src/{components/content → ui/layout}/faq-section.tsx.ejs +2 -2
  88. package/templates/nextjs/base/src/{components/content → ui/layout}/header-account.tsx +3 -3
  89. package/templates/nextjs/base/src/{components/content → ui/layout}/rich-text-block.tsx.ejs +1 -1
  90. package/templates/nextjs/base/src/{components/content → ui/layout}/site-header.tsx.ejs +1 -1
  91. package/templates/nextjs/base/src/{components/products → ui/product}/customization-fields.tsx +18 -51
  92. package/templates/nextjs/base/src/{components/products → ui/product}/discount-badge.tsx +1 -1
  93. package/templates/nextjs/base/src/{components/products → ui/product}/frequently-bought-together.tsx +6 -6
  94. package/templates/nextjs/base/src/{components/products → ui/product}/modifier-group-selector.tsx +10 -77
  95. package/templates/nextjs/base/src/{components/shared → ui/product}/price-display.tsx +2 -2
  96. package/templates/nextjs/base/src/{components/products → ui/product}/product-card.tsx +10 -10
  97. package/templates/nextjs/base/src/{app/products/[slug] → ui/product}/product-client-section.tsx +45 -206
  98. package/templates/nextjs/base/src/{components/products → ui/product}/product-grid.tsx +3 -3
  99. package/templates/nextjs/base/src/ui/product/product-listing.tsx +429 -0
  100. package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx +4 -4
  101. package/templates/nextjs/base/src/{components/reviews → ui/product}/review-form.tsx +2 -2
  102. package/templates/nextjs/base/src/{components/reviews → ui/product}/reviews-section.tsx +1 -1
  103. package/templates/nextjs/base/src/{components/products → ui/product}/stock-badge.tsx +2 -2
  104. package/templates/nextjs/base/src/{components/products → ui/product}/variant-selector.tsx +3 -3
  105. package/templates/nextjs/base/src/ui/shared/cdn-image.tsx +26 -0
  106. package/templates/nextjs/base/src/{components → ui}/shared/loading-spinner.tsx +2 -2
  107. package/templates/nextjs/base/tailwind.config.ts +12 -0
  108. package/templates/nextjs/designs/passepartout/app-overlay/layout.tsx.ejs +253 -0
  109. package/templates/nextjs/designs/passepartout/globals.css +412 -0
  110. package/templates/nextjs/designs/passepartout/messages-patch/en.json +87 -0
  111. package/templates/nextjs/designs/passepartout/messages-patch/he.json +87 -0
  112. package/templates/nextjs/designs/passepartout/ui/cart/cart-bundle-offer.tsx +111 -0
  113. package/templates/nextjs/designs/passepartout/ui/cart/cart-nudges.tsx +39 -0
  114. package/templates/nextjs/designs/passepartout/ui/cart/cart-upgrade-banner.tsx +141 -0
  115. package/templates/nextjs/designs/passepartout/ui/cart/cart-view.tsx +149 -0
  116. package/templates/nextjs/designs/passepartout/ui/cart/free-shipping-bar.tsx +62 -0
  117. package/templates/nextjs/designs/passepartout/ui/cart/reservation-countdown.tsx +103 -0
  118. package/templates/nextjs/designs/passepartout/ui/home/home-client.tsx +401 -0
  119. package/templates/nextjs/designs/passepartout/ui/layout/announcement-bar.tsx +139 -0
  120. package/templates/nextjs/designs/passepartout/ui/layout/cart-link.tsx +45 -0
  121. package/templates/nextjs/designs/passepartout/ui/layout/faq-section.tsx +103 -0
  122. package/templates/nextjs/designs/passepartout/ui/layout/site-footer.tsx +159 -0
  123. package/templates/nextjs/designs/passepartout/ui/layout/site-header.tsx.ejs +155 -0
  124. package/templates/nextjs/designs/passepartout/ui/layout/trust-icons.tsx +60 -0
  125. package/templates/nextjs/designs/passepartout/ui/layout/whatsapp-button.tsx +34 -0
  126. package/templates/nextjs/designs/passepartout/ui/product/discount-badge.tsx +22 -0
  127. package/templates/nextjs/designs/passepartout/ui/product/frequently-bought-together.tsx +205 -0
  128. package/templates/nextjs/designs/passepartout/ui/product/price-display.tsx +111 -0
  129. package/templates/nextjs/designs/passepartout/ui/product/product-card.tsx +265 -0
  130. package/templates/nextjs/designs/passepartout/ui/product/product-client-section.tsx +667 -0
  131. package/templates/nextjs/designs/passepartout/ui/product/product-grid.tsx +35 -0
  132. package/templates/nextjs/designs/passepartout/ui/product/product-listing.tsx +427 -0
  133. package/templates/nextjs/designs/passepartout/ui/product/recommendation-section.tsx +113 -0
  134. package/templates/nextjs/designs/passepartout/ui/product/review-form.tsx +294 -0
  135. package/templates/nextjs/designs/passepartout/ui/product/reviews-section.tsx.ejs +96 -0
  136. package/templates/nextjs/designs/passepartout/ui/product/stock-badge.tsx +52 -0
  137. package/templates/nextjs/designs/passepartout/ui/product/variant-selector.tsx +307 -0
  138. package/templates/nextjs/designs/passepartout/ui/shared/fly-to-cart.ts +85 -0
  139. package/templates/nextjs/designs/passepartout/ui/shared/loading-spinner.tsx +33 -0
  140. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +87 -0
  141. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +121 -0
  142. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +25 -0
  143. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +97 -0
  144. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +103 -0
  145. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +106 -0
  146. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +117 -0
  147. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +52 -0
  148. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +79 -0
  149. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +19 -0
  150. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +23 -0
  151. package/templates/nextjs/ui-canvas/home/hero-section.tsx +21 -0
  152. package/templates/nextjs/ui-canvas/home/home-client.tsx +26 -0
  153. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +101 -0
  154. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +71 -0
  155. package/templates/nextjs/ui-canvas/layout/header-account.tsx +31 -0
  156. package/templates/nextjs/ui-canvas/layout/language-switcher.tsx.ejs +74 -0
  157. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +34 -0
  158. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +82 -0
  159. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +119 -0
  160. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +443 -0
  161. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +17 -0
  162. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +166 -0
  163. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +163 -0
  164. package/templates/nextjs/ui-canvas/product/price-display.tsx +50 -0
  165. package/templates/nextjs/ui-canvas/product/product-card.tsx +197 -0
  166. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +352 -0
  167. package/templates/nextjs/ui-canvas/product/product-grid.tsx +27 -0
  168. package/templates/nextjs/ui-canvas/product/product-listing.tsx +224 -0
  169. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +95 -0
  170. package/templates/nextjs/ui-canvas/product/review-form.tsx +269 -0
  171. package/templates/nextjs/ui-canvas/product/reviews-section.tsx +78 -0
  172. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +43 -0
  173. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +210 -0
  174. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +29 -0
  175. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +25 -0
  176. package/templates/nextjs/base/src/app/home-client.tsx +0 -98
  177. package/templates/nextjs/base/src/components/products/allergen-chips.tsx +0 -78
  178. /package/templates/nextjs/base/src/{lib → core/lib}/auth.ts +0 -0
  179. /package/templates/nextjs/base/src/{lib → core/lib}/csrf.ts +0 -0
  180. /package/templates/nextjs/base/src/{lib → core/lib}/navigation.tsx.ejs +0 -0
  181. /package/templates/nextjs/base/src/{lib → core/lib}/nonce.ts +0 -0
  182. /package/templates/nextjs/base/src/{lib → core/lib}/seo.ts +0 -0
  183. /package/templates/nextjs/base/src/{lib → core/lib}/store-info.ts +0 -0
  184. /package/templates/nextjs/base/src/{lib → core/lib}/translations.ts.ejs +0 -0
  185. /package/templates/nextjs/base/src/{lib → core/lib}/utils.ts +0 -0
  186. /package/templates/nextjs/base/src/{lib → core/lib}/validation.ts +0 -0
  187. /package/templates/nextjs/base/src/{components/content → ui/layout}/announcement-bar.tsx.ejs +0 -0
  188. /package/templates/nextjs/base/src/{components → ui}/layout/language-switcher.tsx.ejs +0 -0
  189. /package/templates/nextjs/base/src/{components/content → ui/layout}/site-footer.tsx.ejs +0 -0
@@ -0,0 +1,294 @@
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
+ export function ReviewForm({ productId }: ReviewFormProps) {
29
+ const [stage, setStage] = useState<Stage>({ kind: 'loading' });
30
+ const t = useTranslations('reviews');
31
+
32
+ useEffect(() => {
33
+ let cancelled = false;
34
+ async function load() {
35
+ const auth = await checkAuthStatus();
36
+ if (cancelled) return;
37
+ if (!auth.isLoggedIn) {
38
+ setStage({ kind: 'signed_out' });
39
+ return;
40
+ }
41
+ try {
42
+ const me = await getClient().getMyProductReview(productId);
43
+ if (cancelled) return;
44
+ if (!me.eligible) {
45
+ setStage({ kind: 'not_eligible', reason: me.reason });
46
+ return;
47
+ }
48
+ if (me.myReview) {
49
+ setStage({ kind: 'edit', review: me.myReview });
50
+ return;
51
+ }
52
+ setStage({ kind: 'submit' });
53
+ } catch {
54
+ if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
55
+ }
56
+ }
57
+ void load();
58
+ return () => {
59
+ cancelled = true;
60
+ };
61
+ }, [productId]);
62
+
63
+ if (stage.kind === 'loading') {
64
+ return <div className="text-muted-foreground text-sm">{t('loading')}</div>;
65
+ }
66
+
67
+ if (stage.kind === 'signed_out') {
68
+ return (
69
+ <div className="border p-4">
70
+ <p className="text-sm">
71
+ <a href="/account/login" className="font-medium underline">
72
+ {t('signIn')}
73
+ </a>{' '}
74
+ {t('signInSuffix')}
75
+ </p>
76
+ </div>
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 (
111
+ <div className="bg-muted/30 border p-4">
112
+ <p className="text-muted-foreground text-sm">{message}</p>
113
+ </div>
114
+ );
115
+ }
116
+
117
+ function SubmitReviewBlock({ productId }: { productId: string }) {
118
+ return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
119
+ }
120
+
121
+ function EditReviewBlock({
122
+ productId,
123
+ initial,
124
+ onDeleted,
125
+ }: {
126
+ productId: string;
127
+ initial: ProductReview;
128
+ onDeleted: () => void;
129
+ }) {
130
+ const [deleting, setDeleting] = useState(false);
131
+ const t = useTranslations('reviews');
132
+ const [deleteError, setDeleteError] = useState<string | null>(null);
133
+
134
+ async function handleDelete() {
135
+ if (!window.confirm(t('confirmDelete'))) return;
136
+ setDeleting(true);
137
+ setDeleteError(null);
138
+ try {
139
+ await getClient().deleteMyProductReview(productId);
140
+ onDeleted();
141
+ window.location.reload();
142
+ } catch {
143
+ setDeleteError(t('deleteFailed'));
144
+ } finally {
145
+ setDeleting(false);
146
+ }
147
+ }
148
+
149
+ return (
150
+ <div className="space-y-3">
151
+ <ReviewEditor
152
+ productId={productId}
153
+ mode="edit"
154
+ initialRating={initial.rating}
155
+ initialBody={initial.body ?? ''}
156
+ />
157
+ <div className="border-border bg-muted/40 flex items-center justify-between border p-3">
158
+ <p className="text-destructive text-xs">{t('startOver')}</p>
159
+ <button
160
+ type="button"
161
+ onClick={handleDelete}
162
+ disabled={deleting}
163
+ className="text-destructive text-xs font-medium underline disabled:opacity-50"
164
+ >
165
+ {deleting ? t('deleting') : t('deleteReview')}
166
+ </button>
167
+ </div>
168
+ {deleteError && (
169
+ <p role="alert" className="text-sm text-red-700">
170
+ {deleteError}
171
+ </p>
172
+ )}
173
+ </div>
174
+ );
175
+ }
176
+
177
+ /**
178
+ * The actual form. Same shape for create and edit — only the API method
179
+ * and the heading differ. Optimistic UX: success state + page reload to
180
+ * let the server-rendered reviews list pick up the change.
181
+ */
182
+ function ReviewEditor({
183
+ productId,
184
+ mode,
185
+ initialRating,
186
+ initialBody,
187
+ }: {
188
+ productId: string;
189
+ mode: 'create' | 'edit';
190
+ initialRating: number;
191
+ initialBody: string;
192
+ }) {
193
+ const [rating, setRating] = useState(initialRating);
194
+ const t = useTranslations('reviews');
195
+ const [body, setBody] = useState(initialBody);
196
+ const [submitting, setSubmitting] = useState(false);
197
+ const [error, setError] = useState<string | null>(null);
198
+ const [success, setSuccess] = useState(false);
199
+
200
+ async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
201
+ event.preventDefault();
202
+ setError(null);
203
+ setSubmitting(true);
204
+ try {
205
+ const client = getClient();
206
+ const input = { rating, body: body.trim() || undefined };
207
+ if (mode === 'edit') {
208
+ await client.updateMyProductReview(productId, input);
209
+ } else {
210
+ await client.submitProductReview(productId, input);
211
+ }
212
+ setSuccess(true);
213
+ setTimeout(() => window.location.reload(), 1200);
214
+ } catch (err) {
215
+ const status = (err as { status?: number })?.status;
216
+ if (status === 409) {
217
+ setError(t('alreadySubmitted'));
218
+ } else if (status === 403) {
219
+ setError(t('onlyPurchasers'));
220
+ } else if (status === 429) {
221
+ setError(t('tooMany'));
222
+ } else {
223
+ setError(
224
+ mode === 'edit' ? t('updateFailed') : t('submitFailed')
225
+ );
226
+ }
227
+ } finally {
228
+ setSubmitting(false);
229
+ }
230
+ }
231
+
232
+ if (success) {
233
+ return (
234
+ <p className="border-border bg-surface text-foreground border p-3 text-sm">
235
+ {mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}
236
+ </p>
237
+ );
238
+ }
239
+
240
+ return (
241
+ <form onSubmit={handleSubmit} className="space-y-3 border p-4">
242
+ <h3 className="font-medium">{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
243
+
244
+ <fieldset>
245
+ <legend className="mb-1 text-sm">{t('yourRating')}</legend>
246
+ <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
247
+ {[1, 2, 3, 4, 5].map((n) => (
248
+ <button
249
+ key={n}
250
+ type="button"
251
+ role="radio"
252
+ aria-checked={rating === n}
253
+ onClick={() => setRating(n)}
254
+ className={`text-2xl leading-none ${n <= rating ? 'text-accent' : 'text-border'}`}
255
+ >
256
+ ★
257
+ </button>
258
+ ))}
259
+ </div>
260
+ </fieldset>
261
+
262
+ <label className="block text-sm">
263
+ {t('yourReview')} <span className="text-muted-foreground text-xs">({t('optionalField')})</span>
264
+ <textarea
265
+ value={body}
266
+ onChange={(event) => setBody(event.target.value)}
267
+ maxLength={5000}
268
+ rows={4}
269
+ className="mt-1 block w-full rounded border px-2 py-1.5 text-sm"
270
+ />
271
+ </label>
272
+
273
+ {error && (
274
+ <p role="alert" className="text-sm text-red-700">
275
+ {error}
276
+ </p>
277
+ )}
278
+
279
+ <button
280
+ type="submit"
281
+ disabled={submitting}
282
+ className="bg-primary text-primary-foreground inline-flex items-center px-4 py-2 text-sm font-semibold disabled:opacity-50"
283
+ >
284
+ {submitting
285
+ ? mode === 'edit'
286
+ ? t('saving')
287
+ : t('submittingBtn')
288
+ : mode === 'edit'
289
+ ? t('saveChanges')
290
+ : t('submitReview')}
291
+ </button>
292
+ </form>
293
+ );
294
+ }
@@ -0,0 +1,96 @@
1
+ import type { ProductReview } from 'brainerce';
2
+ import { getServerClient } from '@/core/lib/brainerce';
3
+ import { ReviewForm } from './review-form';
4
+
5
+ // Server component — it renders before any client i18n context exists, so the
6
+ // three wrapper strings live here, keyed by locale. The store's default
7
+ // language is baked in at scaffold time as the fallback.
8
+ const STRINGS: Record<string, { title: string; empty: string; verified: string }> = {
9
+ he: { title: 'ביקורות', empty: 'אין עדיין ביקורות — היו הראשונים לשתף.', verified: 'רכישה מאומתת' },
10
+ en: { title: 'Reviews', empty: 'No reviews yet — be the first to share your experience.', verified: 'Verified purchase' },
11
+ };
12
+ const DEFAULT_LOCALE = '<%= language %>';
13
+
14
+ interface ReviewsSectionProps {
15
+ productId: string;
16
+ initialReviews?: ProductReview[];
17
+ locale?: string;
18
+ /** Where to send users back to after submit (defaults to the current product URL). */
19
+ returnUrl?: string;
20
+ }
21
+
22
+ /**
23
+ * Renders the visible reviews for a product plus a submit form.
24
+ *
25
+ * Server component — fetches with the SDK on the server so reviews are in
26
+ * the initial HTML payload (good for SEO; JSON-LD on the same page already
27
+ * carries `aggregateRating` when reviewCount > 0).
28
+ */
29
+ export async function ReviewsSection({
30
+ productId,
31
+ initialReviews,
32
+ locale = DEFAULT_LOCALE,
33
+ }: ReviewsSectionProps) {
34
+ const s = STRINGS[locale] ?? STRINGS[DEFAULT_LOCALE] ?? STRINGS.en;
35
+ let reviews: ProductReview[] = initialReviews ?? [];
36
+
37
+ if (!initialReviews) {
38
+ try {
39
+ const result = await getServerClient().listProductReviews(productId, { page: 1, limit: 20 });
40
+ reviews = result.data;
41
+ } catch {
42
+ // Reviews disabled at store level or network error — render the form anyway.
43
+ reviews = [];
44
+ }
45
+ }
46
+
47
+ return (
48
+ <section className="mt-8" aria-labelledby="reviews-heading">
49
+ <h2 id="reviews-heading" className="mb-4 text-xl font-normal">
50
+ {s.title}
51
+ </h2>
52
+
53
+ {reviews.length === 0 ? (
54
+ <p className="text-muted-foreground mb-6 text-sm">{s.empty}</p>
55
+ ) : (
56
+ <ul className="mb-6 space-y-4">
57
+ {reviews.map((review) => (
58
+ <ReviewCard key={review.id} review={review} verifiedLabel={s.verified} />
59
+ ))}
60
+ </ul>
61
+ )}
62
+
63
+ <ReviewForm productId={productId} />
64
+ </section>
65
+ );
66
+ }
67
+
68
+ function ReviewCard({ review, verifiedLabel }: { review: ProductReview; verifiedLabel: string }) {
69
+ return (
70
+ <li className="border-border bg-surface border p-4">
71
+ <header className="flex flex-wrap items-center gap-2">
72
+ <Stars rating={review.rating} />
73
+ <span className="text-sm font-medium">{review.authorName}</span>
74
+ {review.verifiedPurchase && (
75
+ <span className="text-accent text-xs tracking-[0.08em]">{verifiedLabel}</span>
76
+ )}
77
+ <time className="text-muted-foreground ms-auto text-xs">
78
+ {new Date(review.createdAt).toLocaleDateString()}
79
+ </time>
80
+ </header>
81
+ {review.body && <p className="mt-2 whitespace-pre-line break-words text-sm">{review.body}</p>}
82
+ </li>
83
+ );
84
+ }
85
+
86
+ function Stars({ rating }: { rating: number }) {
87
+ return (
88
+ <span aria-label={`${rating} of 5 stars`} className="inline-flex">
89
+ {[1, 2, 3, 4, 5].map((n) => (
90
+ <span key={n} className={n <= rating ? 'text-accent' : 'text-border'}>
91
+ ★
92
+ </span>
93
+ ))}
94
+ </span>
95
+ );
96
+ }
@@ -0,0 +1,52 @@
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
+ * Stock as a museum placard caption — silence means available.
15
+ * The placard only speaks when scarcity or absence needs saying:
16
+ * low stock gets a quiet terracotta dot, absence gets terracotta text.
17
+ */
18
+ export function StockBadge({ inventory, lowStockThreshold = 5, className }: StockBadgeProps) {
19
+ const t = useTranslations('productDetail');
20
+
21
+ const caption = 'text-[0.6875rem] tracking-[0.08em]';
22
+
23
+ if (!inventory) {
24
+ return <span className={cn('text-destructive', caption, className)}>{t('outOfStock')}</span>;
25
+ }
26
+
27
+ const { trackingMode, inStock, available } = inventory;
28
+
29
+ if (trackingMode === 'DISABLED') {
30
+ return <span className={cn('text-destructive', caption, className)}>{t('unavailable')}</span>;
31
+ }
32
+ if (!inStock) {
33
+ return <span className={cn('text-destructive', caption, className)}>{t('outOfStock')}</span>;
34
+ }
35
+ if (trackingMode === 'TRACKED' && available <= lowStockThreshold) {
36
+ return (
37
+ <span
38
+ className={cn(
39
+ 'text-muted-foreground inline-flex items-center gap-1.5',
40
+ caption,
41
+ className
42
+ )}
43
+ >
44
+ <span aria-hidden="true" className="bg-destructive h-1.5 w-1.5 rounded-full" />
45
+ {t('onlyLeft').replace('{available}', String(available))}
46
+ </span>
47
+ );
48
+ }
49
+
50
+ // In stock, no scarcity — the placard stays silent.
51
+ return null;
52
+ }