create-brainerce-store 1.5.6 → 1.6.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.
@@ -1,276 +1,278 @@
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
- <OrderFinancialSummary order={order} currency={currency} />
189
- </div>
190
- )}
191
- </div>
192
- );
193
- }
194
-
195
- function OrderFinancialSummary({ order, currency }: { order: Order; currency: string }) {
196
- const tc = useTranslations('common');
197
- const totalAmount = order.totalAmount || order.total || '0';
198
- const subtotal = order.subtotal ? parseFloat(order.subtotal) : null;
199
- const ruleAmt = order.ruleDiscountAmount ? parseFloat(order.ruleDiscountAmount) : 0;
200
- const couponAmt = order.couponDiscount ? parseFloat(order.couponDiscount) : 0;
201
- const shipping = order.shippingAmount ? parseFloat(order.shippingAmount) : 0;
202
- const tax = order.taxAmount ? parseFloat(order.taxAmount) : 0;
203
- const rules = order.appliedDiscounts;
204
-
205
- const hasBreakdown = subtotal !== null && subtotal > 0;
206
-
207
- if (!hasBreakdown) {
208
- return (
209
- <div className="border-border flex items-center justify-between border-t pt-2">
210
- <span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
211
- <span className="text-foreground text-sm font-semibold">
212
- {formatPrice(parseFloat(totalAmount), { currency }) as string}
213
- </span>
214
- </div>
215
- );
216
- }
217
-
218
- return (
219
- <div className="border-border space-y-1 border-t pt-2 text-sm">
220
- <div className="flex items-center justify-between">
221
- <span className="text-muted-foreground">{tc('subtotal')}</span>
222
- <span className="text-foreground">{formatPrice(subtotal, { currency }) as string}</span>
223
- </div>
224
-
225
- {rules && rules.length > 0
226
- ? rules.map((rule) => (
227
- <div key={rule.ruleId} className="flex items-center justify-between">
228
- <span className="text-muted-foreground">{rule.ruleName}</span>
229
- <span className="text-destructive">
230
- -{formatPrice(parseFloat(rule.discountAmount || '0'), { currency }) as string}
231
- </span>
232
- </div>
233
- ))
234
- : ruleAmt > 0 && (
235
- <div className="flex items-center justify-between">
236
- <span className="text-muted-foreground">{tc('generalDiscount')}</span>
237
- <span className="text-destructive">
238
- -{formatPrice(ruleAmt, { currency }) as string}
239
- </span>
240
- </div>
241
- )}
242
-
243
- {order.couponCode && couponAmt > 0 && (
244
- <div className="flex items-center justify-between">
245
- <span className="text-muted-foreground">
246
- {tc('couponDiscount')} ({order.couponCode})
247
- </span>
248
- <span className="text-destructive">
249
- -{formatPrice(couponAmt, { currency }) as string}
250
- </span>
251
- </div>
252
- )}
253
-
254
- {shipping > 0 && (
255
- <div className="flex items-center justify-between">
256
- <span className="text-muted-foreground">{tc('shipping')}</span>
257
- <span className="text-foreground">{formatPrice(shipping, { currency }) as string}</span>
258
- </div>
259
- )}
260
-
261
- {tax > 0 && (
262
- <div className="flex items-center justify-between">
263
- <span className="text-muted-foreground">{tc('tax')}</span>
264
- <span className="text-foreground">{formatPrice(tax, { currency }) as string}</span>
265
- </div>
266
- )}
267
-
268
- <div className="border-border flex items-center justify-between border-t pt-1">
269
- <span className="text-foreground font-medium">{tc('total')}</span>
270
- <span className="text-foreground font-semibold">
271
- {formatPrice(parseFloat(totalAmount), { currency }) as string}
272
- </span>
273
- </div>
274
- </div>
275
- );
276
- }
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
+ {order.createdAt && !isNaN(new Date(order.createdAt).getTime())
116
+ ? new Date(order.createdAt).toLocaleDateString(undefined, {
117
+ year: 'numeric',
118
+ month: 'short',
119
+ day: 'numeric',
120
+ })
121
+ : '—'}
122
+ </span>
123
+ <span>
124
+ {order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
125
+ </span>
126
+ </div>
127
+ </div>
128
+
129
+ <div className="flex flex-shrink-0 items-center gap-3">
130
+ <span className="text-foreground text-sm font-semibold">
131
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
132
+ </span>
133
+ <svg
134
+ className={cn(
135
+ 'text-muted-foreground h-4 w-4 transition-transform',
136
+ expanded && 'rotate-180'
137
+ )}
138
+ fill="none"
139
+ viewBox="0 0 24 24"
140
+ stroke="currentColor"
141
+ >
142
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
143
+ </svg>
144
+ </div>
145
+ </button>
146
+
147
+ {/* Expanded order items */}
148
+ {expanded && (
149
+ <div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
150
+ {order.items.map((item, index) => (
151
+ <div key={`${item.productId}-${index}`} className="flex items-center gap-3">
152
+ <div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
153
+ {item.image ? (
154
+ <Image
155
+ src={item.image}
156
+ alt={item.name || t('productFallback')}
157
+ fill
158
+ sizes="40px"
159
+ className="object-cover"
160
+ />
161
+ ) : (
162
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
163
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
164
+ <path
165
+ strokeLinecap="round"
166
+ strokeLinejoin="round"
167
+ strokeWidth={1.5}
168
+ 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"
169
+ />
170
+ </svg>
171
+ </div>
172
+ )}
173
+ </div>
174
+
175
+ <div className="min-w-0 flex-1">
176
+ <p className="text-foreground truncate text-sm">
177
+ {item.name || t('productFallback')}
178
+ </p>
179
+ <p className="text-muted-foreground text-xs">
180
+ {tc('qty')} {item.quantity}
181
+ </p>
182
+ </div>
183
+
184
+ <span className="text-foreground flex-shrink-0 text-sm">
185
+ {formatPrice(parseFloat(item.price), { currency }) as string}
186
+ </span>
187
+ </div>
188
+ ))}
189
+
190
+ <OrderFinancialSummary order={order} currency={currency} />
191
+ </div>
192
+ )}
193
+ </div>
194
+ );
195
+ }
196
+
197
+ function OrderFinancialSummary({ order, currency }: { order: Order; currency: string }) {
198
+ const tc = useTranslations('common');
199
+ const totalAmount = order.totalAmount || order.total || '0';
200
+ const subtotal = order.subtotal ? parseFloat(order.subtotal) : null;
201
+ const ruleAmt = order.ruleDiscountAmount ? parseFloat(order.ruleDiscountAmount) : 0;
202
+ const couponAmt = order.couponDiscount ? parseFloat(order.couponDiscount) : 0;
203
+ const shipping = order.shippingAmount ? parseFloat(order.shippingAmount) : 0;
204
+ const tax = order.taxAmount ? parseFloat(order.taxAmount) : 0;
205
+ const rules = order.appliedDiscounts;
206
+
207
+ const hasBreakdown = subtotal !== null && subtotal > 0;
208
+
209
+ if (!hasBreakdown) {
210
+ return (
211
+ <div className="border-border flex items-center justify-between border-t pt-2">
212
+ <span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
213
+ <span className="text-foreground text-sm font-semibold">
214
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
215
+ </span>
216
+ </div>
217
+ );
218
+ }
219
+
220
+ return (
221
+ <div className="border-border space-y-1 border-t pt-2 text-sm">
222
+ <div className="flex items-center justify-between">
223
+ <span className="text-muted-foreground">{tc('subtotal')}</span>
224
+ <span className="text-foreground">{formatPrice(subtotal, { currency }) as string}</span>
225
+ </div>
226
+
227
+ {rules && rules.length > 0
228
+ ? rules.map((rule) => (
229
+ <div key={rule.ruleId} className="flex items-center justify-between">
230
+ <span className="text-muted-foreground">{rule.ruleName}</span>
231
+ <span className="text-destructive">
232
+ -{formatPrice(parseFloat(rule.discountAmount || '0'), { currency }) as string}
233
+ </span>
234
+ </div>
235
+ ))
236
+ : ruleAmt > 0 && (
237
+ <div className="flex items-center justify-between">
238
+ <span className="text-muted-foreground">{tc('generalDiscount')}</span>
239
+ <span className="text-destructive">
240
+ -{formatPrice(ruleAmt, { currency }) as string}
241
+ </span>
242
+ </div>
243
+ )}
244
+
245
+ {order.couponCode && couponAmt > 0 && (
246
+ <div className="flex items-center justify-between">
247
+ <span className="text-muted-foreground">
248
+ {tc('couponDiscount')} ({order.couponCode})
249
+ </span>
250
+ <span className="text-destructive">
251
+ -{formatPrice(couponAmt, { currency }) as string}
252
+ </span>
253
+ </div>
254
+ )}
255
+
256
+ {shipping > 0 && (
257
+ <div className="flex items-center justify-between">
258
+ <span className="text-muted-foreground">{tc('shipping')}</span>
259
+ <span className="text-foreground">{formatPrice(shipping, { currency }) as string}</span>
260
+ </div>
261
+ )}
262
+
263
+ {tax > 0 && (
264
+ <div className="flex items-center justify-between">
265
+ <span className="text-muted-foreground">{tc('tax')}</span>
266
+ <span className="text-foreground">{formatPrice(tax, { currency }) as string}</span>
267
+ </div>
268
+ )}
269
+
270
+ <div className="border-border flex items-center justify-between border-t pt-1">
271
+ <span className="text-foreground font-medium">{tc('total')}</span>
272
+ <span className="text-foreground font-semibold">
273
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
274
+ </span>
275
+ </div>
276
+ </div>
277
+ );
278
+ }
@@ -193,14 +193,16 @@ export function ProfileSection({ profile, onProfileUpdate, className }: ProfileS
193
193
  <p className="text-muted-foreground mt-2 text-sm">{profile.phone}</p>
194
194
  )}
195
195
 
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>
196
+ {profile.createdAt && !isNaN(new Date(profile.createdAt).getTime()) && (
197
+ <p className="text-muted-foreground mt-3 text-xs">
198
+ {t('memberSince')}{' '}
199
+ {new Date(profile.createdAt).toLocaleDateString(undefined, {
200
+ year: 'numeric',
201
+ month: 'long',
202
+ day: 'numeric',
203
+ })}
204
+ </p>
205
+ )}
204
206
  </>
205
207
  )}
206
208