create-brainerce-store 1.3.2 → 1.4.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 +62 -5
- package/messages/en.json +258 -0
- package/messages/he.json +258 -0
- package/package.json +3 -2
- package/templates/nextjs/base/src/app/account/page.tsx +108 -105
- package/templates/nextjs/base/src/app/auth/callback/page.tsx +90 -88
- package/templates/nextjs/base/src/app/cart/page.tsx +110 -109
- package/templates/nextjs/base/src/app/checkout/page.tsx +46 -43
- package/templates/nextjs/base/src/app/layout.tsx.ejs +8 -5
- package/templates/nextjs/base/src/app/login/page.tsx +58 -56
- package/templates/nextjs/base/src/app/order-confirmation/page.tsx +18 -23
- package/templates/nextjs/base/src/app/page.tsx +98 -95
- package/templates/nextjs/base/src/app/products/[slug]/page.tsx +16 -12
- package/templates/nextjs/base/src/app/products/page.tsx +246 -243
- package/templates/nextjs/base/src/app/register/page.tsx +68 -66
- package/templates/nextjs/base/src/app/verify-email/page.tsx +293 -291
- package/templates/nextjs/base/src/components/account/order-history.tsx +198 -184
- package/templates/nextjs/base/src/components/account/profile-section.tsx +75 -73
- package/templates/nextjs/base/src/components/auth/login-form.tsx +94 -92
- package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -134
- package/templates/nextjs/base/src/components/auth/register-form.tsx +184 -177
- package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -150
- package/templates/nextjs/base/src/components/cart/cart-summary.tsx +70 -67
- package/templates/nextjs/base/src/components/cart/coupon-input.tsx +134 -131
- package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +103 -100
- package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +28 -25
- package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +6 -4
- package/templates/nextjs/base/src/components/checkout/payment-step.tsx +133 -103
- package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +15 -11
- package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +110 -111
- package/templates/nextjs/base/src/components/checkout/tax-display.tsx +7 -4
- package/templates/nextjs/base/src/components/layout/footer.tsx +38 -35
- package/templates/nextjs/base/src/components/layout/header.tsx +332 -329
- package/templates/nextjs/base/src/components/products/product-card.tsx +3 -1
- package/templates/nextjs/base/src/components/products/product-grid.tsx +35 -33
- package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +32 -30
- package/templates/nextjs/base/src/i18n.ts.ejs +5 -0
- package/templates/nextjs/base/src/lib/translations.ts +11 -0
|
@@ -1,150 +1,153 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import Image from 'next/image';
|
|
5
|
-
import type { CartItem as CartItemType } from 'brainerce';
|
|
6
|
-
import { getCartItemName, getCartItemImage, formatPrice } from 'brainerce';
|
|
7
|
-
import { getClient } from '@/lib/brainerce';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
{/*
|
|
94
|
-
<p className="text-muted-foreground mt-1 text-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
{removing
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
import type { CartItem as CartItemType } from 'brainerce';
|
|
6
|
+
import { getCartItemName, getCartItemImage, formatPrice } from 'brainerce';
|
|
7
|
+
import { getClient } from '@/lib/brainerce';
|
|
8
|
+
import { useTranslations } from '@/lib/translations';
|
|
9
|
+
import { useStoreInfo } from '@/providers/store-provider';
|
|
10
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
11
|
+
import { cn } from '@/lib/utils';
|
|
12
|
+
|
|
13
|
+
interface CartItemProps {
|
|
14
|
+
item: CartItemType;
|
|
15
|
+
onUpdate: () => void;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function CartItem({ item, onUpdate, className }: CartItemProps) {
|
|
20
|
+
const t = useTranslations('common');
|
|
21
|
+
const td = useTranslations('productDetail');
|
|
22
|
+
const { storeInfo } = useStoreInfo();
|
|
23
|
+
const currency = storeInfo?.currency || 'USD';
|
|
24
|
+
const [updating, setUpdating] = useState(false);
|
|
25
|
+
const [removing, setRemoving] = useState(false);
|
|
26
|
+
|
|
27
|
+
const name = getCartItemName(item);
|
|
28
|
+
const imageUrl = getCartItemImage(item);
|
|
29
|
+
const variantName = item.variant?.name;
|
|
30
|
+
const unitPrice = parseFloat(item.unitPrice);
|
|
31
|
+
const lineTotal = unitPrice * item.quantity;
|
|
32
|
+
|
|
33
|
+
async function handleQuantityChange(newQuantity: number) {
|
|
34
|
+
if (newQuantity < 1 || updating) return;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
setUpdating(true);
|
|
38
|
+
const client = getClient();
|
|
39
|
+
await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
|
|
40
|
+
onUpdate();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error('Failed to update quantity:', err);
|
|
43
|
+
} finally {
|
|
44
|
+
setUpdating(false);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function handleRemove() {
|
|
49
|
+
if (removing) return;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
setRemoving(true);
|
|
53
|
+
const client = getClient();
|
|
54
|
+
await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
|
|
55
|
+
onUpdate();
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error('Failed to remove item:', err);
|
|
58
|
+
} finally {
|
|
59
|
+
setRemoving(false);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
className={cn(
|
|
66
|
+
'border-border flex gap-4 border-b py-4 last:border-0',
|
|
67
|
+
(updating || removing) && 'opacity-60',
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
{/* Image */}
|
|
72
|
+
<div className="bg-muted relative h-20 w-20 flex-shrink-0 overflow-hidden rounded">
|
|
73
|
+
{imageUrl ? (
|
|
74
|
+
<Image src={imageUrl} alt={name} fill sizes="80px" className="object-cover" />
|
|
75
|
+
) : (
|
|
76
|
+
<div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
|
|
77
|
+
<svg className="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
78
|
+
<path
|
|
79
|
+
strokeLinecap="round"
|
|
80
|
+
strokeLinejoin="round"
|
|
81
|
+
strokeWidth={1.5}
|
|
82
|
+
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"
|
|
83
|
+
/>
|
|
84
|
+
</svg>
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
{/* Details */}
|
|
90
|
+
<div className="min-w-0 flex-1">
|
|
91
|
+
<h3 className="text-foreground truncate text-sm font-medium">{name}</h3>
|
|
92
|
+
|
|
93
|
+
{/* Variant name */}
|
|
94
|
+
{variantName && <p className="text-muted-foreground mt-1 text-xs">{variantName}</p>}
|
|
95
|
+
|
|
96
|
+
{/* Unit price */}
|
|
97
|
+
<p className="text-muted-foreground mt-1 text-sm">
|
|
98
|
+
{formatPrice(unitPrice, { currency }) as string}
|
|
99
|
+
</p>
|
|
100
|
+
|
|
101
|
+
{/* Quantity controls */}
|
|
102
|
+
<div className="mt-2 flex items-center gap-3">
|
|
103
|
+
<div className="border-border flex items-center rounded border">
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
onClick={() => handleQuantityChange(item.quantity - 1)}
|
|
107
|
+
disabled={updating || item.quantity <= 1}
|
|
108
|
+
className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
|
109
|
+
aria-label={td('decreaseQuantity')}
|
|
110
|
+
>
|
|
111
|
+
-
|
|
112
|
+
</button>
|
|
113
|
+
<span className="text-foreground min-w-[2.5rem] px-3 py-1 text-center text-sm font-medium">
|
|
114
|
+
{updating ? (
|
|
115
|
+
<LoadingSpinner
|
|
116
|
+
size="sm"
|
|
117
|
+
className="border-muted-foreground/30 border-t-foreground mx-auto"
|
|
118
|
+
/>
|
|
119
|
+
) : (
|
|
120
|
+
item.quantity
|
|
121
|
+
)}
|
|
122
|
+
</span>
|
|
123
|
+
<button
|
|
124
|
+
type="button"
|
|
125
|
+
onClick={() => handleQuantityChange(item.quantity + 1)}
|
|
126
|
+
disabled={updating}
|
|
127
|
+
className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
|
128
|
+
aria-label={td('increaseQuantity')}
|
|
129
|
+
>
|
|
130
|
+
+
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
onClick={handleRemove}
|
|
137
|
+
disabled={removing}
|
|
138
|
+
className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
|
|
139
|
+
>
|
|
140
|
+
{removing ? t('removing') : t('remove')}
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
{/* Line total */}
|
|
146
|
+
<div className="flex-shrink-0 text-end">
|
|
147
|
+
<span className="text-foreground text-sm font-medium">
|
|
148
|
+
{formatPrice(lineTotal, { currency }) as string}
|
|
149
|
+
</span>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -1,67 +1,70 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { formatPrice } from 'brainerce';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</span>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
</span>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
</span>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
</span>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { formatPrice } from 'brainerce';
|
|
4
|
+
import { useTranslations } from '@/lib/translations';
|
|
5
|
+
import { useStoreInfo, useCart } from '@/providers/store-provider';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
|
|
8
|
+
interface CartSummaryProps {
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function CartSummary({ className }: CartSummaryProps) {
|
|
13
|
+
const t = useTranslations('cart');
|
|
14
|
+
const tc = useTranslations('common');
|
|
15
|
+
const { storeInfo } = useStoreInfo();
|
|
16
|
+
const { totals } = useCart();
|
|
17
|
+
const currency = storeInfo?.currency || 'USD';
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className={cn('space-y-3', className)}>
|
|
21
|
+
<h3 className="text-foreground text-lg font-semibold">{t('orderSummary')}</h3>
|
|
22
|
+
|
|
23
|
+
<div className="space-y-2 text-sm">
|
|
24
|
+
{/* Subtotal */}
|
|
25
|
+
<div className="flex items-center justify-between">
|
|
26
|
+
<span className="text-muted-foreground">{tc('subtotal')}</span>
|
|
27
|
+
<span className="text-foreground font-medium">
|
|
28
|
+
{formatPrice(totals.subtotal, { currency }) as string}
|
|
29
|
+
</span>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
{/* Discount */}
|
|
33
|
+
{totals.discount > 0 && (
|
|
34
|
+
<div className="flex items-center justify-between">
|
|
35
|
+
<span className="text-muted-foreground">{tc('discount')}</span>
|
|
36
|
+
<span className="text-destructive font-medium">
|
|
37
|
+
-{formatPrice(totals.discount, { currency }) as string}
|
|
38
|
+
</span>
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
41
|
+
|
|
42
|
+
{/* Shipping */}
|
|
43
|
+
{totals.shipping > 0 && (
|
|
44
|
+
<div className="flex items-center justify-between">
|
|
45
|
+
<span className="text-muted-foreground">{tc('shipping')}</span>
|
|
46
|
+
<span className="text-foreground font-medium">
|
|
47
|
+
{formatPrice(totals.shipping, { currency }) as string}
|
|
48
|
+
</span>
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
51
|
+
|
|
52
|
+
{/* Tax */}
|
|
53
|
+
<div className="flex items-center justify-between">
|
|
54
|
+
<span className="text-muted-foreground">{tc('tax')}</span>
|
|
55
|
+
<span className="text-muted-foreground text-xs">{t('taxAtCheckout')}</span>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
{/* Divider */}
|
|
59
|
+
<div className="border-border mt-2 border-t pt-2">
|
|
60
|
+
<div className="flex items-center justify-between">
|
|
61
|
+
<span className="text-foreground font-semibold">{tc('total')}</span>
|
|
62
|
+
<span className="text-foreground text-base font-semibold">
|
|
63
|
+
{formatPrice(totals.total, { currency }) as string}
|
|
64
|
+
</span>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|