create-brainerce-store 1.68.0 → 1.72.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 +31 -10
- package/dist/index.js +197 -105
- package/messages/en.json +63 -3
- package/messages/he.json +63 -3
- package/package.json +1 -1
- package/templates/nextjs/base/TRANSLATIONS.md +14 -7
- package/templates/nextjs/base/src/app/checkout/page.tsx +1074 -1017
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +21 -2
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +1 -1
- package/templates/nextjs/base/src/app/register/page.tsx +67 -64
- package/templates/nextjs/base/src/components/account/order-history.tsx +25 -39
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +30 -11
- package/templates/nextjs/base/src/components/account/profile-section.tsx +303 -226
- package/templates/nextjs/base/src/components/auth/register-form.tsx +326 -245
- package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +306 -294
- package/templates/nextjs/base/src/components/checkout/date-picker.tsx +13 -1
- package/templates/nextjs/base/src/components/checkout/datetime-picker.tsx +61 -21
- package/templates/nextjs/base/src/components/shared/birthday-picker.tsx +258 -0
- package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +71 -2
- package/templates/nextjs/base/src/core/lib/auth.ts +155 -154
- package/templates/nextjs/base/src/core/lib/birthday.ts +74 -0
- package/templates/nextjs/base/src/core/lib/brainerce.ts.ejs +5 -16
- package/templates/nextjs/base/src/core/lib/store-info.ts +10 -0
- package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +3 -6
- package/templates/nextjs/base/src/ui/cart/cart-item.tsx +19 -1
- package/templates/nextjs/base/src/ui/cart/cart-view.tsx +42 -6
- package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +52 -10
- package/templates/nextjs/base/src/ui/layout/newsletter-signup.tsx +143 -0
- package/templates/nextjs/base/src/ui/layout/site-footer.tsx.ejs +18 -2
- package/templates/nextjs/base/src/ui/product/back-in-stock-form.tsx +173 -0
- package/templates/nextjs/base/src/ui/product/product-client-section.tsx +484 -455
- package/templates/nextjs/base/src/ui/product/review-form.tsx +136 -12
- package/templates/nextjs/base/src/ui/product/reviews-section.tsx.ejs +139 -108
- package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +21 -3
- package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +19 -1
- package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +44 -7
- package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +52 -10
- package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +155 -142
- package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +500 -477
- package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +135 -11
- package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +179 -148
- package/templates/nextjs/ui-canvas/cart/cart-item.tsx +15 -1
- package/templates/nextjs/ui-canvas/cart/cart-view.tsx +38 -4
- package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +54 -11
- package/templates/nextjs/ui-canvas/layout/newsletter-signup.tsx +122 -0
- package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +87 -83
- package/templates/nextjs/ui-canvas/product/back-in-stock-form.tsx +151 -0
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +373 -352
- package/templates/nextjs/ui-canvas/product/review-form.tsx +129 -11
- package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +127 -96
|
@@ -1,294 +1,306 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
</
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
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
|
+
}
|
|
@@ -18,6 +18,12 @@ import { cn } from '@/core/lib/utils';
|
|
|
18
18
|
* — min/max date, blocked weekdays AND blocked specific dates in one call, the
|
|
19
19
|
* exact predicate the server re-runs on submit. Reimplementing any part of it
|
|
20
20
|
* here is how a picker ends up offering a day the API then rejects with 400.
|
|
21
|
+
*
|
|
22
|
+
* `timezone` is the other half of that predicate. The field's relative bounds
|
|
23
|
+
* (`leadTimeMinutes`, `cutoffTime`, `maxDaysAhead`) resolve against the clock
|
|
24
|
+
* rather than a fixed date, and the SDK skips them entirely when no clock is
|
|
25
|
+
* passed — so leaving it out silently reopens every day a lead time was meant
|
|
26
|
+
* to close.
|
|
21
27
|
*/
|
|
22
28
|
interface DatePickerProps {
|
|
23
29
|
id?: string;
|
|
@@ -34,6 +40,8 @@ interface DatePickerProps {
|
|
|
34
40
|
* already committed to a date.
|
|
35
41
|
*/
|
|
36
42
|
isDateSelectable?: (dateYYYYMMDD: string) => boolean;
|
|
43
|
+
/** The store's IANA timezone, from `getStoreInfo().timezone`. Never the browser's. */
|
|
44
|
+
timezone?: string;
|
|
37
45
|
placeholder: string;
|
|
38
46
|
todayLabel: string;
|
|
39
47
|
clearLabel: string;
|
|
@@ -63,6 +71,7 @@ export function DatePicker({
|
|
|
63
71
|
required,
|
|
64
72
|
availability,
|
|
65
73
|
isDateSelectable,
|
|
74
|
+
timezone,
|
|
66
75
|
placeholder,
|
|
67
76
|
todayLabel,
|
|
68
77
|
clearLabel,
|
|
@@ -109,7 +118,10 @@ export function DatePicker({
|
|
|
109
118
|
|
|
110
119
|
function isDisabled(y: number, m: number, d: number): boolean {
|
|
111
120
|
const ymd = toYMD(y, m, d);
|
|
112
|
-
|
|
121
|
+
// `now` is deliberately left to the SDK's default so the calendar re-reads
|
|
122
|
+
// the real clock on every render: a shopper who sits on the page past the
|
|
123
|
+
// cutoff sees the day close under them rather than 400 on submit.
|
|
124
|
+
if (!isCalendarDateAllowed(ymd, availability, timezone ? { timezone } : undefined)) return true;
|
|
113
125
|
return isDateSelectable ? !isDateSelectable(ymd) : false;
|
|
114
126
|
}
|
|
115
127
|
|