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.
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 +133 -103
  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,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 { useStoreInfo } from '@/providers/store-provider';
9
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
10
- import { cn } from '@/lib/utils';
11
-
12
- interface CartItemProps {
13
- item: CartItemType;
14
- onUpdate: () => void;
15
- className?: string;
16
- }
17
-
18
- export function CartItem({ item, onUpdate, className }: CartItemProps) {
19
- const { storeInfo } = useStoreInfo();
20
- const currency = storeInfo?.currency || 'USD';
21
- const [updating, setUpdating] = useState(false);
22
- const [removing, setRemoving] = useState(false);
23
-
24
- const name = getCartItemName(item);
25
- const imageUrl = getCartItemImage(item);
26
- const variantName = item.variant?.name;
27
- const unitPrice = parseFloat(item.unitPrice);
28
- const lineTotal = unitPrice * item.quantity;
29
-
30
- async function handleQuantityChange(newQuantity: number) {
31
- if (newQuantity < 1 || updating) return;
32
-
33
- try {
34
- setUpdating(true);
35
- const client = getClient();
36
- await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
37
- onUpdate();
38
- } catch (err) {
39
- console.error('Failed to update quantity:', err);
40
- } finally {
41
- setUpdating(false);
42
- }
43
- }
44
-
45
- async function handleRemove() {
46
- if (removing) return;
47
-
48
- try {
49
- setRemoving(true);
50
- const client = getClient();
51
- await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
52
- onUpdate();
53
- } catch (err) {
54
- console.error('Failed to remove item:', err);
55
- } finally {
56
- setRemoving(false);
57
- }
58
- }
59
-
60
- return (
61
- <div
62
- className={cn(
63
- 'border-border flex gap-4 border-b py-4 last:border-0',
64
- (updating || removing) && 'opacity-60',
65
- className
66
- )}
67
- >
68
- {/* Image */}
69
- <div className="bg-muted relative h-20 w-20 flex-shrink-0 overflow-hidden rounded">
70
- {imageUrl ? (
71
- <Image src={imageUrl} alt={name} fill sizes="80px" className="object-cover" />
72
- ) : (
73
- <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
74
- <svg className="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
75
- <path
76
- strokeLinecap="round"
77
- strokeLinejoin="round"
78
- strokeWidth={1.5}
79
- 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"
80
- />
81
- </svg>
82
- </div>
83
- )}
84
- </div>
85
-
86
- {/* Details */}
87
- <div className="min-w-0 flex-1">
88
- <h3 className="text-foreground truncate text-sm font-medium">{name}</h3>
89
-
90
- {/* Variant name */}
91
- {variantName && <p className="text-muted-foreground mt-1 text-xs">{variantName}</p>}
92
-
93
- {/* Unit price */}
94
- <p className="text-muted-foreground mt-1 text-sm">
95
- {formatPrice(unitPrice, { currency }) as string}
96
- </p>
97
-
98
- {/* Quantity controls */}
99
- <div className="mt-2 flex items-center gap-3">
100
- <div className="border-border flex items-center rounded border">
101
- <button
102
- type="button"
103
- onClick={() => handleQuantityChange(item.quantity - 1)}
104
- disabled={updating || item.quantity <= 1}
105
- className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
106
- aria-label="Decrease quantity"
107
- >
108
- -
109
- </button>
110
- <span className="text-foreground min-w-[2.5rem] px-3 py-1 text-center text-sm font-medium">
111
- {updating ? (
112
- <LoadingSpinner
113
- size="sm"
114
- className="border-muted-foreground/30 border-t-foreground mx-auto"
115
- />
116
- ) : (
117
- item.quantity
118
- )}
119
- </span>
120
- <button
121
- type="button"
122
- onClick={() => handleQuantityChange(item.quantity + 1)}
123
- disabled={updating}
124
- className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
125
- aria-label="Increase quantity"
126
- >
127
- +
128
- </button>
129
- </div>
130
-
131
- <button
132
- type="button"
133
- onClick={handleRemove}
134
- disabled={removing}
135
- className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
136
- >
137
- {removing ? 'Removing...' : 'Remove'}
138
- </button>
139
- </div>
140
- </div>
141
-
142
- {/* Line total */}
143
- <div className="flex-shrink-0 text-end">
144
- <span className="text-foreground text-sm font-medium">
145
- {formatPrice(lineTotal, { currency }) as string}
146
- </span>
147
- </div>
148
- </div>
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 { useStoreInfo, useCart } from '@/providers/store-provider';
5
- import { cn } from '@/lib/utils';
6
-
7
- interface CartSummaryProps {
8
- className?: string;
9
- }
10
-
11
- export function CartSummary({ className }: CartSummaryProps) {
12
- const { storeInfo } = useStoreInfo();
13
- const { totals } = useCart();
14
- const currency = storeInfo?.currency || 'USD';
15
-
16
- return (
17
- <div className={cn('space-y-3', className)}>
18
- <h3 className="text-foreground text-lg font-semibold">Order Summary</h3>
19
-
20
- <div className="space-y-2 text-sm">
21
- {/* Subtotal */}
22
- <div className="flex items-center justify-between">
23
- <span className="text-muted-foreground">Subtotal</span>
24
- <span className="text-foreground font-medium">
25
- {formatPrice(totals.subtotal, { currency }) as string}
26
- </span>
27
- </div>
28
-
29
- {/* Discount */}
30
- {totals.discount > 0 && (
31
- <div className="flex items-center justify-between">
32
- <span className="text-muted-foreground">Discount</span>
33
- <span className="text-destructive font-medium">
34
- -{formatPrice(totals.discount, { currency }) as string}
35
- </span>
36
- </div>
37
- )}
38
-
39
- {/* Shipping */}
40
- {totals.shipping > 0 && (
41
- <div className="flex items-center justify-between">
42
- <span className="text-muted-foreground">Shipping</span>
43
- <span className="text-foreground font-medium">
44
- {formatPrice(totals.shipping, { currency }) as string}
45
- </span>
46
- </div>
47
- )}
48
-
49
- {/* Tax */}
50
- <div className="flex items-center justify-between">
51
- <span className="text-muted-foreground">Tax</span>
52
- <span className="text-muted-foreground text-xs">Calculated at checkout</span>
53
- </div>
54
-
55
- {/* Divider */}
56
- <div className="border-border mt-2 border-t pt-2">
57
- <div className="flex items-center justify-between">
58
- <span className="text-foreground font-semibold">Total</span>
59
- <span className="text-foreground text-base font-semibold">
60
- {formatPrice(totals.total, { currency }) as string}
61
- </span>
62
- </div>
63
- </div>
64
- </div>
65
- </div>
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
+ }