create-brainerce-store 1.74.0 → 1.76.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/dist/index.js +44 -7
- package/messages/en.json +10 -1
- package/messages/he.json +10 -1
- package/package.json +4 -2
- package/templates/nextjs/base/.env.local.ejs +62 -52
- package/templates/nextjs/base/AGENTS.md.ejs +189 -161
- package/templates/nextjs/base/CLAUDE.md.ejs +200 -172
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +37 -0
- package/templates/nextjs/base/src/app/page.tsx +75 -65
- package/templates/nextjs/base/src/app/register/page.tsx +74 -67
- package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +79 -7
- package/templates/nextjs/base/src/components/account/order-history.tsx +34 -0
- package/templates/nextjs/base/src/components/auth/register-form.tsx +358 -326
- package/templates/nextjs/base/src/components/referral/referral-greeting.tsx +120 -0
- package/templates/nextjs/base/src/core/lib/auth.ts +162 -155
- package/templates/nextjs/base/src/core/lib/referral.ts +95 -0
- package/templates/nextjs/base/src/ui/product/product-card.tsx +5 -0
- package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +5 -0
- package/templates/nextjs/ui-canvas/layout/header-search.tsx +222 -0
- package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +6 -0
- package/templates/nextjs/ui-canvas/product/product-card.tsx +5 -0
- package/templates/nextjs/ui-canvas/product/product-client-section.tsx +382 -375
|
@@ -1,326 +1,358 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useMemo } from 'react';
|
|
4
|
-
import { useTranslations } from '@/core/lib/translations';
|
|
5
|
-
import { cn } from '@/core/lib/utils';
|
|
6
|
-
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
7
|
-
import { getPasswordError } from '@/core/lib/validation';
|
|
8
|
-
import { useStoreInfo } from '@/core/providers/store-provider';
|
|
9
|
-
import { toBirthdayNumber } from '@/core/lib/birthday';
|
|
10
|
-
import { BirthdayPicker } from '@/components/shared/birthday-picker';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const [
|
|
62
|
-
const [
|
|
63
|
-
const [
|
|
64
|
-
const [
|
|
65
|
-
const [
|
|
66
|
-
const [
|
|
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
|
-
if (
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
<
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useMemo, useEffect } from 'react';
|
|
4
|
+
import { useTranslations } from '@/core/lib/translations';
|
|
5
|
+
import { cn } from '@/core/lib/utils';
|
|
6
|
+
import { LoadingSpinner } from '@/ui/shared/loading-spinner';
|
|
7
|
+
import { getPasswordError } from '@/core/lib/validation';
|
|
8
|
+
import { useStoreInfo } from '@/core/providers/store-provider';
|
|
9
|
+
import { toBirthdayNumber } from '@/core/lib/birthday';
|
|
10
|
+
import { BirthdayPicker } from '@/components/shared/birthday-picker';
|
|
11
|
+
import { readReferralCookie } from '@/core/lib/referral';
|
|
12
|
+
|
|
13
|
+
interface RegisterData {
|
|
14
|
+
firstName: string;
|
|
15
|
+
lastName: string;
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
acceptsMarketing: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Birthday month and day, never a year. Sent together or left out entirely:
|
|
21
|
+
* one without the other is rejected with HTTP 400. Omitted rather than
|
|
22
|
+
* nulled when the shopper leaves the field empty, because `registerCustomer()`
|
|
23
|
+
* takes numbers only.
|
|
24
|
+
*/
|
|
25
|
+
birthMonth?: number;
|
|
26
|
+
birthDay?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Loyalty referral share code, captured from a `?ref=` link that may have
|
|
29
|
+
* been clicked days ago. Omitted when nothing was captured; never invented.
|
|
30
|
+
*/
|
|
31
|
+
referralCode?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface RegisterFormProps {
|
|
35
|
+
onSubmit: (data: RegisterData) => Promise<void>;
|
|
36
|
+
error?: string | null;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getPasswordStrength(password: string): { label: string; color: string; width: string } {
|
|
41
|
+
if (password.length === 0) return { label: '', color: '', width: 'w-0' };
|
|
42
|
+
if (password.length < 8) return { label: 'tooShort', color: 'bg-destructive', width: 'w-1/4' };
|
|
43
|
+
|
|
44
|
+
let score = 0;
|
|
45
|
+
if (password.length >= 8) score++;
|
|
46
|
+
if (/[A-Z]/.test(password)) score++;
|
|
47
|
+
if (/[0-9]/.test(password)) score++;
|
|
48
|
+
if (/[^A-Za-z0-9]/.test(password)) score++;
|
|
49
|
+
|
|
50
|
+
if (score <= 1) return { label: 'weak', color: 'bg-orange-500', width: 'w-1/3' };
|
|
51
|
+
if (score <= 2) return { label: 'fair', color: 'bg-yellow-500', width: 'w-1/2' };
|
|
52
|
+
if (score <= 3) return { label: 'good', color: 'bg-primary', width: 'w-3/4' };
|
|
53
|
+
return { label: 'strong', color: 'bg-green-500', width: 'w-full' };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
|
|
57
|
+
const t = useTranslations('auth');
|
|
58
|
+
const tf = useTranslations('checkoutForm');
|
|
59
|
+
const tc = useTranslations('common');
|
|
60
|
+
const { storeInfo } = useStoreInfo();
|
|
61
|
+
const [firstName, setFirstName] = useState('');
|
|
62
|
+
const [lastName, setLastName] = useState('');
|
|
63
|
+
const [email, setEmail] = useState('');
|
|
64
|
+
const [password, setPassword] = useState('');
|
|
65
|
+
const [privacyAccepted, setPrivacyAccepted] = useState(false);
|
|
66
|
+
const [privacyError, setPrivacyError] = useState(false);
|
|
67
|
+
const [passwordError, setPasswordError] = useState<string | null>(null);
|
|
68
|
+
const [acceptsMarketing, setAcceptsMarketing] = useState(false);
|
|
69
|
+
const [birthMonth, setBirthMonth] = useState('');
|
|
70
|
+
const [birthDay, setBirthDay] = useState('');
|
|
71
|
+
const [birthdayError, setBirthdayError] = useState<string | null>(null);
|
|
72
|
+
const [loading, setLoading] = useState(false);
|
|
73
|
+
const [referralCode, setReferralCode] = useState<string | null>(null);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A referral code captured from a `?ref=` link, possibly on a different day.
|
|
77
|
+
* Read in an effect rather than during render because it comes from
|
|
78
|
+
* `document.cookie`, which does not exist during SSR: reading it inline would
|
|
79
|
+
* render one thing on the server and another on the client and trip a
|
|
80
|
+
* hydration mismatch.
|
|
81
|
+
*/
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setReferralCode(readReferralCookie());
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The merchant can make the birthday mandatory at registration on this sales
|
|
88
|
+
* channel; the backend then rejects a register call without it. The flag is a
|
|
89
|
+
* rendering hint only, and absent means optional, so the fields stay optional
|
|
90
|
+
* unless it is explicitly true.
|
|
91
|
+
*/
|
|
92
|
+
const birthdayRequired = storeInfo?.requireBirthday === true;
|
|
93
|
+
|
|
94
|
+
const strength = useMemo(() => getPasswordStrength(password), [password]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The picker hands back both halves at once, or two nulls when the shopper
|
|
98
|
+
* clears the field. State stays as strings so the submit path below is
|
|
99
|
+
* unchanged.
|
|
100
|
+
*/
|
|
101
|
+
function selectBirthday(month: number | null, day: number | null) {
|
|
102
|
+
setBirthMonth(month ? String(month) : '');
|
|
103
|
+
setBirthDay(day ? String(day) : '');
|
|
104
|
+
setBirthdayError(null);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
if (loading) return;
|
|
110
|
+
|
|
111
|
+
const pwCode = getPasswordError(password);
|
|
112
|
+
if (pwCode) {
|
|
113
|
+
setPasswordError(t(pwCode));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setPasswordError(null);
|
|
117
|
+
|
|
118
|
+
const month = toBirthdayNumber(birthMonth);
|
|
119
|
+
const day = toBirthdayNumber(birthDay);
|
|
120
|
+
|
|
121
|
+
if (birthdayRequired && (month === null || day === null)) {
|
|
122
|
+
setBirthdayError(tc('birthdayRequired'));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// Half a birthday is an HTTP 400 at the API, so catch it here rather than
|
|
126
|
+
// letting the shopper find out from a failed registration.
|
|
127
|
+
if ((month === null) !== (day === null)) {
|
|
128
|
+
setBirthdayError(tc('birthdayIncomplete'));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
setBirthdayError(null);
|
|
132
|
+
|
|
133
|
+
if (!privacyAccepted) {
|
|
134
|
+
setPrivacyError(true);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
setLoading(true);
|
|
140
|
+
await onSubmit({
|
|
141
|
+
firstName,
|
|
142
|
+
lastName,
|
|
143
|
+
email,
|
|
144
|
+
password,
|
|
145
|
+
acceptsMarketing,
|
|
146
|
+
// Omitted, never nulled, when the shopper left the field empty:
|
|
147
|
+
// `registerCustomer()` takes numbers only.
|
|
148
|
+
...(month !== null && day !== null ? { birthMonth: month, birthDay: day } : {}),
|
|
149
|
+
// Same rule for the referral: send it only when one was captured. The
|
|
150
|
+
// API validates it after the fact, so a stale code cannot cost this
|
|
151
|
+
// shopper their registration.
|
|
152
|
+
...(referralCode ? { referralCode } : {}),
|
|
153
|
+
});
|
|
154
|
+
} finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
|
|
161
|
+
{error && (
|
|
162
|
+
<div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
|
|
163
|
+
{error}
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
|
|
167
|
+
{/* A referral captured earlier is about to be applied. Worth saying out
|
|
168
|
+
loud: the shopper was promised a welcome gift on a page they may have
|
|
169
|
+
left days ago, and silence here reads as the offer having expired.
|
|
170
|
+
Renders nothing when no code was captured. */}
|
|
171
|
+
{referralCode && (
|
|
172
|
+
<p className="border-primary/20 bg-primary/5 text-muted-foreground rounded-lg border px-4 py-3 text-sm">
|
|
173
|
+
{t('referralApplied')}
|
|
174
|
+
</p>
|
|
175
|
+
)}
|
|
176
|
+
|
|
177
|
+
<div className="grid grid-cols-2 gap-3">
|
|
178
|
+
<div>
|
|
179
|
+
<label
|
|
180
|
+
htmlFor="register-first-name"
|
|
181
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
182
|
+
>
|
|
183
|
+
{tf('firstName')}
|
|
184
|
+
</label>
|
|
185
|
+
<input
|
|
186
|
+
id="register-first-name"
|
|
187
|
+
type="text"
|
|
188
|
+
required
|
|
189
|
+
value={firstName}
|
|
190
|
+
onChange={(e) => setFirstName(e.target.value)}
|
|
191
|
+
placeholder={t('firstNamePlaceholder')}
|
|
192
|
+
autoComplete="given-name"
|
|
193
|
+
className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
|
|
194
|
+
/>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div>
|
|
198
|
+
<label
|
|
199
|
+
htmlFor="register-last-name"
|
|
200
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
201
|
+
>
|
|
202
|
+
{tf('lastName')}
|
|
203
|
+
</label>
|
|
204
|
+
<input
|
|
205
|
+
id="register-last-name"
|
|
206
|
+
type="text"
|
|
207
|
+
required
|
|
208
|
+
value={lastName}
|
|
209
|
+
onChange={(e) => setLastName(e.target.value)}
|
|
210
|
+
placeholder={t('lastNamePlaceholder')}
|
|
211
|
+
autoComplete="family-name"
|
|
212
|
+
className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
|
|
213
|
+
/>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<div>
|
|
218
|
+
<label
|
|
219
|
+
htmlFor="register-email"
|
|
220
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
221
|
+
>
|
|
222
|
+
{t('email')}
|
|
223
|
+
</label>
|
|
224
|
+
<input
|
|
225
|
+
id="register-email"
|
|
226
|
+
type="email"
|
|
227
|
+
required
|
|
228
|
+
value={email}
|
|
229
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
230
|
+
placeholder={t('emailPlaceholder')}
|
|
231
|
+
autoComplete="email"
|
|
232
|
+
className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
|
|
233
|
+
/>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
<div>
|
|
237
|
+
<label
|
|
238
|
+
htmlFor="register-password"
|
|
239
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
240
|
+
>
|
|
241
|
+
{t('password')}
|
|
242
|
+
</label>
|
|
243
|
+
<input
|
|
244
|
+
id="register-password"
|
|
245
|
+
type="password"
|
|
246
|
+
required
|
|
247
|
+
minLength={8}
|
|
248
|
+
value={password}
|
|
249
|
+
onChange={(e) => {
|
|
250
|
+
setPassword(e.target.value);
|
|
251
|
+
if (passwordError) setPasswordError(null);
|
|
252
|
+
}}
|
|
253
|
+
placeholder={t('atLeastChars')}
|
|
254
|
+
autoComplete="new-password"
|
|
255
|
+
className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2"
|
|
256
|
+
/>
|
|
257
|
+
{password.length > 0 && (
|
|
258
|
+
<div className="mt-2">
|
|
259
|
+
<div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
|
|
260
|
+
<div
|
|
261
|
+
className={cn(
|
|
262
|
+
'h-full rounded-full transition-all duration-300',
|
|
263
|
+
strength.color,
|
|
264
|
+
strength.width
|
|
265
|
+
)}
|
|
266
|
+
/>
|
|
267
|
+
</div>
|
|
268
|
+
<p className="text-muted-foreground mt-1 text-xs">
|
|
269
|
+
{strength.label
|
|
270
|
+
? t(strength.label as 'tooShort' | 'weak' | 'fair' | 'good' | 'strong')
|
|
271
|
+
: ''}
|
|
272
|
+
</p>
|
|
273
|
+
</div>
|
|
274
|
+
)}
|
|
275
|
+
{passwordError && <p className="text-destructive mt-1 text-xs">{passwordError}</p>}
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
{/* Birthday: month and day only, never a year. Optional unless the
|
|
279
|
+
merchant made it mandatory on this sales channel. */}
|
|
280
|
+
<div>
|
|
281
|
+
<label
|
|
282
|
+
htmlFor="register-birthday"
|
|
283
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
284
|
+
>
|
|
285
|
+
{tc('birthday')}
|
|
286
|
+
{birthdayRequired && <span className="text-destructive"> *</span>}
|
|
287
|
+
</label>
|
|
288
|
+
<BirthdayPicker
|
|
289
|
+
id="register-birthday"
|
|
290
|
+
month={toBirthdayNumber(birthMonth)}
|
|
291
|
+
day={toBirthdayNumber(birthDay)}
|
|
292
|
+
onChange={selectBirthday}
|
|
293
|
+
required={birthdayRequired}
|
|
294
|
+
invalid={birthdayError !== null}
|
|
295
|
+
/>
|
|
296
|
+
<p className="text-muted-foreground mt-1.5 text-xs">{tc('birthdayGiftNote')}</p>
|
|
297
|
+
{birthdayError && <p className="text-destructive mt-1 text-xs">{birthdayError}</p>}
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
{/* Privacy Policy (required) */}
|
|
301
|
+
<div>
|
|
302
|
+
<label className="flex cursor-pointer items-start gap-2">
|
|
303
|
+
<input
|
|
304
|
+
type="checkbox"
|
|
305
|
+
checked={privacyAccepted}
|
|
306
|
+
onChange={(e) => {
|
|
307
|
+
setPrivacyAccepted(e.target.checked);
|
|
308
|
+
setPrivacyError(false);
|
|
309
|
+
}}
|
|
310
|
+
className="accent-primary mt-0.5"
|
|
311
|
+
/>
|
|
312
|
+
<span className="text-muted-foreground text-sm">
|
|
313
|
+
{t('privacyAcceptPrefix')}{' '}
|
|
314
|
+
<a
|
|
315
|
+
href="/privacy"
|
|
316
|
+
target="_blank"
|
|
317
|
+
rel="noopener noreferrer"
|
|
318
|
+
className="text-primary underline underline-offset-2"
|
|
319
|
+
>
|
|
320
|
+
{t('privacyPolicyLink')}
|
|
321
|
+
</a>{' '}
|
|
322
|
+
<span className="text-destructive">*</span>
|
|
323
|
+
</span>
|
|
324
|
+
</label>
|
|
325
|
+
{privacyError && <p className="text-destructive mt-1 text-xs">{t('privacyRequired')}</p>}
|
|
326
|
+
</div>
|
|
327
|
+
|
|
328
|
+
{/* Marketing consent (optional) */}
|
|
329
|
+
<label className="flex cursor-pointer items-start gap-2">
|
|
330
|
+
<input
|
|
331
|
+
type="checkbox"
|
|
332
|
+
checked={acceptsMarketing}
|
|
333
|
+
onChange={(e) => setAcceptsMarketing(e.target.checked)}
|
|
334
|
+
className="accent-primary mt-0.5"
|
|
335
|
+
/>
|
|
336
|
+
<span className="text-muted-foreground text-sm">{t('acceptsMarketing')}</span>
|
|
337
|
+
</label>
|
|
338
|
+
|
|
339
|
+
<button
|
|
340
|
+
type="submit"
|
|
341
|
+
disabled={loading}
|
|
342
|
+
className="bg-primary text-primary-foreground flex h-10 w-full items-center justify-center gap-2 rounded text-sm font-medium transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50"
|
|
343
|
+
>
|
|
344
|
+
{loading ? (
|
|
345
|
+
<>
|
|
346
|
+
<LoadingSpinner
|
|
347
|
+
size="sm"
|
|
348
|
+
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
349
|
+
/>
|
|
350
|
+
{t('creatingAccount')}
|
|
351
|
+
</>
|
|
352
|
+
) : (
|
|
353
|
+
t('createAccount')
|
|
354
|
+
)}
|
|
355
|
+
</button>
|
|
356
|
+
</form>
|
|
357
|
+
);
|
|
358
|
+
}
|