create-brainerce-store 1.14.2 → 1.14.4

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 (29) hide show
  1. package/dist/index.js +47 -4
  2. package/messages/en.json +36 -4
  3. package/messages/he.json +36 -4
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/scripts/fetch-store-info.mjs +81 -74
  6. package/templates/nextjs/base/src/app/account/layout.tsx +9 -0
  7. package/templates/nextjs/base/src/app/account/page.tsx +122 -112
  8. package/templates/nextjs/base/src/app/cart/layout.tsx +9 -0
  9. package/templates/nextjs/base/src/app/checkout/layout.tsx +9 -0
  10. package/templates/nextjs/base/src/app/checkout/page.tsx +107 -8
  11. package/templates/nextjs/base/src/app/layout.tsx.ejs +29 -1
  12. package/templates/nextjs/base/src/app/login/layout.tsx +9 -0
  13. package/templates/nextjs/base/src/app/order-confirmation/layout.tsx +9 -0
  14. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +5 -1
  15. package/templates/nextjs/base/src/app/products/[slug]/product-client-section.tsx +1 -6
  16. package/templates/nextjs/base/src/app/products/layout.tsx +18 -0
  17. package/templates/nextjs/base/src/app/products/page.tsx +1 -0
  18. package/templates/nextjs/base/src/app/register/layout.tsx +9 -0
  19. package/templates/nextjs/base/src/app/register/page.tsx +1 -0
  20. package/templates/nextjs/base/src/app/verify-email/page.tsx +1 -1
  21. package/templates/nextjs/base/src/components/account/address-book.tsx +432 -0
  22. package/templates/nextjs/base/src/components/account/order-history.tsx +2 -1
  23. package/templates/nextjs/base/src/components/auth/register-form.tsx +232 -184
  24. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
  25. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +359 -305
  26. package/templates/nextjs/base/src/components/products/product-card.tsx +159 -43
  27. package/templates/nextjs/base/src/components/products/stock-badge.tsx +60 -53
  28. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +40 -7
  29. package/templates/nextjs/base/src/lib/auth.ts +1 -0
@@ -1,153 +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 { 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
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import Image from 'next/image';
5
+ import type { CartItem as CartItemType } from 'brainerce';
6
+ import { 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 productName = item.product.name;
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={productName} 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">{productName}</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
+ }