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.
Files changed (38) hide show
  1. package/dist/index.js +62 -5
  2. package/messages/en.json +258 -0
  3. package/messages/he.json +258 -0
  4. package/package.json +3 -2
  5. package/templates/nextjs/base/src/app/account/page.tsx +108 -105
  6. package/templates/nextjs/base/src/app/auth/callback/page.tsx +90 -88
  7. package/templates/nextjs/base/src/app/cart/page.tsx +110 -109
  8. package/templates/nextjs/base/src/app/checkout/page.tsx +46 -43
  9. package/templates/nextjs/base/src/app/layout.tsx.ejs +8 -5
  10. package/templates/nextjs/base/src/app/login/page.tsx +58 -56
  11. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +18 -23
  12. package/templates/nextjs/base/src/app/page.tsx +98 -95
  13. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +16 -12
  14. package/templates/nextjs/base/src/app/products/page.tsx +246 -243
  15. package/templates/nextjs/base/src/app/register/page.tsx +68 -66
  16. package/templates/nextjs/base/src/app/verify-email/page.tsx +293 -291
  17. package/templates/nextjs/base/src/components/account/order-history.tsx +198 -184
  18. package/templates/nextjs/base/src/components/account/profile-section.tsx +75 -73
  19. package/templates/nextjs/base/src/components/auth/login-form.tsx +94 -92
  20. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -134
  21. package/templates/nextjs/base/src/components/auth/register-form.tsx +184 -177
  22. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -150
  23. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +70 -67
  24. package/templates/nextjs/base/src/components/cart/coupon-input.tsx +134 -131
  25. package/templates/nextjs/base/src/components/cart/reservation-countdown.tsx +103 -100
  26. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +28 -25
  27. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +6 -4
  28. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +39 -20
  29. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +15 -11
  30. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +110 -111
  31. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +7 -4
  32. package/templates/nextjs/base/src/components/layout/footer.tsx +38 -35
  33. package/templates/nextjs/base/src/components/layout/header.tsx +332 -329
  34. package/templates/nextjs/base/src/components/products/product-card.tsx +3 -1
  35. package/templates/nextjs/base/src/components/products/product-grid.tsx +35 -33
  36. package/templates/nextjs/base/src/components/shared/loading-spinner.tsx +32 -30
  37. package/templates/nextjs/base/src/i18n.ts.ejs +5 -0
  38. 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 { LoadingSpinner } from '@/components/shared/loading-spinner';
7
- import { cn } from '@/lib/utils';
8
-
9
- interface CouponInputProps {
10
- cart: Cart;
11
- onUpdate: () => void;
12
- className?: string;
13
- }
14
-
15
- export function CouponInput({ cart, onUpdate, className }: CouponInputProps) {
16
- const [code, setCode] = useState('');
17
- const [applying, setApplying] = useState(false);
18
- const [removing, setRemoving] = useState(false);
19
- const [error, setError] = useState<string | null>(null);
20
-
21
- const appliedCoupon = cart.couponCode || null;
22
-
23
- async function handleApply() {
24
- const trimmed = code.trim();
25
- if (!trimmed || applying) return;
26
-
27
- try {
28
- setApplying(true);
29
- setError(null);
30
- const client = getClient();
31
- await client.applyCoupon(cart.id, trimmed);
32
- setCode('');
33
- onUpdate();
34
- } catch (err) {
35
- const message = err instanceof Error ? err.message : 'Invalid coupon code';
36
- setError(message);
37
- } finally {
38
- setApplying(false);
39
- }
40
- }
41
-
42
- async function handleRemove() {
43
- if (removing) return;
44
-
45
- try {
46
- setRemoving(true);
47
- setError(null);
48
- const client = getClient();
49
- await client.removeCoupon(cart.id);
50
- onUpdate();
51
- } catch (err) {
52
- console.error('Failed to remove coupon:', err);
53
- } finally {
54
- setRemoving(false);
55
- }
56
- }
57
-
58
- // Show applied coupon
59
- if (appliedCoupon) {
60
- return (
61
- <div className={cn('space-y-2', className)}>
62
- <div className="bg-muted flex items-center justify-between rounded px-3 py-2">
63
- <div className="flex items-center gap-2">
64
- <svg
65
- className="text-primary h-4 w-4 flex-shrink-0"
66
- fill="none"
67
- viewBox="0 0 24 24"
68
- stroke="currentColor"
69
- >
70
- <path
71
- strokeLinecap="round"
72
- strokeLinejoin="round"
73
- strokeWidth={2}
74
- 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"
75
- />
76
- </svg>
77
- <span className="text-foreground text-sm font-medium">{appliedCoupon}</span>
78
- </div>
79
- <button
80
- type="button"
81
- onClick={handleRemove}
82
- disabled={removing}
83
- className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
84
- >
85
- {removing ? 'Removing...' : 'Remove'}
86
- </button>
87
- </div>
88
- </div>
89
- );
90
- }
91
-
92
- return (
93
- <div className={cn('space-y-2', className)}>
94
- <div className="flex gap-2">
95
- <input
96
- type="text"
97
- value={code}
98
- onChange={(e) => {
99
- setCode(e.target.value);
100
- if (error) setError(null);
101
- }}
102
- onKeyDown={(e) => {
103
- if (e.key === 'Enter') {
104
- e.preventDefault();
105
- handleApply();
106
- }
107
- }}
108
- placeholder="Coupon code"
109
- className={cn(
110
- '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',
111
- error ? 'border-destructive' : 'border-border'
112
- )}
113
- />
114
- <button
115
- type="button"
116
- onClick={handleApply}
117
- disabled={applying || !code.trim()}
118
- 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"
119
- >
120
- {applying ? (
121
- <LoadingSpinner size="sm" className="border-muted-foreground/30 border-t-foreground" />
122
- ) : (
123
- 'Apply'
124
- )}
125
- </button>
126
- </div>
127
-
128
- {error && <p className="text-destructive text-xs">{error}</p>}
129
- </div>
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 { cn } from '@/lib/utils';
6
-
7
- interface ReservationCountdownProps {
8
- reservation: ReservationInfo;
9
- className?: string;
10
- }
11
-
12
- export function ReservationCountdown({ reservation, className }: ReservationCountdownProps) {
13
- const [remainingSeconds, setRemainingSeconds] = useState<number>(0);
14
-
15
- const calculateRemaining = useCallback(() => {
16
- if (!reservation.expiresAt) return 0;
17
- const expiresAtMs = new Date(reservation.expiresAt).getTime();
18
- const nowMs = Date.now();
19
- return Math.max(0, Math.floor((expiresAtMs - nowMs) / 1000));
20
- }, [reservation.expiresAt]);
21
-
22
- useEffect(() => {
23
- setRemainingSeconds(calculateRemaining());
24
-
25
- const interval = setInterval(() => {
26
- const remaining = calculateRemaining();
27
- setRemainingSeconds(remaining);
28
-
29
- if (remaining <= 0) {
30
- clearInterval(interval);
31
- }
32
- }, 1000);
33
-
34
- return () => clearInterval(interval);
35
- }, [calculateRemaining]);
36
-
37
- if (!reservation.hasReservation) return null;
38
-
39
- const minutes = Math.floor(remainingSeconds / 60);
40
- const seconds = remainingSeconds % 60;
41
- const isExpired = remainingSeconds <= 0;
42
- const isUrgent = remainingSeconds > 0 && remainingSeconds < 120;
43
-
44
- const displayMessage = reservation.countdownMessage
45
- ? reservation.countdownMessage.replace(
46
- '{time}',
47
- `${minutes}:${seconds.toString().padStart(2, '0')}`
48
- )
49
- : null;
50
-
51
- return (
52
- <div
53
- className={cn(
54
- 'flex items-center gap-3 rounded-lg px-4 py-3 text-sm',
55
- isExpired
56
- ? 'bg-destructive/10 border-destructive/20 text-destructive border'
57
- : isUrgent
58
- ? 'border border-orange-200 bg-orange-50 text-orange-800 dark:border-orange-800 dark:bg-orange-950/30 dark:text-orange-300'
59
- : 'bg-primary/5 border-primary/20 text-foreground border',
60
- className
61
- )}
62
- >
63
- <svg
64
- className={cn(
65
- 'h-5 w-5 flex-shrink-0',
66
- isExpired
67
- ? 'text-destructive'
68
- : isUrgent
69
- ? 'text-orange-600 dark:text-orange-400'
70
- : 'text-primary'
71
- )}
72
- fill="none"
73
- viewBox="0 0 24 24"
74
- stroke="currentColor"
75
- >
76
- <path
77
- strokeLinecap="round"
78
- strokeLinejoin="round"
79
- strokeWidth={2}
80
- d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
81
- />
82
- </svg>
83
-
84
- <div className="flex-1">
85
- {isExpired ? (
86
- <p className="font-medium">Reservation expired. Items may no longer be available.</p>
87
- ) : displayMessage ? (
88
- <p>{displayMessage}</p>
89
- ) : (
90
- <p>
91
- {isUrgent ? 'Hurry! ' : ''}Items reserved for{' '}
92
- <span className="font-semibold tabular-nums">
93
- {minutes}:{seconds.toString().padStart(2, '0')}
94
- </span>
95
- </p>
96
- )}
97
- </div>
98
- </div>
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
+ }