create-brainerce-store 1.51.0 → 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 (170) hide show
  1. package/README.md +72 -0
  2. package/dist/index.js +9 -68
  3. package/messages/en.json +32 -0
  4. package/messages/he.json +32 -0
  5. package/package.json +1 -1
  6. package/templates/nextjs/base/.claude/commands/design.md +9 -0
  7. package/templates/nextjs/base/AI-GUIDE.md +52 -3
  8. package/templates/nextjs/base/CLAUDE.md +10 -0
  9. package/templates/nextjs/base/package.json.ejs +52 -39
  10. package/templates/nextjs/base/src/app/globals.css +36 -30
  11. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +14 -10
  12. package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
  13. package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
  14. package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
  15. package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
  16. package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
  17. package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
  18. package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
  19. package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
  20. package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
  21. package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
  22. package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
  23. package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
  24. package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
  25. package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
  26. package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
  27. package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
  28. package/templates/nextjs/base/src/ui/cart/cart-bundle-offer.tsx +17 -11
  29. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +2 -8
  30. package/templates/nextjs/base/src/ui/cart/cart-nudges.tsx +28 -39
  31. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +3 -1
  32. package/templates/nextjs/base/src/ui/cart/cart-upgrade-banner.tsx +8 -23
  33. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +18 -27
  34. package/templates/nextjs/base/src/ui/cart/coupon-input.tsx +10 -21
  35. package/templates/nextjs/base/src/ui/cart/free-shipping-bar.tsx +2 -3
  36. package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +95 -103
  37. package/templates/nextjs/base/src/ui/home/hero-section.tsx +4 -6
  38. package/templates/nextjs/base/src/ui/layout/announcement-bar.tsx.ejs +116 -125
  39. package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -103
  40. package/templates/nextjs/base/src/ui/layout/header-account.tsx +2 -17
  41. package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -70
  42. package/templates/nextjs/base/src/ui/layout/site-footer.tsx.ejs +144 -164
  43. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +152 -182
  44. package/templates/nextjs/base/src/ui/product/customization-fields.tsx +456 -444
  45. package/templates/nextjs/base/src/ui/product/discount-badge.tsx +18 -22
  46. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +15 -27
  47. package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -175
  48. package/templates/nextjs/base/src/ui/product/price-display.tsx +3 -2
  49. package/templates/nextjs/base/src/ui/product/product-card.tsx +238 -271
  50. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +455 -470
  51. package/templates/nextjs/base/src/ui/product/product-listing.tsx +96 -79
  52. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +102 -107
  53. package/templates/nextjs/base/src/ui/product/review-form.tsx +44 -43
  54. package/templates/nextjs/{designs/passepartout → base/src}/ui/product/reviews-section.tsx.ejs +108 -96
  55. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +61 -63
  56. package/templates/nextjs/base/tailwind.config.ts +69 -42
  57. package/templates/nextjs/designs/{passepartout → atelier}/app-overlay/layout.tsx.ejs +23 -25
  58. package/templates/nextjs/designs/atelier/globals.css +396 -0
  59. package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
  60. package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
  61. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-bundle-offer.tsx +110 -111
  62. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
  63. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
  64. package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
  65. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
  66. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-upgrade-banner.tsx +123 -141
  67. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
  68. package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
  69. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/free-shipping-bar.tsx +77 -62
  70. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/reservation-countdown.tsx +89 -103
  71. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
  72. package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
  73. package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
  74. package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
  75. package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
  76. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
  77. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
  78. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
  79. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
  80. package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
  81. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
  82. package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
  83. package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
  84. package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
  85. package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
  86. package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
  87. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
  88. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
  89. package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
  90. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/discount-badge.tsx +17 -22
  91. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/frequently-bought-together.tsx +196 -205
  92. package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
  93. package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
  94. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
  95. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
  96. package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
  97. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
  98. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
  99. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/review-form.tsx +267 -294
  100. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
  101. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
  102. package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
  103. package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
  104. package/templates/nextjs/designs/{passepartout → atelier}/ui/shared/fly-to-cart.ts +86 -85
  105. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
  106. package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
  107. package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
  108. package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
  109. package/templates/nextjs/themes/luxury/globals.css +405 -399
  110. package/templates/nextjs/themes/minimal/globals.css +36 -30
  111. package/templates/nextjs/themes/playful/globals.css +406 -400
  112. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +2 -0
  113. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +2 -0
  114. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +2 -0
  115. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +2 -0
  116. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +2 -0
  117. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +2 -2
  118. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +2 -0
  119. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +2 -0
  120. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +2 -0
  121. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +1 -1
  122. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +1 -1
  123. package/templates/nextjs/ui-canvas/home/hero-section.tsx +1 -1
  124. package/templates/nextjs/ui-canvas/home/home-client.tsx +1 -1
  125. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +1 -1
  126. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +2 -2
  127. package/templates/nextjs/ui-canvas/layout/header-account.tsx +1 -1
  128. package/templates/nextjs/ui-canvas/layout/language-switcher.tsx.ejs +2 -0
  129. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +2 -0
  130. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +2 -2
  131. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +2 -2
  132. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +2 -0
  133. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +2 -0
  134. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +2 -0
  135. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +2 -0
  136. package/templates/nextjs/ui-canvas/product/price-display.tsx +2 -0
  137. package/templates/nextjs/ui-canvas/product/product-card.tsx +1 -1
  138. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +1 -1
  139. package/templates/nextjs/ui-canvas/product/product-grid.tsx +1 -1
  140. package/templates/nextjs/ui-canvas/product/product-listing.tsx +1 -1
  141. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +4 -0
  142. package/templates/nextjs/ui-canvas/product/review-form.tsx +29 -32
  143. package/templates/nextjs/ui-canvas/product/{reviews-section.tsx → reviews-section.tsx.ejs} +26 -8
  144. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +2 -0
  145. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +2 -0
  146. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +2 -0
  147. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +2 -0
  148. package/templates/nextjs/base/src/ui/product/reviews-section.tsx +0 -85
  149. package/templates/nextjs/designs/passepartout/globals.css +0 -412
  150. package/templates/nextjs/designs/passepartout/messages-patch/en.json +0 -87
  151. package/templates/nextjs/designs/passepartout/messages-patch/he.json +0 -87
  152. package/templates/nextjs/designs/passepartout/ui/cart/cart-nudges.tsx +0 -39
  153. package/templates/nextjs/designs/passepartout/ui/cart/cart-view.tsx +0 -149
  154. package/templates/nextjs/designs/passepartout/ui/home/home-client.tsx +0 -401
  155. package/templates/nextjs/designs/passepartout/ui/layout/announcement-bar.tsx +0 -139
  156. package/templates/nextjs/designs/passepartout/ui/layout/cart-link.tsx +0 -45
  157. package/templates/nextjs/designs/passepartout/ui/layout/faq-section.tsx +0 -103
  158. package/templates/nextjs/designs/passepartout/ui/layout/site-footer.tsx +0 -159
  159. package/templates/nextjs/designs/passepartout/ui/layout/site-header.tsx.ejs +0 -155
  160. package/templates/nextjs/designs/passepartout/ui/layout/trust-icons.tsx +0 -60
  161. package/templates/nextjs/designs/passepartout/ui/layout/whatsapp-button.tsx +0 -34
  162. package/templates/nextjs/designs/passepartout/ui/product/price-display.tsx +0 -111
  163. package/templates/nextjs/designs/passepartout/ui/product/product-card.tsx +0 -265
  164. package/templates/nextjs/designs/passepartout/ui/product/product-client-section.tsx +0 -667
  165. package/templates/nextjs/designs/passepartout/ui/product/product-grid.tsx +0 -35
  166. package/templates/nextjs/designs/passepartout/ui/product/product-listing.tsx +0 -427
  167. package/templates/nextjs/designs/passepartout/ui/product/recommendation-section.tsx +0 -113
  168. package/templates/nextjs/designs/passepartout/ui/product/stock-badge.tsx +0 -52
  169. package/templates/nextjs/designs/passepartout/ui/product/variant-selector.tsx +0 -307
  170. package/templates/nextjs/designs/passepartout/ui/shared/loading-spinner.tsx +0 -33
@@ -1,8 +1,14 @@
1
1
  'use client';
2
2
 
3
3
  import { useEffect, useState } from 'react';
4
+ import { Star } from 'lucide-react';
4
5
  import { getClient } from '@/core/lib/brainerce';
5
6
  import { checkAuthStatus } from '@/core/lib/auth';
7
+ import { Link } from '@/core/lib/navigation';
8
+ import { useTranslations } from '@/core/lib/translations';
9
+ import { Button } from '@/components/ui/button';
10
+ import { Label } from '@/components/ui/label';
11
+ import { Textarea } from '@/components/ui/textarea';
6
12
  import type { MyProductReview, ProductReview } from 'brainerce';
7
13
 
8
14
  interface ReviewFormProps {
@@ -26,6 +32,7 @@ type Stage =
26
32
  */
27
33
  export function ReviewForm({ productId }: ReviewFormProps) {
28
34
  const [stage, setStage] = useState<Stage>({ kind: 'loading' });
35
+ const t = useTranslations('reviews');
29
36
 
30
37
  useEffect(() => {
31
38
  let cancelled = false;
@@ -59,17 +66,17 @@ export function ReviewForm({ productId }: ReviewFormProps) {
59
66
  }, [productId]);
60
67
 
61
68
  if (stage.kind === 'loading') {
62
- return <div className="text-muted-foreground text-sm">Loading…</div>;
69
+ return <div className="text-muted-foreground text-sm">{t('loading')}</div>;
63
70
  }
64
71
 
65
72
  if (stage.kind === 'signed_out') {
66
73
  return (
67
74
  <div className="rounded-md border p-4">
68
75
  <p className="text-sm">
69
- <a href="/account/login" className="font-medium underline">
70
- Sign in
71
- </a>{' '}
72
- to leave a review for this product.
76
+ <Link href="/account/login" className="font-medium underline">
77
+ {t('signIn')}
78
+ </Link>{' '}
79
+ {t('signInSuffix')}
73
80
  </p>
74
81
  </div>
75
82
  );
@@ -93,16 +100,17 @@ export function ReviewForm({ productId }: ReviewFormProps) {
93
100
  }
94
101
 
95
102
  function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
103
+ const t = useTranslations('reviews');
96
104
  let message: string;
97
105
  switch (reason) {
98
106
  case 'no_eligible_order':
99
- message = 'Only customers who purchased this product can leave a review.';
107
+ message = t('onlyPurchasers');
100
108
  break;
101
109
  case 'reviews_disabled':
102
- message = 'Reviews are not enabled for this store.';
110
+ message = t('reviewsDisabled');
103
111
  break;
104
112
  default:
105
- message = 'You cannot review this product right now.';
113
+ message = t('cannotReview');
106
114
  }
107
115
  return (
108
116
  <div className="bg-muted/30 rounded-md border p-4">
@@ -125,10 +133,11 @@ function EditReviewBlock({
125
133
  onDeleted: () => void;
126
134
  }) {
127
135
  const [deleting, setDeleting] = useState(false);
136
+ const t = useTranslations('reviews');
128
137
  const [deleteError, setDeleteError] = useState<string | null>(null);
129
138
 
130
139
  async function handleDelete() {
131
- if (!window.confirm('Delete your review for this product?')) return;
140
+ if (!window.confirm(t('confirmDelete'))) return;
132
141
  setDeleting(true);
133
142
  setDeleteError(null);
134
143
  try {
@@ -136,7 +145,7 @@ function EditReviewBlock({
136
145
  onDeleted();
137
146
  window.location.reload();
138
147
  } catch {
139
- setDeleteError('Could not delete your review. Please try again.');
148
+ setDeleteError(t('deleteFailed'));
140
149
  } finally {
141
150
  setDeleting(false);
142
151
  }
@@ -151,14 +160,14 @@ function EditReviewBlock({
151
160
  initialBody={initial.body ?? ''}
152
161
  />
153
162
  <div className="flex items-center justify-between rounded-md border border-red-100 bg-red-50/50 p-3">
154
- <p className="text-xs text-red-700">Want to start over? You can delete your review.</p>
163
+ <p className="text-xs text-red-700">{t('startOver')}</p>
155
164
  <button
156
165
  type="button"
157
166
  onClick={handleDelete}
158
167
  disabled={deleting}
159
168
  className="text-xs font-medium text-red-700 underline disabled:opacity-50"
160
169
  >
161
- {deleting ? 'Deleting…' : 'Delete review'}
170
+ {deleting ? t('deleting') : t('deleteReview')}
162
171
  </button>
163
172
  </div>
164
173
  {deleteError && (
@@ -187,6 +196,7 @@ function ReviewEditor({
187
196
  initialBody: string;
188
197
  }) {
189
198
  const [rating, setRating] = useState(initialRating);
199
+ const t = useTranslations('reviews');
190
200
  const [body, setBody] = useState(initialBody);
191
201
  const [submitting, setSubmitting] = useState(false);
192
202
  const [error, setError] = useState<string | null>(null);
@@ -209,17 +219,13 @@ function ReviewEditor({
209
219
  } catch (err) {
210
220
  const status = (err as { status?: number })?.status;
211
221
  if (status === 409) {
212
- setError("You've already submitted a review for this product.");
222
+ setError(t('alreadySubmitted'));
213
223
  } else if (status === 403) {
214
- setError('Only customers who purchased this product can leave a review.');
224
+ setError(t('onlyPurchasers'));
215
225
  } else if (status === 429) {
216
- setError('Too many submissions. Please try again in a few minutes.');
226
+ setError(t('tooMany'));
217
227
  } else {
218
- setError(
219
- mode === 'edit'
220
- ? 'Could not update your review. Please try again.'
221
- : 'Could not submit your review. Please try again.'
222
- );
228
+ setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
223
229
  }
224
230
  } finally {
225
231
  setSubmitting(false);
@@ -229,20 +235,18 @@ function ReviewEditor({
229
235
  if (success) {
230
236
  return (
231
237
  <p className="rounded-md border border-emerald-200 bg-emerald-50 p-3 text-sm text-emerald-700">
232
- {mode === 'edit'
233
- ? 'Thanks! Your review has been updated.'
234
- : 'Thanks! Your review has been submitted.'}
238
+ {mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}
235
239
  </p>
236
240
  );
237
241
  }
238
242
 
239
243
  return (
240
244
  <form onSubmit={handleSubmit} className="space-y-3 rounded-md border p-4">
241
- <h3 className="font-medium">{mode === 'edit' ? 'Edit your review' : 'Write a review'}</h3>
245
+ <h3 className="font-medium">{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
242
246
 
243
247
  <fieldset>
244
- <legend className="mb-1 text-sm">Your rating</legend>
245
- <div className="inline-flex gap-1" role="radiogroup" aria-label="Star rating">
248
+ <legend className="mb-1 text-sm">{t('yourRating')}</legend>
249
+ <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
246
250
  {[1, 2, 3, 4, 5].map((n) => (
247
251
  <button
248
252
  key={n}
@@ -250,24 +254,25 @@ function ReviewEditor({
250
254
  role="radio"
251
255
  aria-checked={rating === n}
252
256
  onClick={() => setRating(n)}
253
- className={`text-2xl leading-none ${n <= rating ? 'text-yellow-500' : 'text-gray-300'}`}
257
+ className={n <= rating ? 'text-yellow-500' : 'text-gray-300'}
254
258
  >
255
-
259
+ <Star className="h-6 w-6 fill-current" aria-hidden="true" />
256
260
  </button>
257
261
  ))}
258
262
  </div>
259
263
  </fieldset>
260
264
 
261
- <label className="block text-sm">
262
- Your review <span className="text-muted-foreground text-xs">(optional)</span>
263
- <textarea
265
+ <Label className="block text-sm font-normal">
266
+ {t('yourReview')}{' '}
267
+ <span className="text-muted-foreground text-xs">({t('optionalField')})</span>
268
+ <Textarea
264
269
  value={body}
265
270
  onChange={(event) => setBody(event.target.value)}
266
271
  maxLength={5000}
267
272
  rows={4}
268
- className="mt-1 block w-full rounded border px-2 py-1.5 text-sm"
273
+ className="mt-1 rounded"
269
274
  />
270
- </label>
275
+ </Label>
271
276
 
272
277
  {error && (
273
278
  <p role="alert" className="text-sm text-red-700">
@@ -275,19 +280,15 @@ function ReviewEditor({
275
280
  </p>
276
281
  )}
277
282
 
278
- <button
279
- type="submit"
280
- disabled={submitting}
281
- className="inline-flex items-center rounded bg-black px-4 py-2 text-sm text-white disabled:opacity-50"
282
- >
283
+ <Button type="submit" disabled={submitting}>
283
284
  {submitting
284
285
  ? mode === 'edit'
285
- ? 'Saving…'
286
- : 'Submitting…'
286
+ ? t('saving')
287
+ : t('submittingBtn')
287
288
  : mode === 'edit'
288
- ? 'Save changes'
289
- : 'Submit review'}
290
- </button>
289
+ ? t('saveChanges')
290
+ : t('submitReview')}
291
+ </Button>
291
292
  </form>
292
293
  );
293
294
  }
@@ -1,96 +1,108 @@
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
- }
1
+ import { Star } from 'lucide-react';
2
+ import type { ProductReview } from 'brainerce';
3
+ import { getServerClient } from '@/core/lib/brainerce';
4
+ import { Badge } from '@/components/ui/badge';
5
+ <% if (i18nEnabled) { %>import { getMessages, defaultLocale } from '@/i18n';<% } else { %>import { defaultLocale, messages } from '@/i18n';<% } %>
6
+ import { ReviewForm } from './review-form';
7
+
8
+ // Server component it renders before any client i18n context exists, so the
9
+ // wrapper strings (title / empty state / verified badge) are read straight
10
+ // from the `reviews` namespace in messages/, keyed by the store locale.
11
+ type ReviewStrings = Record<string, string>;
12
+
13
+ <% if (i18nEnabled) { %>async function getReviewStrings(locale: string): Promise<ReviewStrings> {
14
+ return ((await getMessages(locale)).reviews ?? {}) as ReviewStrings;
15
+ }<% } else { %>async function getReviewStrings(_locale: string): Promise<ReviewStrings> {
16
+ return messages.reviews as ReviewStrings;
17
+ }<% } %>
18
+
19
+ interface ReviewsSectionProps {
20
+ productId: string;
21
+ initialReviews?: ProductReview[];
22
+ locale?: string;
23
+ /** Where to send users back to after submit (defaults to the current product URL). */
24
+ returnUrl?: string;
25
+ }
26
+
27
+ /**
28
+ * Renders the visible reviews for a product plus a submit form.
29
+ *
30
+ * Server component — fetches with the SDK on the server so reviews are in
31
+ * the initial HTML payload (good for SEO; JSON-LD on the same page already
32
+ * carries `aggregateRating` when reviewCount > 0).
33
+ */
34
+ export async function ReviewsSection({
35
+ productId,
36
+ initialReviews,
37
+ locale = defaultLocale,
38
+ }: ReviewsSectionProps) {
39
+ const t = await getReviewStrings(locale);
40
+ let reviews: ProductReview[] = initialReviews ?? [];
41
+
42
+ if (!initialReviews) {
43
+ try {
44
+ const result = await getServerClient().listProductReviews(productId, { page: 1, limit: 20 });
45
+ reviews = result.data;
46
+ } catch {
47
+ // Review listing disabled at store level or network error — render the form anyway.
48
+ reviews = [];
49
+ }
50
+ }
51
+
52
+ return (
53
+ <section className="mt-8" aria-labelledby="reviews-heading">
54
+ <h2 id="reviews-heading" className="mb-4 text-xl font-semibold">
55
+ {t.title}
56
+ </h2>
57
+
58
+ {reviews.length === 0 ? (
59
+ <p className="text-muted-foreground mb-6 text-sm">{t.noReviews}</p>
60
+ ) : (
61
+ <ul className="mb-6 space-y-4">
62
+ {reviews.map((review) => (
63
+ <ReviewCard key={review.id} review={review} verifiedLabel={t.verifiedPurchase} />
64
+ ))}
65
+ </ul>
66
+ )}
67
+
68
+ <ReviewForm productId={productId} />
69
+ </section>
70
+ );
71
+ }
72
+
73
+ function ReviewCard({ review, verifiedLabel }: { review: ProductReview; verifiedLabel: string }) {
74
+ return (
75
+ <li className="rounded-md border p-4">
76
+ <header className="flex flex-wrap items-center gap-2">
77
+ <Stars rating={review.rating} />
78
+ <span className="text-sm font-medium">{review.authorName}</span>
79
+ {review.verifiedPurchase && (
80
+ <Badge
81
+ variant="outline"
82
+ className="rounded border-transparent bg-emerald-50 px-2 py-0.5 font-normal text-emerald-700"
83
+ >
84
+ {verifiedLabel}
85
+ </Badge>
86
+ )}
87
+ <time className="text-muted-foreground ms-auto text-xs">
88
+ {new Date(review.createdAt).toLocaleDateString()}
89
+ </time>
90
+ </header>
91
+ {review.body && <p className="mt-2 whitespace-pre-line break-words text-sm">{review.body}</p>}
92
+ </li>
93
+ );
94
+ }
95
+
96
+ function Stars({ rating }: { rating: number }) {
97
+ return (
98
+ <span aria-label={`${rating} of 5 stars`} className="inline-flex">
99
+ {[1, 2, 3, 4, 5].map((n) => (
100
+ <Star
101
+ key={n}
102
+ className={`h-4 w-4 fill-current ${n <= rating ? 'text-yellow-500' : 'text-gray-300'}`}
103
+ aria-hidden="true"
104
+ />
105
+ ))}
106
+ </span>
107
+ );
108
+ }
@@ -1,63 +1,61 @@
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
- export function StockBadge({ inventory, lowStockThreshold = 5, className }: StockBadgeProps) {
14
- const t = useTranslations('productDetail');
15
- const label = getStockLabel(inventory, lowStockThreshold, t);
16
- const color = getStockColor(inventory, lowStockThreshold);
17
-
18
- return (
19
- <span
20
- className={cn(
21
- 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
22
- color,
23
- className
24
- )}
25
- >
26
- {label}
27
- </span>
28
- );
29
- }
30
-
31
- function getStockLabel(
32
- inventory: InventoryInfo | null | undefined,
33
- lowStockThreshold: number,
34
- t: (key: string) => string
35
- ): string {
36
- if (!inventory) return t('outOfStock');
37
-
38
- const { trackingMode, inStock, available } = inventory;
39
-
40
- if (trackingMode === 'DISABLED') return t('unavailable');
41
- if (!inStock) return t('outOfStock');
42
- if (trackingMode === 'UNLIMITED') return t('inStock');
43
-
44
- // TRACKED — show actual quantity
45
- if (available <= lowStockThreshold) {
46
- return t('onlyLeft').replace('{available}', String(available));
47
- }
48
- return t('availableInStock').replace('{available}', String(available));
49
- }
50
-
51
- function getStockColor(
52
- inventory: InventoryInfo | null | undefined,
53
- lowStockThreshold: number
54
- ): string {
55
- if (!inventory) return 'bg-red-100 text-red-800';
56
-
57
- const { trackingMode, inStock, available } = inventory;
58
-
59
- if (trackingMode === 'DISABLED' || !inStock) return 'bg-red-100 text-red-800';
60
- if (trackingMode === 'TRACKED' && available <= lowStockThreshold)
61
- return 'bg-yellow-100 text-yellow-800';
62
- return 'bg-green-100 text-green-800';
63
- }
1
+ 'use client';
2
+
3
+ import type { InventoryInfo } from 'brainerce';
4
+ import { Badge } from '@/components/ui/badge';
5
+ import { cn } from '@/core/lib/utils';
6
+ import { useTranslations } from '@/core/lib/translations';
7
+
8
+ interface StockBadgeProps {
9
+ inventory: InventoryInfo | null | undefined;
10
+ lowStockThreshold?: number;
11
+ className?: string;
12
+ }
13
+
14
+ export function StockBadge({ inventory, lowStockThreshold = 5, className }: StockBadgeProps) {
15
+ const t = useTranslations('productDetail');
16
+ const label = getStockLabel(inventory, lowStockThreshold, t);
17
+ const color = getStockColor(inventory, lowStockThreshold);
18
+
19
+ return (
20
+ <Badge
21
+ variant="outline"
22
+ className={cn('border-transparent px-2 py-0.5 font-medium', color, className)}
23
+ >
24
+ {label}
25
+ </Badge>
26
+ );
27
+ }
28
+
29
+ function getStockLabel(
30
+ inventory: InventoryInfo | null | undefined,
31
+ lowStockThreshold: number,
32
+ t: (key: string) => string
33
+ ): string {
34
+ if (!inventory) return t('outOfStock');
35
+
36
+ const { trackingMode, inStock, available } = inventory;
37
+
38
+ if (trackingMode === 'DISABLED') return t('unavailable');
39
+ if (!inStock) return t('outOfStock');
40
+ if (trackingMode === 'UNLIMITED') return t('inStock');
41
+
42
+ // TRACKED show actual quantity
43
+ if (available <= lowStockThreshold) {
44
+ return t('onlyLeft').replace('{available}', String(available));
45
+ }
46
+ return t('availableInStock').replace('{available}', String(available));
47
+ }
48
+
49
+ function getStockColor(
50
+ inventory: InventoryInfo | null | undefined,
51
+ lowStockThreshold: number
52
+ ): string {
53
+ if (!inventory) return 'bg-red-100 text-red-800';
54
+
55
+ const { trackingMode, inStock, available } = inventory;
56
+
57
+ if (trackingMode === 'DISABLED' || !inStock) return 'bg-red-100 text-red-800';
58
+ if (trackingMode === 'TRACKED' && available <= lowStockThreshold)
59
+ return 'bg-yellow-100 text-yellow-800';
60
+ return 'bg-green-100 text-green-800';
61
+ }