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,112 +1,111 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import Image from 'next/image';
5
- import type { CartBundleOffer as CartBundleOfferType } from 'brainerce';
6
- import { formatPrice } from 'brainerce';
7
- import { useStoreInfo } from '@/providers/store-provider';
8
- import { useTranslations } from '@/lib/translations';
9
- import { cn } from '@/lib/utils';
10
-
11
- interface CartBundleOfferCardProps {
12
- offer: CartBundleOfferType;
13
- cartId: string;
14
- onAdd: () => void;
15
- className?: string;
16
- }
17
-
18
- export function CartBundleOfferCard({ offer, cartId, onAdd, className }: CartBundleOfferCardProps) {
19
- const { storeInfo } = useStoreInfo();
20
- const t = useTranslations('cart');
21
- const currency = storeInfo?.currency || process.env.NEXT_PUBLIC_STORE_CURRENCY || 'USD';
22
- const [adding, setAdding] = useState(false);
23
-
24
- const offered = offer.offeredProducts;
25
-
26
- const totalOriginal = parseFloat(offer.totalOriginalPrice);
27
- const totalDiscounted = parseFloat(offer.totalDiscountedPrice);
28
- const discountLabel =
29
- offer.discountType === 'PERCENTAGE'
30
- ? `${offer.discountValue}%`
31
- : (formatPrice(parseFloat(offer.discountValue), { currency }) as string);
32
-
33
- async function handleAdd() {
34
- if (adding) return;
35
- try {
36
- setAdding(true);
37
- const { getClient } = await import('@/lib/brainerce');
38
- const client = getClient();
39
- // No variant selections in the default template products with
40
- // variants are best handled with a dedicated picker per offered item.
41
- await client.addBundleToCart(cartId, offer.id);
42
- onAdd();
43
- } catch (err) {
44
- console.error('Failed to add bundle:', err);
45
- } finally {
46
- setAdding(false);
47
- }
48
- }
49
-
50
- return (
51
- <div className={cn('bg-background border-border rounded-lg border p-4', className)}>
52
- <div className="mb-3">
53
- <p className="text-foreground text-sm font-medium">{offer.name}</p>
54
- {offer.description && (
55
- <p className="text-muted-foreground mt-0.5 text-xs">{offer.description}</p>
56
- )}
57
- </div>
58
-
59
- <ul className="space-y-2">
60
- {offered.map((p) => {
61
- const firstImage = p.images?.[0];
62
- const imageUrl = firstImage?.url ?? null;
63
- return (
64
- <li key={p.id} className="flex items-center gap-3">
65
- <div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
66
- {imageUrl ? (
67
- <Image src={imageUrl} alt={p.name} fill sizes="48px" className="object-cover" />
68
- ) : null}
69
- </div>
70
- <div className="min-w-0 flex-1">
71
- <p className="text-foreground truncate text-sm">{p.name}</p>
72
- <div className="mt-0.5 flex items-center gap-2">
73
- <span className="text-muted-foreground text-xs line-through">
74
- {formatPrice(parseFloat(p.originalPrice), { currency }) as string}
75
- </span>
76
- <span className="text-foreground text-xs font-semibold">
77
- {formatPrice(parseFloat(p.discountedPrice), { currency }) as string}
78
- </span>
79
- </div>
80
- </div>
81
- </li>
82
- );
83
- })}
84
- </ul>
85
-
86
- <div className="border-border mt-3 flex items-center justify-between border-t pt-3">
87
- <div className="flex items-center gap-2">
88
- <span className="text-muted-foreground text-sm line-through">
89
- {formatPrice(totalOriginal, { currency }) as string}
90
- </span>
91
- <span className="text-foreground text-sm font-semibold">
92
- {formatPrice(totalDiscounted, { currency }) as string}
93
- </span>
94
- <span className="bg-destructive/10 text-destructive rounded px-1.5 py-0.5 text-xs font-medium">
95
- -{discountLabel}
96
- </span>
97
- </div>
98
- <button
99
- type="button"
100
- onClick={handleAdd}
101
- disabled={adding}
102
- className={cn(
103
- 'bg-primary text-primary-foreground flex-shrink-0 rounded px-4 py-2 text-xs font-medium transition-opacity hover:opacity-90',
104
- 'disabled:cursor-not-allowed disabled:opacity-50'
105
- )}
106
- >
107
- {adding ? t('addingBundle') : t('addBundleItem')}
108
- </button>
109
- </div>
110
- </div>
111
- );
112
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import Image from 'next/image';
5
+ import type { CartBundleOffer as CartBundleOfferType } from 'brainerce';
6
+ import { formatPrice } from 'brainerce';
7
+ import { useCurrency } from '@/lib/use-currency';
8
+ import { useTranslations } from '@/lib/translations';
9
+ import { cn } from '@/lib/utils';
10
+
11
+ interface CartBundleOfferCardProps {
12
+ offer: CartBundleOfferType;
13
+ cartId: string;
14
+ onAdd: () => void;
15
+ className?: string;
16
+ }
17
+
18
+ export function CartBundleOfferCard({ offer, cartId, onAdd, className }: CartBundleOfferCardProps) {
19
+ const t = useTranslations('cart');
20
+ const currency = useCurrency();
21
+ const [adding, setAdding] = useState(false);
22
+
23
+ const offered = offer.offeredProducts;
24
+
25
+ const totalOriginal = parseFloat(offer.totalOriginalPrice);
26
+ const totalDiscounted = parseFloat(offer.totalDiscountedPrice);
27
+ const discountLabel =
28
+ offer.discountType === 'PERCENTAGE'
29
+ ? `${offer.discountValue}%`
30
+ : (formatPrice(parseFloat(offer.discountValue), { currency }) as string);
31
+
32
+ async function handleAdd() {
33
+ if (adding) return;
34
+ try {
35
+ setAdding(true);
36
+ const { getClient } = await import('@/lib/brainerce');
37
+ const client = getClient();
38
+ // No variant selections in the default template — products with
39
+ // variants are best handled with a dedicated picker per offered item.
40
+ await client.addBundleToCart(cartId, offer.id);
41
+ onAdd();
42
+ } catch (err) {
43
+ console.error('Failed to add bundle:', err);
44
+ } finally {
45
+ setAdding(false);
46
+ }
47
+ }
48
+
49
+ return (
50
+ <div className={cn('bg-background border-border rounded-lg border p-4', className)}>
51
+ <div className="mb-3">
52
+ <p className="text-foreground text-sm font-medium">{offer.name}</p>
53
+ {offer.description && (
54
+ <p className="text-muted-foreground mt-0.5 text-xs">{offer.description}</p>
55
+ )}
56
+ </div>
57
+
58
+ <ul className="space-y-2">
59
+ {offered.map((p) => {
60
+ const firstImage = p.images?.[0];
61
+ const imageUrl = firstImage?.url ?? null;
62
+ return (
63
+ <li key={p.id} className="flex items-center gap-3">
64
+ <div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
65
+ {imageUrl ? (
66
+ <Image src={imageUrl} alt={p.name} fill sizes="48px" className="object-cover" />
67
+ ) : null}
68
+ </div>
69
+ <div className="min-w-0 flex-1">
70
+ <p className="text-foreground truncate text-sm">{p.name}</p>
71
+ <div className="mt-0.5 flex items-center gap-2">
72
+ <span className="text-muted-foreground text-xs line-through">
73
+ {formatPrice(parseFloat(p.originalPrice), { currency }) as string}
74
+ </span>
75
+ <span className="text-foreground text-xs font-semibold">
76
+ {formatPrice(parseFloat(p.discountedPrice), { currency }) as string}
77
+ </span>
78
+ </div>
79
+ </div>
80
+ </li>
81
+ );
82
+ })}
83
+ </ul>
84
+
85
+ <div className="border-border mt-3 flex items-center justify-between border-t pt-3">
86
+ <div className="flex items-center gap-2">
87
+ <span className="text-muted-foreground text-sm line-through">
88
+ {formatPrice(totalOriginal, { currency }) as string}
89
+ </span>
90
+ <span className="text-foreground text-sm font-semibold">
91
+ {formatPrice(totalDiscounted, { currency }) as string}
92
+ </span>
93
+ <span className="bg-destructive/10 text-destructive rounded px-1.5 py-0.5 text-xs font-medium">
94
+ -{discountLabel}
95
+ </span>
96
+ </div>
97
+ <button
98
+ type="button"
99
+ onClick={handleAdd}
100
+ disabled={adding}
101
+ className={cn(
102
+ 'bg-primary text-primary-foreground flex-shrink-0 rounded px-4 py-2 text-xs font-medium transition-opacity hover:opacity-90',
103
+ 'disabled:cursor-not-allowed disabled:opacity-50'
104
+ )}
105
+ >
106
+ {adding ? t('addingBundle') : t('addBundleItem')}
107
+ </button>
108
+ </div>
109
+ </div>
110
+ );
111
+ }
@@ -1,153 +1,152 @@
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 || process.env.NEXT_PUBLIC_STORE_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
- }
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 { useCurrency } from '@/lib/use-currency';
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 currency = useCurrency();
23
+ const [updating, setUpdating] = useState(false);
24
+ const [removing, setRemoving] = useState(false);
25
+
26
+ const productName = item.product.name;
27
+ const imageUrl = getCartItemImage(item);
28
+ const variantName = item.variant?.name;
29
+ const unitPrice = parseFloat(item.unitPrice);
30
+ const lineTotal = unitPrice * item.quantity;
31
+
32
+ async function handleQuantityChange(newQuantity: number) {
33
+ if (newQuantity < 1 || updating) return;
34
+
35
+ try {
36
+ setUpdating(true);
37
+ const client = getClient();
38
+ await client.smartUpdateCartItem(item.productId, newQuantity, item.variantId || undefined);
39
+ onUpdate();
40
+ } catch (err) {
41
+ console.error('Failed to update quantity:', err);
42
+ } finally {
43
+ setUpdating(false);
44
+ }
45
+ }
46
+
47
+ async function handleRemove() {
48
+ if (removing) return;
49
+
50
+ try {
51
+ setRemoving(true);
52
+ const client = getClient();
53
+ await client.smartRemoveFromCart(item.productId, item.variantId || undefined);
54
+ onUpdate();
55
+ } catch (err) {
56
+ console.error('Failed to remove item:', err);
57
+ } finally {
58
+ setRemoving(false);
59
+ }
60
+ }
61
+
62
+ return (
63
+ <div
64
+ className={cn(
65
+ 'border-border flex gap-4 border-b py-4 last:border-0',
66
+ (updating || removing) && 'opacity-60',
67
+ className
68
+ )}
69
+ >
70
+ {/* Image */}
71
+ <div className="bg-muted relative h-20 w-20 flex-shrink-0 overflow-hidden rounded">
72
+ {imageUrl ? (
73
+ <Image src={imageUrl} alt={productName} fill sizes="80px" className="object-cover" />
74
+ ) : (
75
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
76
+ <svg className="h-8 w-8" fill="none" viewBox="0 0 24 24" stroke="currentColor">
77
+ <path
78
+ strokeLinecap="round"
79
+ strokeLinejoin="round"
80
+ strokeWidth={1.5}
81
+ 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"
82
+ />
83
+ </svg>
84
+ </div>
85
+ )}
86
+ </div>
87
+
88
+ {/* Details */}
89
+ <div className="min-w-0 flex-1">
90
+ <h3 className="text-foreground truncate text-sm font-medium">{productName}</h3>
91
+
92
+ {/* Variant name */}
93
+ {variantName && <p className="text-muted-foreground mt-1 text-xs">{variantName}</p>}
94
+
95
+ {/* Unit price */}
96
+ <p className="text-muted-foreground mt-1 text-sm">
97
+ {formatPrice(unitPrice, { currency }) as string}
98
+ </p>
99
+
100
+ {/* Quantity controls */}
101
+ <div className="mt-2 flex items-center gap-3">
102
+ <div className="border-border flex items-center rounded border">
103
+ <button
104
+ type="button"
105
+ onClick={() => handleQuantityChange(item.quantity - 1)}
106
+ disabled={updating || item.quantity <= 1}
107
+ className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
108
+ aria-label={td('decreaseQuantity')}
109
+ >
110
+ -
111
+ </button>
112
+ <span className="text-foreground min-w-[2.5rem] px-3 py-1 text-center text-sm font-medium">
113
+ {updating ? (
114
+ <LoadingSpinner
115
+ size="sm"
116
+ className="border-muted-foreground/30 border-t-foreground mx-auto"
117
+ />
118
+ ) : (
119
+ item.quantity
120
+ )}
121
+ </span>
122
+ <button
123
+ type="button"
124
+ onClick={() => handleQuantityChange(item.quantity + 1)}
125
+ disabled={updating}
126
+ className="text-foreground hover:bg-muted px-2 py-1 text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-40"
127
+ aria-label={td('increaseQuantity')}
128
+ >
129
+ +
130
+ </button>
131
+ </div>
132
+
133
+ <button
134
+ type="button"
135
+ onClick={handleRemove}
136
+ disabled={removing}
137
+ className="text-destructive hover:text-destructive/80 text-xs transition-colors disabled:opacity-40"
138
+ >
139
+ {removing ? t('removing') : t('remove')}
140
+ </button>
141
+ </div>
142
+ </div>
143
+
144
+ {/* Line total */}
145
+ <div className="flex-shrink-0 text-end">
146
+ <span className="text-foreground text-sm font-medium">
147
+ {formatPrice(lineTotal, { currency }) as string}
148
+ </span>
149
+ </div>
150
+ </div>
151
+ );
152
+ }