create-brainerce-store 1.4.1 → 1.5.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 (36) hide show
  1. package/dist/index.js +1 -1
  2. package/messages/en.json +266 -258
  3. package/messages/he.json +266 -258
  4. package/package.json +45 -45
  5. package/templates/nextjs/base/src/app/account/page.tsx +108 -108
  6. package/templates/nextjs/base/src/app/auth/callback/page.tsx +90 -90
  7. package/templates/nextjs/base/src/app/cart/page.tsx +110 -110
  8. package/templates/nextjs/base/src/app/checkout/page.tsx +614 -614
  9. package/templates/nextjs/base/src/app/login/page.tsx +58 -58
  10. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +193 -193
  11. package/templates/nextjs/base/src/app/page.tsx +98 -98
  12. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +435 -435
  13. package/templates/nextjs/base/src/app/products/page.tsx +246 -246
  14. package/templates/nextjs/base/src/app/register/page.tsx +68 -68
  15. package/templates/nextjs/base/src/app/verify-email/page.tsx +293 -293
  16. package/templates/nextjs/base/src/components/account/order-history.tsx +198 -198
  17. package/templates/nextjs/base/src/components/account/profile-section.tsx +210 -75
  18. package/templates/nextjs/base/src/components/auth/login-form.tsx +94 -94
  19. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
  20. package/templates/nextjs/base/src/components/auth/register-form.tsx +184 -184
  21. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
  22. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +70 -70
  23. package/templates/nextjs/base/src/components/cart/coupon-input.tsx +134 -134
  24. package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +103 -103
  25. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +305 -305
  26. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +64 -64
  27. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +350 -344
  28. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +199 -199
  29. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +110 -110
  30. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +65 -65
  31. package/templates/nextjs/base/src/components/layout/footer.tsx +38 -38
  32. package/templates/nextjs/base/src/components/layout/header.tsx +332 -332
  33. package/templates/nextjs/base/src/components/products/product-card.tsx +96 -96
  34. package/templates/nextjs/base/src/components/products/product-grid.tsx +35 -35
  35. package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +32 -32
  36. package/templates/nextjs/base/src/lib/translations.ts +11 -11
@@ -1,137 +1,137 @@
1
- 'use client';
2
-
3
- import { useState, useEffect } from 'react';
4
- import type { CustomerOAuthProvider } from 'brainerce';
5
- import { getClient } from '@/lib/brainerce';
6
- import { useTranslations } from '@/lib/translations';
7
- import { cn } from '@/lib/utils';
8
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
9
-
10
- const PROVIDER_CONFIG: Record<CustomerOAuthProvider, { labelKey: string; icon: React.ReactNode }> =
11
- {
12
- GOOGLE: {
13
- labelKey: 'google',
14
- icon: (
15
- <svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
16
- <path
17
- d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"
18
- fill="#4285F4"
19
- />
20
- <path
21
- d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
22
- fill="#34A853"
23
- />
24
- <path
25
- d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
26
- fill="#FBBC05"
27
- />
28
- <path
29
- d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
30
- fill="#EA4335"
31
- />
32
- </svg>
33
- ),
34
- },
35
- FACEBOOK: {
36
- labelKey: 'facebook',
37
- icon: (
38
- <svg className="h-5 w-5" viewBox="0 0 24 24" fill="#1877F2">
39
- <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
40
- </svg>
41
- ),
42
- },
43
- GITHUB: {
44
- labelKey: 'github',
45
- icon: (
46
- <svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
47
- <path d="M12 0C5.374 0 0 5.373 0 12c0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z" />
48
- </svg>
49
- ),
50
- },
51
- };
52
-
53
- interface OAuthButtonsProps {
54
- className?: string;
55
- }
56
-
57
- export function OAuthButtons({ className }: OAuthButtonsProps) {
58
- const t = useTranslations('auth');
59
- const [providers, setProviders] = useState<CustomerOAuthProvider[]>([]);
60
- const [loading, setLoading] = useState(true);
61
- const [redirecting, setRedirecting] = useState<CustomerOAuthProvider | null>(null);
62
-
63
- useEffect(() => {
64
- async function fetchProviders() {
65
- try {
66
- const client = getClient();
67
- const result = await client.getAvailableOAuthProviders();
68
- setProviders(result.providers);
69
- } catch {
70
- // OAuth not available - silently hide buttons
71
- setProviders([]);
72
- } finally {
73
- setLoading(false);
74
- }
75
- }
76
-
77
- fetchProviders();
78
- }, []);
79
-
80
- async function handleOAuthClick(provider: CustomerOAuthProvider) {
81
- if (redirecting) return;
82
-
83
- try {
84
- setRedirecting(provider);
85
- const client = getClient();
86
- const redirectUrl = window.location.origin + '/auth/callback';
87
- const result = await client.getOAuthAuthorizeUrl(provider, { redirectUrl });
88
- window.location.href = result.authorizationUrl;
89
- } catch (err) {
90
- console.error('OAuth redirect failed:', err);
91
- setRedirecting(null);
92
- }
93
- }
94
-
95
- if (loading) {
96
- return null;
97
- }
98
-
99
- if (providers.length === 0) {
100
- return null;
101
- }
102
-
103
- return (
104
- <div className={cn('space-y-3', className)}>
105
- <div className="relative">
106
- <div className="absolute inset-0 flex items-center">
107
- <div className="border-border w-full border-t" />
108
- </div>
109
- <div className="relative flex justify-center text-xs uppercase">
110
- <span className="bg-background text-muted-foreground px-2">{t('orContinueWith')}</span>
111
- </div>
112
- </div>
113
-
114
- <div className="grid gap-2">
115
- {providers.map((provider) => {
116
- const config = PROVIDER_CONFIG[provider];
117
- if (!config) return null;
118
-
119
- const isRedirecting = redirecting === provider;
120
-
121
- return (
122
- <button
123
- key={provider}
124
- type="button"
125
- onClick={() => handleOAuthClick(provider)}
126
- disabled={!!redirecting}
127
- className="border-border text-foreground bg-background hover:bg-muted flex h-10 w-full items-center justify-center gap-2 rounded border text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50"
128
- >
129
- {isRedirecting ? <LoadingSpinner size="sm" /> : config.icon}
130
- {t(config.labelKey as 'google' | 'facebook' | 'github')}
131
- </button>
132
- );
133
- })}
134
- </div>
135
- </div>
136
- );
137
- }
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import type { CustomerOAuthProvider } from 'brainerce';
5
+ import { getClient } from '@/lib/brainerce';
6
+ import { useTranslations } from '@/lib/translations';
7
+ import { cn } from '@/lib/utils';
8
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
9
+
10
+ const PROVIDER_CONFIG: Record<CustomerOAuthProvider, { labelKey: string; icon: React.ReactNode }> =
11
+ {
12
+ GOOGLE: {
13
+ labelKey: 'google',
14
+ icon: (
15
+ <svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
16
+ <path
17
+ d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 01-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1z"
18
+ fill="#4285F4"
19
+ />
20
+ <path
21
+ d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
22
+ fill="#34A853"
23
+ />
24
+ <path
25
+ d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
26
+ fill="#FBBC05"
27
+ />
28
+ <path
29
+ d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
30
+ fill="#EA4335"
31
+ />
32
+ </svg>
33
+ ),
34
+ },
35
+ FACEBOOK: {
36
+ labelKey: 'facebook',
37
+ icon: (
38
+ <svg className="h-5 w-5" viewBox="0 0 24 24" fill="#1877F2">
39
+ <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
40
+ </svg>
41
+ ),
42
+ },
43
+ GITHUB: {
44
+ labelKey: 'github',
45
+ icon: (
46
+ <svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
47
+ <path d="M12 0C5.374 0 0 5.373 0 12c0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23A11.509 11.509 0 0112 5.803c1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576C20.566 21.797 24 17.3 24 12c0-6.627-5.373-12-12-12z" />
48
+ </svg>
49
+ ),
50
+ },
51
+ };
52
+
53
+ interface OAuthButtonsProps {
54
+ className?: string;
55
+ }
56
+
57
+ export function OAuthButtons({ className }: OAuthButtonsProps) {
58
+ const t = useTranslations('auth');
59
+ const [providers, setProviders] = useState<CustomerOAuthProvider[]>([]);
60
+ const [loading, setLoading] = useState(true);
61
+ const [redirecting, setRedirecting] = useState<CustomerOAuthProvider | null>(null);
62
+
63
+ useEffect(() => {
64
+ async function fetchProviders() {
65
+ try {
66
+ const client = getClient();
67
+ const result = await client.getAvailableOAuthProviders();
68
+ setProviders(result.providers);
69
+ } catch {
70
+ // OAuth not available - silently hide buttons
71
+ setProviders([]);
72
+ } finally {
73
+ setLoading(false);
74
+ }
75
+ }
76
+
77
+ fetchProviders();
78
+ }, []);
79
+
80
+ async function handleOAuthClick(provider: CustomerOAuthProvider) {
81
+ if (redirecting) return;
82
+
83
+ try {
84
+ setRedirecting(provider);
85
+ const client = getClient();
86
+ const redirectUrl = window.location.origin + '/auth/callback';
87
+ const result = await client.getOAuthAuthorizeUrl(provider, { redirectUrl });
88
+ window.location.href = result.authorizationUrl;
89
+ } catch (err) {
90
+ console.error('OAuth redirect failed:', err);
91
+ setRedirecting(null);
92
+ }
93
+ }
94
+
95
+ if (loading) {
96
+ return null;
97
+ }
98
+
99
+ if (providers.length === 0) {
100
+ return null;
101
+ }
102
+
103
+ return (
104
+ <div className={cn('space-y-3', className)}>
105
+ <div className="relative">
106
+ <div className="absolute inset-0 flex items-center">
107
+ <div className="border-border w-full border-t" />
108
+ </div>
109
+ <div className="relative flex justify-center text-xs uppercase">
110
+ <span className="bg-background text-muted-foreground px-2">{t('orContinueWith')}</span>
111
+ </div>
112
+ </div>
113
+
114
+ <div className="grid gap-2">
115
+ {providers.map((provider) => {
116
+ const config = PROVIDER_CONFIG[provider];
117
+ if (!config) return null;
118
+
119
+ const isRedirecting = redirecting === provider;
120
+
121
+ return (
122
+ <button
123
+ key={provider}
124
+ type="button"
125
+ onClick={() => handleOAuthClick(provider)}
126
+ disabled={!!redirecting}
127
+ className="border-border text-foreground bg-background hover:bg-muted flex h-10 w-full items-center justify-center gap-2 rounded border text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50"
128
+ >
129
+ {isRedirecting ? <LoadingSpinner size="sm" /> : config.icon}
130
+ {t(config.labelKey as 'google' | 'facebook' | 'github')}
131
+ </button>
132
+ );
133
+ })}
134
+ </div>
135
+ </div>
136
+ );
137
+ }
@@ -1,184 +1,184 @@
1
- 'use client';
2
-
3
- import { useState, useMemo } from 'react';
4
- import { useTranslations } from '@/lib/translations';
5
- import { cn } from '@/lib/utils';
6
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
-
8
- interface RegisterData {
9
- firstName: string;
10
- lastName: string;
11
- email: string;
12
- password: string;
13
- }
14
-
15
- interface RegisterFormProps {
16
- onSubmit: (data: RegisterData) => Promise<void>;
17
- error?: string | null;
18
- className?: string;
19
- }
20
-
21
- function getPasswordStrength(password: string): { label: string; color: string; width: string } {
22
- if (password.length === 0) return { label: '', color: '', width: 'w-0' };
23
- if (password.length < 6) return { label: 'tooShort', color: 'bg-destructive', width: 'w-1/4' };
24
-
25
- let score = 0;
26
- if (password.length >= 8) score++;
27
- if (/[A-Z]/.test(password)) score++;
28
- if (/[0-9]/.test(password)) score++;
29
- if (/[^A-Za-z0-9]/.test(password)) score++;
30
-
31
- if (score <= 1) return { label: 'weak', color: 'bg-orange-500', width: 'w-1/3' };
32
- if (score <= 2) return { label: 'fair', color: 'bg-yellow-500', width: 'w-1/2' };
33
- if (score <= 3) return { label: 'good', color: 'bg-primary', width: 'w-3/4' };
34
- return { label: 'strong', color: 'bg-green-500', width: 'w-full' };
35
- }
36
-
37
- export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
38
- const t = useTranslations('auth');
39
- const tf = useTranslations('checkoutForm');
40
- const [firstName, setFirstName] = useState('');
41
- const [lastName, setLastName] = useState('');
42
- const [email, setEmail] = useState('');
43
- const [password, setPassword] = useState('');
44
- const [loading, setLoading] = useState(false);
45
-
46
- const strength = useMemo(() => getPasswordStrength(password), [password]);
47
-
48
- async function handleSubmit(e: React.FormEvent) {
49
- e.preventDefault();
50
- if (loading) return;
51
-
52
- try {
53
- setLoading(true);
54
- await onSubmit({ firstName, lastName, email, password });
55
- } finally {
56
- setLoading(false);
57
- }
58
- }
59
-
60
- return (
61
- <form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
62
- {error && (
63
- <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
64
- {error}
65
- </div>
66
- )}
67
-
68
- <div className="grid grid-cols-2 gap-3">
69
- <div>
70
- <label
71
- htmlFor="register-first-name"
72
- className="text-foreground mb-1.5 block text-sm font-medium"
73
- >
74
- {tf('firstName')}
75
- </label>
76
- <input
77
- id="register-first-name"
78
- type="text"
79
- required
80
- value={firstName}
81
- onChange={(e) => setFirstName(e.target.value)}
82
- placeholder={t('firstNamePlaceholder')}
83
- autoComplete="given-name"
84
- 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"
85
- />
86
- </div>
87
-
88
- <div>
89
- <label
90
- htmlFor="register-last-name"
91
- className="text-foreground mb-1.5 block text-sm font-medium"
92
- >
93
- {tf('lastName')}
94
- </label>
95
- <input
96
- id="register-last-name"
97
- type="text"
98
- required
99
- value={lastName}
100
- onChange={(e) => setLastName(e.target.value)}
101
- placeholder={t('lastNamePlaceholder')}
102
- autoComplete="family-name"
103
- 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"
104
- />
105
- </div>
106
- </div>
107
-
108
- <div>
109
- <label
110
- htmlFor="register-email"
111
- className="text-foreground mb-1.5 block text-sm font-medium"
112
- >
113
- {t('email')}
114
- </label>
115
- <input
116
- id="register-email"
117
- type="email"
118
- required
119
- value={email}
120
- onChange={(e) => setEmail(e.target.value)}
121
- placeholder={t('emailPlaceholder')}
122
- autoComplete="email"
123
- 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"
124
- />
125
- </div>
126
-
127
- <div>
128
- <label
129
- htmlFor="register-password"
130
- className="text-foreground mb-1.5 block text-sm font-medium"
131
- >
132
- {t('password')}
133
- </label>
134
- <input
135
- id="register-password"
136
- type="password"
137
- required
138
- minLength={6}
139
- value={password}
140
- onChange={(e) => setPassword(e.target.value)}
141
- placeholder={t('atLeastChars')}
142
- autoComplete="new-password"
143
- 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"
144
- />
145
- {password.length > 0 && (
146
- <div className="mt-2">
147
- <div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
148
- <div
149
- className={cn(
150
- 'h-full rounded-full transition-all duration-300',
151
- strength.color,
152
- strength.width
153
- )}
154
- />
155
- </div>
156
- <p className="text-muted-foreground mt-1 text-xs">
157
- {strength.label
158
- ? t(strength.label as 'tooShort' | 'weak' | 'fair' | 'good' | 'strong')
159
- : ''}
160
- </p>
161
- </div>
162
- )}
163
- </div>
164
-
165
- <button
166
- type="submit"
167
- disabled={loading}
168
- 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"
169
- >
170
- {loading ? (
171
- <>
172
- <LoadingSpinner
173
- size="sm"
174
- className="border-primary-foreground/30 border-t-primary-foreground"
175
- />
176
- {t('creatingAccount')}
177
- </>
178
- ) : (
179
- t('createAccount')
180
- )}
181
- </button>
182
- </form>
183
- );
184
- }
1
+ 'use client';
2
+
3
+ import { useState, useMemo } from 'react';
4
+ import { useTranslations } from '@/lib/translations';
5
+ import { cn } from '@/lib/utils';
6
+ import { LoadingSpinner } from '@/components/shared/loading-spinner';
7
+
8
+ interface RegisterData {
9
+ firstName: string;
10
+ lastName: string;
11
+ email: string;
12
+ password: string;
13
+ }
14
+
15
+ interface RegisterFormProps {
16
+ onSubmit: (data: RegisterData) => Promise<void>;
17
+ error?: string | null;
18
+ className?: string;
19
+ }
20
+
21
+ function getPasswordStrength(password: string): { label: string; color: string; width: string } {
22
+ if (password.length === 0) return { label: '', color: '', width: 'w-0' };
23
+ if (password.length < 6) return { label: 'tooShort', color: 'bg-destructive', width: 'w-1/4' };
24
+
25
+ let score = 0;
26
+ if (password.length >= 8) score++;
27
+ if (/[A-Z]/.test(password)) score++;
28
+ if (/[0-9]/.test(password)) score++;
29
+ if (/[^A-Za-z0-9]/.test(password)) score++;
30
+
31
+ if (score <= 1) return { label: 'weak', color: 'bg-orange-500', width: 'w-1/3' };
32
+ if (score <= 2) return { label: 'fair', color: 'bg-yellow-500', width: 'w-1/2' };
33
+ if (score <= 3) return { label: 'good', color: 'bg-primary', width: 'w-3/4' };
34
+ return { label: 'strong', color: 'bg-green-500', width: 'w-full' };
35
+ }
36
+
37
+ export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
38
+ const t = useTranslations('auth');
39
+ const tf = useTranslations('checkoutForm');
40
+ const [firstName, setFirstName] = useState('');
41
+ const [lastName, setLastName] = useState('');
42
+ const [email, setEmail] = useState('');
43
+ const [password, setPassword] = useState('');
44
+ const [loading, setLoading] = useState(false);
45
+
46
+ const strength = useMemo(() => getPasswordStrength(password), [password]);
47
+
48
+ async function handleSubmit(e: React.FormEvent) {
49
+ e.preventDefault();
50
+ if (loading) return;
51
+
52
+ try {
53
+ setLoading(true);
54
+ await onSubmit({ firstName, lastName, email, password });
55
+ } finally {
56
+ setLoading(false);
57
+ }
58
+ }
59
+
60
+ return (
61
+ <form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
62
+ {error && (
63
+ <div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
64
+ {error}
65
+ </div>
66
+ )}
67
+
68
+ <div className="grid grid-cols-2 gap-3">
69
+ <div>
70
+ <label
71
+ htmlFor="register-first-name"
72
+ className="text-foreground mb-1.5 block text-sm font-medium"
73
+ >
74
+ {tf('firstName')}
75
+ </label>
76
+ <input
77
+ id="register-first-name"
78
+ type="text"
79
+ required
80
+ value={firstName}
81
+ onChange={(e) => setFirstName(e.target.value)}
82
+ placeholder={t('firstNamePlaceholder')}
83
+ autoComplete="given-name"
84
+ 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"
85
+ />
86
+ </div>
87
+
88
+ <div>
89
+ <label
90
+ htmlFor="register-last-name"
91
+ className="text-foreground mb-1.5 block text-sm font-medium"
92
+ >
93
+ {tf('lastName')}
94
+ </label>
95
+ <input
96
+ id="register-last-name"
97
+ type="text"
98
+ required
99
+ value={lastName}
100
+ onChange={(e) => setLastName(e.target.value)}
101
+ placeholder={t('lastNamePlaceholder')}
102
+ autoComplete="family-name"
103
+ 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"
104
+ />
105
+ </div>
106
+ </div>
107
+
108
+ <div>
109
+ <label
110
+ htmlFor="register-email"
111
+ className="text-foreground mb-1.5 block text-sm font-medium"
112
+ >
113
+ {t('email')}
114
+ </label>
115
+ <input
116
+ id="register-email"
117
+ type="email"
118
+ required
119
+ value={email}
120
+ onChange={(e) => setEmail(e.target.value)}
121
+ placeholder={t('emailPlaceholder')}
122
+ autoComplete="email"
123
+ 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"
124
+ />
125
+ </div>
126
+
127
+ <div>
128
+ <label
129
+ htmlFor="register-password"
130
+ className="text-foreground mb-1.5 block text-sm font-medium"
131
+ >
132
+ {t('password')}
133
+ </label>
134
+ <input
135
+ id="register-password"
136
+ type="password"
137
+ required
138
+ minLength={6}
139
+ value={password}
140
+ onChange={(e) => setPassword(e.target.value)}
141
+ placeholder={t('atLeastChars')}
142
+ autoComplete="new-password"
143
+ 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"
144
+ />
145
+ {password.length > 0 && (
146
+ <div className="mt-2">
147
+ <div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
148
+ <div
149
+ className={cn(
150
+ 'h-full rounded-full transition-all duration-300',
151
+ strength.color,
152
+ strength.width
153
+ )}
154
+ />
155
+ </div>
156
+ <p className="text-muted-foreground mt-1 text-xs">
157
+ {strength.label
158
+ ? t(strength.label as 'tooShort' | 'weak' | 'fair' | 'good' | 'strong')
159
+ : ''}
160
+ </p>
161
+ </div>
162
+ )}
163
+ </div>
164
+
165
+ <button
166
+ type="submit"
167
+ disabled={loading}
168
+ 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"
169
+ >
170
+ {loading ? (
171
+ <>
172
+ <LoadingSpinner
173
+ size="sm"
174
+ className="border-primary-foreground/30 border-t-primary-foreground"
175
+ />
176
+ {t('creatingAccount')}
177
+ </>
178
+ ) : (
179
+ t('createAccount')
180
+ )}
181
+ </button>
182
+ </form>
183
+ );
184
+ }