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.
- package/README.md +72 -0
- package/dist/index.js +9 -68
- package/messages/en.json +32 -0
- package/messages/he.json +32 -0
- package/package.json +1 -1
- package/templates/nextjs/base/.claude/commands/design.md +9 -0
- package/templates/nextjs/base/AI-GUIDE.md +52 -3
- package/templates/nextjs/base/CLAUDE.md +10 -0
- package/templates/nextjs/base/package.json.ejs +52 -39
- package/templates/nextjs/base/src/app/globals.css +36 -30
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +14 -10
- package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
- package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
- package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
- package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
- package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
- package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
- package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
- package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
- package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
- package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
- package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
- package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
- package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
- package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
- package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
- package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
- package/templates/nextjs/base/src/ui/cart/cart-bundle-offer.tsx +17 -11
- package/templates/nextjs/base/src/ui/cart/cart-item.tsx +2 -8
- package/templates/nextjs/base/src/ui/cart/cart-nudges.tsx +28 -39
- package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +3 -1
- package/templates/nextjs/base/src/ui/cart/cart-upgrade-banner.tsx +8 -23
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +18 -27
- package/templates/nextjs/base/src/ui/cart/coupon-input.tsx +10 -21
- package/templates/nextjs/base/src/ui/cart/free-shipping-bar.tsx +2 -3
- package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +95 -103
- package/templates/nextjs/base/src/ui/home/hero-section.tsx +4 -6
- package/templates/nextjs/base/src/ui/layout/announcement-bar.tsx.ejs +116 -125
- package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -103
- package/templates/nextjs/base/src/ui/layout/header-account.tsx +2 -17
- package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -70
- package/templates/nextjs/base/src/ui/layout/site-footer.tsx.ejs +144 -164
- package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +152 -182
- package/templates/nextjs/base/src/ui/product/customization-fields.tsx +456 -444
- package/templates/nextjs/base/src/ui/product/discount-badge.tsx +18 -22
- package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +15 -27
- package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -175
- package/templates/nextjs/base/src/ui/product/price-display.tsx +3 -2
- package/templates/nextjs/base/src/ui/product/product-card.tsx +238 -271
- package/templates/nextjs/base/src/ui/product/product-client-section.tsx +455 -470
- package/templates/nextjs/base/src/ui/product/product-listing.tsx +96 -79
- package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +102 -107
- package/templates/nextjs/base/src/ui/product/review-form.tsx +44 -43
- package/templates/nextjs/{designs/passepartout → base/src}/ui/product/reviews-section.tsx.ejs +108 -96
- package/templates/nextjs/base/src/ui/product/stock-badge.tsx +61 -63
- package/templates/nextjs/base/tailwind.config.ts +69 -42
- package/templates/nextjs/designs/{passepartout → atelier}/app-overlay/layout.tsx.ejs +23 -25
- package/templates/nextjs/designs/atelier/globals.css +396 -0
- package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
- package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-bundle-offer.tsx +110 -111
- package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
- package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
- package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
- package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-upgrade-banner.tsx +123 -141
- package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
- package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/free-shipping-bar.tsx +77 -62
- package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/reservation-countdown.tsx +89 -103
- package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
- package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
- package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
- package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
- package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
- package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
- package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
- package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
- package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
- package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
- package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
- package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
- package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
- package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
- package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
- package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
- package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
- package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
- package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/product/discount-badge.tsx +17 -22
- package/templates/nextjs/designs/{passepartout → atelier}/ui/product/frequently-bought-together.tsx +196 -205
- package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
- package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
- package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
- package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
- package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
- package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
- package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/product/review-form.tsx +267 -294
- package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
- package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
- package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
- package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
- package/templates/nextjs/designs/{passepartout → atelier}/ui/shared/fly-to-cart.ts +86 -85
- package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
- package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
- package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
- package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
- package/templates/nextjs/themes/luxury/globals.css +405 -399
- package/templates/nextjs/themes/minimal/globals.css +36 -30
- package/templates/nextjs/themes/playful/globals.css +406 -400
- package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +2 -2
- package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +2 -0
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +2 -0
- package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +1 -1
- package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +1 -1
- package/templates/nextjs/ui-canvas/home/hero-section.tsx +1 -1
- package/templates/nextjs/ui-canvas/home/home-client.tsx +1 -1
- package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +1 -1
- package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +2 -2
- package/templates/nextjs/ui-canvas/layout/header-account.tsx +1 -1
- package/templates/nextjs/ui-canvas/layout/language-switcher.tsx.ejs +2 -0
- package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +2 -0
- package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +2 -2
- package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +2 -2
- package/templates/nextjs/ui-canvas/product/customization-fields.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/discount-badge.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/price-display.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/product-card.tsx +1 -1
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +1 -1
- package/templates/nextjs/ui-canvas/product/product-grid.tsx +1 -1
- package/templates/nextjs/ui-canvas/product/product-listing.tsx +1 -1
- package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +4 -0
- package/templates/nextjs/ui-canvas/product/review-form.tsx +29 -32
- package/templates/nextjs/ui-canvas/product/{reviews-section.tsx → reviews-section.tsx.ejs} +26 -8
- package/templates/nextjs/ui-canvas/product/stock-badge.tsx +2 -0
- package/templates/nextjs/ui-canvas/product/variant-selector.tsx +2 -0
- package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +2 -0
- package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +2 -0
- package/templates/nextjs/base/src/ui/product/reviews-section.tsx +0 -85
- package/templates/nextjs/designs/passepartout/globals.css +0 -412
- package/templates/nextjs/designs/passepartout/messages-patch/en.json +0 -87
- package/templates/nextjs/designs/passepartout/messages-patch/he.json +0 -87
- package/templates/nextjs/designs/passepartout/ui/cart/cart-nudges.tsx +0 -39
- package/templates/nextjs/designs/passepartout/ui/cart/cart-view.tsx +0 -149
- package/templates/nextjs/designs/passepartout/ui/home/home-client.tsx +0 -401
- package/templates/nextjs/designs/passepartout/ui/layout/announcement-bar.tsx +0 -139
- package/templates/nextjs/designs/passepartout/ui/layout/cart-link.tsx +0 -45
- package/templates/nextjs/designs/passepartout/ui/layout/faq-section.tsx +0 -103
- package/templates/nextjs/designs/passepartout/ui/layout/site-footer.tsx +0 -159
- package/templates/nextjs/designs/passepartout/ui/layout/site-header.tsx.ejs +0 -155
- package/templates/nextjs/designs/passepartout/ui/layout/trust-icons.tsx +0 -60
- package/templates/nextjs/designs/passepartout/ui/layout/whatsapp-button.tsx +0 -34
- package/templates/nextjs/designs/passepartout/ui/product/price-display.tsx +0 -111
- package/templates/nextjs/designs/passepartout/ui/product/product-card.tsx +0 -265
- package/templates/nextjs/designs/passepartout/ui/product/product-client-section.tsx +0 -667
- package/templates/nextjs/designs/passepartout/ui/product/product-grid.tsx +0 -35
- package/templates/nextjs/designs/passepartout/ui/product/product-listing.tsx +0 -427
- package/templates/nextjs/designs/passepartout/ui/product/recommendation-section.tsx +0 -113
- package/templates/nextjs/designs/passepartout/ui/product/stock-badge.tsx +0 -52
- package/templates/nextjs/designs/passepartout/ui/product/variant-selector.tsx +0 -307
- 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">
|
|
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
|
-
<
|
|
70
|
-
|
|
71
|
-
</
|
|
72
|
-
|
|
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 = '
|
|
107
|
+
message = t('onlyPurchasers');
|
|
100
108
|
break;
|
|
101
109
|
case 'reviews_disabled':
|
|
102
|
-
message = '
|
|
110
|
+
message = t('reviewsDisabled');
|
|
103
111
|
break;
|
|
104
112
|
default:
|
|
105
|
-
message = '
|
|
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('
|
|
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('
|
|
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">
|
|
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 ? '
|
|
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(
|
|
222
|
+
setError(t('alreadySubmitted'));
|
|
213
223
|
} else if (status === 403) {
|
|
214
|
-
setError('
|
|
224
|
+
setError(t('onlyPurchasers'));
|
|
215
225
|
} else if (status === 429) {
|
|
216
|
-
setError('
|
|
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' ? '
|
|
245
|
+
<h3 className="font-medium">{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
|
|
242
246
|
|
|
243
247
|
<fieldset>
|
|
244
|
-
<legend className="mb-1 text-sm">
|
|
245
|
-
<div className="inline-flex gap-1" role="radiogroup" aria-label=
|
|
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={
|
|
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
|
-
<
|
|
262
|
-
|
|
263
|
-
<
|
|
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
|
|
273
|
+
className="mt-1 rounded"
|
|
269
274
|
/>
|
|
270
|
-
</
|
|
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
|
-
<
|
|
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
|
-
? '
|
|
286
|
-
: '
|
|
286
|
+
? t('saving')
|
|
287
|
+
: t('submittingBtn')
|
|
287
288
|
: mode === 'edit'
|
|
288
|
-
? '
|
|
289
|
-
: '
|
|
290
|
-
</
|
|
289
|
+
? t('saveChanges')
|
|
290
|
+
: t('submitReview')}
|
|
291
|
+
</Button>
|
|
291
292
|
</form>
|
|
292
293
|
);
|
|
293
294
|
}
|
package/templates/nextjs/{designs/passepartout → base/src}/ui/product/reviews-section.tsx.ejs
RENAMED
|
@@ -1,96 +1,108 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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 {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (trackingMode === '
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|