create-brainerce-store 1.42.0 → 1.43.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 (22) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
  3. package/templates/nextjs/base/scripts/fetch-store-info.mjs +10 -4
  4. package/templates/nextjs/base/src/app/checkout/page.tsx +982 -981
  5. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +118 -117
  6. package/templates/nextjs/base/src/components/account/order-history.tsx +368 -367
  7. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +111 -112
  8. package/templates/nextjs/base/src/components/cart/cart-item.tsx +152 -153
  9. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +108 -108
  10. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +141 -142
  11. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +62 -59
  12. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +242 -243
  13. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +198 -199
  14. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +109 -110
  15. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +64 -65
  16. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +203 -202
  17. package/templates/nextjs/base/src/components/products/product-card.tsx +226 -226
  18. package/templates/nextjs/base/src/components/products/variant-selector.tsx +291 -292
  19. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +129 -125
  20. package/templates/nextjs/base/src/components/shared/price-display.tsx +61 -65
  21. package/templates/nextjs/base/src/lib/resolve-currency.ts +25 -0
  22. package/templates/nextjs/base/src/lib/use-currency.ts +24 -0
@@ -1,226 +1,226 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import { Link, useRouter } from '@/lib/navigation';
5
- import Image from 'next/image';
6
- import type { Product } from 'brainerce';
7
- import { getProductPriceInfo, getVariantPrice, formatPrice } from 'brainerce';
8
- import { useTranslations } from '@/lib/translations';
9
- import { PriceDisplay } from '@/components/shared/price-display';
10
- import { StockBadge } from '@/components/products/stock-badge';
11
- import { DiscountBadge } from '@/components/products/discount-badge';
12
- import { useCart, useStoreInfo } from '@/providers/store-provider';
13
- import { cn } from '@/lib/utils';
14
-
15
- interface ProductCardProps {
16
- product: Product;
17
- className?: string;
18
- }
19
-
20
- function VariantPriceRange({ product }: { product: Product }) {
21
- const { storeInfo } = useStoreInfo();
22
- const currency = storeInfo?.currency || process.env.NEXT_PUBLIC_STORE_CURRENCY || 'USD';
23
-
24
- let min: number;
25
- let max: number;
26
- if (product.priceMin && product.priceMax) {
27
- min = parseFloat(product.priceMin);
28
- max = parseFloat(product.priceMax);
29
- } else {
30
- const variants = product.variants ?? [];
31
- if (variants.length === 0) return null;
32
- const prices = variants.map((v) => getVariantPrice(v, product.basePrice));
33
- min = Math.min(...prices);
34
- max = Math.max(...prices);
35
- }
36
-
37
- if (isNaN(min) || isNaN(max)) return null;
38
-
39
- return (
40
- <span className="text-foreground text-sm font-medium">
41
- {min === max
42
- ? (formatPrice(min, { currency }) as string)
43
- : `${formatPrice(min, { currency })} – ${formatPrice(max, { currency })}`}
44
- </span>
45
- );
46
- }
47
-
48
- export function ProductCard({ product, className }: ProductCardProps) {
49
- const t = useTranslations('common');
50
- const tp = useTranslations('productDetail');
51
- const tProd = useTranslations('products');
52
- const router = useRouter();
53
- const { refreshCart } = useCart();
54
- const { price, originalPrice, isOnSale } = getProductPriceInfo(product);
55
- const mainImage = product.images?.[0];
56
- const imageUrl = mainImage?.url || null;
57
- const slug = product.slug || product.id;
58
- const isVariable = product.type === 'VARIABLE';
59
-
60
- const [adding, setAdding] = useState(false);
61
- const [added, setAdded] = useState(false);
62
-
63
- const canPurchase = product.inventory?.canPurchase !== false;
64
-
65
- async function handleAddToCart(e: React.MouseEvent) {
66
- e.preventDefault();
67
- e.stopPropagation();
68
-
69
- if (isVariable) {
70
- router.push(`/products/${slug}`);
71
- return;
72
- }
73
-
74
- if (adding || !canPurchase) return;
75
-
76
- try {
77
- setAdding(true);
78
- const { getClient } = await import('@/lib/brainerce');
79
- const client = getClient();
80
- await client.smartAddToCart({ productId: product.id, quantity: 1 });
81
- await refreshCart();
82
- setAdded(true);
83
- setTimeout(() => setAdded(false), 2000);
84
- } catch (err) {
85
- console.error('Failed to add to cart:', err);
86
- } finally {
87
- setAdding(false);
88
- }
89
- }
90
-
91
- return (
92
- <div
93
- className={cn(
94
- 'border-border bg-background group block overflow-hidden rounded-lg border transition-shadow hover:shadow-md',
95
- className
96
- )}
97
- >
98
- {/* Image — clickable */}
99
- <Link href={`/products/${slug}`} className="block">
100
- <div className="bg-muted relative aspect-square overflow-hidden">
101
- {imageUrl ? (
102
- <Image
103
- src={imageUrl}
104
- alt={mainImage?.alt || product.name}
105
- fill
106
- sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 25vw"
107
- className="object-cover transition-transform duration-300 group-hover:scale-105"
108
- />
109
- ) : (
110
- <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
111
- <svg className="h-12 w-12" fill="none" viewBox="0 0 24 24" stroke="currentColor">
112
- <path
113
- strokeLinecap="round"
114
- strokeLinejoin="round"
115
- strokeWidth={1.5}
116
- 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"
117
- />
118
- </svg>
119
- </div>
120
- )}
121
-
122
- {/* Badges */}
123
- <div className="absolute start-2 top-2 flex flex-col gap-1">
124
- {isOnSale && (
125
- <span className="bg-destructive text-destructive-foreground rounded px-2 py-1 text-xs font-bold">
126
- {t('sale')}
127
- </span>
128
- )}
129
- <DiscountBadge discount={product.discount} />
130
- {product.isDownloadable && (
131
- <span className="bg-primary text-primary-foreground rounded px-2 py-1 text-xs font-bold">
132
- {tp('digitalProduct')}
133
- </span>
134
- )}
135
- </div>
136
-
137
- {/* Add to cart overlay button */}
138
- {(isVariable || canPurchase) && (
139
- <button
140
- onClick={handleAddToCart}
141
- disabled={adding}
142
- aria-label={isVariable ? tProd('selectOptions') : tp('addToCart')}
143
- className={cn(
144
- 'absolute bottom-2 end-2 flex h-8 w-8 items-center justify-center rounded-full shadow-md transition-all',
145
- 'translate-y-2 opacity-0 group-hover:translate-y-0 group-hover:opacity-100',
146
- added
147
- ? 'bg-green-500 text-white'
148
- : 'bg-primary text-primary-foreground hover:opacity-90'
149
- )}
150
- >
151
- {added ? (
152
- <svg
153
- className="h-4 w-4"
154
- fill="none"
155
- viewBox="0 0 24 24"
156
- stroke="currentColor"
157
- strokeWidth={2.5}
158
- >
159
- <path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
160
- </svg>
161
- ) : isVariable ? (
162
- <svg
163
- className="h-4 w-4"
164
- fill="none"
165
- viewBox="0 0 24 24"
166
- stroke="currentColor"
167
- strokeWidth={2}
168
- >
169
- <path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
170
- </svg>
171
- ) : (
172
- <svg
173
- className="h-4 w-4"
174
- fill="none"
175
- viewBox="0 0 24 24"
176
- stroke="currentColor"
177
- strokeWidth={2}
178
- >
179
- <path
180
- strokeLinecap="round"
181
- strokeLinejoin="round"
182
- d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"
183
- />
184
- </svg>
185
- )}
186
- </button>
187
- )}
188
- </div>
189
- </Link>
190
-
191
- {/* Content */}
192
- <div className="space-y-2 p-3">
193
- {/* Categories */}
194
- {product.categories && product.categories.length > 0 && (
195
- <div className="flex flex-wrap gap-1">
196
- {product.categories.slice(0, 2).map((cat) => (
197
- <span
198
- key={cat.id}
199
- className="text-muted-foreground bg-muted rounded px-1.5 py-0.5 text-[10px]"
200
- >
201
- {cat.name}
202
- </span>
203
- ))}
204
- </div>
205
- )}
206
-
207
- {/* Name — clickable */}
208
- <Link href={`/products/${slug}`}>
209
- <h3 className="text-foreground hover:text-primary line-clamp-2 text-sm font-medium transition-colors">
210
- {product.name}
211
- </h3>
212
- </Link>
213
-
214
- {/* Price */}
215
- {isVariable ? (
216
- <VariantPriceRange product={product} />
217
- ) : (
218
- <PriceDisplay price={originalPrice} salePrice={isOnSale ? price : undefined} size="sm" />
219
- )}
220
-
221
- {/* Stock */}
222
- <StockBadge inventory={product.inventory} />
223
- </div>
224
- </div>
225
- );
226
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import { Link, useRouter } from '@/lib/navigation';
5
+ import Image from 'next/image';
6
+ import type { Product } from 'brainerce';
7
+ import { getProductPriceInfo, getVariantPrice, formatPrice } from 'brainerce';
8
+ import { useTranslations } from '@/lib/translations';
9
+ import { PriceDisplay } from '@/components/shared/price-display';
10
+ import { StockBadge } from '@/components/products/stock-badge';
11
+ import { DiscountBadge } from '@/components/products/discount-badge';
12
+ import { useCart } from '@/providers/store-provider';
13
+ import { useCurrency } from '@/lib/use-currency';
14
+ import { cn } from '@/lib/utils';
15
+
16
+ interface ProductCardProps {
17
+ product: Product;
18
+ className?: string;
19
+ }
20
+
21
+ function VariantPriceRange({ product }: { product: Product }) {
22
+ const currency = useCurrency();
23
+
24
+ let min: number;
25
+ let max: number;
26
+ if (product.priceMin && product.priceMax) {
27
+ min = parseFloat(product.priceMin);
28
+ max = parseFloat(product.priceMax);
29
+ } else {
30
+ const variants = product.variants ?? [];
31
+ if (variants.length === 0) return null;
32
+ const prices = variants.map((v) => getVariantPrice(v, product.basePrice));
33
+ min = Math.min(...prices);
34
+ max = Math.max(...prices);
35
+ }
36
+
37
+ if (isNaN(min) || isNaN(max)) return null;
38
+
39
+ return (
40
+ <span className="text-foreground text-sm font-medium">
41
+ {min === max
42
+ ? (formatPrice(min, { currency }) as string)
43
+ : `${formatPrice(min, { currency })} – ${formatPrice(max, { currency })}`}
44
+ </span>
45
+ );
46
+ }
47
+
48
+ export function ProductCard({ product, className }: ProductCardProps) {
49
+ const t = useTranslations('common');
50
+ const tp = useTranslations('productDetail');
51
+ const tProd = useTranslations('products');
52
+ const router = useRouter();
53
+ const { refreshCart } = useCart();
54
+ const { price, originalPrice, isOnSale } = getProductPriceInfo(product);
55
+ const mainImage = product.images?.[0];
56
+ const imageUrl = mainImage?.url || null;
57
+ const slug = product.slug || product.id;
58
+ const isVariable = product.type === 'VARIABLE';
59
+
60
+ const [adding, setAdding] = useState(false);
61
+ const [added, setAdded] = useState(false);
62
+
63
+ const canPurchase = product.inventory?.canPurchase !== false;
64
+
65
+ async function handleAddToCart(e: React.MouseEvent) {
66
+ e.preventDefault();
67
+ e.stopPropagation();
68
+
69
+ if (isVariable) {
70
+ router.push(`/products/${slug}`);
71
+ return;
72
+ }
73
+
74
+ if (adding || !canPurchase) return;
75
+
76
+ try {
77
+ setAdding(true);
78
+ const { getClient } = await import('@/lib/brainerce');
79
+ const client = getClient();
80
+ await client.smartAddToCart({ productId: product.id, quantity: 1 });
81
+ await refreshCart();
82
+ setAdded(true);
83
+ setTimeout(() => setAdded(false), 2000);
84
+ } catch (err) {
85
+ console.error('Failed to add to cart:', err);
86
+ } finally {
87
+ setAdding(false);
88
+ }
89
+ }
90
+
91
+ return (
92
+ <div
93
+ className={cn(
94
+ 'border-border bg-background group block overflow-hidden rounded-lg border transition-shadow hover:shadow-md',
95
+ className
96
+ )}
97
+ >
98
+ {/* Image — clickable */}
99
+ <Link href={`/products/${slug}`} className="block">
100
+ <div className="bg-muted relative aspect-square overflow-hidden">
101
+ {imageUrl ? (
102
+ <Image
103
+ src={imageUrl}
104
+ alt={mainImage?.alt || product.name}
105
+ fill
106
+ sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 25vw"
107
+ className="object-cover transition-transform duration-300 group-hover:scale-105"
108
+ />
109
+ ) : (
110
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
111
+ <svg className="h-12 w-12" fill="none" viewBox="0 0 24 24" stroke="currentColor">
112
+ <path
113
+ strokeLinecap="round"
114
+ strokeLinejoin="round"
115
+ strokeWidth={1.5}
116
+ 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"
117
+ />
118
+ </svg>
119
+ </div>
120
+ )}
121
+
122
+ {/* Badges */}
123
+ <div className="absolute start-2 top-2 flex flex-col gap-1">
124
+ {isOnSale && (
125
+ <span className="bg-destructive text-destructive-foreground rounded px-2 py-1 text-xs font-bold">
126
+ {t('sale')}
127
+ </span>
128
+ )}
129
+ <DiscountBadge discount={product.discount} />
130
+ {product.isDownloadable && (
131
+ <span className="bg-primary text-primary-foreground rounded px-2 py-1 text-xs font-bold">
132
+ {tp('digitalProduct')}
133
+ </span>
134
+ )}
135
+ </div>
136
+
137
+ {/* Add to cart overlay button */}
138
+ {(isVariable || canPurchase) && (
139
+ <button
140
+ onClick={handleAddToCart}
141
+ disabled={adding}
142
+ aria-label={isVariable ? tProd('selectOptions') : tp('addToCart')}
143
+ className={cn(
144
+ 'absolute bottom-2 end-2 flex h-8 w-8 items-center justify-center rounded-full shadow-md transition-all',
145
+ 'translate-y-2 opacity-0 group-hover:translate-y-0 group-hover:opacity-100',
146
+ added
147
+ ? 'bg-green-500 text-white'
148
+ : 'bg-primary text-primary-foreground hover:opacity-90'
149
+ )}
150
+ >
151
+ {added ? (
152
+ <svg
153
+ className="h-4 w-4"
154
+ fill="none"
155
+ viewBox="0 0 24 24"
156
+ stroke="currentColor"
157
+ strokeWidth={2.5}
158
+ >
159
+ <path strokeLinecap="round" strokeLinejoin="round" d="M5 13l4 4L19 7" />
160
+ </svg>
161
+ ) : isVariable ? (
162
+ <svg
163
+ className="h-4 w-4"
164
+ fill="none"
165
+ viewBox="0 0 24 24"
166
+ stroke="currentColor"
167
+ strokeWidth={2}
168
+ >
169
+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
170
+ </svg>
171
+ ) : (
172
+ <svg
173
+ className="h-4 w-4"
174
+ fill="none"
175
+ viewBox="0 0 24 24"
176
+ stroke="currentColor"
177
+ strokeWidth={2}
178
+ >
179
+ <path
180
+ strokeLinecap="round"
181
+ strokeLinejoin="round"
182
+ d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"
183
+ />
184
+ </svg>
185
+ )}
186
+ </button>
187
+ )}
188
+ </div>
189
+ </Link>
190
+
191
+ {/* Content */}
192
+ <div className="space-y-2 p-3">
193
+ {/* Categories */}
194
+ {product.categories && product.categories.length > 0 && (
195
+ <div className="flex flex-wrap gap-1">
196
+ {product.categories.slice(0, 2).map((cat) => (
197
+ <span
198
+ key={cat.id}
199
+ className="text-muted-foreground bg-muted rounded px-1.5 py-0.5 text-[10px]"
200
+ >
201
+ {cat.name}
202
+ </span>
203
+ ))}
204
+ </div>
205
+ )}
206
+
207
+ {/* Name — clickable */}
208
+ <Link href={`/products/${slug}`}>
209
+ <h3 className="text-foreground hover:text-primary line-clamp-2 text-sm font-medium transition-colors">
210
+ {product.name}
211
+ </h3>
212
+ </Link>
213
+
214
+ {/* Price */}
215
+ {isVariable ? (
216
+ <VariantPriceRange product={product} />
217
+ ) : (
218
+ <PriceDisplay price={originalPrice} salePrice={isOnSale ? price : undefined} size="sm" />
219
+ )}
220
+
221
+ {/* Stock */}
222
+ <StockBadge inventory={product.inventory} />
223
+ </div>
224
+ </div>
225
+ );
226
+ }