create-brainerce-store 1.43.0 → 1.43.1

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 (24) hide show
  1. package/dist/index.js +1 -1
  2. package/messages/en.json +1 -0
  3. package/messages/he.json +1 -0
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/next.config.ts +68 -69
  6. package/templates/nextjs/base/scripts/fetch-store-info.mjs +91 -93
  7. package/templates/nextjs/base/src/app/checkout/page.tsx +1004 -982
  8. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +118 -118
  9. package/templates/nextjs/base/src/components/account/order-history.tsx +368 -368
  10. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +111 -111
  11. package/templates/nextjs/base/src/components/cart/cart-item.tsx +152 -152
  12. package/templates/nextjs/base/src/components/cart/cart-summary.tsx +108 -108
  13. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +141 -141
  14. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +62 -62
  15. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +242 -242
  16. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +198 -198
  17. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +109 -109
  18. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +74 -64
  19. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +203 -203
  20. package/templates/nextjs/base/src/components/products/variant-selector.tsx +291 -291
  21. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +125 -129
  22. package/templates/nextjs/base/src/components/shared/price-display.tsx +61 -61
  23. package/templates/nextjs/base/src/lib/resolve-currency.ts +1 -6
  24. package/templates/nextjs/base/src/lib/use-currency.ts +1 -6
@@ -1,111 +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 { 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
+ '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,152 +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 { 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
- }
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
+ }