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,445 +1,457 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import type { ProductCustomizationField } from 'brainerce';
5
- import { useTranslations } from '@/core/lib/translations';
6
- import { cn } from '@/core/lib/utils';
7
- import { LoadingSpinner } from '@/ui/shared/loading-spinner';
8
- import type { CustomizationValues } from '@/core/lib/product-options';
9
-
10
- // The pure validation logic lives in core (zero markup) so that
11
- // `core/hooks/use-product-page` never imports from `ui/`. Re-exported here
12
- // for backward compatibility with existing imports.
13
- export { validateCustomization } from '@/core/lib/product-options';
14
- export type { CustomizationValues } from '@/core/lib/product-options';
15
-
16
- interface CustomizationFieldsProps {
17
- fields: ProductCustomizationField[];
18
- values: CustomizationValues;
19
- onChange: (values: CustomizationValues) => void;
20
- errors?: Record<string, string>;
21
- }
22
-
23
- export function CustomizationFields({
24
- fields,
25
- values,
26
- onChange,
27
- errors = {},
28
- }: CustomizationFieldsProps) {
29
- const t = useTranslations('customization');
30
-
31
- if (fields.length === 0) return null;
32
-
33
- const sorted = [...fields].sort((a, b) => a.position - b.position);
34
-
35
- const setValue = (key: string, value: unknown) => {
36
- onChange({ ...values, [key]: value });
37
- };
38
-
39
- return (
40
- <div className="border-border space-y-4 border-t pt-4">
41
- <h2 className="text-foreground text-lg font-semibold">{t('title')}</h2>
42
- <div className="space-y-4">
43
- {sorted.map((field) => (
44
- <CustomizationFieldRow
45
- key={field.definitionId}
46
- field={field}
47
- value={values[field.key]}
48
- error={errors[field.key]}
49
- onChange={(v) => setValue(field.key, v)}
50
- />
51
- ))}
52
- </div>
53
- </div>
54
- );
55
- }
56
-
57
- interface RowProps {
58
- field: ProductCustomizationField;
59
- value: unknown;
60
- error?: string;
61
- onChange: (value: unknown) => void;
62
- }
63
-
64
- function CustomizationFieldRow({ field, value, error, onChange }: RowProps) {
65
- const t = useTranslations('customization');
66
- const labelText = (
67
- <span className="text-foreground mb-1.5 block text-sm font-medium">
68
- {field.name}
69
- {field.required && <span className="text-destructive ms-1">*</span>}
70
- </span>
71
- );
72
-
73
- const help = field.description ? (
74
- <p className="text-muted-foreground mt-1 text-xs">{field.description}</p>
75
- ) : null;
76
-
77
- const errorHint = error ? <p className="text-destructive mt-1 text-xs">{error}</p> : null;
78
-
79
- const inputBase =
80
- 'border-border bg-background focus:border-primary w-full rounded border px-3 py-2 text-sm outline-none focus:ring-1';
81
-
82
- switch (field.type) {
83
- case 'TEXTAREA':
84
- return (
85
- <div>
86
- {labelText}
87
- <textarea
88
- value={typeof value === 'string' ? value : ''}
89
- onChange={(e) => onChange(e.target.value)}
90
- minLength={field.minLength ?? undefined}
91
- maxLength={field.maxLength ?? undefined}
92
- required={field.required}
93
- rows={3}
94
- className={cn(inputBase, 'resize-y')}
95
- />
96
- {help}
97
- {errorHint}
98
- </div>
99
- );
100
-
101
- case 'NUMBER':
102
- return (
103
- <div>
104
- {labelText}
105
- <input
106
- type="number"
107
- value={typeof value === 'number' ? value : ''}
108
- onChange={(e) => onChange(e.target.value === '' ? undefined : Number(e.target.value))}
109
- min={field.minValue ?? undefined}
110
- max={field.maxValue ?? undefined}
111
- required={field.required}
112
- className={inputBase}
113
- />
114
- {help}
115
- {errorHint}
116
- </div>
117
- );
118
-
119
- case 'BOOLEAN':
120
- return (
121
- <div>
122
- <label className="inline-flex items-center gap-2">
123
- <input
124
- type="checkbox"
125
- checked={value === true}
126
- onChange={(e) => onChange(e.target.checked)}
127
- className="h-4 w-4"
128
- />
129
- <span className="text-foreground text-sm font-medium">
130
- {field.name}
131
- {field.required && <span className="text-destructive ms-1">*</span>}
132
- </span>
133
- </label>
134
- {help}
135
- {errorHint}
136
- </div>
137
- );
138
-
139
- case 'DATE':
140
- return (
141
- <div>
142
- {labelText}
143
- <input
144
- type="date"
145
- value={typeof value === 'string' ? value : ''}
146
- onChange={(e) => onChange(e.target.value)}
147
- required={field.required}
148
- className={inputBase}
149
- />
150
- {help}
151
- {errorHint}
152
- </div>
153
- );
154
-
155
- case 'DATETIME':
156
- return (
157
- <div>
158
- {labelText}
159
- <input
160
- type="datetime-local"
161
- value={typeof value === 'string' ? value : ''}
162
- onChange={(e) => onChange(e.target.value)}
163
- required={field.required}
164
- className={inputBase}
165
- />
166
- {help}
167
- {errorHint}
168
- </div>
169
- );
170
-
171
- case 'COLOR':
172
- return (
173
- <div>
174
- {labelText}
175
- <input
176
- type="color"
177
- value={typeof value === 'string' && value ? value : '#000000'}
178
- onChange={(e) => onChange(e.target.value)}
179
- required={field.required}
180
- className="border-border h-10 w-20 rounded border p-1"
181
- />
182
- {help}
183
- {errorHint}
184
- </div>
185
- );
186
-
187
- case 'SELECT': {
188
- const options = field.enumValues ?? [];
189
- return (
190
- <div>
191
- {labelText}
192
- <select
193
- value={typeof value === 'string' ? value : ''}
194
- onChange={(e) => onChange(e.target.value || undefined)}
195
- required={field.required}
196
- className={inputBase}
197
- >
198
- <option value="">{t('selectPlaceholder')}</option>
199
- {options.map((opt) => (
200
- <option key={opt.value} value={opt.value}>
201
- {opt.label || opt.value}
202
- </option>
203
- ))}
204
- </select>
205
- {help}
206
- {errorHint}
207
- </div>
208
- );
209
- }
210
-
211
- case 'MULTI_SELECT': {
212
- const options = field.enumValues ?? [];
213
- const current = Array.isArray(value) ? (value as string[]) : [];
214
- const toggle = (opt: string) => {
215
- onChange(current.includes(opt) ? current.filter((v) => v !== opt) : [...current, opt]);
216
- };
217
- return (
218
- <div>
219
- {labelText}
220
- <div className="space-y-1.5">
221
- {options.map((opt) => (
222
- <label key={opt.value} className="me-4 inline-flex items-center gap-2">
223
- <input
224
- type="checkbox"
225
- checked={current.includes(opt.value)}
226
- onChange={() => toggle(opt.value)}
227
- className="h-4 w-4"
228
- />
229
- <span className="text-foreground text-sm">{opt.label || opt.value}</span>
230
- </label>
231
- ))}
232
- </div>
233
- {help}
234
- {errorHint}
235
- </div>
236
- );
237
- }
238
-
239
- case 'IMAGE':
240
- return (
241
- <SingleImageField
242
- field={field}
243
- value={typeof value === 'string' ? value : undefined}
244
- onChange={onChange}
245
- labelText={labelText}
246
- help={help}
247
- errorHint={errorHint}
248
- />
249
- );
250
-
251
- case 'GALLERY':
252
- return (
253
- <GalleryField
254
- field={field}
255
- value={Array.isArray(value) ? (value as string[]) : []}
256
- onChange={onChange}
257
- labelText={labelText}
258
- help={help}
259
- errorHint={errorHint}
260
- />
261
- );
262
-
263
- case 'URL':
264
- return (
265
- <div>
266
- {labelText}
267
- <input
268
- type="url"
269
- value={typeof value === 'string' ? value : ''}
270
- onChange={(e) => onChange(e.target.value)}
271
- required={field.required}
272
- className={inputBase}
273
- />
274
- {help}
275
- {errorHint}
276
- </div>
277
- );
278
-
279
- default:
280
- return (
281
- <div>
282
- {labelText}
283
- <input
284
- type="text"
285
- value={typeof value === 'string' ? value : ''}
286
- onChange={(e) => onChange(e.target.value)}
287
- minLength={field.minLength ?? undefined}
288
- maxLength={field.maxLength ?? undefined}
289
- required={field.required}
290
- className={inputBase}
291
- />
292
- {help}
293
- {errorHint}
294
- </div>
295
- );
296
- }
297
- }
298
-
299
- interface FileFieldProps {
300
- field: ProductCustomizationField;
301
- labelText: React.ReactNode;
302
- help: React.ReactNode;
303
- errorHint: React.ReactNode;
304
- onChange: (value: unknown) => void;
305
- }
306
-
307
- function SingleImageField({
308
- field,
309
- value,
310
- onChange,
311
- labelText,
312
- help,
313
- errorHint,
314
- }: FileFieldProps & { value?: string }) {
315
- const t = useTranslations('customization');
316
- const [uploading, setUploading] = useState(false);
317
- const [uploadError, setUploadError] = useState<string | null>(null);
318
-
319
- async function handleFile(file: File | null) {
320
- if (!file) return;
321
- setUploading(true);
322
- setUploadError(null);
323
- try {
324
- const { getClient } = await import('@/core/lib/brainerce');
325
- const client = getClient();
326
- const result = await client.uploadCustomizationFile(file);
327
- onChange(result.url);
328
- } catch (err) {
329
- console.error('Upload failed', err);
330
- setUploadError(t('uploadFailed'));
331
- } finally {
332
- setUploading(false);
333
- }
334
- }
335
-
336
- return (
337
- <div>
338
- {labelText}
339
- <input
340
- type="file"
341
- accept="image/*"
342
- onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
343
- disabled={uploading}
344
- required={field.required && !value}
345
- className="text-foreground text-sm"
346
- />
347
- {uploading && (
348
- <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
349
- <LoadingSpinner size="sm" />
350
- {t('uploading')}
351
- </span>
352
- )}
353
- {value && !uploading && (
354
- <div className="mt-2">
355
- <img src={value} alt="" className="border-border h-20 w-20 rounded border object-cover" />
356
- </div>
357
- )}
358
- {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
359
- {help}
360
- {errorHint}
361
- </div>
362
- );
363
- }
364
-
365
- function GalleryField({
366
- field,
367
- value,
368
- onChange,
369
- labelText,
370
- help,
371
- errorHint,
372
- }: FileFieldProps & { value: string[] }) {
373
- const t = useTranslations('customization');
374
- const [uploading, setUploading] = useState(false);
375
- const [uploadError, setUploadError] = useState<string | null>(null);
376
-
377
- async function handleFiles(fileList: FileList | null) {
378
- if (!fileList || fileList.length === 0) return;
379
- setUploading(true);
380
- setUploadError(null);
381
- try {
382
- const { getClient } = await import('@/core/lib/brainerce');
383
- const client = getClient();
384
- const newUrls: string[] = [];
385
- for (const file of Array.from(fileList)) {
386
- const result = await client.uploadCustomizationFile(file);
387
- newUrls.push(result.url);
388
- }
389
- onChange([...value, ...newUrls]);
390
- } catch (err) {
391
- console.error('Upload failed', err);
392
- setUploadError(t('uploadFailed'));
393
- } finally {
394
- setUploading(false);
395
- }
396
- }
397
-
398
- function removeAt(idx: number) {
399
- onChange(value.filter((_, i) => i !== idx));
400
- }
401
-
402
- return (
403
- <div>
404
- {labelText}
405
- <input
406
- type="file"
407
- accept="image/*"
408
- multiple
409
- onChange={(e) => handleFiles(e.target.files)}
410
- disabled={uploading}
411
- className="text-foreground text-sm"
412
- />
413
- {uploading && (
414
- <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
415
- <LoadingSpinner size="sm" />
416
- {t('uploading')}
417
- </span>
418
- )}
419
- {value.length > 0 && (
420
- <div className="mt-2 flex flex-wrap gap-2">
421
- {value.map((url, idx) => (
422
- <div key={`${url}-${idx}`} className="relative">
423
- <img
424
- src={url}
425
- alt=""
426
- className="border-border h-16 w-16 rounded border object-cover"
427
- />
428
- <button
429
- type="button"
430
- onClick={() => removeAt(idx)}
431
- aria-label={t('removeImage')}
432
- className="bg-destructive text-destructive-foreground absolute -end-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full text-xs"
433
- >
434
- ×
435
- </button>
436
- </div>
437
- ))}
438
- </div>
439
- )}
440
- {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
441
- {help}
442
- {errorHint}
443
- </div>
444
- );
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import type { ProductCustomizationField } from 'brainerce';
5
+ import { useTranslations } from '@/core/lib/translations';
6
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
7
+ import { Checkbox } from '@/components/ui/checkbox';
8
+ import { Input } from '@/components/ui/input';
9
+ import { Label } from '@/components/ui/label';
10
+ import {
11
+ Select,
12
+ SelectContent,
13
+ SelectItem,
14
+ SelectTrigger,
15
+ SelectValue,
16
+ } from '@/components/ui/select';
17
+ import { Textarea } from '@/components/ui/textarea';
18
+ import type { CustomizationValues } from '@/core/lib/product-options';
19
+
20
+ // The pure validation logic lives in core (zero markup) so that
21
+ // `core/hooks/use-product-page` never imports from `ui/`. Re-exported here
22
+ // for backward compatibility with existing imports.
23
+ export { validateCustomization } from '@/core/lib/product-options';
24
+ export type { CustomizationValues } from '@/core/lib/product-options';
25
+
26
+ interface CustomizationFieldsProps {
27
+ fields: ProductCustomizationField[];
28
+ values: CustomizationValues;
29
+ onChange: (values: CustomizationValues) => void;
30
+ errors?: Record<string, string>;
31
+ }
32
+
33
+ export function CustomizationFields({
34
+ fields,
35
+ values,
36
+ onChange,
37
+ errors = {},
38
+ }: CustomizationFieldsProps) {
39
+ const t = useTranslations('customization');
40
+
41
+ if (fields.length === 0) return null;
42
+
43
+ const sorted = [...fields].sort((a, b) => a.position - b.position);
44
+
45
+ const setValue = (key: string, value: unknown) => {
46
+ onChange({ ...values, [key]: value });
47
+ };
48
+
49
+ return (
50
+ <div className="border-border space-y-4 border-t pt-4">
51
+ <h2 className="text-foreground text-lg font-semibold">{t('title')}</h2>
52
+ <div className="space-y-4">
53
+ {sorted.map((field) => (
54
+ <CustomizationFieldRow
55
+ key={field.definitionId}
56
+ field={field}
57
+ value={values[field.key]}
58
+ error={errors[field.key]}
59
+ onChange={(v) => setValue(field.key, v)}
60
+ />
61
+ ))}
62
+ </div>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ interface RowProps {
68
+ field: ProductCustomizationField;
69
+ value: unknown;
70
+ error?: string;
71
+ onChange: (value: unknown) => void;
72
+ }
73
+
74
+ /** Radix Select items can't carry an empty-string value, so "no choice"
75
+ * round-trips through this sentinel and is written back as undefined. */
76
+ const NONE = '__none__';
77
+
78
+ function CustomizationFieldRow({ field, value, error, onChange }: RowProps) {
79
+ const t = useTranslations('customization');
80
+ const labelText = (
81
+ <Label className="text-foreground mb-1.5 block text-sm font-medium">
82
+ {field.name}
83
+ {field.required && <span className="text-destructive ms-1">*</span>}
84
+ </Label>
85
+ );
86
+
87
+ const help = field.description ? (
88
+ <p className="text-muted-foreground mt-1 text-xs">{field.description}</p>
89
+ ) : null;
90
+
91
+ const errorHint = error ? <p className="text-destructive mt-1 text-xs">{error}</p> : null;
92
+
93
+ switch (field.type) {
94
+ case 'TEXTAREA':
95
+ return (
96
+ <div>
97
+ {labelText}
98
+ <Textarea
99
+ value={typeof value === 'string' ? value : ''}
100
+ onChange={(e) => onChange(e.target.value)}
101
+ minLength={field.minLength ?? undefined}
102
+ maxLength={field.maxLength ?? undefined}
103
+ required={field.required}
104
+ rows={3}
105
+ className="rounded"
106
+ />
107
+ {help}
108
+ {errorHint}
109
+ </div>
110
+ );
111
+
112
+ case 'NUMBER':
113
+ return (
114
+ <div>
115
+ {labelText}
116
+ <Input
117
+ type="number"
118
+ value={typeof value === 'number' ? value : ''}
119
+ onChange={(e) => onChange(e.target.value === '' ? undefined : Number(e.target.value))}
120
+ min={field.minValue ?? undefined}
121
+ max={field.maxValue ?? undefined}
122
+ required={field.required}
123
+ className="rounded"
124
+ />
125
+ {help}
126
+ {errorHint}
127
+ </div>
128
+ );
129
+
130
+ case 'BOOLEAN':
131
+ return (
132
+ <div>
133
+ <Label className="inline-flex items-center gap-2">
134
+ <Checkbox
135
+ checked={value === true}
136
+ onCheckedChange={(checked) => onChange(checked === true)}
137
+ />
138
+ <span className="text-foreground text-sm font-medium">
139
+ {field.name}
140
+ {field.required && <span className="text-destructive ms-1">*</span>}
141
+ </span>
142
+ </Label>
143
+ {help}
144
+ {errorHint}
145
+ </div>
146
+ );
147
+
148
+ case 'DATE':
149
+ return (
150
+ <div>
151
+ {labelText}
152
+ <Input
153
+ type="date"
154
+ value={typeof value === 'string' ? value : ''}
155
+ onChange={(e) => onChange(e.target.value)}
156
+ required={field.required}
157
+ className="rounded"
158
+ />
159
+ {help}
160
+ {errorHint}
161
+ </div>
162
+ );
163
+
164
+ case 'DATETIME':
165
+ return (
166
+ <div>
167
+ {labelText}
168
+ <Input
169
+ type="datetime-local"
170
+ value={typeof value === 'string' ? value : ''}
171
+ onChange={(e) => onChange(e.target.value)}
172
+ required={field.required}
173
+ className="rounded"
174
+ />
175
+ {help}
176
+ {errorHint}
177
+ </div>
178
+ );
179
+
180
+ case 'COLOR':
181
+ return (
182
+ <div>
183
+ {labelText}
184
+ <Input
185
+ type="color"
186
+ value={typeof value === 'string' && value ? value : '#000000'}
187
+ onChange={(e) => onChange(e.target.value)}
188
+ required={field.required}
189
+ className="h-10 w-20 rounded p-1"
190
+ />
191
+ {help}
192
+ {errorHint}
193
+ </div>
194
+ );
195
+
196
+ case 'SELECT': {
197
+ const options = field.enumValues ?? [];
198
+ return (
199
+ <div>
200
+ {labelText}
201
+ <Select
202
+ value={typeof value === 'string' && value ? value : NONE}
203
+ onValueChange={(v) => onChange(v === NONE ? undefined : v)}
204
+ >
205
+ <SelectTrigger className="rounded" aria-label={field.name}>
206
+ <SelectValue placeholder={t('selectPlaceholder')} />
207
+ </SelectTrigger>
208
+ <SelectContent>
209
+ <SelectItem value={NONE}>{t('selectPlaceholder')}</SelectItem>
210
+ {options.map((opt) => (
211
+ <SelectItem key={opt.value} value={opt.value}>
212
+ {opt.label || opt.value}
213
+ </SelectItem>
214
+ ))}
215
+ </SelectContent>
216
+ </Select>
217
+ {help}
218
+ {errorHint}
219
+ </div>
220
+ );
221
+ }
222
+
223
+ case 'MULTI_SELECT': {
224
+ const options = field.enumValues ?? [];
225
+ const current = Array.isArray(value) ? (value as string[]) : [];
226
+ const toggle = (opt: string) => {
227
+ onChange(current.includes(opt) ? current.filter((v) => v !== opt) : [...current, opt]);
228
+ };
229
+ return (
230
+ <div>
231
+ {labelText}
232
+ <div className="space-y-1.5">
233
+ {options.map((opt) => (
234
+ <Label key={opt.value} className="me-4 inline-flex items-center gap-2">
235
+ <Checkbox
236
+ checked={current.includes(opt.value)}
237
+ onCheckedChange={() => toggle(opt.value)}
238
+ />
239
+ <span className="text-foreground text-sm font-normal">
240
+ {opt.label || opt.value}
241
+ </span>
242
+ </Label>
243
+ ))}
244
+ </div>
245
+ {help}
246
+ {errorHint}
247
+ </div>
248
+ );
249
+ }
250
+
251
+ case 'IMAGE':
252
+ return (
253
+ <SingleImageField
254
+ field={field}
255
+ value={typeof value === 'string' ? value : undefined}
256
+ onChange={onChange}
257
+ labelText={labelText}
258
+ help={help}
259
+ errorHint={errorHint}
260
+ />
261
+ );
262
+
263
+ case 'GALLERY':
264
+ return (
265
+ <GalleryField
266
+ field={field}
267
+ value={Array.isArray(value) ? (value as string[]) : []}
268
+ onChange={onChange}
269
+ labelText={labelText}
270
+ help={help}
271
+ errorHint={errorHint}
272
+ />
273
+ );
274
+
275
+ case 'URL':
276
+ return (
277
+ <div>
278
+ {labelText}
279
+ <Input
280
+ type="url"
281
+ value={typeof value === 'string' ? value : ''}
282
+ onChange={(e) => onChange(e.target.value)}
283
+ required={field.required}
284
+ className="rounded"
285
+ />
286
+ {help}
287
+ {errorHint}
288
+ </div>
289
+ );
290
+
291
+ default:
292
+ return (
293
+ <div>
294
+ {labelText}
295
+ <Input
296
+ type="text"
297
+ value={typeof value === 'string' ? value : ''}
298
+ onChange={(e) => onChange(e.target.value)}
299
+ minLength={field.minLength ?? undefined}
300
+ maxLength={field.maxLength ?? undefined}
301
+ required={field.required}
302
+ className="rounded"
303
+ />
304
+ {help}
305
+ {errorHint}
306
+ </div>
307
+ );
308
+ }
309
+ }
310
+
311
+ interface FileFieldProps {
312
+ field: ProductCustomizationField;
313
+ labelText: React.ReactNode;
314
+ help: React.ReactNode;
315
+ errorHint: React.ReactNode;
316
+ onChange: (value: unknown) => void;
317
+ }
318
+
319
+ function SingleImageField({
320
+ field,
321
+ value,
322
+ onChange,
323
+ labelText,
324
+ help,
325
+ errorHint,
326
+ }: FileFieldProps & { value?: string }) {
327
+ const t = useTranslations('customization');
328
+ const [uploading, setUploading] = useState(false);
329
+ const [uploadError, setUploadError] = useState<string | null>(null);
330
+
331
+ async function handleFile(file: File | null) {
332
+ if (!file) return;
333
+ setUploading(true);
334
+ setUploadError(null);
335
+ try {
336
+ const { getClient } = await import('@/core/lib/brainerce');
337
+ const client = getClient();
338
+ const result = await client.uploadCustomizationFile(file);
339
+ onChange(result.url);
340
+ } catch (err) {
341
+ console.error('Upload failed', err);
342
+ setUploadError(t('uploadFailed'));
343
+ } finally {
344
+ setUploading(false);
345
+ }
346
+ }
347
+
348
+ return (
349
+ <div>
350
+ {labelText}
351
+ <input
352
+ type="file"
353
+ accept="image/*"
354
+ onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
355
+ disabled={uploading}
356
+ required={field.required && !value}
357
+ className="text-foreground text-sm"
358
+ />
359
+ {uploading && (
360
+ <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
361
+ <LoadingSpinner size="sm" />
362
+ {t('uploading')}
363
+ </span>
364
+ )}
365
+ {value && !uploading && (
366
+ <div className="mt-2">
367
+ <img src={value} alt="" className="border-border h-20 w-20 rounded border object-cover" />
368
+ </div>
369
+ )}
370
+ {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
371
+ {help}
372
+ {errorHint}
373
+ </div>
374
+ );
375
+ }
376
+
377
+ function GalleryField({
378
+ field,
379
+ value,
380
+ onChange,
381
+ labelText,
382
+ help,
383
+ errorHint,
384
+ }: FileFieldProps & { value: string[] }) {
385
+ const t = useTranslations('customization');
386
+ const [uploading, setUploading] = useState(false);
387
+ const [uploadError, setUploadError] = useState<string | null>(null);
388
+
389
+ async function handleFiles(fileList: FileList | null) {
390
+ if (!fileList || fileList.length === 0) return;
391
+ setUploading(true);
392
+ setUploadError(null);
393
+ try {
394
+ const { getClient } = await import('@/core/lib/brainerce');
395
+ const client = getClient();
396
+ const newUrls: string[] = [];
397
+ for (const file of Array.from(fileList)) {
398
+ const result = await client.uploadCustomizationFile(file);
399
+ newUrls.push(result.url);
400
+ }
401
+ onChange([...value, ...newUrls]);
402
+ } catch (err) {
403
+ console.error('Upload failed', err);
404
+ setUploadError(t('uploadFailed'));
405
+ } finally {
406
+ setUploading(false);
407
+ }
408
+ }
409
+
410
+ function removeAt(idx: number) {
411
+ onChange(value.filter((_, i) => i !== idx));
412
+ }
413
+
414
+ return (
415
+ <div>
416
+ {labelText}
417
+ <input
418
+ type="file"
419
+ accept="image/*"
420
+ multiple
421
+ onChange={(e) => handleFiles(e.target.files)}
422
+ disabled={uploading}
423
+ className="text-foreground text-sm"
424
+ />
425
+ {uploading && (
426
+ <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
427
+ <LoadingSpinner size="sm" />
428
+ {t('uploading')}
429
+ </span>
430
+ )}
431
+ {value.length > 0 && (
432
+ <div className="mt-2 flex flex-wrap gap-2">
433
+ {value.map((url, idx) => (
434
+ <div key={`${url}-${idx}`} className="relative">
435
+ <img
436
+ src={url}
437
+ alt=""
438
+ className="border-border h-16 w-16 rounded border object-cover"
439
+ />
440
+ <button
441
+ type="button"
442
+ onClick={() => removeAt(idx)}
443
+ aria-label={t('removeImage')}
444
+ className="bg-destructive text-destructive-foreground absolute -end-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full text-xs"
445
+ >
446
+ ×
447
+ </button>
448
+ </div>
449
+ ))}
450
+ </div>
451
+ )}
452
+ {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
453
+ {help}
454
+ {errorHint}
455
+ </div>
456
+ );
445
457
  }