create-brainerce-store 1.0.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.d.ts +1 -0
- package/dist/index.js +502 -0
- package/package.json +44 -0
- package/templates/nextjs/base/.env.local.ejs +3 -0
- package/templates/nextjs/base/.eslintrc.json +3 -0
- package/templates/nextjs/base/gitignore +30 -0
- package/templates/nextjs/base/next.config.ts +9 -0
- package/templates/nextjs/base/package.json.ejs +30 -0
- package/templates/nextjs/base/postcss.config.mjs +9 -0
- package/templates/nextjs/base/src/app/account/page.tsx +105 -0
- package/templates/nextjs/base/src/app/auth/callback/page.tsx +99 -0
- package/templates/nextjs/base/src/app/cart/page.tsx +263 -0
- package/templates/nextjs/base/src/app/checkout/page.tsx +463 -0
- package/templates/nextjs/base/src/app/globals.css +30 -0
- package/templates/nextjs/base/src/app/layout.tsx.ejs +33 -0
- package/templates/nextjs/base/src/app/login/page.tsx +56 -0
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +191 -0
- package/templates/nextjs/base/src/app/page.tsx +95 -0
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +346 -0
- package/templates/nextjs/base/src/app/products/page.tsx +243 -0
- package/templates/nextjs/base/src/app/register/page.tsx +66 -0
- package/templates/nextjs/base/src/app/verify-email/page.tsx +291 -0
- package/templates/nextjs/base/src/components/account/order-history.tsx +184 -0
- package/templates/nextjs/base/src/components/account/profile-section.tsx +73 -0
- package/templates/nextjs/base/src/components/auth/login-form.tsx +92 -0
- package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +134 -0
- package/templates/nextjs/base/src/components/auth/register-form.tsx +177 -0
- package/templates/nextjs/base/src/components/cart/cart-item.tsx +150 -0
- package/templates/nextjs/base/src/components/cart/cart-nudges.tsx +39 -0
- package/templates/nextjs/base/src/components/cart/cart-summary.tsx +67 -0
- package/templates/nextjs/base/src/components/cart/coupon-input.tsx +131 -0
- package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +100 -0
- package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +273 -0
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +124 -0
- package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +111 -0
- package/templates/nextjs/base/src/components/checkout/tax-display.tsx +62 -0
- package/templates/nextjs/base/src/components/layout/footer.tsx +35 -0
- package/templates/nextjs/base/src/components/layout/header.tsx +329 -0
- package/templates/nextjs/base/src/components/products/discount-badge.tsx +36 -0
- package/templates/nextjs/base/src/components/products/product-card.tsx +94 -0
- package/templates/nextjs/base/src/components/products/product-grid.tsx +33 -0
- package/templates/nextjs/base/src/components/products/stock-badge.tsx +34 -0
- package/templates/nextjs/base/src/components/products/variant-selector.tsx +147 -0
- package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +30 -0
- package/templates/nextjs/base/src/components/shared/price-display.tsx +62 -0
- package/templates/nextjs/base/src/hooks/use-search.ts +77 -0
- package/templates/nextjs/base/src/lib/brainerce.ts.ejs +59 -0
- package/templates/nextjs/base/src/lib/utils.ts +6 -0
- package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +168 -0
- package/templates/nextjs/base/tailwind.config.ts +30 -0
- package/templates/nextjs/base/tsconfig.json +23 -0
- package/templates/nextjs/themes/minimal/globals.css +30 -0
- package/templates/nextjs/themes/minimal/theme.json +23 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
import type { Order, OrderStatus } from 'brainerce';
|
|
6
|
+
import { formatPrice } from 'brainerce';
|
|
7
|
+
import { cn } from '@/lib/utils';
|
|
8
|
+
|
|
9
|
+
const STATUS_CONFIG: Record<OrderStatus, { label: string; className: string }> = {
|
|
10
|
+
pending: {
|
|
11
|
+
label: 'Pending',
|
|
12
|
+
className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
|
|
13
|
+
},
|
|
14
|
+
processing: {
|
|
15
|
+
label: 'Processing',
|
|
16
|
+
className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
|
|
17
|
+
},
|
|
18
|
+
shipped: {
|
|
19
|
+
label: 'Shipped',
|
|
20
|
+
className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
|
|
21
|
+
},
|
|
22
|
+
delivered: {
|
|
23
|
+
label: 'Delivered',
|
|
24
|
+
className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
|
|
25
|
+
},
|
|
26
|
+
cancelled: {
|
|
27
|
+
label: 'Cancelled',
|
|
28
|
+
className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
|
|
29
|
+
},
|
|
30
|
+
refunded: {
|
|
31
|
+
label: 'Refunded',
|
|
32
|
+
className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
interface OrderHistoryProps {
|
|
37
|
+
orders: Order[];
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function OrderHistory({ orders, className }: OrderHistoryProps) {
|
|
42
|
+
if (orders.length === 0) {
|
|
43
|
+
return (
|
|
44
|
+
<div className={cn('py-12 text-center', className)}>
|
|
45
|
+
<svg
|
|
46
|
+
className="text-muted-foreground mx-auto mb-3 h-12 w-12"
|
|
47
|
+
fill="none"
|
|
48
|
+
viewBox="0 0 24 24"
|
|
49
|
+
stroke="currentColor"
|
|
50
|
+
>
|
|
51
|
+
<path
|
|
52
|
+
strokeLinecap="round"
|
|
53
|
+
strokeLinejoin="round"
|
|
54
|
+
strokeWidth={1.5}
|
|
55
|
+
d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
|
|
56
|
+
/>
|
|
57
|
+
</svg>
|
|
58
|
+
<h3 className="text-foreground text-lg font-semibold">No orders yet</h3>
|
|
59
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
60
|
+
Your order history will appear here after your first purchase.
|
|
61
|
+
</p>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className={cn('space-y-4', className)}>
|
|
68
|
+
{orders.map((order) => (
|
|
69
|
+
<OrderCard key={order.id} order={order} />
|
|
70
|
+
))}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function OrderCard({ order }: { order: Order }) {
|
|
76
|
+
const [expanded, setExpanded] = useState(false);
|
|
77
|
+
const statusConfig = STATUS_CONFIG[order.status] || STATUS_CONFIG.pending;
|
|
78
|
+
const currency = order.currency || 'USD';
|
|
79
|
+
const totalAmount = order.totalAmount || order.total || '0';
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div className="border-border overflow-hidden rounded-lg border">
|
|
83
|
+
{/* Order header */}
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
onClick={() => setExpanded(!expanded)}
|
|
87
|
+
className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
|
|
88
|
+
>
|
|
89
|
+
<div className="min-w-0 flex-1">
|
|
90
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
91
|
+
<span className="text-foreground text-sm font-semibold">
|
|
92
|
+
{order.orderNumber || `Order ${order.id.slice(0, 8)}`}
|
|
93
|
+
</span>
|
|
94
|
+
<span
|
|
95
|
+
className={cn(
|
|
96
|
+
'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
|
|
97
|
+
statusConfig.className
|
|
98
|
+
)}
|
|
99
|
+
>
|
|
100
|
+
{statusConfig.label}
|
|
101
|
+
</span>
|
|
102
|
+
</div>
|
|
103
|
+
<div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
|
|
104
|
+
<span>
|
|
105
|
+
{new Date(order.createdAt).toLocaleDateString(undefined, {
|
|
106
|
+
year: 'numeric',
|
|
107
|
+
month: 'short',
|
|
108
|
+
day: 'numeric',
|
|
109
|
+
})}
|
|
110
|
+
</span>
|
|
111
|
+
<span>
|
|
112
|
+
{order.items.length} {order.items.length === 1 ? 'item' : 'items'}
|
|
113
|
+
</span>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<div className="flex flex-shrink-0 items-center gap-3">
|
|
118
|
+
<span className="text-foreground text-sm font-semibold">
|
|
119
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
120
|
+
</span>
|
|
121
|
+
<svg
|
|
122
|
+
className={cn(
|
|
123
|
+
'text-muted-foreground h-4 w-4 transition-transform',
|
|
124
|
+
expanded && 'rotate-180'
|
|
125
|
+
)}
|
|
126
|
+
fill="none"
|
|
127
|
+
viewBox="0 0 24 24"
|
|
128
|
+
stroke="currentColor"
|
|
129
|
+
>
|
|
130
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
131
|
+
</svg>
|
|
132
|
+
</div>
|
|
133
|
+
</button>
|
|
134
|
+
|
|
135
|
+
{/* Expanded order items */}
|
|
136
|
+
{expanded && (
|
|
137
|
+
<div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
|
|
138
|
+
{order.items.map((item, index) => (
|
|
139
|
+
<div key={`${item.productId}-${index}`} className="flex items-center gap-3">
|
|
140
|
+
<div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
|
|
141
|
+
{item.image ? (
|
|
142
|
+
<Image
|
|
143
|
+
src={item.image}
|
|
144
|
+
alt={item.name || 'Product'}
|
|
145
|
+
fill
|
|
146
|
+
sizes="40px"
|
|
147
|
+
className="object-cover"
|
|
148
|
+
/>
|
|
149
|
+
) : (
|
|
150
|
+
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
151
|
+
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
152
|
+
<path
|
|
153
|
+
strokeLinecap="round"
|
|
154
|
+
strokeLinejoin="round"
|
|
155
|
+
strokeWidth={1.5}
|
|
156
|
+
d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
|
|
157
|
+
/>
|
|
158
|
+
</svg>
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<div className="min-w-0 flex-1">
|
|
164
|
+
<p className="text-foreground truncate text-sm">{item.name || 'Product'}</p>
|
|
165
|
+
<p className="text-muted-foreground text-xs">Qty: {item.quantity}</p>
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<span className="text-foreground flex-shrink-0 text-sm">
|
|
169
|
+
{formatPrice(parseFloat(item.price), { currency }) as string}
|
|
170
|
+
</span>
|
|
171
|
+
</div>
|
|
172
|
+
))}
|
|
173
|
+
|
|
174
|
+
<div className="border-border flex items-center justify-between border-t pt-2">
|
|
175
|
+
<span className="text-muted-foreground text-sm font-medium">Total</span>
|
|
176
|
+
<span className="text-foreground text-sm font-semibold">
|
|
177
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
178
|
+
</span>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type { CustomerProfile } from 'brainerce';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
|
|
6
|
+
interface ProfileSectionProps {
|
|
7
|
+
profile: CustomerProfile;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ProfileSection({ profile, className }: ProfileSectionProps) {
|
|
12
|
+
const fullName = [profile.firstName, profile.lastName].filter(Boolean).join(' ');
|
|
13
|
+
const initials =
|
|
14
|
+
[profile.firstName?.[0], profile.lastName?.[0]].filter(Boolean).join('').toUpperCase() ||
|
|
15
|
+
profile.email[0].toUpperCase();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className={cn('border-border rounded-lg border p-6', className)}>
|
|
19
|
+
<div className="flex items-start gap-4">
|
|
20
|
+
{/* Avatar */}
|
|
21
|
+
<div className="bg-primary/10 text-primary flex h-14 w-14 flex-shrink-0 items-center justify-center rounded-full text-lg font-semibold">
|
|
22
|
+
{initials}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div className="min-w-0 flex-1">
|
|
26
|
+
{fullName && (
|
|
27
|
+
<h2 className="text-foreground truncate text-lg font-semibold">{fullName}</h2>
|
|
28
|
+
)}
|
|
29
|
+
<p className="text-muted-foreground truncate text-sm">{profile.email}</p>
|
|
30
|
+
|
|
31
|
+
<div className="mt-2 flex items-center gap-2">
|
|
32
|
+
{profile.emailVerified ? (
|
|
33
|
+
<span className="inline-flex items-center gap-1 rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700 dark:bg-green-950/30 dark:text-green-400">
|
|
34
|
+
<svg className="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
35
|
+
<path
|
|
36
|
+
strokeLinecap="round"
|
|
37
|
+
strokeLinejoin="round"
|
|
38
|
+
strokeWidth={2}
|
|
39
|
+
d="M5 13l4 4L19 7"
|
|
40
|
+
/>
|
|
41
|
+
</svg>
|
|
42
|
+
Verified
|
|
43
|
+
</span>
|
|
44
|
+
) : (
|
|
45
|
+
<span className="inline-flex items-center gap-1 rounded-full bg-orange-100 px-2 py-0.5 text-xs font-medium text-orange-700 dark:bg-orange-950/30 dark:text-orange-400">
|
|
46
|
+
<svg className="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
47
|
+
<path
|
|
48
|
+
strokeLinecap="round"
|
|
49
|
+
strokeLinejoin="round"
|
|
50
|
+
strokeWidth={2}
|
|
51
|
+
d="M12 9v2m0 4h.01"
|
|
52
|
+
/>
|
|
53
|
+
</svg>
|
|
54
|
+
Unverified
|
|
55
|
+
</span>
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
{profile.phone && <p className="text-muted-foreground mt-2 text-sm">{profile.phone}</p>}
|
|
60
|
+
|
|
61
|
+
<p className="text-muted-foreground mt-3 text-xs">
|
|
62
|
+
Member since{' '}
|
|
63
|
+
{new Date(profile.createdAt).toLocaleDateString(undefined, {
|
|
64
|
+
year: 'numeric',
|
|
65
|
+
month: 'long',
|
|
66
|
+
day: 'numeric',
|
|
67
|
+
})}
|
|
68
|
+
</p>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
6
|
+
|
|
7
|
+
interface LoginFormProps {
|
|
8
|
+
onSubmit: (email: string, password: string) => Promise<void>;
|
|
9
|
+
error?: string | null;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function LoginForm({ onSubmit, error, className }: LoginFormProps) {
|
|
14
|
+
const [email, setEmail] = useState('');
|
|
15
|
+
const [password, setPassword] = useState('');
|
|
16
|
+
const [loading, setLoading] = useState(false);
|
|
17
|
+
|
|
18
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
if (loading) return;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
setLoading(true);
|
|
24
|
+
await onSubmit(email, password);
|
|
25
|
+
} finally {
|
|
26
|
+
setLoading(false);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
|
|
32
|
+
{error && (
|
|
33
|
+
<div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
|
|
34
|
+
{error}
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
|
|
38
|
+
<div>
|
|
39
|
+
<label htmlFor="login-email" className="text-foreground mb-1.5 block text-sm font-medium">
|
|
40
|
+
Email
|
|
41
|
+
</label>
|
|
42
|
+
<input
|
|
43
|
+
id="login-email"
|
|
44
|
+
type="email"
|
|
45
|
+
required
|
|
46
|
+
value={email}
|
|
47
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
48
|
+
placeholder="you@example.com"
|
|
49
|
+
autoComplete="email"
|
|
50
|
+
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"
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div>
|
|
55
|
+
<label
|
|
56
|
+
htmlFor="login-password"
|
|
57
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
58
|
+
>
|
|
59
|
+
Password
|
|
60
|
+
</label>
|
|
61
|
+
<input
|
|
62
|
+
id="login-password"
|
|
63
|
+
type="password"
|
|
64
|
+
required
|
|
65
|
+
value={password}
|
|
66
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
67
|
+
placeholder="Enter your password"
|
|
68
|
+
autoComplete="current-password"
|
|
69
|
+
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"
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<button
|
|
74
|
+
type="submit"
|
|
75
|
+
disabled={loading}
|
|
76
|
+
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"
|
|
77
|
+
>
|
|
78
|
+
{loading ? (
|
|
79
|
+
<>
|
|
80
|
+
<LoadingSpinner
|
|
81
|
+
size="sm"
|
|
82
|
+
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
83
|
+
/>
|
|
84
|
+
Signing in...
|
|
85
|
+
</>
|
|
86
|
+
) : (
|
|
87
|
+
'Sign In'
|
|
88
|
+
)}
|
|
89
|
+
</button>
|
|
90
|
+
</form>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import type { CustomerOAuthProvider } from 'brainerce';
|
|
5
|
+
import { getClient } from '@/lib/brainerce';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
8
|
+
|
|
9
|
+
const PROVIDER_CONFIG: Record<CustomerOAuthProvider, { label: string; icon: React.ReactNode }> = {
|
|
10
|
+
GOOGLE: {
|
|
11
|
+
label: 'Google',
|
|
12
|
+
icon: (
|
|
13
|
+
<svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
|
|
14
|
+
<path
|
|
15
|
+
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"
|
|
16
|
+
fill="#4285F4"
|
|
17
|
+
/>
|
|
18
|
+
<path
|
|
19
|
+
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"
|
|
20
|
+
fill="#34A853"
|
|
21
|
+
/>
|
|
22
|
+
<path
|
|
23
|
+
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"
|
|
24
|
+
fill="#FBBC05"
|
|
25
|
+
/>
|
|
26
|
+
<path
|
|
27
|
+
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"
|
|
28
|
+
fill="#EA4335"
|
|
29
|
+
/>
|
|
30
|
+
</svg>
|
|
31
|
+
),
|
|
32
|
+
},
|
|
33
|
+
FACEBOOK: {
|
|
34
|
+
label: 'Facebook',
|
|
35
|
+
icon: (
|
|
36
|
+
<svg className="h-5 w-5" viewBox="0 0 24 24" fill="#1877F2">
|
|
37
|
+
<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" />
|
|
38
|
+
</svg>
|
|
39
|
+
),
|
|
40
|
+
},
|
|
41
|
+
GITHUB: {
|
|
42
|
+
label: 'GitHub',
|
|
43
|
+
icon: (
|
|
44
|
+
<svg className="h-5 w-5" viewBox="0 0 24 24" fill="currentColor">
|
|
45
|
+
<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" />
|
|
46
|
+
</svg>
|
|
47
|
+
),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface OAuthButtonsProps {
|
|
52
|
+
className?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function OAuthButtons({ className }: OAuthButtonsProps) {
|
|
56
|
+
const [providers, setProviders] = useState<CustomerOAuthProvider[]>([]);
|
|
57
|
+
const [loading, setLoading] = useState(true);
|
|
58
|
+
const [redirecting, setRedirecting] = useState<CustomerOAuthProvider | null>(null);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
async function fetchProviders() {
|
|
62
|
+
try {
|
|
63
|
+
const client = getClient();
|
|
64
|
+
const result = await client.getAvailableOAuthProviders();
|
|
65
|
+
setProviders(result.providers);
|
|
66
|
+
} catch {
|
|
67
|
+
// OAuth not available - silently hide buttons
|
|
68
|
+
setProviders([]);
|
|
69
|
+
} finally {
|
|
70
|
+
setLoading(false);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fetchProviders();
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
async function handleOAuthClick(provider: CustomerOAuthProvider) {
|
|
78
|
+
if (redirecting) return;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
setRedirecting(provider);
|
|
82
|
+
const client = getClient();
|
|
83
|
+
const redirectUrl = window.location.origin + '/auth/callback?provider=' + provider;
|
|
84
|
+
const result = await client.getOAuthAuthorizeUrl(provider, { redirectUrl });
|
|
85
|
+
window.location.href = result.authorizationUrl;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error('OAuth redirect failed:', err);
|
|
88
|
+
setRedirecting(null);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (loading) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (providers.length === 0) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div className={cn('space-y-3', className)}>
|
|
102
|
+
<div className="relative">
|
|
103
|
+
<div className="absolute inset-0 flex items-center">
|
|
104
|
+
<div className="border-border w-full border-t" />
|
|
105
|
+
</div>
|
|
106
|
+
<div className="relative flex justify-center text-xs uppercase">
|
|
107
|
+
<span className="bg-background text-muted-foreground px-2">or continue with</span>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<div className="grid gap-2">
|
|
112
|
+
{providers.map((provider) => {
|
|
113
|
+
const config = PROVIDER_CONFIG[provider];
|
|
114
|
+
if (!config) return null;
|
|
115
|
+
|
|
116
|
+
const isRedirecting = redirecting === provider;
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<button
|
|
120
|
+
key={provider}
|
|
121
|
+
type="button"
|
|
122
|
+
onClick={() => handleOAuthClick(provider)}
|
|
123
|
+
disabled={!!redirecting}
|
|
124
|
+
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"
|
|
125
|
+
>
|
|
126
|
+
{isRedirecting ? <LoadingSpinner size="sm" /> : config.icon}
|
|
127
|
+
{config.label}
|
|
128
|
+
</button>
|
|
129
|
+
);
|
|
130
|
+
})}
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useMemo } from 'react';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
6
|
+
|
|
7
|
+
interface RegisterData {
|
|
8
|
+
firstName: string;
|
|
9
|
+
lastName: string;
|
|
10
|
+
email: string;
|
|
11
|
+
password: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface RegisterFormProps {
|
|
15
|
+
onSubmit: (data: RegisterData) => Promise<void>;
|
|
16
|
+
error?: string | null;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getPasswordStrength(password: string): { label: string; color: string; width: string } {
|
|
21
|
+
if (password.length === 0) return { label: '', color: '', width: 'w-0' };
|
|
22
|
+
if (password.length < 6) return { label: 'Too short', color: 'bg-destructive', width: 'w-1/4' };
|
|
23
|
+
|
|
24
|
+
let score = 0;
|
|
25
|
+
if (password.length >= 8) score++;
|
|
26
|
+
if (/[A-Z]/.test(password)) score++;
|
|
27
|
+
if (/[0-9]/.test(password)) score++;
|
|
28
|
+
if (/[^A-Za-z0-9]/.test(password)) score++;
|
|
29
|
+
|
|
30
|
+
if (score <= 1) return { label: 'Weak', color: 'bg-orange-500', width: 'w-1/3' };
|
|
31
|
+
if (score <= 2) return { label: 'Fair', color: 'bg-yellow-500', width: 'w-1/2' };
|
|
32
|
+
if (score <= 3) return { label: 'Good', color: 'bg-primary', width: 'w-3/4' };
|
|
33
|
+
return { label: 'Strong', color: 'bg-green-500', width: 'w-full' };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function RegisterForm({ onSubmit, error, className }: RegisterFormProps) {
|
|
37
|
+
const [firstName, setFirstName] = useState('');
|
|
38
|
+
const [lastName, setLastName] = useState('');
|
|
39
|
+
const [email, setEmail] = useState('');
|
|
40
|
+
const [password, setPassword] = useState('');
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
|
|
43
|
+
const strength = useMemo(() => getPasswordStrength(password), [password]);
|
|
44
|
+
|
|
45
|
+
async function handleSubmit(e: React.FormEvent) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
if (loading) return;
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
setLoading(true);
|
|
51
|
+
await onSubmit({ firstName, lastName, email, password });
|
|
52
|
+
} finally {
|
|
53
|
+
setLoading(false);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<form onSubmit={handleSubmit} className={cn('space-y-4', className)}>
|
|
59
|
+
{error && (
|
|
60
|
+
<div className="bg-destructive/10 border-destructive/20 text-destructive rounded-lg border px-4 py-3 text-sm">
|
|
61
|
+
{error}
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
64
|
+
|
|
65
|
+
<div className="grid grid-cols-2 gap-3">
|
|
66
|
+
<div>
|
|
67
|
+
<label
|
|
68
|
+
htmlFor="register-first-name"
|
|
69
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
70
|
+
>
|
|
71
|
+
First Name
|
|
72
|
+
</label>
|
|
73
|
+
<input
|
|
74
|
+
id="register-first-name"
|
|
75
|
+
type="text"
|
|
76
|
+
required
|
|
77
|
+
value={firstName}
|
|
78
|
+
onChange={(e) => setFirstName(e.target.value)}
|
|
79
|
+
placeholder="Jane"
|
|
80
|
+
autoComplete="given-name"
|
|
81
|
+
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"
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<div>
|
|
86
|
+
<label
|
|
87
|
+
htmlFor="register-last-name"
|
|
88
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
89
|
+
>
|
|
90
|
+
Last Name
|
|
91
|
+
</label>
|
|
92
|
+
<input
|
|
93
|
+
id="register-last-name"
|
|
94
|
+
type="text"
|
|
95
|
+
required
|
|
96
|
+
value={lastName}
|
|
97
|
+
onChange={(e) => setLastName(e.target.value)}
|
|
98
|
+
placeholder="Doe"
|
|
99
|
+
autoComplete="family-name"
|
|
100
|
+
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"
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div>
|
|
106
|
+
<label
|
|
107
|
+
htmlFor="register-email"
|
|
108
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
109
|
+
>
|
|
110
|
+
Email
|
|
111
|
+
</label>
|
|
112
|
+
<input
|
|
113
|
+
id="register-email"
|
|
114
|
+
type="email"
|
|
115
|
+
required
|
|
116
|
+
value={email}
|
|
117
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
118
|
+
placeholder="you@example.com"
|
|
119
|
+
autoComplete="email"
|
|
120
|
+
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"
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div>
|
|
125
|
+
<label
|
|
126
|
+
htmlFor="register-password"
|
|
127
|
+
className="text-foreground mb-1.5 block text-sm font-medium"
|
|
128
|
+
>
|
|
129
|
+
Password
|
|
130
|
+
</label>
|
|
131
|
+
<input
|
|
132
|
+
id="register-password"
|
|
133
|
+
type="password"
|
|
134
|
+
required
|
|
135
|
+
minLength={6}
|
|
136
|
+
value={password}
|
|
137
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
138
|
+
placeholder="At least 6 characters"
|
|
139
|
+
autoComplete="new-password"
|
|
140
|
+
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"
|
|
141
|
+
/>
|
|
142
|
+
{password.length > 0 && (
|
|
143
|
+
<div className="mt-2">
|
|
144
|
+
<div className="bg-muted h-1.5 w-full overflow-hidden rounded-full">
|
|
145
|
+
<div
|
|
146
|
+
className={cn(
|
|
147
|
+
'h-full rounded-full transition-all duration-300',
|
|
148
|
+
strength.color,
|
|
149
|
+
strength.width
|
|
150
|
+
)}
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
153
|
+
<p className="text-muted-foreground mt-1 text-xs">{strength.label}</p>
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<button
|
|
159
|
+
type="submit"
|
|
160
|
+
disabled={loading}
|
|
161
|
+
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"
|
|
162
|
+
>
|
|
163
|
+
{loading ? (
|
|
164
|
+
<>
|
|
165
|
+
<LoadingSpinner
|
|
166
|
+
size="sm"
|
|
167
|
+
className="border-primary-foreground/30 border-t-primary-foreground"
|
|
168
|
+
/>
|
|
169
|
+
Creating account...
|
|
170
|
+
</>
|
|
171
|
+
) : (
|
|
172
|
+
'Create Account'
|
|
173
|
+
)}
|
|
174
|
+
</button>
|
|
175
|
+
</form>
|
|
176
|
+
);
|
|
177
|
+
}
|