create-brainerce-store 1.29.13 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/messages/en.json +29 -1
- package/messages/he.json +29 -1
- package/package.json +1 -1
- package/templates/nextjs/base/src/app/contact/page.tsx +211 -0
- package/templates/nextjs/base/src/components/account/order-customizations.tsx +125 -0
- package/templates/nextjs/base/src/components/account/order-history.tsx +367 -350
- package/templates/nextjs/base/src/components/account/order-payment-block.tsx +58 -0
- package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +79 -0
- package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +66 -0
- package/templates/nextjs/base/src/components/layout/footer.tsx +47 -41
- package/templates/nextjs/base/tsconfig.tsbuildinfo +1 -0
|
@@ -1,350 +1,367 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect } from 'react';
|
|
4
|
-
import Image from 'next/image';
|
|
5
|
-
import type { Order, OrderStatus, OrderDownloadLink } from 'brainerce';
|
|
6
|
-
import { formatPrice } from 'brainerce';
|
|
7
|
-
import { getClient } from '@/lib/brainerce';
|
|
8
|
-
import { useTranslations } from '@/lib/translations';
|
|
9
|
-
import { cn } from '@/lib/utils';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
labelKey: '
|
|
18
|
-
className: 'bg-
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
labelKey: '
|
|
22
|
-
className: 'bg-
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
labelKey: '
|
|
26
|
-
className: 'bg-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
labelKey: '
|
|
30
|
-
className: 'bg-
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
labelKey: '
|
|
34
|
-
className: 'bg-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
statusConfig.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
| '
|
|
111
|
-
| '
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
className="
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
import type { Order, OrderStatus, OrderDownloadLink } from 'brainerce';
|
|
6
|
+
import { formatPrice } from 'brainerce';
|
|
7
|
+
import { getClient } from '@/lib/brainerce';
|
|
8
|
+
import { useTranslations } from '@/lib/translations';
|
|
9
|
+
import { cn } from '@/lib/utils';
|
|
10
|
+
import { OrderCustomizations } from './order-customizations';
|
|
11
|
+
import { OrderStatusTimeline } from './order-status-timeline';
|
|
12
|
+
import { OrderShippingBlock } from './order-shipping-block';
|
|
13
|
+
import { OrderPaymentBlock } from './order-payment-block';
|
|
14
|
+
|
|
15
|
+
const STATUS_CONFIG: Record<OrderStatus, { labelKey: string; className: string }> = {
|
|
16
|
+
pending: {
|
|
17
|
+
labelKey: 'statusPending',
|
|
18
|
+
className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
|
|
19
|
+
},
|
|
20
|
+
processing: {
|
|
21
|
+
labelKey: 'statusProcessing',
|
|
22
|
+
className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
|
|
23
|
+
},
|
|
24
|
+
shipped: {
|
|
25
|
+
labelKey: 'statusShipped',
|
|
26
|
+
className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
|
|
27
|
+
},
|
|
28
|
+
delivered: {
|
|
29
|
+
labelKey: 'statusDelivered',
|
|
30
|
+
className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
|
|
31
|
+
},
|
|
32
|
+
cancelled: {
|
|
33
|
+
labelKey: 'statusCancelled',
|
|
34
|
+
className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
|
|
35
|
+
},
|
|
36
|
+
refunded: {
|
|
37
|
+
labelKey: 'statusRefunded',
|
|
38
|
+
className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
interface OrderHistoryProps {
|
|
43
|
+
orders: Order[];
|
|
44
|
+
className?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function OrderHistory({ orders, className }: OrderHistoryProps) {
|
|
48
|
+
const t = useTranslations('account');
|
|
49
|
+
if (orders.length === 0) {
|
|
50
|
+
return (
|
|
51
|
+
<div className={cn('py-12 text-center', className)}>
|
|
52
|
+
<svg
|
|
53
|
+
className="text-muted-foreground mx-auto mb-3 h-12 w-12"
|
|
54
|
+
fill="none"
|
|
55
|
+
viewBox="0 0 24 24"
|
|
56
|
+
stroke="currentColor"
|
|
57
|
+
>
|
|
58
|
+
<path
|
|
59
|
+
strokeLinecap="round"
|
|
60
|
+
strokeLinejoin="round"
|
|
61
|
+
strokeWidth={1.5}
|
|
62
|
+
d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
|
|
63
|
+
/>
|
|
64
|
+
</svg>
|
|
65
|
+
<h3 className="text-foreground text-lg font-semibold">{t('noOrders')}</h3>
|
|
66
|
+
<p className="text-muted-foreground mt-1 text-sm">{t('noOrdersDesc')}</p>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className={cn('space-y-4', className)}>
|
|
73
|
+
{orders.map((order) => (
|
|
74
|
+
<OrderCard key={order.id} order={order} />
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function OrderCard({ order }: { order: Order }) {
|
|
81
|
+
const t = useTranslations('account');
|
|
82
|
+
const tc = useTranslations('common');
|
|
83
|
+
const [expanded, setExpanded] = useState(false);
|
|
84
|
+
const statusConfig =
|
|
85
|
+
STATUS_CONFIG[order.status?.toLowerCase() as OrderStatus] || STATUS_CONFIG.pending;
|
|
86
|
+
const currency = order.currency || 'USD';
|
|
87
|
+
const totalAmount = order.totalAmount || order.total || '0';
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div className="border-border overflow-hidden rounded-lg border">
|
|
91
|
+
{/* Order header */}
|
|
92
|
+
<button
|
|
93
|
+
type="button"
|
|
94
|
+
onClick={() => setExpanded(!expanded)}
|
|
95
|
+
className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
|
|
96
|
+
>
|
|
97
|
+
<div className="min-w-0 flex-1">
|
|
98
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
99
|
+
<span className="text-foreground text-sm font-semibold">
|
|
100
|
+
{order.orderNumber || `${t('orderPrefix')} ${order.id.slice(0, 8)}`}
|
|
101
|
+
</span>
|
|
102
|
+
<span
|
|
103
|
+
className={cn(
|
|
104
|
+
'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
|
|
105
|
+
statusConfig.className
|
|
106
|
+
)}
|
|
107
|
+
>
|
|
108
|
+
{t(
|
|
109
|
+
statusConfig.labelKey as
|
|
110
|
+
| 'statusPending'
|
|
111
|
+
| 'statusProcessing'
|
|
112
|
+
| 'statusShipped'
|
|
113
|
+
| 'statusDelivered'
|
|
114
|
+
| 'statusCancelled'
|
|
115
|
+
| 'statusRefunded'
|
|
116
|
+
)}
|
|
117
|
+
</span>
|
|
118
|
+
</div>
|
|
119
|
+
<div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
|
|
120
|
+
<span>
|
|
121
|
+
{order.createdAt && !isNaN(new Date(order.createdAt).getTime())
|
|
122
|
+
? new Date(order.createdAt).toLocaleDateString(undefined, {
|
|
123
|
+
year: 'numeric',
|
|
124
|
+
month: 'short',
|
|
125
|
+
day: 'numeric',
|
|
126
|
+
})
|
|
127
|
+
: '—'}
|
|
128
|
+
</span>
|
|
129
|
+
<span>
|
|
130
|
+
{order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
|
|
131
|
+
</span>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div className="flex flex-shrink-0 items-center gap-3">
|
|
136
|
+
<span className="text-foreground text-sm font-semibold">
|
|
137
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
138
|
+
</span>
|
|
139
|
+
<svg
|
|
140
|
+
className={cn(
|
|
141
|
+
'text-muted-foreground h-4 w-4 transition-transform',
|
|
142
|
+
expanded && 'rotate-180'
|
|
143
|
+
)}
|
|
144
|
+
fill="none"
|
|
145
|
+
viewBox="0 0 24 24"
|
|
146
|
+
stroke="currentColor"
|
|
147
|
+
>
|
|
148
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
|
|
149
|
+
</svg>
|
|
150
|
+
</div>
|
|
151
|
+
</button>
|
|
152
|
+
|
|
153
|
+
{/* Expanded order items */}
|
|
154
|
+
{expanded && (
|
|
155
|
+
<div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
|
|
156
|
+
{order.items.map((item, index) => (
|
|
157
|
+
<div key={`${item.productId}-${index}`} className="space-y-1">
|
|
158
|
+
<div className="flex items-center gap-3">
|
|
159
|
+
<div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
|
|
160
|
+
{item.image ? (
|
|
161
|
+
<Image
|
|
162
|
+
src={item.image}
|
|
163
|
+
alt={item.name || t('productFallback')}
|
|
164
|
+
fill
|
|
165
|
+
sizes="40px"
|
|
166
|
+
className="object-cover"
|
|
167
|
+
/>
|
|
168
|
+
) : (
|
|
169
|
+
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
170
|
+
<svg
|
|
171
|
+
className="h-4 w-4"
|
|
172
|
+
fill="none"
|
|
173
|
+
viewBox="0 0 24 24"
|
|
174
|
+
stroke="currentColor"
|
|
175
|
+
>
|
|
176
|
+
<path
|
|
177
|
+
strokeLinecap="round"
|
|
178
|
+
strokeLinejoin="round"
|
|
179
|
+
strokeWidth={1.5}
|
|
180
|
+
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"
|
|
181
|
+
/>
|
|
182
|
+
</svg>
|
|
183
|
+
</div>
|
|
184
|
+
)}
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<div className="min-w-0 flex-1">
|
|
188
|
+
<p className="text-foreground truncate text-sm">
|
|
189
|
+
{item.name || t('productFallback')}
|
|
190
|
+
</p>
|
|
191
|
+
<p className="text-muted-foreground text-xs">
|
|
192
|
+
{tc('qty')} {item.quantity}
|
|
193
|
+
</p>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<span className="text-foreground flex-shrink-0 text-sm">
|
|
197
|
+
{formatPrice(parseFloat(item.price), { currency }) as string}
|
|
198
|
+
</span>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
{item.customizations && <OrderCustomizations customizations={item.customizations} />}
|
|
202
|
+
</div>
|
|
203
|
+
))}
|
|
204
|
+
|
|
205
|
+
<OrderStatusTimeline history={order.statusHistory} />
|
|
206
|
+
<OrderShippingBlock order={order} />
|
|
207
|
+
<OrderPaymentBlock order={order} />
|
|
208
|
+
|
|
209
|
+
{/* Downloads section */}
|
|
210
|
+
{order.hasDownloads && <OrderDownloads orderId={order.id} />}
|
|
211
|
+
|
|
212
|
+
<OrderFinancialSummary order={order} currency={currency} />
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
</div>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function OrderDownloads({ orderId }: { orderId: string }) {
|
|
220
|
+
const t = useTranslations('account');
|
|
221
|
+
const [downloads, setDownloads] = useState<OrderDownloadLink[] | null>(null);
|
|
222
|
+
const [loading, setLoading] = useState(true);
|
|
223
|
+
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
let cancelled = false;
|
|
226
|
+
async function fetch() {
|
|
227
|
+
try {
|
|
228
|
+
const client = getClient();
|
|
229
|
+
const links = await client.getOrderDownloads(orderId);
|
|
230
|
+
if (!cancelled) setDownloads(links);
|
|
231
|
+
} catch {
|
|
232
|
+
if (!cancelled) setDownloads([]);
|
|
233
|
+
} finally {
|
|
234
|
+
if (!cancelled) setLoading(false);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
fetch();
|
|
238
|
+
return () => {
|
|
239
|
+
cancelled = true;
|
|
240
|
+
};
|
|
241
|
+
}, [orderId]);
|
|
242
|
+
|
|
243
|
+
if (loading) {
|
|
244
|
+
return (
|
|
245
|
+
<div className="border-border border-t pt-2">
|
|
246
|
+
<p className="text-muted-foreground animate-pulse text-xs">{t('downloads')}...</p>
|
|
247
|
+
</div>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!downloads || downloads.length === 0) return null;
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<div className="border-border space-y-2 border-t pt-2">
|
|
255
|
+
<p className="text-foreground text-sm font-medium">{t('downloads')}</p>
|
|
256
|
+
{downloads.map((link, idx) => (
|
|
257
|
+
<div key={idx} className="flex items-center gap-3">
|
|
258
|
+
<div className="min-w-0 flex-1">
|
|
259
|
+
<p className="text-foreground truncate text-sm">{link.fileName}</p>
|
|
260
|
+
<p className="text-muted-foreground text-xs">
|
|
261
|
+
{link.productName}
|
|
262
|
+
{' · '}
|
|
263
|
+
{link.downloadLimit != null
|
|
264
|
+
? `${link.downloadsUsed}/${link.downloadLimit} ${t('downloadsRemaining')}`
|
|
265
|
+
: t('unlimitedDownloads')}
|
|
266
|
+
{' · '}
|
|
267
|
+
{link.expiresAt
|
|
268
|
+
? `${t('expiresAt')} ${new Date(link.expiresAt).toLocaleDateString()}`
|
|
269
|
+
: t('noExpiry')}
|
|
270
|
+
</p>
|
|
271
|
+
</div>
|
|
272
|
+
<a
|
|
273
|
+
href={link.downloadUrl}
|
|
274
|
+
target="_blank"
|
|
275
|
+
rel="noopener noreferrer"
|
|
276
|
+
className="bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1 text-xs font-medium hover:opacity-90"
|
|
277
|
+
>
|
|
278
|
+
{t('downloadFile')}
|
|
279
|
+
</a>
|
|
280
|
+
</div>
|
|
281
|
+
))}
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function OrderFinancialSummary({ order, currency }: { order: Order; currency: string }) {
|
|
287
|
+
const tc = useTranslations('common');
|
|
288
|
+
const totalAmount = order.totalAmount || order.total || '0';
|
|
289
|
+
const subtotal = order.subtotal ? parseFloat(order.subtotal) : null;
|
|
290
|
+
const ruleAmt = order.ruleDiscountAmount ? parseFloat(order.ruleDiscountAmount) : 0;
|
|
291
|
+
const couponAmt = order.couponDiscount ? parseFloat(order.couponDiscount) : 0;
|
|
292
|
+
const shipping = order.shippingAmount ? parseFloat(order.shippingAmount) : 0;
|
|
293
|
+
const tax = order.taxAmount ? parseFloat(order.taxAmount) : 0;
|
|
294
|
+
const rules = order.appliedDiscounts;
|
|
295
|
+
|
|
296
|
+
const hasBreakdown = subtotal !== null && subtotal > 0;
|
|
297
|
+
|
|
298
|
+
if (!hasBreakdown) {
|
|
299
|
+
return (
|
|
300
|
+
<div className="border-border flex items-center justify-between border-t pt-2">
|
|
301
|
+
<span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
|
|
302
|
+
<span className="text-foreground text-sm font-semibold">
|
|
303
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
304
|
+
</span>
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<div className="border-border space-y-1 border-t pt-2 text-sm">
|
|
311
|
+
<div className="flex items-center justify-between">
|
|
312
|
+
<span className="text-muted-foreground">{tc('subtotal')}</span>
|
|
313
|
+
<span className="text-foreground">{formatPrice(subtotal, { currency }) as string}</span>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
{rules && rules.length > 0
|
|
317
|
+
? rules.map((rule) => (
|
|
318
|
+
<div key={rule.ruleId} className="flex items-center justify-between">
|
|
319
|
+
<span className="text-muted-foreground">{rule.ruleName}</span>
|
|
320
|
+
<span className="text-destructive">
|
|
321
|
+
-{formatPrice(parseFloat(rule.discountAmount || '0'), { currency }) as string}
|
|
322
|
+
</span>
|
|
323
|
+
</div>
|
|
324
|
+
))
|
|
325
|
+
: ruleAmt > 0 && (
|
|
326
|
+
<div className="flex items-center justify-between">
|
|
327
|
+
<span className="text-muted-foreground">{tc('generalDiscount')}</span>
|
|
328
|
+
<span className="text-destructive">
|
|
329
|
+
-{formatPrice(ruleAmt, { currency }) as string}
|
|
330
|
+
</span>
|
|
331
|
+
</div>
|
|
332
|
+
)}
|
|
333
|
+
|
|
334
|
+
{order.couponCode && couponAmt > 0 && (
|
|
335
|
+
<div className="flex items-center justify-between">
|
|
336
|
+
<span className="text-muted-foreground">
|
|
337
|
+
{tc('couponDiscount')} ({order.couponCode})
|
|
338
|
+
</span>
|
|
339
|
+
<span className="text-destructive">
|
|
340
|
+
-{formatPrice(couponAmt, { currency }) as string}
|
|
341
|
+
</span>
|
|
342
|
+
</div>
|
|
343
|
+
)}
|
|
344
|
+
|
|
345
|
+
{shipping > 0 && (
|
|
346
|
+
<div className="flex items-center justify-between">
|
|
347
|
+
<span className="text-muted-foreground">{tc('shipping')}</span>
|
|
348
|
+
<span className="text-foreground">{formatPrice(shipping, { currency }) as string}</span>
|
|
349
|
+
</div>
|
|
350
|
+
)}
|
|
351
|
+
|
|
352
|
+
{tax > 0 && (
|
|
353
|
+
<div className="flex items-center justify-between">
|
|
354
|
+
<span className="text-muted-foreground">{tc('tax')}</span>
|
|
355
|
+
<span className="text-foreground">{formatPrice(tax, { currency }) as string}</span>
|
|
356
|
+
</div>
|
|
357
|
+
)}
|
|
358
|
+
|
|
359
|
+
<div className="border-border flex items-center justify-between border-t pt-1">
|
|
360
|
+
<span className="text-foreground font-medium">{tc('total')}</span>
|
|
361
|
+
<span className="text-foreground font-semibold">
|
|
362
|
+
{formatPrice(parseFloat(totalAmount), { currency }) as string}
|
|
363
|
+
</span>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
);
|
|
367
|
+
}
|