create-brainerce-store 1.65.0 → 1.67.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 (49) hide show
  1. package/dist/index.js +2 -2
  2. package/messages/en.json +505 -502
  3. package/messages/he.json +505 -502
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/.env.local.ejs +45 -24
  6. package/templates/nextjs/base/.eslintrc.json +51 -57
  7. package/templates/nextjs/base/AGENTS.md.ejs +107 -81
  8. package/templates/nextjs/base/CLAUDE.md.ejs +118 -92
  9. package/templates/nextjs/base/next.config.ts +103 -86
  10. package/templates/nextjs/base/scripts/fetch-store-info.mjs +104 -97
  11. package/templates/nextjs/base/src/app/agents.md/route.ts +4 -3
  12. package/templates/nextjs/base/src/app/api/auth/me/route.ts +65 -59
  13. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +255 -242
  14. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +311 -308
  15. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +277 -276
  16. package/templates/nextjs/base/src/app/blog/rss.xml/route.ts +4 -3
  17. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +6 -5
  18. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +46 -46
  19. package/templates/nextjs/base/src/app/indexnow-key.txt/route.ts +25 -26
  20. package/templates/nextjs/base/src/app/layout.tsx.ejs +273 -257
  21. package/templates/nextjs/base/src/app/llms.txt/route.ts +4 -3
  22. package/templates/nextjs/base/src/app/opengraph-image.tsx +1 -1
  23. package/templates/nextjs/base/src/app/page.tsx +65 -64
  24. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +92 -92
  25. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +10 -5
  26. package/templates/nextjs/base/src/app/robots.ts +3 -2
  27. package/templates/nextjs/base/src/app/sitemap.ts +4 -3
  28. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +294 -292
  29. package/templates/nextjs/base/src/components/seo/article-json-ld.tsx +60 -59
  30. package/templates/nextjs/base/src/components/seo/category-json-ld.tsx +60 -61
  31. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +16 -2
  32. package/templates/nextjs/base/src/core/lib/brainerce.server.ts +81 -0
  33. package/templates/nextjs/base/src/core/lib/brainerce.ts.ejs +60 -110
  34. package/templates/nextjs/base/src/core/lib/site-url.ts +197 -0
  35. package/templates/nextjs/base/src/ui/product/faq-section.tsx.ejs +46 -0
  36. package/templates/nextjs/base/src/ui/product/review-form.tsx +294 -294
  37. package/templates/nextjs/base/src/ui/product/reviews-section.tsx.ejs +108 -108
  38. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +301 -285
  39. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +97 -96
  40. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +142 -141
  41. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +139 -138
  42. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +295 -267
  43. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -148
  44. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +72 -71
  45. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +83 -82
  46. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +120 -119
  47. package/templates/nextjs/ui-canvas/product/faq-section.tsx.ejs +54 -0
  48. package/templates/nextjs/ui-canvas/product/review-form.tsx +267 -266
  49. package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -96
@@ -1,267 +1,295 @@
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
- import { IconStar } from '@/ui/shared/icons';
9
-
10
- interface ReviewFormProps {
11
- productId: string;
12
- }
13
-
14
- type Stage =
15
- | { kind: 'loading' }
16
- | { kind: 'signed_out' }
17
- | { kind: 'not_eligible'; reason: MyProductReview['reason'] }
18
- | { kind: 'submit' }
19
- | { kind: 'edit'; review: ProductReview };
20
-
21
- /**
22
- * Single component that decides which UI to render for a customer on a PDP:
23
- * - Loading while we check auth state and eligibility
24
- * - Signed out -> sign-in CTA
25
- * - Signed in but not eligible -> "purchase this product to review"
26
- * - Eligible without review -> submit form
27
- * - Eligible with existing review -> edit/delete form (rating + body prefilled)
28
- *
29
- * DESIGN ME — review submit/edit form; auth via checkAuthStatus(), eligibility
30
- * + existing review via getClient().getMyProductReview(productId).
31
- */
32
- export function ReviewForm({ productId }: ReviewFormProps) {
33
- const [stage, setStage] = useState<Stage>({ kind: 'loading' });
34
- const t = useTranslations('reviews');
35
-
36
- useEffect(() => {
37
- let cancelled = false;
38
- async function load() {
39
- const auth = await checkAuthStatus();
40
- if (cancelled) return;
41
- if (!auth.isLoggedIn) {
42
- setStage({ kind: 'signed_out' });
43
- return;
44
- }
45
- try {
46
- const me = await getClient().getMyProductReview(productId);
47
- if (cancelled) return;
48
- if (!me.eligible) {
49
- setStage({ kind: 'not_eligible', reason: me.reason });
50
- return;
51
- }
52
- if (me.myReview) {
53
- setStage({ kind: 'edit', review: me.myReview });
54
- return;
55
- }
56
- setStage({ kind: 'submit' });
57
- } catch {
58
- if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
59
- }
60
- }
61
- void load();
62
- return () => {
63
- cancelled = true;
64
- };
65
- }, [productId]);
66
-
67
- if (stage.kind === 'loading') {
68
- return <p role="status" className="text-sm text-muted-foreground">{t('loading')}</p>;
69
- }
70
-
71
- if (stage.kind === 'signed_out') {
72
- return (
73
- <p className="text-sm text-muted-foreground">
74
- <a href="/account/login" className="font-semibold text-primary underline underline-offset-2">{t('signIn')}</a> {t('signInSuffix')}
75
- </p>
76
- );
77
- }
78
-
79
- if (stage.kind === 'not_eligible') {
80
- return <NotEligibleMessage reason={stage.reason} />;
81
- }
82
-
83
- if (stage.kind === 'edit') {
84
- return (
85
- <EditReviewBlock
86
- productId={productId}
87
- initial={stage.review}
88
- onDeleted={() => setStage({ kind: 'submit' })}
89
- />
90
- );
91
- }
92
-
93
- return <SubmitReviewBlock productId={productId} />;
94
- }
95
-
96
- function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
97
- const t = useTranslations('reviews');
98
- let message: string;
99
- switch (reason) {
100
- case 'no_eligible_order':
101
- message = t('onlyPurchasers');
102
- break;
103
- case 'reviews_disabled':
104
- message = t('reviewsDisabled');
105
- break;
106
- default:
107
- message = t('cannotReview');
108
- }
109
- return <p className="text-sm text-muted-foreground">{message}</p>;
110
- }
111
-
112
- function SubmitReviewBlock({ productId }: { productId: string }) {
113
- return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
114
- }
115
-
116
- function EditReviewBlock({
117
- productId,
118
- initial,
119
- onDeleted,
120
- }: {
121
- productId: string;
122
- initial: ProductReview;
123
- onDeleted: () => void;
124
- }) {
125
- const [deleting, setDeleting] = useState(false);
126
- const t = useTranslations('reviews');
127
- const [deleteError, setDeleteError] = useState<string | null>(null);
128
-
129
- async function handleDelete() {
130
- if (!window.confirm(t('confirmDelete'))) return;
131
- setDeleting(true);
132
- setDeleteError(null);
133
- try {
134
- await getClient().deleteMyProductReview(productId);
135
- onDeleted();
136
- window.location.reload();
137
- } catch {
138
- setDeleteError(t('deleteFailed'));
139
- } finally {
140
- setDeleting(false);
141
- }
142
- }
143
-
144
- return (
145
- <div>
146
- <ReviewEditor
147
- productId={productId}
148
- mode="edit"
149
- initialRating={initial.rating}
150
- initialBody={initial.body ?? ''}
151
- />
152
- <div className="mt-4 flex flex-wrap items-center gap-2 border-t pt-4">
153
- <p className="text-xs text-muted-foreground">{t('startOver')}</p>
154
- <button type="button" onClick={handleDelete} disabled={deleting} className="text-xs font-semibold text-destructive underline underline-offset-2 disabled:opacity-50">
155
- {deleting ? t('deleting') : t('deleteReview')}
156
- </button>
157
- </div>
158
- {deleteError && <p role="alert" className="mt-2 text-sm font-medium text-destructive">{deleteError}</p>}
159
- </div>
160
- );
161
- }
162
-
163
- /**
164
- * The actual form. Same shape for create and edit — only the API method
165
- * and the heading differ. Optimistic UX: success state + page reload to
166
- * let the server-rendered reviews list pick up the change.
167
- */
168
- function ReviewEditor({
169
- productId,
170
- mode,
171
- initialRating,
172
- initialBody,
173
- }: {
174
- productId: string;
175
- mode: 'create' | 'edit';
176
- initialRating: number;
177
- initialBody: string;
178
- }) {
179
- const [rating, setRating] = useState(initialRating);
180
- const t = useTranslations('reviews');
181
- const [body, setBody] = useState(initialBody);
182
- const [submitting, setSubmitting] = useState(false);
183
- const [error, setError] = useState<string | null>(null);
184
- const [success, setSuccess] = useState(false);
185
-
186
- async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
187
- event.preventDefault();
188
- setError(null);
189
- setSubmitting(true);
190
- try {
191
- const client = getClient();
192
- const input = { rating, body: body.trim() || undefined };
193
- if (mode === 'edit') {
194
- await client.updateMyProductReview(productId, input);
195
- } else {
196
- await client.submitProductReview(productId, input);
197
- }
198
- setSuccess(true);
199
- setTimeout(() => window.location.reload(), 1200);
200
- } catch (err) {
201
- const status = (err as { status?: number })?.status;
202
- if (status === 409) {
203
- setError(t('alreadySubmitted'));
204
- } else if (status === 403) {
205
- setError(t('onlyPurchasers'));
206
- } else if (status === 429) {
207
- setError(t('tooMany'));
208
- } else {
209
- setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
210
- }
211
- } finally {
212
- setSubmitting(false);
213
- }
214
- }
215
-
216
- if (success) {
217
- return <p role="status" className="text-sm font-semibold text-primary">{mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}</p>;
218
- }
219
-
220
- return (
221
- <form onSubmit={handleSubmit} className="space-y-4">
222
- <h3 className="font-sans text-base font-semibold">{mode === 'edit' ? t('editYourReview') : t('writeReview')}</h3>
223
-
224
- <fieldset>
225
- <legend className="mb-1.5 text-sm font-medium">{t('yourRating')}</legend>
226
- <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
227
- {[1, 2, 3, 4, 5].map((n) => (
228
- <button
229
- key={n}
230
- type="button"
231
- role="radio"
232
- aria-checked={rating === n}
233
- onClick={() => setRating(n)}
234
- className={n <= rating ? 'text-primary' : 'text-border hover:text-primary/50'}
235
- >
236
- <IconStar size={24} filled={n <= rating} />
237
- <span className="sr-only">{n}</span>
238
- </button>
239
- ))}
240
- </div>
241
- </fieldset>
242
-
243
- <label className="block text-sm font-medium">
244
- {t('yourReview')} <span className="font-normal text-muted-foreground">({t('optionalField')})</span>
245
- <textarea
246
- value={body}
247
- onChange={(event) => setBody(event.target.value)}
248
- maxLength={5000}
249
- rows={4}
250
- className="input mt-1.5 h-auto min-h-24 py-2.5"
251
- />
252
- </label>
253
-
254
- {error && <p role="alert" className="text-sm font-medium text-destructive">{error}</p>}
255
-
256
- <button type="submit" disabled={submitting} className="btn-primary btn-sm">
257
- {submitting
258
- ? mode === 'edit'
259
- ? t('saving')
260
- : t('submittingBtn')
261
- : mode === 'edit'
262
- ? t('saveChanges')
263
- : t('submitReview')}
264
- </button>
265
- </form>
266
- );
267
- }
1
+ 'use client';
2
+
3
+ import { useEffect, useState } from 'react';
4
+ import { Link } from '@/core/lib/navigation';
5
+ import { getClient } from '@/core/lib/brainerce';
6
+ import { checkAuthStatus } from '@/core/lib/auth';
7
+ import { useTranslations } from '@/core/lib/translations';
8
+ import type { MyProductReview, ProductReview } from 'brainerce';
9
+ import { IconStar } from '@/ui/shared/icons';
10
+
11
+ interface ReviewFormProps {
12
+ productId: string;
13
+ }
14
+
15
+ type Stage =
16
+ | { kind: 'loading' }
17
+ | { kind: 'signed_out' }
18
+ | { kind: 'not_eligible'; reason: MyProductReview['reason'] }
19
+ | { kind: 'submit' }
20
+ | { kind: 'edit'; review: ProductReview };
21
+
22
+ /**
23
+ * Single component that decides which UI to render for a customer on a PDP:
24
+ * - Loading while we check auth state and eligibility
25
+ * - Signed out -> sign-in CTA
26
+ * - Signed in but not eligible -> "purchase this product to review"
27
+ * - Eligible without review -> submit form
28
+ * - Eligible with existing review -> edit/delete form (rating + body prefilled)
29
+ *
30
+ * DESIGN ME review submit/edit form; auth via checkAuthStatus(), eligibility
31
+ * + existing review via getClient().getMyProductReview(productId).
32
+ */
33
+ export function ReviewForm({ productId }: ReviewFormProps) {
34
+ const [stage, setStage] = useState<Stage>({ kind: 'loading' });
35
+ const t = useTranslations('reviews');
36
+
37
+ useEffect(() => {
38
+ let cancelled = false;
39
+ async function load() {
40
+ const auth = await checkAuthStatus();
41
+ if (cancelled) return;
42
+ if (!auth.isLoggedIn) {
43
+ setStage({ kind: 'signed_out' });
44
+ return;
45
+ }
46
+ try {
47
+ const me = await getClient().getMyProductReview(productId);
48
+ if (cancelled) return;
49
+ if (!me.eligible) {
50
+ setStage({ kind: 'not_eligible', reason: me.reason });
51
+ return;
52
+ }
53
+ if (me.myReview) {
54
+ setStage({ kind: 'edit', review: me.myReview });
55
+ return;
56
+ }
57
+ setStage({ kind: 'submit' });
58
+ } catch {
59
+ if (!cancelled) setStage({ kind: 'not_eligible', reason: 'product_not_found' });
60
+ }
61
+ }
62
+ void load();
63
+ return () => {
64
+ cancelled = true;
65
+ };
66
+ }, [productId]);
67
+
68
+ if (stage.kind === 'loading') {
69
+ return (
70
+ <p role="status" className="text-muted-foreground text-sm">
71
+ {t('loading')}
72
+ </p>
73
+ );
74
+ }
75
+
76
+ if (stage.kind === 'signed_out') {
77
+ return (
78
+ <p className="text-muted-foreground text-sm">
79
+ <Link href="/login" className="text-primary font-semibold underline underline-offset-2">
80
+ {t('signIn')}
81
+ </Link>{' '}
82
+ {t('signInSuffix')}
83
+ </p>
84
+ );
85
+ }
86
+
87
+ if (stage.kind === 'not_eligible') {
88
+ return <NotEligibleMessage reason={stage.reason} />;
89
+ }
90
+
91
+ if (stage.kind === 'edit') {
92
+ return (
93
+ <EditReviewBlock
94
+ productId={productId}
95
+ initial={stage.review}
96
+ onDeleted={() => setStage({ kind: 'submit' })}
97
+ />
98
+ );
99
+ }
100
+
101
+ return <SubmitReviewBlock productId={productId} />;
102
+ }
103
+
104
+ function NotEligibleMessage({ reason }: { reason: MyProductReview['reason'] }) {
105
+ const t = useTranslations('reviews');
106
+ let message: string;
107
+ switch (reason) {
108
+ case 'no_eligible_order':
109
+ message = t('onlyPurchasers');
110
+ break;
111
+ case 'reviews_disabled':
112
+ message = t('reviewsDisabled');
113
+ break;
114
+ default:
115
+ message = t('cannotReview');
116
+ }
117
+ return <p className="text-muted-foreground text-sm">{message}</p>;
118
+ }
119
+
120
+ function SubmitReviewBlock({ productId }: { productId: string }) {
121
+ return <ReviewEditor productId={productId} mode="create" initialRating={5} initialBody="" />;
122
+ }
123
+
124
+ function EditReviewBlock({
125
+ productId,
126
+ initial,
127
+ onDeleted,
128
+ }: {
129
+ productId: string;
130
+ initial: ProductReview;
131
+ onDeleted: () => void;
132
+ }) {
133
+ const [deleting, setDeleting] = useState(false);
134
+ const t = useTranslations('reviews');
135
+ const [deleteError, setDeleteError] = useState<string | null>(null);
136
+
137
+ async function handleDelete() {
138
+ if (!window.confirm(t('confirmDelete'))) return;
139
+ setDeleting(true);
140
+ setDeleteError(null);
141
+ try {
142
+ await getClient().deleteMyProductReview(productId);
143
+ onDeleted();
144
+ window.location.reload();
145
+ } catch {
146
+ setDeleteError(t('deleteFailed'));
147
+ } finally {
148
+ setDeleting(false);
149
+ }
150
+ }
151
+
152
+ return (
153
+ <div>
154
+ <ReviewEditor
155
+ productId={productId}
156
+ mode="edit"
157
+ initialRating={initial.rating}
158
+ initialBody={initial.body ?? ''}
159
+ />
160
+ <div className="mt-4 flex flex-wrap items-center gap-2 border-t pt-4">
161
+ <p className="text-muted-foreground text-xs">{t('startOver')}</p>
162
+ <button
163
+ type="button"
164
+ onClick={handleDelete}
165
+ disabled={deleting}
166
+ className="text-destructive text-xs font-semibold underline underline-offset-2 disabled:opacity-50"
167
+ >
168
+ {deleting ? t('deleting') : t('deleteReview')}
169
+ </button>
170
+ </div>
171
+ {deleteError && (
172
+ <p role="alert" className="text-destructive mt-2 text-sm font-medium">
173
+ {deleteError}
174
+ </p>
175
+ )}
176
+ </div>
177
+ );
178
+ }
179
+
180
+ /**
181
+ * The actual form. Same shape for create and edit — only the API method
182
+ * and the heading differ. Optimistic UX: success state + page reload to
183
+ * let the server-rendered reviews list pick up the change.
184
+ */
185
+ function ReviewEditor({
186
+ productId,
187
+ mode,
188
+ initialRating,
189
+ initialBody,
190
+ }: {
191
+ productId: string;
192
+ mode: 'create' | 'edit';
193
+ initialRating: number;
194
+ initialBody: string;
195
+ }) {
196
+ const [rating, setRating] = useState(initialRating);
197
+ const t = useTranslations('reviews');
198
+ const [body, setBody] = useState(initialBody);
199
+ const [submitting, setSubmitting] = useState(false);
200
+ const [error, setError] = useState<string | null>(null);
201
+ const [success, setSuccess] = useState(false);
202
+
203
+ async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
204
+ event.preventDefault();
205
+ setError(null);
206
+ setSubmitting(true);
207
+ try {
208
+ const client = getClient();
209
+ const input = { rating, body: body.trim() || undefined };
210
+ if (mode === 'edit') {
211
+ await client.updateMyProductReview(productId, input);
212
+ } else {
213
+ await client.submitProductReview(productId, input);
214
+ }
215
+ setSuccess(true);
216
+ setTimeout(() => window.location.reload(), 1200);
217
+ } catch (err) {
218
+ const status = (err as { status?: number })?.status;
219
+ if (status === 409) {
220
+ setError(t('alreadySubmitted'));
221
+ } else if (status === 403) {
222
+ setError(t('onlyPurchasers'));
223
+ } else if (status === 429) {
224
+ setError(t('tooMany'));
225
+ } else {
226
+ setError(mode === 'edit' ? t('updateFailed') : t('submitFailed'));
227
+ }
228
+ } finally {
229
+ setSubmitting(false);
230
+ }
231
+ }
232
+
233
+ if (success) {
234
+ return (
235
+ <p role="status" className="text-primary text-sm font-semibold">
236
+ {mode === 'edit' ? t('thanksUpdated') : t('thanksSubmitted')}
237
+ </p>
238
+ );
239
+ }
240
+
241
+ return (
242
+ <form onSubmit={handleSubmit} className="space-y-4">
243
+ <h3 className="font-sans text-base font-semibold">
244
+ {mode === 'edit' ? t('editYourReview') : t('writeReview')}
245
+ </h3>
246
+
247
+ <fieldset>
248
+ <legend className="mb-1.5 text-sm font-medium">{t('yourRating')}</legend>
249
+ <div className="inline-flex gap-1" role="radiogroup" aria-label={t('starRating')}>
250
+ {[1, 2, 3, 4, 5].map((n) => (
251
+ <button
252
+ key={n}
253
+ type="button"
254
+ role="radio"
255
+ aria-checked={rating === n}
256
+ onClick={() => setRating(n)}
257
+ className={n <= rating ? 'text-primary' : 'text-border hover:text-primary/50'}
258
+ >
259
+ <IconStar size={24} filled={n <= rating} />
260
+ <span className="sr-only">{n}</span>
261
+ </button>
262
+ ))}
263
+ </div>
264
+ </fieldset>
265
+
266
+ <label className="block text-sm font-medium">
267
+ {t('yourReview')}{' '}
268
+ <span className="text-muted-foreground font-normal">({t('optionalField')})</span>
269
+ <textarea
270
+ value={body}
271
+ onChange={(event) => setBody(event.target.value)}
272
+ maxLength={5000}
273
+ rows={4}
274
+ className="input mt-1.5 h-auto min-h-24 py-2.5"
275
+ />
276
+ </label>
277
+
278
+ {error && (
279
+ <p role="alert" className="text-destructive text-sm font-medium">
280
+ {error}
281
+ </p>
282
+ )}
283
+
284
+ <button type="submit" disabled={submitting} className="btn-primary btn-sm">
285
+ {submitting
286
+ ? mode === 'edit'
287
+ ? t('saving')
288
+ : t('submittingBtn')
289
+ : mode === 'edit'
290
+ ? t('saveChanges')
291
+ : t('submitReview')}
292
+ </button>
293
+ </form>
294
+ );
295
+ }