create-brainerce-store 1.3.3 → 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 +39 -20
- 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,131 +1,134 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import type { Cart } from 'brainerce';
|
|
5
|
-
import { getClient } from '@/lib/brainerce';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const [
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
{removing
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{applying
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import type { Cart } from 'brainerce';
|
|
5
|
+
import { getClient } from '@/lib/brainerce';
|
|
6
|
+
import { useTranslations } from '@/lib/translations';
|
|
7
|
+
import { LoadingSpinner } from '@/components/shared/loading-spinner';
|
|
8
|
+
import { cn } from '@/lib/utils';
|
|
9
|
+
|
|
10
|
+
interface CouponInputProps {
|
|
11
|
+
cart: Cart;
|
|
12
|
+
onUpdate: () => void;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function CouponInput({ cart, onUpdate, className }: CouponInputProps) {
|
|
17
|
+
const t = useTranslations('coupon');
|
|
18
|
+
const tc = useTranslations('common');
|
|
19
|
+
const [code, setCode] = useState('');
|
|
20
|
+
const [applying, setApplying] = useState(false);
|
|
21
|
+
const [removing, setRemoving] = useState(false);
|
|
22
|
+
const [error, setError] = useState<string | null>(null);
|
|
23
|
+
|
|
24
|
+
const appliedCoupon = cart.couponCode || null;
|
|
25
|
+
|
|
26
|
+
async function handleApply() {
|
|
27
|
+
const trimmed = code.trim();
|
|
28
|
+
if (!trimmed || applying) return;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
setApplying(true);
|
|
32
|
+
setError(null);
|
|
33
|
+
const client = getClient();
|
|
34
|
+
await client.applyCoupon(cart.id, trimmed);
|
|
35
|
+
setCode('');
|
|
36
|
+
onUpdate();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
const message = err instanceof Error ? err.message : t('invalidCode');
|
|
39
|
+
setError(message);
|
|
40
|
+
} finally {
|
|
41
|
+
setApplying(false);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function handleRemove() {
|
|
46
|
+
if (removing) return;
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
setRemoving(true);
|
|
50
|
+
setError(null);
|
|
51
|
+
const client = getClient();
|
|
52
|
+
await client.removeCoupon(cart.id);
|
|
53
|
+
onUpdate();
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error('Failed to remove coupon:', err);
|
|
56
|
+
} finally {
|
|
57
|
+
setRemoving(false);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Show applied coupon
|
|
62
|
+
if (appliedCoupon) {
|
|
63
|
+
return (
|
|
64
|
+
<div className={cn('space-y-2', className)}>
|
|
65
|
+
<div className="bg-muted flex items-center justify-between rounded px-3 py-2">
|
|
66
|
+
<div className="flex items-center gap-2">
|
|
67
|
+
<svg
|
|
68
|
+
className="text-primary h-4 w-4 flex-shrink-0"
|
|
69
|
+
fill="none"
|
|
70
|
+
viewBox="0 0 24 24"
|
|
71
|
+
stroke="currentColor"
|
|
72
|
+
>
|
|
73
|
+
<path
|
|
74
|
+
strokeLinecap="round"
|
|
75
|
+
strokeLinejoin="round"
|
|
76
|
+
strokeWidth={2}
|
|
77
|
+
d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"
|
|
78
|
+
/>
|
|
79
|
+
</svg>
|
|
80
|
+
<span className="text-foreground text-sm font-medium">{appliedCoupon}</span>
|
|
81
|
+
</div>
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
onClick={handleRemove}
|
|
85
|
+
disabled={removing}
|
|
86
|
+
className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
|
|
87
|
+
>
|
|
88
|
+
{removing ? tc('removing') : tc('remove')}
|
|
89
|
+
</button>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className={cn('space-y-2', className)}>
|
|
97
|
+
<div className="flex gap-2">
|
|
98
|
+
<input
|
|
99
|
+
type="text"
|
|
100
|
+
value={code}
|
|
101
|
+
onChange={(e) => {
|
|
102
|
+
setCode(e.target.value);
|
|
103
|
+
if (error) setError(null);
|
|
104
|
+
}}
|
|
105
|
+
onKeyDown={(e) => {
|
|
106
|
+
if (e.key === 'Enter') {
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
handleApply();
|
|
109
|
+
}
|
|
110
|
+
}}
|
|
111
|
+
placeholder={t('placeholder')}
|
|
112
|
+
className={cn(
|
|
113
|
+
'bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-9 flex-1 rounded border px-3 text-sm focus:outline-none focus:ring-2',
|
|
114
|
+
error ? 'border-destructive' : 'border-border'
|
|
115
|
+
)}
|
|
116
|
+
/>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
onClick={handleApply}
|
|
120
|
+
disabled={applying || !code.trim()}
|
|
121
|
+
className="border-border bg-background text-foreground hover:bg-muted h-9 rounded border px-4 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-40"
|
|
122
|
+
>
|
|
123
|
+
{applying ? (
|
|
124
|
+
<LoadingSpinner size="sm" className="border-muted-foreground/30 border-t-foreground" />
|
|
125
|
+
) : (
|
|
126
|
+
tc('apply')
|
|
127
|
+
)}
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
{error && <p className="text-destructive text-xs">{error}</p>}
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
@@ -1,100 +1,103 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
-
import type { ReservationInfo } from 'brainerce';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
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
|
-
<p>{
|
|
89
|
-
) : (
|
|
90
|
-
<p>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import type { ReservationInfo } from 'brainerce';
|
|
5
|
+
import { useTranslations } from '@/lib/translations';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
|
|
8
|
+
interface ReservationCountdownProps {
|
|
9
|
+
reservation: ReservationInfo;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ReservationCountdown({ reservation, className }: ReservationCountdownProps) {
|
|
14
|
+
const t = useTranslations('reservation');
|
|
15
|
+
const [remainingSeconds, setRemainingSeconds] = useState<number>(0);
|
|
16
|
+
|
|
17
|
+
const calculateRemaining = useCallback(() => {
|
|
18
|
+
if (!reservation.expiresAt) return 0;
|
|
19
|
+
const expiresAtMs = new Date(reservation.expiresAt).getTime();
|
|
20
|
+
const nowMs = Date.now();
|
|
21
|
+
return Math.max(0, Math.floor((expiresAtMs - nowMs) / 1000));
|
|
22
|
+
}, [reservation.expiresAt]);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setRemainingSeconds(calculateRemaining());
|
|
26
|
+
|
|
27
|
+
const interval = setInterval(() => {
|
|
28
|
+
const remaining = calculateRemaining();
|
|
29
|
+
setRemainingSeconds(remaining);
|
|
30
|
+
|
|
31
|
+
if (remaining <= 0) {
|
|
32
|
+
clearInterval(interval);
|
|
33
|
+
}
|
|
34
|
+
}, 1000);
|
|
35
|
+
|
|
36
|
+
return () => clearInterval(interval);
|
|
37
|
+
}, [calculateRemaining]);
|
|
38
|
+
|
|
39
|
+
if (!reservation.hasReservation) return null;
|
|
40
|
+
|
|
41
|
+
const minutes = Math.floor(remainingSeconds / 60);
|
|
42
|
+
const seconds = remainingSeconds % 60;
|
|
43
|
+
const isExpired = remainingSeconds <= 0;
|
|
44
|
+
const isUrgent = remainingSeconds > 0 && remainingSeconds < 120;
|
|
45
|
+
|
|
46
|
+
const displayMessage = reservation.countdownMessage
|
|
47
|
+
? reservation.countdownMessage.replace(
|
|
48
|
+
'{time}',
|
|
49
|
+
`${minutes}:${seconds.toString().padStart(2, '0')}`
|
|
50
|
+
)
|
|
51
|
+
: null;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<div
|
|
55
|
+
className={cn(
|
|
56
|
+
'flex items-center gap-3 rounded-lg px-4 py-3 text-sm',
|
|
57
|
+
isExpired
|
|
58
|
+
? 'bg-destructive/10 border-destructive/20 text-destructive border'
|
|
59
|
+
: isUrgent
|
|
60
|
+
? 'border border-orange-200 bg-orange-50 text-orange-800 dark:border-orange-800 dark:bg-orange-950/30 dark:text-orange-300'
|
|
61
|
+
: 'bg-primary/5 border-primary/20 text-foreground border',
|
|
62
|
+
className
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
<svg
|
|
66
|
+
className={cn(
|
|
67
|
+
'h-5 w-5 flex-shrink-0',
|
|
68
|
+
isExpired
|
|
69
|
+
? 'text-destructive'
|
|
70
|
+
: isUrgent
|
|
71
|
+
? 'text-orange-600 dark:text-orange-400'
|
|
72
|
+
: 'text-primary'
|
|
73
|
+
)}
|
|
74
|
+
fill="none"
|
|
75
|
+
viewBox="0 0 24 24"
|
|
76
|
+
stroke="currentColor"
|
|
77
|
+
>
|
|
78
|
+
<path
|
|
79
|
+
strokeLinecap="round"
|
|
80
|
+
strokeLinejoin="round"
|
|
81
|
+
strokeWidth={2}
|
|
82
|
+
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
83
|
+
/>
|
|
84
|
+
</svg>
|
|
85
|
+
|
|
86
|
+
<div className="flex-1">
|
|
87
|
+
{isExpired ? (
|
|
88
|
+
<p className="font-medium">{t('expired')}</p>
|
|
89
|
+
) : displayMessage ? (
|
|
90
|
+
<p>{displayMessage}</p>
|
|
91
|
+
) : (
|
|
92
|
+
<p>
|
|
93
|
+
{isUrgent ? `${t('hurry')} ` : ''}
|
|
94
|
+
{t('reservedFor')}{' '}
|
|
95
|
+
<span className="font-semibold tabular-nums">
|
|
96
|
+
{minutes}:{seconds.toString().padStart(2, '0')}
|
|
97
|
+
</span>
|
|
98
|
+
</p>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|