create-brainerce-store 1.4.1 → 1.5.1
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 +1 -1
- package/messages/en.json +9 -1
- package/messages/he.json +9 -1
- package/package.json +1 -1
- package/templates/nextjs/base/src/app/account/page.tsx +8 -4
- package/templates/nextjs/base/src/app/auth/callback/page.tsx +90 -90
- package/templates/nextjs/base/src/app/cart/page.tsx +110 -110
- package/templates/nextjs/base/src/app/checkout/page.tsx +614 -614
- package/templates/nextjs/base/src/app/login/page.tsx +58 -58
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +193 -193
- package/templates/nextjs/base/src/app/page.tsx +98 -98
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +435 -435
- package/templates/nextjs/base/src/app/products/page.tsx +246 -246
- package/templates/nextjs/base/src/app/register/page.tsx +68 -68
- package/templates/nextjs/base/src/app/verify-email/page.tsx +293 -293
- package/templates/nextjs/base/src/components/account/order-history.tsx +198 -198
- package/templates/nextjs/base/src/components/account/profile-section.tsx +189 -40
- package/templates/nextjs/base/src/components/auth/login-form.tsx +94 -94
- package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
- package/templates/nextjs/base/src/components/auth/register-form.tsx +184 -184
- package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
- package/templates/nextjs/base/src/components/cart/cart-summary.tsx +70 -70
- package/templates/nextjs/base/src/components/cart/coupon-input.tsx +134 -134
- package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +103 -103
- package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +305 -305
- package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +64 -64
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +350 -344
- package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +199 -199
- package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +110 -110
- package/templates/nextjs/base/src/components/checkout/tax-display.tsx +65 -65
- package/templates/nextjs/base/src/components/layout/footer.tsx +38 -38
- package/templates/nextjs/base/src/components/layout/header.tsx +332 -332
- package/templates/nextjs/base/src/components/products/product-card.tsx +96 -96
- package/templates/nextjs/base/src/components/products/product-grid.tsx +35 -35
- package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +32 -32
- package/templates/nextjs/base/src/lib/translations.ts +11 -11
- package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +5 -1
|
@@ -1,198 +1,198 @@
|
|
|
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 { useTranslations } from '@/lib/translations';
|
|
8
|
-
import { cn } from '@/lib/utils';
|
|
9
|
-
|
|
10
|
-
const STATUS_CONFIG: Record<OrderStatus, { labelKey: string; className: string }> = {
|
|
11
|
-
pending: {
|
|
12
|
-
labelKey: 'statusPending',
|
|
13
|
-
className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
|
|
14
|
-
},
|
|
15
|
-
processing: {
|
|
16
|
-
labelKey: 'statusProcessing',
|
|
17
|
-
className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
|
|
18
|
-
},
|
|
19
|
-
shipped: {
|
|
20
|
-
labelKey: 'statusShipped',
|
|
21
|
-
className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
|
|
22
|
-
},
|
|
23
|
-
delivered: {
|
|
24
|
-
labelKey: 'statusDelivered',
|
|
25
|
-
className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
|
|
26
|
-
},
|
|
27
|
-
cancelled: {
|
|
28
|
-
labelKey: 'statusCancelled',
|
|
29
|
-
className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
|
|
30
|
-
},
|
|
31
|
-
refunded: {
|
|
32
|
-
labelKey: 'statusRefunded',
|
|
33
|
-
className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
interface OrderHistoryProps {
|
|
38
|
-
orders: Order[];
|
|
39
|
-
className?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function OrderHistory({ orders, className }: OrderHistoryProps) {
|
|
43
|
-
const t = useTranslations('account');
|
|
44
|
-
if (orders.length === 0) {
|
|
45
|
-
return (
|
|
46
|
-
<div className={cn('py-12 text-center', className)}>
|
|
47
|
-
<svg
|
|
48
|
-
className="text-muted-foreground mx-auto mb-3 h-12 w-12"
|
|
49
|
-
fill="none"
|
|
50
|
-
viewBox="0 0 24 24"
|
|
51
|
-
stroke="currentColor"
|
|
52
|
-
>
|
|
53
|
-
<path
|
|
54
|
-
strokeLinecap="round"
|
|
55
|
-
strokeLinejoin="round"
|
|
56
|
-
strokeWidth={1.5}
|
|
57
|
-
d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
|
|
58
|
-
/>
|
|
59
|
-
</svg>
|
|
60
|
-
<h3 className="text-foreground text-lg font-semibold">{t('noOrders')}</h3>
|
|
61
|
-
<p className="text-muted-foreground mt-1 text-sm">{t('noOrdersDesc')}</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 t = useTranslations('account');
|
|
77
|
-
const tc = useTranslations('common');
|
|
78
|
-
const [expanded, setExpanded] = useState(false);
|
|
79
|
-
const statusConfig = STATUS_CONFIG[order.status] || STATUS_CONFIG.pending;
|
|
80
|
-
const currency = order.currency || 'USD';
|
|
81
|
-
const totalAmount = order.totalAmount || order.total || '0';
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<div className="border-border overflow-hidden rounded-lg border">
|
|
85
|
-
{/* Order header */}
|
|
86
|
-
<button
|
|
87
|
-
type="button"
|
|
88
|
-
onClick={() => setExpanded(!expanded)}
|
|
89
|
-
className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
|
|
90
|
-
>
|
|
91
|
-
<div className="min-w-0 flex-1">
|
|
92
|
-
<div className="flex flex-wrap items-center gap-3">
|
|
93
|
-
<span className="text-foreground text-sm font-semibold">
|
|
94
|
-
{order.orderNumber || `${t('orderPrefix')} ${order.id.slice(0, 8)}`}
|
|
95
|
-
</span>
|
|
96
|
-
<span
|
|
97
|
-
className={cn(
|
|
98
|
-
'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
|
|
99
|
-
statusConfig.className
|
|
100
|
-
)}
|
|
101
|
-
>
|
|
102
|
-
{t(
|
|
103
|
-
statusConfig.labelKey as
|
|
104
|
-
| 'statusPending'
|
|
105
|
-
| 'statusProcessing'
|
|
106
|
-
| 'statusShipped'
|
|
107
|
-
| 'statusDelivered'
|
|
108
|
-
| 'statusCancelled'
|
|
109
|
-
| 'statusRefunded'
|
|
110
|
-
)}
|
|
111
|
-
</span>
|
|
112
|
-
</div>
|
|
113
|
-
<div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
|
|
114
|
-
<span>
|
|
115
|
-
{new Date(order.createdAt).toLocaleDateString(undefined, {
|
|
116
|
-
year: 'numeric',
|
|
117
|
-
month: 'short',
|
|
118
|
-
day: 'numeric',
|
|
119
|
-
})}
|
|
120
|
-
</span>
|
|
121
|
-
<span>
|
|
122
|
-
{order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
|
|
123
|
-
</span>
|
|
124
|
-
</div>
|
|
125
|
-
</div>
|
|
126
|
-
|
|
127
|
-
<div className="flex flex-shrink-0 items-center gap-3">
|
|
128
|
-
<span className="text-foreground text-sm font-semibold">
|
|
129
|
-
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
130
|
-
</span>
|
|
131
|
-
<svg
|
|
132
|
-
className={cn(
|
|
133
|
-
'text-muted-foreground h-4 w-4 transition-transform',
|
|
134
|
-
expanded && 'rotate-180'
|
|
135
|
-
)}
|
|
136
|
-
fill="none"
|
|
137
|
-
viewBox="0 0 24 24"
|
|
138
|
-
stroke="currentColor"
|
|
139
|
-
>
|
|
140
|
-
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
141
|
-
</svg>
|
|
142
|
-
</div>
|
|
143
|
-
</button>
|
|
144
|
-
|
|
145
|
-
{/* Expanded order items */}
|
|
146
|
-
{expanded && (
|
|
147
|
-
<div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
|
|
148
|
-
{order.items.map((item, index) => (
|
|
149
|
-
<div key={`${item.productId}-${index}`} className="flex items-center gap-3">
|
|
150
|
-
<div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
|
|
151
|
-
{item.image ? (
|
|
152
|
-
<Image
|
|
153
|
-
src={item.image}
|
|
154
|
-
alt={item.name || t('productFallback')}
|
|
155
|
-
fill
|
|
156
|
-
sizes="40px"
|
|
157
|
-
className="object-cover"
|
|
158
|
-
/>
|
|
159
|
-
) : (
|
|
160
|
-
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
161
|
-
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
162
|
-
<path
|
|
163
|
-
strokeLinecap="round"
|
|
164
|
-
strokeLinejoin="round"
|
|
165
|
-
strokeWidth={1.5}
|
|
166
|
-
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"
|
|
167
|
-
/>
|
|
168
|
-
</svg>
|
|
169
|
-
</div>
|
|
170
|
-
)}
|
|
171
|
-
</div>
|
|
172
|
-
|
|
173
|
-
<div className="min-w-0 flex-1">
|
|
174
|
-
<p className="text-foreground truncate text-sm">
|
|
175
|
-
{item.name || t('productFallback')}
|
|
176
|
-
</p>
|
|
177
|
-
<p className="text-muted-foreground text-xs">
|
|
178
|
-
{tc('qty')} {item.quantity}
|
|
179
|
-
</p>
|
|
180
|
-
</div>
|
|
181
|
-
|
|
182
|
-
<span className="text-foreground flex-shrink-0 text-sm">
|
|
183
|
-
{formatPrice(parseFloat(item.price), { currency }) as string}
|
|
184
|
-
</span>
|
|
185
|
-
</div>
|
|
186
|
-
))}
|
|
187
|
-
|
|
188
|
-
<div className="border-border flex items-center justify-between border-t pt-2">
|
|
189
|
-
<span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
|
|
190
|
-
<span className="text-foreground text-sm font-semibold">
|
|
191
|
-
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
192
|
-
</span>
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
)}
|
|
196
|
-
</div>
|
|
197
|
-
);
|
|
198
|
-
}
|
|
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 { useTranslations } from '@/lib/translations';
|
|
8
|
+
import { cn } from '@/lib/utils';
|
|
9
|
+
|
|
10
|
+
const STATUS_CONFIG: Record<OrderStatus, { labelKey: string; className: string }> = {
|
|
11
|
+
pending: {
|
|
12
|
+
labelKey: 'statusPending',
|
|
13
|
+
className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
|
|
14
|
+
},
|
|
15
|
+
processing: {
|
|
16
|
+
labelKey: 'statusProcessing',
|
|
17
|
+
className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
|
|
18
|
+
},
|
|
19
|
+
shipped: {
|
|
20
|
+
labelKey: 'statusShipped',
|
|
21
|
+
className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
|
|
22
|
+
},
|
|
23
|
+
delivered: {
|
|
24
|
+
labelKey: 'statusDelivered',
|
|
25
|
+
className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
|
|
26
|
+
},
|
|
27
|
+
cancelled: {
|
|
28
|
+
labelKey: 'statusCancelled',
|
|
29
|
+
className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
|
|
30
|
+
},
|
|
31
|
+
refunded: {
|
|
32
|
+
labelKey: 'statusRefunded',
|
|
33
|
+
className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
interface OrderHistoryProps {
|
|
38
|
+
orders: Order[];
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function OrderHistory({ orders, className }: OrderHistoryProps) {
|
|
43
|
+
const t = useTranslations('account');
|
|
44
|
+
if (orders.length === 0) {
|
|
45
|
+
return (
|
|
46
|
+
<div className={cn('py-12 text-center', className)}>
|
|
47
|
+
<svg
|
|
48
|
+
className="text-muted-foreground mx-auto mb-3 h-12 w-12"
|
|
49
|
+
fill="none"
|
|
50
|
+
viewBox="0 0 24 24"
|
|
51
|
+
stroke="currentColor"
|
|
52
|
+
>
|
|
53
|
+
<path
|
|
54
|
+
strokeLinecap="round"
|
|
55
|
+
strokeLinejoin="round"
|
|
56
|
+
strokeWidth={1.5}
|
|
57
|
+
d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
|
|
58
|
+
/>
|
|
59
|
+
</svg>
|
|
60
|
+
<h3 className="text-foreground text-lg font-semibold">{t('noOrders')}</h3>
|
|
61
|
+
<p className="text-muted-foreground mt-1 text-sm">{t('noOrdersDesc')}</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 t = useTranslations('account');
|
|
77
|
+
const tc = useTranslations('common');
|
|
78
|
+
const [expanded, setExpanded] = useState(false);
|
|
79
|
+
const statusConfig = STATUS_CONFIG[order.status] || STATUS_CONFIG.pending;
|
|
80
|
+
const currency = order.currency || 'USD';
|
|
81
|
+
const totalAmount = order.totalAmount || order.total || '0';
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className="border-border overflow-hidden rounded-lg border">
|
|
85
|
+
{/* Order header */}
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
onClick={() => setExpanded(!expanded)}
|
|
89
|
+
className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
|
|
90
|
+
>
|
|
91
|
+
<div className="min-w-0 flex-1">
|
|
92
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
93
|
+
<span className="text-foreground text-sm font-semibold">
|
|
94
|
+
{order.orderNumber || `${t('orderPrefix')} ${order.id.slice(0, 8)}`}
|
|
95
|
+
</span>
|
|
96
|
+
<span
|
|
97
|
+
className={cn(
|
|
98
|
+
'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
|
|
99
|
+
statusConfig.className
|
|
100
|
+
)}
|
|
101
|
+
>
|
|
102
|
+
{t(
|
|
103
|
+
statusConfig.labelKey as
|
|
104
|
+
| 'statusPending'
|
|
105
|
+
| 'statusProcessing'
|
|
106
|
+
| 'statusShipped'
|
|
107
|
+
| 'statusDelivered'
|
|
108
|
+
| 'statusCancelled'
|
|
109
|
+
| 'statusRefunded'
|
|
110
|
+
)}
|
|
111
|
+
</span>
|
|
112
|
+
</div>
|
|
113
|
+
<div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
|
|
114
|
+
<span>
|
|
115
|
+
{new Date(order.createdAt).toLocaleDateString(undefined, {
|
|
116
|
+
year: 'numeric',
|
|
117
|
+
month: 'short',
|
|
118
|
+
day: 'numeric',
|
|
119
|
+
})}
|
|
120
|
+
</span>
|
|
121
|
+
<span>
|
|
122
|
+
{order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
|
|
123
|
+
</span>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<div className="flex flex-shrink-0 items-center gap-3">
|
|
128
|
+
<span className="text-foreground text-sm font-semibold">
|
|
129
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
130
|
+
</span>
|
|
131
|
+
<svg
|
|
132
|
+
className={cn(
|
|
133
|
+
'text-muted-foreground h-4 w-4 transition-transform',
|
|
134
|
+
expanded && 'rotate-180'
|
|
135
|
+
)}
|
|
136
|
+
fill="none"
|
|
137
|
+
viewBox="0 0 24 24"
|
|
138
|
+
stroke="currentColor"
|
|
139
|
+
>
|
|
140
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
141
|
+
</svg>
|
|
142
|
+
</div>
|
|
143
|
+
</button>
|
|
144
|
+
|
|
145
|
+
{/* Expanded order items */}
|
|
146
|
+
{expanded && (
|
|
147
|
+
<div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
|
|
148
|
+
{order.items.map((item, index) => (
|
|
149
|
+
<div key={`${item.productId}-${index}`} className="flex items-center gap-3">
|
|
150
|
+
<div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
|
|
151
|
+
{item.image ? (
|
|
152
|
+
<Image
|
|
153
|
+
src={item.image}
|
|
154
|
+
alt={item.name || t('productFallback')}
|
|
155
|
+
fill
|
|
156
|
+
sizes="40px"
|
|
157
|
+
className="object-cover"
|
|
158
|
+
/>
|
|
159
|
+
) : (
|
|
160
|
+
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
161
|
+
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
162
|
+
<path
|
|
163
|
+
strokeLinecap="round"
|
|
164
|
+
strokeLinejoin="round"
|
|
165
|
+
strokeWidth={1.5}
|
|
166
|
+
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"
|
|
167
|
+
/>
|
|
168
|
+
</svg>
|
|
169
|
+
</div>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<div className="min-w-0 flex-1">
|
|
174
|
+
<p className="text-foreground truncate text-sm">
|
|
175
|
+
{item.name || t('productFallback')}
|
|
176
|
+
</p>
|
|
177
|
+
<p className="text-muted-foreground text-xs">
|
|
178
|
+
{tc('qty')} {item.quantity}
|
|
179
|
+
</p>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<span className="text-foreground flex-shrink-0 text-sm">
|
|
183
|
+
{formatPrice(parseFloat(item.price), { currency }) as string}
|
|
184
|
+
</span>
|
|
185
|
+
</div>
|
|
186
|
+
))}
|
|
187
|
+
|
|
188
|
+
<div className="border-border flex items-center justify-between border-t pt-2">
|
|
189
|
+
<span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
|
|
190
|
+
<span className="text-foreground text-sm font-semibold">
|
|
191
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
192
|
+
</span>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
)}
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -1,21 +1,71 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { useState } from 'react';
|
|
3
4
|
import type { CustomerProfile } from 'brainerce';
|
|
5
|
+
import { getClient } from '@/lib/brainerce';
|
|
4
6
|
import { useTranslations } from '@/lib/translations';
|
|
5
7
|
import { cn } from '@/lib/utils';
|
|
6
8
|
|
|
7
9
|
interface ProfileSectionProps {
|
|
8
10
|
profile: CustomerProfile;
|
|
11
|
+
onProfileUpdate?: (updated: CustomerProfile) => void;
|
|
9
12
|
className?: string;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export function ProfileSection({ profile, className }: ProfileSectionProps) {
|
|
15
|
+
export function ProfileSection({ profile, onProfileUpdate, className }: ProfileSectionProps) {
|
|
13
16
|
const t = useTranslations('account');
|
|
17
|
+
const [editing, setEditing] = useState(false);
|
|
18
|
+
const [saving, setSaving] = useState(false);
|
|
19
|
+
const [message, setMessage] = useState<{ type: 'success' | 'error'; text: string } | null>(null);
|
|
20
|
+
const [form, setForm] = useState({
|
|
21
|
+
firstName: profile.firstName || '',
|
|
22
|
+
lastName: profile.lastName || '',
|
|
23
|
+
phone: profile.phone || '',
|
|
24
|
+
});
|
|
25
|
+
|
|
14
26
|
const fullName = [profile.firstName, profile.lastName].filter(Boolean).join(' ');
|
|
15
27
|
const initials =
|
|
16
28
|
[profile.firstName?.[0], profile.lastName?.[0]].filter(Boolean).join('').toUpperCase() ||
|
|
17
29
|
profile.email[0].toUpperCase();
|
|
18
30
|
|
|
31
|
+
function startEditing() {
|
|
32
|
+
setForm({
|
|
33
|
+
firstName: profile.firstName || '',
|
|
34
|
+
lastName: profile.lastName || '',
|
|
35
|
+
phone: profile.phone || '',
|
|
36
|
+
});
|
|
37
|
+
setMessage(null);
|
|
38
|
+
setEditing(true);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function cancelEditing() {
|
|
42
|
+
setEditing(false);
|
|
43
|
+
setMessage(null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function handleSave(e: React.FormEvent) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
setSaving(true);
|
|
49
|
+
setMessage(null);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const client = getClient();
|
|
53
|
+
const updated = await client.updateMyProfile({
|
|
54
|
+
firstName: form.firstName || undefined,
|
|
55
|
+
lastName: form.lastName || undefined,
|
|
56
|
+
phone: form.phone || undefined,
|
|
57
|
+
});
|
|
58
|
+
onProfileUpdate?.(updated);
|
|
59
|
+
setEditing(false);
|
|
60
|
+
setMessage({ type: 'success', text: t('profileUpdated') });
|
|
61
|
+
setTimeout(() => setMessage(null), 3000);
|
|
62
|
+
} catch {
|
|
63
|
+
setMessage({ type: 'error', text: t('profileUpdateFailed') });
|
|
64
|
+
} finally {
|
|
65
|
+
setSaving(false);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
19
69
|
return (
|
|
20
70
|
<div className={cn('border-border rounded-lg border p-6', className)}>
|
|
21
71
|
<div className="flex items-start gap-4">
|
|
@@ -25,49 +75,148 @@ export function ProfileSection({ profile, className }: ProfileSectionProps) {
|
|
|
25
75
|
</div>
|
|
26
76
|
|
|
27
77
|
<div className="min-w-0 flex-1">
|
|
28
|
-
{
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
d="M5 13l4 4L19 7"
|
|
78
|
+
{editing ? (
|
|
79
|
+
<form onSubmit={handleSave} className="space-y-3">
|
|
80
|
+
<div className="grid grid-cols-2 gap-3">
|
|
81
|
+
<div>
|
|
82
|
+
<label className="text-muted-foreground mb-1 block text-xs font-medium">
|
|
83
|
+
{t('firstName')}
|
|
84
|
+
</label>
|
|
85
|
+
<input
|
|
86
|
+
type="text"
|
|
87
|
+
value={form.firstName}
|
|
88
|
+
onChange={(e) => setForm((f) => ({ ...f, firstName: e.target.value }))}
|
|
89
|
+
className="border-border bg-background text-foreground focus:border-primary w-full rounded-md border px-3 py-1.5 text-sm outline-none"
|
|
90
|
+
autoFocus
|
|
42
91
|
/>
|
|
43
|
-
</
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
d="M12 9v2m0 4h.01"
|
|
92
|
+
</div>
|
|
93
|
+
<div>
|
|
94
|
+
<label className="text-muted-foreground mb-1 block text-xs font-medium">
|
|
95
|
+
{t('lastName')}
|
|
96
|
+
</label>
|
|
97
|
+
<input
|
|
98
|
+
type="text"
|
|
99
|
+
value={form.lastName}
|
|
100
|
+
onChange={(e) => setForm((f) => ({ ...f, lastName: e.target.value }))}
|
|
101
|
+
className="border-border bg-background text-foreground focus:border-primary w-full rounded-md border px-3 py-1.5 text-sm outline-none"
|
|
54
102
|
/>
|
|
55
|
-
</
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
<div>
|
|
106
|
+
<label className="text-muted-foreground mb-1 block text-xs font-medium">
|
|
107
|
+
{t('phone')}
|
|
108
|
+
</label>
|
|
109
|
+
<input
|
|
110
|
+
type="tel"
|
|
111
|
+
value={form.phone}
|
|
112
|
+
onChange={(e) => setForm((f) => ({ ...f, phone: e.target.value }))}
|
|
113
|
+
className="border-border bg-background text-foreground focus:border-primary w-full rounded-md border px-3 py-1.5 text-sm outline-none"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
<p className="text-muted-foreground truncate text-sm">{profile.email}</p>
|
|
117
|
+
<div className="flex items-center gap-2">
|
|
118
|
+
<button
|
|
119
|
+
type="submit"
|
|
120
|
+
disabled={saving}
|
|
121
|
+
className="bg-primary text-primary-foreground rounded-md px-4 py-1.5 text-sm font-medium transition-opacity hover:opacity-90 disabled:opacity-50"
|
|
122
|
+
>
|
|
123
|
+
{saving ? '...' : t('save')}
|
|
124
|
+
</button>
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
onClick={cancelEditing}
|
|
128
|
+
disabled={saving}
|
|
129
|
+
className="text-muted-foreground hover:text-foreground rounded-md px-4 py-1.5 text-sm transition-colors disabled:opacity-50"
|
|
130
|
+
>
|
|
131
|
+
{t('cancel')}
|
|
132
|
+
</button>
|
|
133
|
+
</div>
|
|
134
|
+
</form>
|
|
135
|
+
) : (
|
|
136
|
+
<>
|
|
137
|
+
<div className="flex items-center gap-2">
|
|
138
|
+
{fullName && (
|
|
139
|
+
<h2 className="text-foreground truncate text-lg font-semibold">{fullName}</h2>
|
|
140
|
+
)}
|
|
141
|
+
<button
|
|
142
|
+
type="button"
|
|
143
|
+
onClick={startEditing}
|
|
144
|
+
className="text-muted-foreground hover:text-foreground flex-shrink-0 rounded p-1 transition-colors"
|
|
145
|
+
title={t('editProfile')}
|
|
146
|
+
>
|
|
147
|
+
<svg
|
|
148
|
+
className="h-4 w-4"
|
|
149
|
+
fill="none"
|
|
150
|
+
viewBox="0 0 24 24"
|
|
151
|
+
stroke="currentColor"
|
|
152
|
+
strokeWidth={2}
|
|
153
|
+
>
|
|
154
|
+
<path
|
|
155
|
+
strokeLinecap="round"
|
|
156
|
+
strokeLinejoin="round"
|
|
157
|
+
d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"
|
|
158
|
+
/>
|
|
159
|
+
</svg>
|
|
160
|
+
</button>
|
|
161
|
+
</div>
|
|
162
|
+
<p className="text-muted-foreground truncate text-sm">{profile.email}</p>
|
|
163
|
+
|
|
164
|
+
<div className="mt-2 flex items-center gap-2">
|
|
165
|
+
{profile.emailVerified ? (
|
|
166
|
+
<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">
|
|
167
|
+
<svg className="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
168
|
+
<path
|
|
169
|
+
strokeLinecap="round"
|
|
170
|
+
strokeLinejoin="round"
|
|
171
|
+
strokeWidth={2}
|
|
172
|
+
d="M5 13l4 4L19 7"
|
|
173
|
+
/>
|
|
174
|
+
</svg>
|
|
175
|
+
{t('verified')}
|
|
176
|
+
</span>
|
|
177
|
+
) : (
|
|
178
|
+
<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">
|
|
179
|
+
<svg className="h-3 w-3" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
180
|
+
<path
|
|
181
|
+
strokeLinecap="round"
|
|
182
|
+
strokeLinejoin="round"
|
|
183
|
+
strokeWidth={2}
|
|
184
|
+
d="M12 9v2m0 4h.01"
|
|
185
|
+
/>
|
|
186
|
+
</svg>
|
|
187
|
+
{t('unverified')}
|
|
188
|
+
</span>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
60
191
|
|
|
61
|
-
|
|
192
|
+
{profile.phone && (
|
|
193
|
+
<p className="text-muted-foreground mt-2 text-sm">{profile.phone}</p>
|
|
194
|
+
)}
|
|
62
195
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
196
|
+
<p className="text-muted-foreground mt-3 text-xs">
|
|
197
|
+
{t('memberSince')}{' '}
|
|
198
|
+
{new Date(profile.createdAt).toLocaleDateString(undefined, {
|
|
199
|
+
year: 'numeric',
|
|
200
|
+
month: 'long',
|
|
201
|
+
day: 'numeric',
|
|
202
|
+
})}
|
|
203
|
+
</p>
|
|
204
|
+
</>
|
|
205
|
+
)}
|
|
206
|
+
|
|
207
|
+
{/* Success/Error message */}
|
|
208
|
+
{message && (
|
|
209
|
+
<p
|
|
210
|
+
className={cn(
|
|
211
|
+
'mt-2 text-sm',
|
|
212
|
+
message.type === 'success'
|
|
213
|
+
? 'text-green-600 dark:text-green-400'
|
|
214
|
+
: 'text-red-600 dark:text-red-400'
|
|
215
|
+
)}
|
|
216
|
+
>
|
|
217
|
+
{message.text}
|
|
218
|
+
</p>
|
|
219
|
+
)}
|
|
71
220
|
</div>
|
|
72
221
|
</div>
|
|
73
222
|
</div>
|