create-brainerce-store 1.73.0 → 1.74.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 (77) hide show
  1. package/dist/index.js +35 -2
  2. package/messages/en.json +27 -1
  3. package/messages/he.json +27 -1
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/AGENTS.md.ejs +63 -16
  6. package/templates/nextjs/base/AI-GUIDE.md +17 -4
  7. package/templates/nextjs/base/CLAUDE.md.ejs +67 -20
  8. package/templates/nextjs/base/src/app/account/page.tsx +168 -122
  9. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +10 -1
  10. package/templates/nextjs/base/src/app/checkout/page.tsx +145 -40
  11. package/templates/nextjs/base/src/app/layout.tsx.ejs +48 -4
  12. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +98 -3
  13. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +14 -2
  14. package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +226 -0
  15. package/templates/nextjs/base/src/components/account/order-history.tsx +58 -7
  16. package/templates/nextjs/base/src/components/account/saved-payment-methods.tsx +104 -0
  17. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +618 -612
  18. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +354 -306
  19. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +141 -74
  20. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +97 -6
  21. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +63 -51
  22. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +379 -295
  23. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +33 -1
  24. package/templates/nextjs/base/src/core/lib/capabilities.ts +65 -0
  25. package/templates/nextjs/base/src/core/lib/display-price.ts +139 -0
  26. package/templates/nextjs/base/src/core/lib/region.server.ts +112 -0
  27. package/templates/nextjs/base/src/core/lib/region.ts +112 -0
  28. package/templates/nextjs/base/src/core/lib/store-info.ts +19 -0
  29. package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +423 -243
  30. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +10 -0
  31. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +109 -110
  32. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +45 -2
  33. package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +191 -0
  34. package/templates/nextjs/base/src/ui/cart/tax-estimate-line.tsx +108 -0
  35. package/templates/nextjs/base/src/ui/home/home-client.tsx +27 -29
  36. package/templates/nextjs/base/src/ui/layout/header-search.tsx +249 -0
  37. package/templates/nextjs/base/src/ui/layout/region-switcher.tsx +59 -0
  38. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +171 -152
  39. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +197 -191
  40. package/templates/nextjs/base/src/ui/product/product-card.tsx +25 -52
  41. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +12 -3
  42. package/templates/nextjs/base/src/ui/product/product-listing.tsx +460 -446
  43. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +108 -102
  44. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +15 -3
  45. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +48 -4
  46. package/templates/nextjs/designs/atelier/messages-patch/en.json +21 -25
  47. package/templates/nextjs/designs/atelier/messages-patch/he.json +21 -25
  48. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +10 -0
  49. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +106 -107
  50. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +56 -11
  51. package/templates/nextjs/designs/atelier/ui/cart/tax-estimate-line.tsx +108 -0
  52. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +10 -1
  53. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +178 -174
  54. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +4 -6
  55. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +150 -78
  56. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +79 -46
  57. package/templates/nextjs/designs/atelier/ui/layout/header-search.tsx +264 -0
  58. package/templates/nextjs/designs/atelier/ui/layout/region-switcher.tsx +44 -0
  59. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +5 -0
  60. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +202 -196
  61. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +27 -52
  62. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +12 -3
  63. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +332 -260
  64. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +101 -95
  65. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +17 -2
  66. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +9 -0
  67. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +98 -99
  68. package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +142 -0
  69. package/templates/nextjs/ui-canvas/cart/tax-estimate-line.tsx +104 -0
  70. package/templates/nextjs/ui-canvas/home/home-client.tsx +24 -26
  71. package/templates/nextjs/ui-canvas/layout/region-switcher.tsx +51 -0
  72. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +3 -0
  73. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +174 -168
  74. package/templates/nextjs/ui-canvas/product/product-card.tsx +9 -51
  75. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +5 -3
  76. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +105 -99
  77. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +17 -2
@@ -1,306 +1,354 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import type { CheckoutCustomFieldDefinition } from 'brainerce';
5
- import { useTranslations } from '@/core/lib/translations';
6
- import { cn } from '@/core/lib/utils';
7
- import { DatePicker } from '@/components/checkout/date-picker';
8
- import { DateTimePicker } from '@/components/checkout/datetime-picker';
9
-
10
- /** Inline, dependency-free — this file lives in the base template and must
11
- * not assume any design pack (e.g. Atelier's icon set) is present; canvas
12
- * scaffolds skip design packs entirely. */
13
- const INPUT_CLASS =
14
- 'h-11 w-full rounded-lg border bg-background px-3.5 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary';
15
-
16
- interface CustomFieldsStepProps {
17
- fields: CheckoutCustomFieldDefinition[];
18
- values: Record<string, unknown>;
19
- onChange: (key: string, value: unknown) => void;
20
- onApply: () => void;
21
- onUploadFile?: (file: File) => Promise<{ url: string; key: string }>;
22
- /**
23
- * The store's IANA timezone (`storeInfo.timezone`). DATE/DATETIME fields need
24
- * it to apply a field's leadTimeMinutes/cutoffTime/maxDaysAhead: the SDK
25
- * skips those bounds when no clock reaches it, so the picker would offer days
26
- * the API rejects.
27
- */
28
- timezone?: string;
29
- loading?: boolean;
30
- className?: string;
31
- }
32
-
33
- const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 5 MB
34
- const ACCEPTED_IMAGE_TYPES = 'image/jpeg,image/png,image/webp,image/gif';
35
-
36
- export function CustomFieldsStep({
37
- fields,
38
- values,
39
- onChange,
40
- onApply,
41
- onUploadFile,
42
- timezone,
43
- loading = false,
44
- className,
45
- }: CustomFieldsStepProps) {
46
- const t = useTranslations('checkout');
47
- const [uploadingKeys, setUploadingKeys] = useState<Set<string>>(new Set());
48
-
49
- const isMissing = fields.some((f) => {
50
- if (!f.required) return false;
51
- const v = values[f.key];
52
- return v === undefined || v === null || v === '';
53
- });
54
-
55
- return (
56
- <div className={cn('space-y-4', className)}>
57
- <p className="text-muted-foreground text-sm">{t('customFieldsSubtitle')}</p>
58
-
59
- {fields.map((field) => {
60
- const value = values[field.key];
61
- const labelEl = (
62
- <label
63
- htmlFor={`cf-${field.key}`}
64
- className="text-foreground mb-1 block text-sm font-medium"
65
- >
66
- {field.name}
67
- {field.required && <span className="text-destructive ms-1">*</span>}
68
- </label>
69
- );
70
- const helpEl = field.description ? (
71
- <p className="text-muted-foreground mt-1 whitespace-pre-line text-xs">
72
- {field.description}
73
- </p>
74
- ) : null;
75
-
76
- switch (field.type) {
77
- case 'TEXT':
78
- return (
79
- <div key={field.key}>
80
- {labelEl}
81
- <input
82
- id={`cf-${field.key}`}
83
- type="text"
84
- value={(value as string) ?? ''}
85
- onChange={(e) => onChange(field.key, e.target.value)}
86
- required={field.required}
87
- minLength={field.minLength ?? undefined}
88
- maxLength={field.maxLength ?? undefined}
89
- className={INPUT_CLASS}
90
- />
91
- {helpEl}
92
- </div>
93
- );
94
-
95
- case 'TEXTAREA':
96
- return (
97
- <div key={field.key}>
98
- {labelEl}
99
- <textarea
100
- id={`cf-${field.key}`}
101
- value={(value as string) ?? ''}
102
- onChange={(e) => onChange(field.key, e.target.value)}
103
- required={field.required}
104
- minLength={field.minLength ?? undefined}
105
- maxLength={field.maxLength ?? undefined}
106
- rows={3}
107
- className="border-border bg-background text-foreground placeholder:text-muted-foreground focus-visible:ring-primary w-full rounded-lg border px-3.5 py-2.5 text-sm focus-visible:outline-none focus-visible:ring-2"
108
- />
109
- {helpEl}
110
- </div>
111
- );
112
-
113
- case 'NUMBER':
114
- return (
115
- <div key={field.key}>
116
- {labelEl}
117
- <input
118
- id={`cf-${field.key}`}
119
- type="number"
120
- value={(value as number | string) ?? ''}
121
- onChange={(e) =>
122
- onChange(field.key, e.target.value === '' ? '' : Number(e.target.value))
123
- }
124
- required={field.required}
125
- min={field.minValue ?? undefined}
126
- max={field.maxValue ?? undefined}
127
- className={INPUT_CLASS}
128
- />
129
- {helpEl}
130
- </div>
131
- );
132
-
133
- case 'BOOLEAN':
134
- return (
135
- <div key={field.key} className="flex items-start gap-2">
136
- <input
137
- id={`cf-${field.key}`}
138
- type="checkbox"
139
- checked={value === true}
140
- onChange={(e) => onChange(field.key, e.target.checked)}
141
- className="mt-1"
142
- />
143
- <div className="flex-1">
144
- <label
145
- htmlFor={`cf-${field.key}`}
146
- className="text-foreground text-sm font-medium"
147
- >
148
- {field.name}
149
- {field.required && <span className="text-destructive ms-1">*</span>}
150
- </label>
151
- {helpEl}
152
- </div>
153
- </div>
154
- );
155
-
156
- case 'SELECT':
157
- return (
158
- <div key={field.key}>
159
- {labelEl}
160
- <select
161
- id={`cf-${field.key}`}
162
- value={(value as string) ?? ''}
163
- onChange={(e) => onChange(field.key, e.target.value)}
164
- required={field.required}
165
- className={INPUT_CLASS}
166
- >
167
- <option value="">{t('customFieldsSelectPlaceholder')}</option>
168
- {field.options?.map((opt) => (
169
- <option key={opt.value} value={opt.value}>
170
- {opt.label}
171
- </option>
172
- ))}
173
- </select>
174
- {helpEl}
175
- </div>
176
- );
177
-
178
- case 'DATE':
179
- return (
180
- <div key={field.key}>
181
- {labelEl}
182
- <DatePicker
183
- id={`cf-${field.key}`}
184
- value={(value as string) ?? ''}
185
- onChange={(v) => onChange(field.key, v)}
186
- required={field.required}
187
- availability={field.dateAvailability}
188
- timezone={timezone}
189
- placeholder={t('customFieldsDatePlaceholder')}
190
- todayLabel={t('customFieldsDateToday')}
191
- clearLabel={t('customFieldsDateClear')}
192
- prevMonthLabel={t('customFieldsDatePrevMonth')}
193
- nextMonthLabel={t('customFieldsDateNextMonth')}
194
- />
195
- {helpEl}
196
- </div>
197
- );
198
-
199
- case 'DATETIME':
200
- return (
201
- <div key={field.key}>
202
- {labelEl}
203
- <DateTimePicker
204
- id={`cf-${field.key}`}
205
- value={(value as string) ?? ''}
206
- onChange={(v) => onChange(field.key, v)}
207
- required={field.required}
208
- availability={field.dateAvailability}
209
- timezone={timezone}
210
- placeholder={t('customFieldsDatePlaceholder')}
211
- todayLabel={t('customFieldsDateToday')}
212
- clearLabel={t('customFieldsDateClear')}
213
- prevMonthLabel={t('customFieldsDatePrevMonth')}
214
- nextMonthLabel={t('customFieldsDateNextMonth')}
215
- timeLabel={t('customFieldsTimeLabel')}
216
- closedLabel={t('customFieldsTimeClosed')}
217
- noTimesLabel={t('customFieldsTimeNoneLeft')}
218
- toLabel={t('customFieldsTimeTo')}
219
- />
220
- {helpEl}
221
- </div>
222
- );
223
-
224
- case 'IMAGE': {
225
- const isUploading = uploadingKeys.has(field.key);
226
- return (
227
- <div key={field.key}>
228
- {labelEl}
229
- {value ? (
230
- <div className="relative inline-block">
231
- <img
232
- src={value as string}
233
- alt={field.name}
234
- className="border-border max-h-32 rounded border object-contain"
235
- />
236
- <button
237
- type="button"
238
- onClick={() => onChange(field.key, '')}
239
- className="bg-background/80 text-foreground absolute end-1 top-1 rounded-full p-1 text-xs leading-none"
240
- aria-label={t('customFieldsImageRemove')}
241
- >
242
-
243
- </button>
244
- </div>
245
- ) : (
246
- <label
247
- htmlFor={`cf-${field.key}`}
248
- className={cn(
249
- 'border-border flex cursor-pointer flex-col items-center gap-2 rounded border-2 border-dashed p-6 text-center transition-colors',
250
- isUploading ? 'opacity-50' : 'hover:border-primary/40'
251
- )}
252
- >
253
- <span className="text-muted-foreground text-sm">
254
- {isUploading ? t('customFieldsImageUploading') : t('customFieldsImageUpload')}
255
- </span>
256
- <input
257
- id={`cf-${field.key}`}
258
- type="file"
259
- accept={ACCEPTED_IMAGE_TYPES}
260
- disabled={isUploading || !onUploadFile}
261
- className="hidden"
262
- onChange={async (e) => {
263
- const file = e.target.files?.[0];
264
- if (!file || !onUploadFile) return;
265
- if (file.size > MAX_IMAGE_SIZE) {
266
- alert(t('customFieldsImageTooLarge'));
267
- return;
268
- }
269
- setUploadingKeys((prev) => new Set(prev).add(field.key));
270
- try {
271
- const result = await onUploadFile(file);
272
- onChange(field.key, result.url);
273
- } catch {
274
- // Upload failed — user can retry
275
- } finally {
276
- setUploadingKeys((prev) => {
277
- const next = new Set(prev);
278
- next.delete(field.key);
279
- return next;
280
- });
281
- }
282
- }}
283
- />
284
- </label>
285
- )}
286
- {helpEl}
287
- </div>
288
- );
289
- }
290
-
291
- default:
292
- return null;
293
- }
294
- })}
295
-
296
- <button
297
- type="button"
298
- onClick={onApply}
299
- disabled={loading || isMissing}
300
- className="bg-primary text-primary-foreground hover:bg-primary/90 inline-flex h-12 w-full select-none items-center justify-center gap-2 whitespace-nowrap rounded-full px-8 text-base font-semibold transition-colors duration-200 disabled:pointer-events-none disabled:opacity-50"
301
- >
302
- {loading ? t('customFieldsApplying') : t('customFieldsApply')}
303
- </button>
304
- </div>
305
- );
306
- }
1
+ 'use client';
2
+
3
+ import { useMemo, useState } from 'react';
4
+ import type { CheckoutCustomFieldDefinition } from 'brainerce';
5
+ import { isDateValueAllowed } from 'brainerce';
6
+ import { useTranslations } from '@/core/lib/translations';
7
+ import { cn } from '@/core/lib/utils';
8
+ import { DatePicker } from '@/components/checkout/date-picker';
9
+ import { DateTimePicker } from '@/components/checkout/datetime-picker';
10
+
11
+ /** Inline, dependency-free this file lives in the base template and must
12
+ * not assume any design pack (e.g. Atelier's icon set) is present; canvas
13
+ * scaffolds skip design packs entirely. */
14
+ const INPUT_CLASS =
15
+ 'h-11 w-full rounded-lg border bg-background px-3.5 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary';
16
+
17
+ interface CustomFieldsStepProps {
18
+ fields: CheckoutCustomFieldDefinition[];
19
+ values: Record<string, unknown>;
20
+ onChange: (key: string, value: unknown) => void;
21
+ onApply: () => void;
22
+ onUploadFile?: (file: File) => Promise<{ url: string; key: string }>;
23
+ /**
24
+ * The store's IANA timezone (`storeInfo.timezone`). DATE/DATETIME fields need
25
+ * it to apply a field's leadTimeMinutes/cutoffTime/maxDaysAhead: the SDK
26
+ * skips those bounds when no clock reaches it, so the picker would offer days
27
+ * the API rejects.
28
+ */
29
+ timezone?: string;
30
+ loading?: boolean;
31
+ className?: string;
32
+ }
33
+
34
+ const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 5 MB
35
+ const ACCEPTED_IMAGE_TYPES = 'image/jpeg,image/png,image/webp,image/gif';
36
+
37
+ export function CustomFieldsStep({
38
+ fields,
39
+ values,
40
+ onChange,
41
+ onApply,
42
+ onUploadFile,
43
+ timezone,
44
+ loading = false,
45
+ className,
46
+ }: CustomFieldsStepProps) {
47
+ const t = useTranslations('checkout');
48
+ const [uploadingKeys, setUploadingKeys] = useState<Set<string>>(new Set());
49
+
50
+ const isMissing = fields.some((f) => {
51
+ if (!f.required) return false;
52
+ const v = values[f.key];
53
+ return v === undefined || v === null || v === '';
54
+ });
55
+
56
+ // ---- Pre-submit date guard ----
57
+ //
58
+ // The pickers disable unavailable days and times at the moment they render,
59
+ // but a shopper can sit on this step long enough for a `leadTimeMinutes` or
60
+ // `cutoffTime` bound to overtake the value they already picked. Submitting
61
+ // it then 400s AFTER they have committed. `isDateValueAllowed` is the
62
+ // authoritative client-side re-check, so run it on every keystroke-free
63
+ // render and keep the button shut while anything is stale.
64
+ //
65
+ // The clock is what applies leadTimeMinutes / cutoffTime / maxDaysAhead, and
66
+ // `isDateValueAllowed` requires a real IANA `timezone` (it is typed
67
+ // `string`, not optional). `timezone` on this component IS optional, so when
68
+ // the store has none we skip the guard entirely rather than pass an empty
69
+ // string, which would evaluate the bounds against a bogus zone.
70
+ const staleDateKeys = useMemo(() => {
71
+ const stale = new Set<string>();
72
+ if (!timezone) return stale;
73
+
74
+ for (const field of fields) {
75
+ if (field.type !== 'DATE' && field.type !== 'DATETIME') continue;
76
+ if (!field.dateAvailability) continue;
77
+
78
+ const raw = values[field.key];
79
+ if (typeof raw !== 'string' || raw === '') continue;
80
+
81
+ // A DATE value is "YYYY-MM-DD", which parses to UTC midnight — exactly
82
+ // what isDateValueAllowed reads back with getUTC* for the DATE branch.
83
+ const instant = new Date(raw);
84
+ if (Number.isNaN(instant.getTime())) continue;
85
+
86
+ const verdict = isDateValueAllowed(instant, field.dateAvailability, field.type, timezone);
87
+ if (!verdict.allowed) {
88
+ stale.add(field.key);
89
+ // `reason` is untranslated English prose meant for developers — log
90
+ // it, never render it. The shopper gets the localized line below.
91
+ console.warn(`Checkout field "${field.key}" is no longer available:`, verdict.reason);
92
+ }
93
+ }
94
+ return stale;
95
+ }, [fields, values, timezone]);
96
+
97
+ return (
98
+ <div className={cn('space-y-4', className)}>
99
+ <p className="text-muted-foreground text-sm">{t('customFieldsSubtitle')}</p>
100
+
101
+ {fields.map((field) => {
102
+ const value = values[field.key];
103
+ const labelEl = (
104
+ <label
105
+ htmlFor={`cf-${field.key}`}
106
+ className="text-foreground mb-1 block text-sm font-medium"
107
+ >
108
+ {field.name}
109
+ {field.required && <span className="text-destructive ms-1">*</span>}
110
+ </label>
111
+ );
112
+ const helpEl = field.description ? (
113
+ <p className="text-muted-foreground mt-1 whitespace-pre-line text-xs">
114
+ {field.description}
115
+ </p>
116
+ ) : null;
117
+
118
+ switch (field.type) {
119
+ case 'TEXT':
120
+ return (
121
+ <div key={field.key}>
122
+ {labelEl}
123
+ <input
124
+ id={`cf-${field.key}`}
125
+ type="text"
126
+ value={(value as string) ?? ''}
127
+ onChange={(e) => onChange(field.key, e.target.value)}
128
+ required={field.required}
129
+ minLength={field.minLength ?? undefined}
130
+ maxLength={field.maxLength ?? undefined}
131
+ className={INPUT_CLASS}
132
+ />
133
+ {helpEl}
134
+ </div>
135
+ );
136
+
137
+ case 'TEXTAREA':
138
+ return (
139
+ <div key={field.key}>
140
+ {labelEl}
141
+ <textarea
142
+ id={`cf-${field.key}`}
143
+ value={(value as string) ?? ''}
144
+ onChange={(e) => onChange(field.key, e.target.value)}
145
+ required={field.required}
146
+ minLength={field.minLength ?? undefined}
147
+ maxLength={field.maxLength ?? undefined}
148
+ rows={3}
149
+ className="border-border bg-background text-foreground placeholder:text-muted-foreground focus-visible:ring-primary w-full rounded-lg border px-3.5 py-2.5 text-sm focus-visible:outline-none focus-visible:ring-2"
150
+ />
151
+ {helpEl}
152
+ </div>
153
+ );
154
+
155
+ case 'NUMBER':
156
+ return (
157
+ <div key={field.key}>
158
+ {labelEl}
159
+ <input
160
+ id={`cf-${field.key}`}
161
+ type="number"
162
+ value={(value as number | string) ?? ''}
163
+ onChange={(e) =>
164
+ onChange(field.key, e.target.value === '' ? '' : Number(e.target.value))
165
+ }
166
+ required={field.required}
167
+ min={field.minValue ?? undefined}
168
+ max={field.maxValue ?? undefined}
169
+ className={INPUT_CLASS}
170
+ />
171
+ {helpEl}
172
+ </div>
173
+ );
174
+
175
+ case 'BOOLEAN':
176
+ return (
177
+ <div key={field.key} className="flex items-start gap-2">
178
+ <input
179
+ id={`cf-${field.key}`}
180
+ type="checkbox"
181
+ checked={value === true}
182
+ onChange={(e) => onChange(field.key, e.target.checked)}
183
+ className="mt-1"
184
+ />
185
+ <div className="flex-1">
186
+ <label
187
+ htmlFor={`cf-${field.key}`}
188
+ className="text-foreground text-sm font-medium"
189
+ >
190
+ {field.name}
191
+ {field.required && <span className="text-destructive ms-1">*</span>}
192
+ </label>
193
+ {helpEl}
194
+ </div>
195
+ </div>
196
+ );
197
+
198
+ case 'SELECT':
199
+ return (
200
+ <div key={field.key}>
201
+ {labelEl}
202
+ <select
203
+ id={`cf-${field.key}`}
204
+ value={(value as string) ?? ''}
205
+ onChange={(e) => onChange(field.key, e.target.value)}
206
+ required={field.required}
207
+ className={INPUT_CLASS}
208
+ >
209
+ <option value="">{t('customFieldsSelectPlaceholder')}</option>
210
+ {field.options?.map((opt) => (
211
+ <option key={opt.value} value={opt.value}>
212
+ {opt.label}
213
+ </option>
214
+ ))}
215
+ </select>
216
+ {helpEl}
217
+ </div>
218
+ );
219
+
220
+ case 'DATE':
221
+ return (
222
+ <div key={field.key}>
223
+ {labelEl}
224
+ <DatePicker
225
+ id={`cf-${field.key}`}
226
+ value={(value as string) ?? ''}
227
+ onChange={(v) => onChange(field.key, v)}
228
+ required={field.required}
229
+ availability={field.dateAvailability}
230
+ timezone={timezone}
231
+ placeholder={t('customFieldsDatePlaceholder')}
232
+ todayLabel={t('customFieldsDateToday')}
233
+ clearLabel={t('customFieldsDateClear')}
234
+ prevMonthLabel={t('customFieldsDatePrevMonth')}
235
+ nextMonthLabel={t('customFieldsDateNextMonth')}
236
+ />
237
+ {helpEl}
238
+ {staleDateKeys.has(field.key) && (
239
+ <p className="text-destructive mt-1 text-xs">{t('customFieldsTimeNoneLeft')}</p>
240
+ )}
241
+ </div>
242
+ );
243
+
244
+ case 'DATETIME':
245
+ return (
246
+ <div key={field.key}>
247
+ {labelEl}
248
+ <DateTimePicker
249
+ id={`cf-${field.key}`}
250
+ value={(value as string) ?? ''}
251
+ onChange={(v) => onChange(field.key, v)}
252
+ required={field.required}
253
+ availability={field.dateAvailability}
254
+ timezone={timezone}
255
+ placeholder={t('customFieldsDatePlaceholder')}
256
+ todayLabel={t('customFieldsDateToday')}
257
+ clearLabel={t('customFieldsDateClear')}
258
+ prevMonthLabel={t('customFieldsDatePrevMonth')}
259
+ nextMonthLabel={t('customFieldsDateNextMonth')}
260
+ timeLabel={t('customFieldsTimeLabel')}
261
+ closedLabel={t('customFieldsTimeClosed')}
262
+ noTimesLabel={t('customFieldsTimeNoneLeft')}
263
+ toLabel={t('customFieldsTimeTo')}
264
+ />
265
+ {helpEl}
266
+ {staleDateKeys.has(field.key) && (
267
+ <p className="text-destructive mt-1 text-xs">{t('customFieldsTimeNoneLeft')}</p>
268
+ )}
269
+ </div>
270
+ );
271
+
272
+ case 'IMAGE': {
273
+ const isUploading = uploadingKeys.has(field.key);
274
+ return (
275
+ <div key={field.key}>
276
+ {labelEl}
277
+ {value ? (
278
+ <div className="relative inline-block">
279
+ <img
280
+ src={value as string}
281
+ alt={field.name}
282
+ className="border-border max-h-32 rounded border object-contain"
283
+ />
284
+ <button
285
+ type="button"
286
+ onClick={() => onChange(field.key, '')}
287
+ className="bg-background/80 text-foreground absolute end-1 top-1 rounded-full p-1 text-xs leading-none"
288
+ aria-label={t('customFieldsImageRemove')}
289
+ >
290
+
291
+ </button>
292
+ </div>
293
+ ) : (
294
+ <label
295
+ htmlFor={`cf-${field.key}`}
296
+ className={cn(
297
+ 'border-border flex cursor-pointer flex-col items-center gap-2 rounded border-2 border-dashed p-6 text-center transition-colors',
298
+ isUploading ? 'opacity-50' : 'hover:border-primary/40'
299
+ )}
300
+ >
301
+ <span className="text-muted-foreground text-sm">
302
+ {isUploading ? t('customFieldsImageUploading') : t('customFieldsImageUpload')}
303
+ </span>
304
+ <input
305
+ id={`cf-${field.key}`}
306
+ type="file"
307
+ accept={ACCEPTED_IMAGE_TYPES}
308
+ disabled={isUploading || !onUploadFile}
309
+ className="hidden"
310
+ onChange={async (e) => {
311
+ const file = e.target.files?.[0];
312
+ if (!file || !onUploadFile) return;
313
+ if (file.size > MAX_IMAGE_SIZE) {
314
+ alert(t('customFieldsImageTooLarge'));
315
+ return;
316
+ }
317
+ setUploadingKeys((prev) => new Set(prev).add(field.key));
318
+ try {
319
+ const result = await onUploadFile(file);
320
+ onChange(field.key, result.url);
321
+ } catch {
322
+ // Upload failed — user can retry
323
+ } finally {
324
+ setUploadingKeys((prev) => {
325
+ const next = new Set(prev);
326
+ next.delete(field.key);
327
+ return next;
328
+ });
329
+ }
330
+ }}
331
+ />
332
+ </label>
333
+ )}
334
+ {helpEl}
335
+ </div>
336
+ );
337
+ }
338
+
339
+ default:
340
+ return null;
341
+ }
342
+ })}
343
+
344
+ <button
345
+ type="button"
346
+ onClick={onApply}
347
+ disabled={loading || isMissing || staleDateKeys.size > 0}
348
+ className="bg-primary text-primary-foreground hover:bg-primary/90 inline-flex h-12 w-full select-none items-center justify-center gap-2 whitespace-nowrap rounded-full px-8 text-base font-semibold transition-colors duration-200 disabled:pointer-events-none disabled:opacity-50"
349
+ >
350
+ {loading ? t('customFieldsApplying') : t('customFieldsApply')}
351
+ </button>
352
+ </div>
353
+ );
354
+ }