create-brainerce-store 1.43.0 → 1.43.2

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 (25) hide show
  1. package/dist/index.js +11 -8
  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 +98 -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/product-card.tsx +46 -1
  21. package/templates/nextjs/base/src/components/products/variant-selector.tsx +291 -291
  22. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +125 -129
  23. package/templates/nextjs/base/src/components/shared/price-display.tsx +61 -61
  24. package/templates/nextjs/base/src/lib/resolve-currency.ts +1 -6
  25. package/templates/nextjs/base/src/lib/use-currency.ts +1 -6
@@ -1,242 +1,242 @@
1
- 'use client';
2
-
3
- import { useState, useMemo } from 'react';
4
- import Image from 'next/image';
5
- import type { OrderBump, RecommendationVariant } from 'brainerce';
6
- import { formatPrice, getVariantOptions } from 'brainerce';
7
- import { useCurrency } from '@/lib/use-currency';
8
- import { useTranslations } from '@/lib/translations';
9
- import { cn } from '@/lib/utils';
10
-
11
- interface OrderBumpCardProps {
12
- bump: OrderBump;
13
- isAdded: boolean;
14
- onToggle: (bumpId: string, add: boolean, variantId?: string) => void;
15
- loading: boolean;
16
- className?: string;
17
- }
18
-
19
- export function OrderBumpCard({ bump, isAdded, onToggle, loading, className }: OrderBumpCardProps) {
20
- const t = useTranslations('checkout');
21
- const currency = useCurrency();
22
- const [selectedVariantId, setSelectedVariantId] = useState<string | null>(null);
23
-
24
- const product = bump.bumpProduct;
25
- const variants = product.variants;
26
- const requiresSelection = bump.requiresVariantSelection && variants && variants.length > 0;
27
-
28
- // Build attribute groups from variants for pill selector
29
- const attributeGroups = useMemo(() => {
30
- if (!requiresSelection || !variants) return [];
31
- const groups = new Map<string, Set<string>>();
32
- for (const v of variants) {
33
- const opts = getVariantOptions(v as any);
34
- for (const opt of opts) {
35
- if (!groups.has(opt.name)) groups.set(opt.name, new Set());
36
- groups.get(opt.name)!.add(opt.value);
37
- }
38
- }
39
- return Array.from(groups.entries()).map(([name, values]) => ({
40
- name,
41
- values: Array.from(values),
42
- }));
43
- }, [requiresSelection, variants]);
44
-
45
- // Track selected attributes
46
- const [selectedAttrs, setSelectedAttrs] = useState<Record<string, string>>({});
47
-
48
- // Find matching variant based on selected attributes
49
- const selectedVariant = useMemo(() => {
50
- if (!requiresSelection || !variants) return null;
51
- return (
52
- variants.find((v) => {
53
- const opts = getVariantOptions(v as any);
54
- return attributeGroups.every((group) => {
55
- const opt = opts.find((o) => o.name === group.name);
56
- return opt && selectedAttrs[group.name] === opt.value;
57
- });
58
- }) ?? null
59
- );
60
- }, [requiresSelection, variants, selectedAttrs, attributeGroups]);
61
-
62
- // Update selectedVariantId when variant match changes
63
- const effectiveVariantId = selectedVariant?.id ?? selectedVariantId;
64
-
65
- function handleAttrSelect(attrName: string, value: string) {
66
- const next = { ...selectedAttrs, [attrName]: value };
67
- setSelectedAttrs(next);
68
- // Find matching variant with new selection
69
- if (variants) {
70
- const match = variants.find((v) => {
71
- const opts = getVariantOptions(v as any);
72
- return attributeGroups.every((group) => {
73
- const opt = opts.find((o) => o.name === group.name);
74
- return opt && next[group.name] === opt.value;
75
- });
76
- });
77
- setSelectedVariantId(match?.id ?? null);
78
- }
79
- }
80
-
81
- // Compute display price
82
- const { displayOriginal, displayDiscounted } = useMemo(() => {
83
- let effectivePrice: number;
84
- if (selectedVariant) {
85
- const vSale = selectedVariant.salePrice ? parseFloat(selectedVariant.salePrice) : null;
86
- const vPrice = selectedVariant.price ? parseFloat(selectedVariant.price) : null;
87
- effectivePrice = vSale ?? vPrice ?? parseFloat(bump.originalPrice);
88
- } else {
89
- effectivePrice = parseFloat(bump.originalPrice);
90
- }
91
-
92
- let discounted: number | null = null;
93
- if (bump.discountType && bump.discountValue) {
94
- const dv = parseFloat(bump.discountValue);
95
- if (bump.discountType === 'PERCENTAGE') {
96
- discounted = effectivePrice * (1 - dv / 100);
97
- } else {
98
- discounted = Math.max(0, effectivePrice - dv);
99
- }
100
- }
101
-
102
- return { displayOriginal: effectivePrice, displayDiscounted: discounted };
103
- }, [selectedVariant, bump.originalPrice, bump.discountType, bump.discountValue]);
104
-
105
- // Check if selected variant is out of stock
106
- const isOos =
107
- selectedVariant?.inventory?.trackingMode !== 'NOT_TRACKED' &&
108
- selectedVariant?.inventory?.available != null &&
109
- selectedVariant.inventory.available <= 0;
110
-
111
- // Locked variant label
112
- const lockedLabel =
113
- bump.lockedVariant?.name ??
114
- (bump.lockedVariant?.attributes
115
- ? Object.values(bump.lockedVariant.attributes).join(' / ')
116
- : null);
117
-
118
- const firstImage = product.images?.[0];
119
- const imageUrl = firstImage
120
- ? typeof firstImage === 'string'
121
- ? firstImage
122
- : firstImage.url
123
- : null;
124
-
125
- const canToggle = !requiresSelection || !!effectiveVariantId;
126
-
127
- return (
128
- <div
129
- className={cn(
130
- 'border-border hover:border-primary/50 rounded-lg border p-3 transition-colors',
131
- isAdded && 'border-primary bg-primary/5',
132
- loading && 'pointer-events-none opacity-60',
133
- className
134
- )}
135
- >
136
- <label className="flex cursor-pointer items-start gap-3">
137
- <input
138
- type="checkbox"
139
- checked={isAdded}
140
- onChange={() => {
141
- if (canToggle) {
142
- onToggle(bump.id, !isAdded, effectiveVariantId ?? undefined);
143
- }
144
- }}
145
- disabled={loading || !canToggle || isOos}
146
- className="mt-1 h-4 w-4 shrink-0 rounded"
147
- />
148
-
149
- {/* Image */}
150
- {imageUrl && (
151
- <div className="bg-muted relative h-10 w-10 shrink-0 overflow-hidden rounded">
152
- <Image src={imageUrl} alt={product.name} fill sizes="40px" className="object-cover" />
153
- </div>
154
- )}
155
-
156
- {/* Content */}
157
- <div className="min-w-0 flex-1">
158
- <p className="text-foreground text-sm font-medium">{bump.title}</p>
159
- {bump.description && (
160
- <p className="text-muted-foreground mt-0.5 text-xs">{bump.description}</p>
161
- )}
162
-
163
- {/* Locked variant label */}
164
- {lockedLabel && <p className="text-muted-foreground mt-0.5 text-xs">{lockedLabel}</p>}
165
-
166
- {/* Price */}
167
- <div className="mt-1 flex items-center gap-2">
168
- {displayDiscounted != null ? (
169
- <>
170
- <span className="text-muted-foreground text-xs line-through">
171
- {formatPrice(displayOriginal, { currency }) as string}
172
- </span>
173
- <span className="text-foreground text-sm font-semibold">
174
- {formatPrice(displayDiscounted, { currency }) as string}
175
- </span>
176
- </>
177
- ) : (
178
- <span className="text-foreground text-sm font-semibold">
179
- {formatPrice(displayOriginal, { currency }) as string}
180
- </span>
181
- )}
182
- {requiresSelection && !effectiveVariantId && (
183
- <span className="text-muted-foreground text-xs">
184
- {t('selectOptions') || 'Select options'}
185
- </span>
186
- )}
187
- </div>
188
- </div>
189
- </label>
190
-
191
- {/* Compact variant selector */}
192
- {requiresSelection && !isAdded && (
193
- <div className="ms-7 mt-2 space-y-1.5">
194
- {attributeGroups.map((group) => (
195
- <div key={group.name} className="flex flex-wrap items-center gap-1.5">
196
- <span className="text-muted-foreground text-xs">{group.name}:</span>
197
- {group.values.map((value) => {
198
- const isSelected = selectedAttrs[group.name] === value;
199
- // Check if this value leads to any available variant
200
- const variantForValue = variants?.find((v) => {
201
- const opts = getVariantOptions(v as any);
202
- const matchesValue = opts.some((o) => o.name === group.name && o.value === value);
203
- if (!matchesValue) return false;
204
- // Check other selected attrs
205
- return Object.entries(selectedAttrs).every(([k, sv]) => {
206
- if (k === group.name) return true;
207
- return opts.some((o) => o.name === k && o.value === sv);
208
- });
209
- });
210
- const isVariantOos =
211
- variantForValue?.inventory?.trackingMode !== 'NOT_TRACKED' &&
212
- variantForValue?.inventory?.available != null &&
213
- variantForValue.inventory.available <= 0;
214
-
215
- return (
216
- <button
217
- key={value}
218
- type="button"
219
- onClick={() => handleAttrSelect(group.name, value)}
220
- disabled={isVariantOos}
221
- className={cn(
222
- 'rounded-full border px-2.5 py-0.5 text-xs transition-colors',
223
- isSelected
224
- ? 'border-primary bg-primary text-primary-foreground'
225
- : 'border-border text-foreground hover:border-primary/50',
226
- isVariantOos && 'cursor-not-allowed line-through opacity-40'
227
- )}
228
- >
229
- {value}
230
- </button>
231
- );
232
- })}
233
- </div>
234
- ))}
235
- {isOos && effectiveVariantId && (
236
- <p className="text-destructive text-xs">{t('outOfStock') || 'Out of stock'}</p>
237
- )}
238
- </div>
239
- )}
240
- </div>
241
- );
242
- }
1
+ 'use client';
2
+
3
+ import { useState, useMemo } from 'react';
4
+ import Image from 'next/image';
5
+ import type { OrderBump, RecommendationVariant } from 'brainerce';
6
+ import { formatPrice, getVariantOptions } from 'brainerce';
7
+ import { useCurrency } from '@/lib/use-currency';
8
+ import { useTranslations } from '@/lib/translations';
9
+ import { cn } from '@/lib/utils';
10
+
11
+ interface OrderBumpCardProps {
12
+ bump: OrderBump;
13
+ isAdded: boolean;
14
+ onToggle: (bumpId: string, add: boolean, variantId?: string) => void;
15
+ loading: boolean;
16
+ className?: string;
17
+ }
18
+
19
+ export function OrderBumpCard({ bump, isAdded, onToggle, loading, className }: OrderBumpCardProps) {
20
+ const t = useTranslations('checkout');
21
+ const currency = useCurrency();
22
+ const [selectedVariantId, setSelectedVariantId] = useState<string | null>(null);
23
+
24
+ const product = bump.bumpProduct;
25
+ const variants = product.variants;
26
+ const requiresSelection = bump.requiresVariantSelection && variants && variants.length > 0;
27
+
28
+ // Build attribute groups from variants for pill selector
29
+ const attributeGroups = useMemo(() => {
30
+ if (!requiresSelection || !variants) return [];
31
+ const groups = new Map<string, Set<string>>();
32
+ for (const v of variants) {
33
+ const opts = getVariantOptions(v as any);
34
+ for (const opt of opts) {
35
+ if (!groups.has(opt.name)) groups.set(opt.name, new Set());
36
+ groups.get(opt.name)!.add(opt.value);
37
+ }
38
+ }
39
+ return Array.from(groups.entries()).map(([name, values]) => ({
40
+ name,
41
+ values: Array.from(values),
42
+ }));
43
+ }, [requiresSelection, variants]);
44
+
45
+ // Track selected attributes
46
+ const [selectedAttrs, setSelectedAttrs] = useState<Record<string, string>>({});
47
+
48
+ // Find matching variant based on selected attributes
49
+ const selectedVariant = useMemo(() => {
50
+ if (!requiresSelection || !variants) return null;
51
+ return (
52
+ variants.find((v) => {
53
+ const opts = getVariantOptions(v as any);
54
+ return attributeGroups.every((group) => {
55
+ const opt = opts.find((o) => o.name === group.name);
56
+ return opt && selectedAttrs[group.name] === opt.value;
57
+ });
58
+ }) ?? null
59
+ );
60
+ }, [requiresSelection, variants, selectedAttrs, attributeGroups]);
61
+
62
+ // Update selectedVariantId when variant match changes
63
+ const effectiveVariantId = selectedVariant?.id ?? selectedVariantId;
64
+
65
+ function handleAttrSelect(attrName: string, value: string) {
66
+ const next = { ...selectedAttrs, [attrName]: value };
67
+ setSelectedAttrs(next);
68
+ // Find matching variant with new selection
69
+ if (variants) {
70
+ const match = variants.find((v) => {
71
+ const opts = getVariantOptions(v as any);
72
+ return attributeGroups.every((group) => {
73
+ const opt = opts.find((o) => o.name === group.name);
74
+ return opt && next[group.name] === opt.value;
75
+ });
76
+ });
77
+ setSelectedVariantId(match?.id ?? null);
78
+ }
79
+ }
80
+
81
+ // Compute display price
82
+ const { displayOriginal, displayDiscounted } = useMemo(() => {
83
+ let effectivePrice: number;
84
+ if (selectedVariant) {
85
+ const vSale = selectedVariant.salePrice ? parseFloat(selectedVariant.salePrice) : null;
86
+ const vPrice = selectedVariant.price ? parseFloat(selectedVariant.price) : null;
87
+ effectivePrice = vSale ?? vPrice ?? parseFloat(bump.originalPrice);
88
+ } else {
89
+ effectivePrice = parseFloat(bump.originalPrice);
90
+ }
91
+
92
+ let discounted: number | null = null;
93
+ if (bump.discountType && bump.discountValue) {
94
+ const dv = parseFloat(bump.discountValue);
95
+ if (bump.discountType === 'PERCENTAGE') {
96
+ discounted = effectivePrice * (1 - dv / 100);
97
+ } else {
98
+ discounted = Math.max(0, effectivePrice - dv);
99
+ }
100
+ }
101
+
102
+ return { displayOriginal: effectivePrice, displayDiscounted: discounted };
103
+ }, [selectedVariant, bump.originalPrice, bump.discountType, bump.discountValue]);
104
+
105
+ // Check if selected variant is out of stock
106
+ const isOos =
107
+ selectedVariant?.inventory?.trackingMode !== 'NOT_TRACKED' &&
108
+ selectedVariant?.inventory?.available != null &&
109
+ selectedVariant.inventory.available <= 0;
110
+
111
+ // Locked variant label
112
+ const lockedLabel =
113
+ bump.lockedVariant?.name ??
114
+ (bump.lockedVariant?.attributes
115
+ ? Object.values(bump.lockedVariant.attributes).join(' / ')
116
+ : null);
117
+
118
+ const firstImage = product.images?.[0];
119
+ const imageUrl = firstImage
120
+ ? typeof firstImage === 'string'
121
+ ? firstImage
122
+ : firstImage.url
123
+ : null;
124
+
125
+ const canToggle = !requiresSelection || !!effectiveVariantId;
126
+
127
+ return (
128
+ <div
129
+ className={cn(
130
+ 'border-border hover:border-primary/50 rounded-lg border p-3 transition-colors',
131
+ isAdded && 'border-primary bg-primary/5',
132
+ loading && 'pointer-events-none opacity-60',
133
+ className
134
+ )}
135
+ >
136
+ <label className="flex cursor-pointer items-start gap-3">
137
+ <input
138
+ type="checkbox"
139
+ checked={isAdded}
140
+ onChange={() => {
141
+ if (canToggle) {
142
+ onToggle(bump.id, !isAdded, effectiveVariantId ?? undefined);
143
+ }
144
+ }}
145
+ disabled={loading || !canToggle || isOos}
146
+ className="mt-1 h-4 w-4 shrink-0 rounded"
147
+ />
148
+
149
+ {/* Image */}
150
+ {imageUrl && (
151
+ <div className="bg-muted relative h-10 w-10 shrink-0 overflow-hidden rounded">
152
+ <Image src={imageUrl} alt={product.name} fill sizes="40px" className="object-cover" />
153
+ </div>
154
+ )}
155
+
156
+ {/* Content */}
157
+ <div className="min-w-0 flex-1">
158
+ <p className="text-foreground text-sm font-medium">{bump.title}</p>
159
+ {bump.description && (
160
+ <p className="text-muted-foreground mt-0.5 text-xs">{bump.description}</p>
161
+ )}
162
+
163
+ {/* Locked variant label */}
164
+ {lockedLabel && <p className="text-muted-foreground mt-0.5 text-xs">{lockedLabel}</p>}
165
+
166
+ {/* Price */}
167
+ <div className="mt-1 flex items-center gap-2">
168
+ {displayDiscounted != null ? (
169
+ <>
170
+ <span className="text-muted-foreground text-xs line-through">
171
+ {formatPrice(displayOriginal, { currency }) as string}
172
+ </span>
173
+ <span className="text-foreground text-sm font-semibold">
174
+ {formatPrice(displayDiscounted, { currency }) as string}
175
+ </span>
176
+ </>
177
+ ) : (
178
+ <span className="text-foreground text-sm font-semibold">
179
+ {formatPrice(displayOriginal, { currency }) as string}
180
+ </span>
181
+ )}
182
+ {requiresSelection && !effectiveVariantId && (
183
+ <span className="text-muted-foreground text-xs">
184
+ {t('selectOptions') || 'Select options'}
185
+ </span>
186
+ )}
187
+ </div>
188
+ </div>
189
+ </label>
190
+
191
+ {/* Compact variant selector */}
192
+ {requiresSelection && !isAdded && (
193
+ <div className="ms-7 mt-2 space-y-1.5">
194
+ {attributeGroups.map((group) => (
195
+ <div key={group.name} className="flex flex-wrap items-center gap-1.5">
196
+ <span className="text-muted-foreground text-xs">{group.name}:</span>
197
+ {group.values.map((value) => {
198
+ const isSelected = selectedAttrs[group.name] === value;
199
+ // Check if this value leads to any available variant
200
+ const variantForValue = variants?.find((v) => {
201
+ const opts = getVariantOptions(v as any);
202
+ const matchesValue = opts.some((o) => o.name === group.name && o.value === value);
203
+ if (!matchesValue) return false;
204
+ // Check other selected attrs
205
+ return Object.entries(selectedAttrs).every(([k, sv]) => {
206
+ if (k === group.name) return true;
207
+ return opts.some((o) => o.name === k && o.value === sv);
208
+ });
209
+ });
210
+ const isVariantOos =
211
+ variantForValue?.inventory?.trackingMode !== 'NOT_TRACKED' &&
212
+ variantForValue?.inventory?.available != null &&
213
+ variantForValue.inventory.available <= 0;
214
+
215
+ return (
216
+ <button
217
+ key={value}
218
+ type="button"
219
+ onClick={() => handleAttrSelect(group.name, value)}
220
+ disabled={isVariantOos}
221
+ className={cn(
222
+ 'rounded-full border px-2.5 py-0.5 text-xs transition-colors',
223
+ isSelected
224
+ ? 'border-primary bg-primary text-primary-foreground'
225
+ : 'border-border text-foreground hover:border-primary/50',
226
+ isVariantOos && 'cursor-not-allowed line-through opacity-40'
227
+ )}
228
+ >
229
+ {value}
230
+ </button>
231
+ );
232
+ })}
233
+ </div>
234
+ ))}
235
+ {isOos && effectiveVariantId && (
236
+ <p className="text-destructive text-xs">{t('outOfStock') || 'Out of stock'}</p>
237
+ )}
238
+ </div>
239
+ )}
240
+ </div>
241
+ );
242
+ }