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,291 +1,291 @@
1
- 'use client';
2
-
3
- import { useMemo } from 'react';
4
- import type { Product, ProductVariant } from 'brainerce';
5
- import { getVariantOptions, getProductSwatches, formatPrice } from 'brainerce';
6
- import type { InventoryInfo } from 'brainerce';
7
- import { useCurrency } from '@/lib/use-currency';
8
- import { useTranslations } from '@/lib/translations';
9
- import { cn } from '@/lib/utils';
10
-
11
- interface VariantSelectorProps {
12
- product: Product;
13
- selectedVariant: ProductVariant | null;
14
- onVariantChange: (variant: ProductVariant) => void;
15
- className?: string;
16
- }
17
-
18
- interface AttributeGroup {
19
- name: string;
20
- displayType: string;
21
- values: Array<{
22
- value: string;
23
- swatchColor?: string | null;
24
- swatchColor2?: string | null;
25
- swatchImageUrl?: string | null;
26
- variants: ProductVariant[];
27
- }>;
28
- }
29
-
30
- export function VariantSelector({
31
- product,
32
- selectedVariant,
33
- onVariantChange,
34
- className,
35
- }: VariantSelectorProps) {
36
- const t = useTranslations('productDetail');
37
- const currency = useCurrency();
38
- const variants = useMemo(() => product.variants || [], [product.variants]);
39
-
40
- // Get swatch metadata from product attribute options
41
- const swatchData = useMemo(() => getProductSwatches(product), [product]);
42
- const swatchMap = useMemo(() => {
43
- const map = new Map<
44
- string,
45
- {
46
- displayType: string;
47
- options: Map<
48
- string,
49
- {
50
- swatchColor?: string | null;
51
- swatchColor2?: string | null;
52
- swatchImageUrl?: string | null;
53
- }
54
- >;
55
- }
56
- >();
57
- for (const attr of swatchData) {
58
- const optMap = new Map<
59
- string,
60
- {
61
- swatchColor?: string | null;
62
- swatchColor2?: string | null;
63
- swatchImageUrl?: string | null;
64
- }
65
- >();
66
- for (const opt of attr.options) {
67
- optMap.set(opt.name, {
68
- swatchColor: opt.swatchColor,
69
- swatchColor2: opt.swatchColor2,
70
- swatchImageUrl: opt.swatchImageUrl,
71
- });
72
- }
73
- map.set(attr.attributeName, { displayType: attr.displayType, options: optMap });
74
- }
75
- return map;
76
- }, [swatchData]);
77
-
78
- // Build attribute groups from variant data, enriched with swatch info
79
- const attributeGroups = useMemo<AttributeGroup[]>(() => {
80
- const groups = new Map<string, Map<string, ProductVariant[]>>();
81
-
82
- for (const variant of variants) {
83
- const options = getVariantOptions(variant);
84
- for (const { name, value } of options) {
85
- if (!groups.has(name)) {
86
- groups.set(name, new Map());
87
- }
88
- const valuesMap = groups.get(name)!;
89
- if (!valuesMap.has(value)) {
90
- valuesMap.set(value, []);
91
- }
92
- valuesMap.get(value)!.push(variant);
93
- }
94
- }
95
-
96
- return Array.from(groups.entries()).map(([name, valuesMap]) => {
97
- const attrSwatch = swatchMap.get(name);
98
- return {
99
- name,
100
- displayType: attrSwatch?.displayType || 'DROPDOWN',
101
- values: Array.from(valuesMap.entries()).map(([value, variantList]) => {
102
- const optSwatch = attrSwatch?.options.get(value);
103
- return {
104
- value,
105
- swatchColor: optSwatch?.swatchColor,
106
- swatchColor2: optSwatch?.swatchColor2,
107
- swatchImageUrl: optSwatch?.swatchImageUrl,
108
- variants: variantList,
109
- };
110
- }),
111
- };
112
- });
113
- }, [variants, swatchMap]);
114
-
115
- // Get currently selected attribute values
116
- const selectedOptions = useMemo(() => {
117
- if (!selectedVariant) return new Map<string, string>();
118
- const opts = getVariantOptions(selectedVariant);
119
- return new Map(opts.map(({ name, value }) => [name, value]));
120
- }, [selectedVariant]);
121
-
122
- // Find the variant that matches all selected attributes
123
- function findMatchingVariant(
124
- attributeName: string,
125
- newValue: string
126
- ): ProductVariant | undefined {
127
- const nextSelection = new Map(selectedOptions);
128
- nextSelection.set(attributeName, newValue);
129
-
130
- return variants.find((v) => {
131
- const opts = getVariantOptions(v);
132
- return Array.from(nextSelection.entries()).every(([name, value]) =>
133
- opts.some((o) => o.name === name && o.value === value)
134
- );
135
- });
136
- }
137
-
138
- if (attributeGroups.length === 0) return null;
139
-
140
- return (
141
- <div className={cn('space-y-4', className)}>
142
- {attributeGroups.map((group) => (
143
- <div key={group.name}>
144
- <label className="text-foreground mb-2 block text-sm font-medium">
145
- {group.name}
146
- {selectedOptions.get(group.name) && (
147
- <span className="text-muted-foreground ms-1 font-normal">
148
- : {selectedOptions.get(group.name)}
149
- </span>
150
- )}
151
- </label>
152
- <div className="flex flex-wrap gap-2">
153
- {group.values.map(
154
- ({
155
- value,
156
- swatchColor,
157
- swatchColor2,
158
- swatchImageUrl,
159
- variants: matchingVariants,
160
- }) => {
161
- const isSelected = selectedOptions.get(group.name) === value;
162
- const matchedVariant = findMatchingVariant(group.name, value);
163
- const isAvailable = matchedVariant?.inventory?.canPurchase !== false;
164
-
165
- // Color swatch rendering
166
- if (group.displayType === 'COLOR_SWATCH' && swatchColor) {
167
- return (
168
- <button
169
- key={value}
170
- type="button"
171
- disabled={!isAvailable}
172
- title={value}
173
- onClick={() => {
174
- const variant = matchedVariant || matchingVariants[0];
175
- if (variant) onVariantChange(variant);
176
- }}
177
- className={cn(
178
- 'h-9 w-9 rounded-full border-2 transition-all',
179
- isSelected
180
- ? 'border-primary ring-primary/30 ring-2'
181
- : isAvailable
182
- ? 'border-border hover:border-primary'
183
- : 'cursor-not-allowed opacity-40'
184
- )}
185
- style={{
186
- background: swatchColor2
187
- ? `linear-gradient(135deg, ${swatchColor} 50%, ${swatchColor2} 50%)`
188
- : swatchColor,
189
- }}
190
- >
191
- {!isAvailable && (
192
- <span
193
- className="bg-muted-foreground block h-full w-full rounded-full opacity-50"
194
- style={{
195
- backgroundImage:
196
- 'linear-gradient(135deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%)',
197
- }}
198
- />
199
- )}
200
- </button>
201
- );
202
- }
203
-
204
- // Image swatch rendering
205
- if (group.displayType === 'IMAGE_SWATCH' && swatchImageUrl) {
206
- return (
207
- <button
208
- key={value}
209
- type="button"
210
- disabled={!isAvailable}
211
- title={value}
212
- onClick={() => {
213
- const variant = matchedVariant || matchingVariants[0];
214
- if (variant) onVariantChange(variant);
215
- }}
216
- className={cn(
217
- 'h-10 w-10 overflow-hidden rounded-lg border-2 transition-all',
218
- isSelected
219
- ? 'border-primary ring-primary/30 ring-2'
220
- : isAvailable
221
- ? 'border-border hover:border-primary'
222
- : 'cursor-not-allowed opacity-40'
223
- )}
224
- >
225
- <img
226
- src={swatchImageUrl}
227
- alt={value}
228
- className="h-full w-full object-cover"
229
- />
230
- </button>
231
- );
232
- }
233
-
234
- // Default button rendering (BUTTON, DROPDOWN, or fallback)
235
- return (
236
- <button
237
- key={value}
238
- type="button"
239
- disabled={!isAvailable}
240
- onClick={() => {
241
- const variant = matchedVariant || matchingVariants[0];
242
- if (variant) onVariantChange(variant);
243
- }}
244
- className={cn(
245
- 'rounded border px-4 py-2 text-sm transition-colors',
246
- isSelected
247
- ? 'border-primary bg-primary text-primary-foreground'
248
- : isAvailable
249
- ? 'border-border bg-background text-foreground hover:border-primary'
250
- : 'border-border bg-muted text-muted-foreground cursor-not-allowed line-through opacity-50'
251
- )}
252
- >
253
- {value}
254
- </button>
255
- );
256
- }
257
- )}
258
- </div>
259
- </div>
260
- ))}
261
-
262
- {/* Variant-specific info */}
263
- {selectedVariant && (
264
- <div className="text-muted-foreground flex items-center gap-3 pt-1 text-sm">
265
- {selectedVariant.price && (
266
- <span>
267
- {
268
- formatPrice(selectedVariant.salePrice || selectedVariant.price, {
269
- currency,
270
- }) as string
271
- }
272
- </span>
273
- )}
274
- <span>{getTranslatedStockStatus(selectedVariant.inventory, t)}</span>
275
- </div>
276
- )}
277
- </div>
278
- );
279
- }
280
-
281
- function getTranslatedStockStatus(
282
- inventory: InventoryInfo | null | undefined,
283
- t: (key: string) => string
284
- ): string {
285
- if (!inventory) return t('outOfStock');
286
- const { trackingMode, inStock, available } = inventory;
287
- if (trackingMode === 'DISABLED') return t('unavailable');
288
- if (!inStock) return t('outOfStock');
289
- if (trackingMode === 'UNLIMITED') return t('inStock');
290
- return t('availableInStock').replace('{available}', String(available));
291
- }
1
+ 'use client';
2
+
3
+ import { useMemo } from 'react';
4
+ import type { Product, ProductVariant } from 'brainerce';
5
+ import { getVariantOptions, getProductSwatches, formatPrice } from 'brainerce';
6
+ import type { InventoryInfo } from 'brainerce';
7
+ import { useCurrency } from '@/lib/use-currency';
8
+ import { useTranslations } from '@/lib/translations';
9
+ import { cn } from '@/lib/utils';
10
+
11
+ interface VariantSelectorProps {
12
+ product: Product;
13
+ selectedVariant: ProductVariant | null;
14
+ onVariantChange: (variant: ProductVariant) => void;
15
+ className?: string;
16
+ }
17
+
18
+ interface AttributeGroup {
19
+ name: string;
20
+ displayType: string;
21
+ values: Array<{
22
+ value: string;
23
+ swatchColor?: string | null;
24
+ swatchColor2?: string | null;
25
+ swatchImageUrl?: string | null;
26
+ variants: ProductVariant[];
27
+ }>;
28
+ }
29
+
30
+ export function VariantSelector({
31
+ product,
32
+ selectedVariant,
33
+ onVariantChange,
34
+ className,
35
+ }: VariantSelectorProps) {
36
+ const t = useTranslations('productDetail');
37
+ const currency = useCurrency();
38
+ const variants = useMemo(() => product.variants || [], [product.variants]);
39
+
40
+ // Get swatch metadata from product attribute options
41
+ const swatchData = useMemo(() => getProductSwatches(product), [product]);
42
+ const swatchMap = useMemo(() => {
43
+ const map = new Map<
44
+ string,
45
+ {
46
+ displayType: string;
47
+ options: Map<
48
+ string,
49
+ {
50
+ swatchColor?: string | null;
51
+ swatchColor2?: string | null;
52
+ swatchImageUrl?: string | null;
53
+ }
54
+ >;
55
+ }
56
+ >();
57
+ for (const attr of swatchData) {
58
+ const optMap = new Map<
59
+ string,
60
+ {
61
+ swatchColor?: string | null;
62
+ swatchColor2?: string | null;
63
+ swatchImageUrl?: string | null;
64
+ }
65
+ >();
66
+ for (const opt of attr.options) {
67
+ optMap.set(opt.name, {
68
+ swatchColor: opt.swatchColor,
69
+ swatchColor2: opt.swatchColor2,
70
+ swatchImageUrl: opt.swatchImageUrl,
71
+ });
72
+ }
73
+ map.set(attr.attributeName, { displayType: attr.displayType, options: optMap });
74
+ }
75
+ return map;
76
+ }, [swatchData]);
77
+
78
+ // Build attribute groups from variant data, enriched with swatch info
79
+ const attributeGroups = useMemo<AttributeGroup[]>(() => {
80
+ const groups = new Map<string, Map<string, ProductVariant[]>>();
81
+
82
+ for (const variant of variants) {
83
+ const options = getVariantOptions(variant);
84
+ for (const { name, value } of options) {
85
+ if (!groups.has(name)) {
86
+ groups.set(name, new Map());
87
+ }
88
+ const valuesMap = groups.get(name)!;
89
+ if (!valuesMap.has(value)) {
90
+ valuesMap.set(value, []);
91
+ }
92
+ valuesMap.get(value)!.push(variant);
93
+ }
94
+ }
95
+
96
+ return Array.from(groups.entries()).map(([name, valuesMap]) => {
97
+ const attrSwatch = swatchMap.get(name);
98
+ return {
99
+ name,
100
+ displayType: attrSwatch?.displayType || 'DROPDOWN',
101
+ values: Array.from(valuesMap.entries()).map(([value, variantList]) => {
102
+ const optSwatch = attrSwatch?.options.get(value);
103
+ return {
104
+ value,
105
+ swatchColor: optSwatch?.swatchColor,
106
+ swatchColor2: optSwatch?.swatchColor2,
107
+ swatchImageUrl: optSwatch?.swatchImageUrl,
108
+ variants: variantList,
109
+ };
110
+ }),
111
+ };
112
+ });
113
+ }, [variants, swatchMap]);
114
+
115
+ // Get currently selected attribute values
116
+ const selectedOptions = useMemo(() => {
117
+ if (!selectedVariant) return new Map<string, string>();
118
+ const opts = getVariantOptions(selectedVariant);
119
+ return new Map(opts.map(({ name, value }) => [name, value]));
120
+ }, [selectedVariant]);
121
+
122
+ // Find the variant that matches all selected attributes
123
+ function findMatchingVariant(
124
+ attributeName: string,
125
+ newValue: string
126
+ ): ProductVariant | undefined {
127
+ const nextSelection = new Map(selectedOptions);
128
+ nextSelection.set(attributeName, newValue);
129
+
130
+ return variants.find((v) => {
131
+ const opts = getVariantOptions(v);
132
+ return Array.from(nextSelection.entries()).every(([name, value]) =>
133
+ opts.some((o) => o.name === name && o.value === value)
134
+ );
135
+ });
136
+ }
137
+
138
+ if (attributeGroups.length === 0) return null;
139
+
140
+ return (
141
+ <div className={cn('space-y-4', className)}>
142
+ {attributeGroups.map((group) => (
143
+ <div key={group.name}>
144
+ <label className="text-foreground mb-2 block text-sm font-medium">
145
+ {group.name}
146
+ {selectedOptions.get(group.name) && (
147
+ <span className="text-muted-foreground ms-1 font-normal">
148
+ : {selectedOptions.get(group.name)}
149
+ </span>
150
+ )}
151
+ </label>
152
+ <div className="flex flex-wrap gap-2">
153
+ {group.values.map(
154
+ ({
155
+ value,
156
+ swatchColor,
157
+ swatchColor2,
158
+ swatchImageUrl,
159
+ variants: matchingVariants,
160
+ }) => {
161
+ const isSelected = selectedOptions.get(group.name) === value;
162
+ const matchedVariant = findMatchingVariant(group.name, value);
163
+ const isAvailable = matchedVariant?.inventory?.canPurchase !== false;
164
+
165
+ // Color swatch rendering
166
+ if (group.displayType === 'COLOR_SWATCH' && swatchColor) {
167
+ return (
168
+ <button
169
+ key={value}
170
+ type="button"
171
+ disabled={!isAvailable}
172
+ title={value}
173
+ onClick={() => {
174
+ const variant = matchedVariant || matchingVariants[0];
175
+ if (variant) onVariantChange(variant);
176
+ }}
177
+ className={cn(
178
+ 'h-9 w-9 rounded-full border-2 transition-all',
179
+ isSelected
180
+ ? 'border-primary ring-primary/30 ring-2'
181
+ : isAvailable
182
+ ? 'border-border hover:border-primary'
183
+ : 'cursor-not-allowed opacity-40'
184
+ )}
185
+ style={{
186
+ background: swatchColor2
187
+ ? `linear-gradient(135deg, ${swatchColor} 50%, ${swatchColor2} 50%)`
188
+ : swatchColor,
189
+ }}
190
+ >
191
+ {!isAvailable && (
192
+ <span
193
+ className="bg-muted-foreground block h-full w-full rounded-full opacity-50"
194
+ style={{
195
+ backgroundImage:
196
+ 'linear-gradient(135deg, transparent 45%, currentColor 45%, currentColor 55%, transparent 55%)',
197
+ }}
198
+ />
199
+ )}
200
+ </button>
201
+ );
202
+ }
203
+
204
+ // Image swatch rendering
205
+ if (group.displayType === 'IMAGE_SWATCH' && swatchImageUrl) {
206
+ return (
207
+ <button
208
+ key={value}
209
+ type="button"
210
+ disabled={!isAvailable}
211
+ title={value}
212
+ onClick={() => {
213
+ const variant = matchedVariant || matchingVariants[0];
214
+ if (variant) onVariantChange(variant);
215
+ }}
216
+ className={cn(
217
+ 'h-10 w-10 overflow-hidden rounded-lg border-2 transition-all',
218
+ isSelected
219
+ ? 'border-primary ring-primary/30 ring-2'
220
+ : isAvailable
221
+ ? 'border-border hover:border-primary'
222
+ : 'cursor-not-allowed opacity-40'
223
+ )}
224
+ >
225
+ <img
226
+ src={swatchImageUrl}
227
+ alt={value}
228
+ className="h-full w-full object-cover"
229
+ />
230
+ </button>
231
+ );
232
+ }
233
+
234
+ // Default button rendering (BUTTON, DROPDOWN, or fallback)
235
+ return (
236
+ <button
237
+ key={value}
238
+ type="button"
239
+ disabled={!isAvailable}
240
+ onClick={() => {
241
+ const variant = matchedVariant || matchingVariants[0];
242
+ if (variant) onVariantChange(variant);
243
+ }}
244
+ className={cn(
245
+ 'rounded border px-4 py-2 text-sm transition-colors',
246
+ isSelected
247
+ ? 'border-primary bg-primary text-primary-foreground'
248
+ : isAvailable
249
+ ? 'border-border bg-background text-foreground hover:border-primary'
250
+ : 'border-border bg-muted text-muted-foreground cursor-not-allowed line-through opacity-50'
251
+ )}
252
+ >
253
+ {value}
254
+ </button>
255
+ );
256
+ }
257
+ )}
258
+ </div>
259
+ </div>
260
+ ))}
261
+
262
+ {/* Variant-specific info */}
263
+ {selectedVariant && (
264
+ <div className="text-muted-foreground flex items-center gap-3 pt-1 text-sm">
265
+ {selectedVariant.price && (
266
+ <span>
267
+ {
268
+ formatPrice(selectedVariant.salePrice || selectedVariant.price, {
269
+ currency,
270
+ }) as string
271
+ }
272
+ </span>
273
+ )}
274
+ <span>{getTranslatedStockStatus(selectedVariant.inventory, t)}</span>
275
+ </div>
276
+ )}
277
+ </div>
278
+ );
279
+ }
280
+
281
+ function getTranslatedStockStatus(
282
+ inventory: InventoryInfo | null | undefined,
283
+ t: (key: string) => string
284
+ ): string {
285
+ if (!inventory) return t('outOfStock');
286
+ const { trackingMode, inStock, available } = inventory;
287
+ if (trackingMode === 'DISABLED') return t('unavailable');
288
+ if (!inStock) return t('outOfStock');
289
+ if (trackingMode === 'UNLIMITED') return t('inStock');
290
+ return t('availableInStock').replace('{available}', String(available));
291
+ }