create-brainerce-store 1.18.0 → 1.20.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 (67) hide show
  1. package/LICENSE +0 -0
  2. package/dist/index.js +31 -9
  3. package/messages/en.json +366 -362
  4. package/messages/he.json +366 -362
  5. package/package.json +8 -8
  6. package/templates/nextjs/base/next.config.ts +31 -31
  7. package/templates/nextjs/base/scripts/fetch-store-info.mjs +81 -81
  8. package/templates/nextjs/base/src/app/.well-known/apple-developer-merchantid-domain-association/route.ts +26 -26
  9. package/templates/nextjs/base/src/app/account/layout.tsx +9 -9
  10. package/templates/nextjs/base/src/app/account/page.tsx +122 -122
  11. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +14 -14
  12. package/templates/nextjs/base/src/app/api/auth/me/route.ts +56 -56
  13. package/templates/nextjs/base/src/app/api/auth/oauth-callback/route.ts +59 -59
  14. package/templates/nextjs/base/src/app/api/auth/reset-callback/route.ts +41 -41
  15. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +77 -77
  16. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +198 -198
  17. package/templates/nextjs/base/src/app/auth/callback/page.tsx +92 -92
  18. package/templates/nextjs/base/src/app/cart/layout.tsx +9 -9
  19. package/templates/nextjs/base/src/app/cart/page.tsx +204 -204
  20. package/templates/nextjs/base/src/app/checkout/layout.tsx +9 -9
  21. package/templates/nextjs/base/src/app/checkout/page.tsx +860 -860
  22. package/templates/nextjs/base/src/app/forgot-password/page.tsx +112 -112
  23. package/templates/nextjs/base/src/app/layout.tsx.ejs +75 -0
  24. package/templates/nextjs/base/src/app/login/layout.tsx +9 -9
  25. package/templates/nextjs/base/src/app/login/page.tsx +59 -59
  26. package/templates/nextjs/base/src/app/order-confirmation/layout.tsx +9 -9
  27. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +17 -0
  28. package/templates/nextjs/base/src/app/payment-complete/page.tsx +59 -0
  29. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +67 -67
  30. package/templates/nextjs/base/src/app/products/[slug]/product-client-section.tsx +486 -486
  31. package/templates/nextjs/base/src/app/products/layout.tsx +18 -18
  32. package/templates/nextjs/base/src/app/products/page.tsx +431 -431
  33. package/templates/nextjs/base/src/app/register/layout.tsx +9 -9
  34. package/templates/nextjs/base/src/app/register/page.tsx +65 -65
  35. package/templates/nextjs/base/src/app/reset-password/page.tsx +132 -132
  36. package/templates/nextjs/base/src/app/robots.ts +14 -14
  37. package/templates/nextjs/base/src/app/sitemap.ts +25 -25
  38. package/templates/nextjs/base/src/app/verify-email/page.tsx +258 -258
  39. package/templates/nextjs/base/src/components/account/address-book.tsx +432 -432
  40. package/templates/nextjs/base/src/components/account/order-history.tsx +350 -350
  41. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
  42. package/templates/nextjs/base/src/components/auth/register-form.tsx +232 -232
  43. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +247 -111
  44. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
  45. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +142 -142
  46. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +59 -59
  47. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +415 -415
  48. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +243 -83
  49. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +49 -3
  50. package/templates/nextjs/base/src/components/layout/footer.tsx +41 -41
  51. package/templates/nextjs/base/src/components/layout/header.tsx +336 -336
  52. package/templates/nextjs/base/src/components/layout/language-switcher.tsx.ejs +63 -0
  53. package/templates/nextjs/base/src/components/products/discount-badge.tsx +22 -22
  54. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +202 -202
  55. package/templates/nextjs/base/src/components/products/product-card.tsx +218 -218
  56. package/templates/nextjs/base/src/components/products/recommendation-section.tsx +107 -107
  57. package/templates/nextjs/base/src/components/products/stock-badge.tsx +63 -63
  58. package/templates/nextjs/base/src/components/products/variant-selector.tsx +292 -292
  59. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +72 -72
  60. package/templates/nextjs/base/src/i18n.ts.ejs +21 -0
  61. package/templates/nextjs/base/src/lib/auth.ts +149 -149
  62. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +9 -0
  63. package/templates/nextjs/base/src/lib/translations.ts.ejs +31 -0
  64. package/templates/nextjs/base/src/middleware.ts.ejs +81 -0
  65. package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +41 -0
  66. package/templates/nextjs/base/src/lib/translations.ts +0 -11
  67. package/templates/nextjs/base/src/middleware.ts +0 -25
@@ -1,153 +1,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 { 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 || '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 { 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 || '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,142 +1,142 @@
1
- 'use client';
2
-
3
- import { useState, useEffect } from 'react';
4
- import Image from 'next/image';
5
- import type { CartUpgradeSuggestion, CartItem as CartItemType } from 'brainerce';
6
- import { formatPrice } from 'brainerce';
7
- import { getClient } from '@/lib/brainerce';
8
- import { useStoreInfo } from '@/providers/store-provider';
9
- import { useTranslations } from '@/lib/translations';
10
- import { cn } from '@/lib/utils';
11
-
12
- interface CartUpgradeBannerProps {
13
- suggestion: CartUpgradeSuggestion;
14
- cartItem: CartItemType;
15
- onUpgrade: () => void;
16
- className?: string;
17
- }
18
-
19
- export function CartUpgradeBanner({
20
- suggestion,
21
- cartItem,
22
- onUpgrade,
23
- className,
24
- }: CartUpgradeBannerProps) {
25
- const { storeInfo } = useStoreInfo();
26
- const t = useTranslations('cart');
27
- const currency = storeInfo?.currency || 'USD';
28
- const [upgrading, setUpgrading] = useState(false);
29
- const [dismissed, setDismissed] = useState(false);
30
-
31
- const storageKey = `dismissed_upgrade_${suggestion.sourceProductId}`;
32
-
33
- useEffect(() => {
34
- try {
35
- if (sessionStorage.getItem(storageKey)) {
36
- setDismissed(true);
37
- }
38
- } catch {
39
- /* ignore */
40
- }
41
- }, [storageKey]);
42
-
43
- if (dismissed) return null;
44
-
45
- const target = suggestion.targetProduct;
46
- const firstImage = target.images?.[0];
47
- const imageUrl = firstImage
48
- ? typeof firstImage === 'string'
49
- ? firstImage
50
- : firstImage.url
51
- : null;
52
- const formattedDelta = formatPrice(parseFloat(suggestion.priceDelta), { currency }) as string;
53
-
54
- function handleDismiss() {
55
- try {
56
- sessionStorage.setItem(storageKey, '1');
57
- } catch {
58
- /* ignore */
59
- }
60
- setDismissed(true);
61
- }
62
-
63
- async function handleUpgrade() {
64
- if (upgrading) return;
65
- try {
66
- setUpgrading(true);
67
- const client = getClient();
68
- await client.smartRemoveFromCart(cartItem.productId, cartItem.variantId || undefined);
69
- await client.smartAddToCart({ productId: target.id, quantity: cartItem.quantity });
70
- onUpgrade();
71
- } catch (err) {
72
- console.error('Failed to upgrade cart item:', err);
73
- } finally {
74
- setUpgrading(false);
75
- }
76
- }
77
-
78
- return (
79
- <div
80
- className={cn(
81
- 'bg-primary/5 border-primary/20 relative flex items-center gap-3 rounded-lg border px-4 py-3',
82
- className
83
- )}
84
- >
85
- {/* Dismiss button */}
86
- <button
87
- type="button"
88
- onClick={handleDismiss}
89
- className="text-muted-foreground hover:text-foreground absolute end-2 top-2 text-xs"
90
- aria-label={t('dismissUpgrade')}
91
- >
92
- <svg
93
- className="h-4 w-4"
94
- fill="none"
95
- viewBox="0 0 24 24"
96
- stroke="currentColor"
97
- strokeWidth={2}
98
- >
99
- <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
100
- </svg>
101
- </button>
102
-
103
- {/* Product image */}
104
- <div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
105
- {imageUrl ? (
106
- <Image src={imageUrl} alt={target.name} fill sizes="48px" className="object-cover" />
107
- ) : (
108
- <div className="text-muted-foreground flex h-full w-full items-center justify-center">
109
- <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
110
- <path
111
- strokeLinecap="round"
112
- strokeLinejoin="round"
113
- strokeWidth={1.5}
114
- 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"
115
- />
116
- </svg>
117
- </div>
118
- )}
119
- </div>
120
-
121
- {/* Text */}
122
- <div className="min-w-0 flex-1">
123
- <p className="text-foreground text-sm font-medium">
124
- {t('upgradeFor', { name: target.name, amount: formattedDelta })}
125
- </p>
126
- </div>
127
-
128
- {/* Upgrade button */}
129
- <button
130
- type="button"
131
- onClick={handleUpgrade}
132
- disabled={upgrading}
133
- className={cn(
134
- 'bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1.5 text-xs font-medium transition-opacity hover:opacity-90',
135
- 'disabled:cursor-not-allowed disabled:opacity-50'
136
- )}
137
- >
138
- {upgrading ? t('upgrading') : t('upgrade')}
139
- </button>
140
- </div>
141
- );
142
- }
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import Image from 'next/image';
5
+ import type { CartUpgradeSuggestion, CartItem as CartItemType } from 'brainerce';
6
+ import { formatPrice } from 'brainerce';
7
+ import { getClient } from '@/lib/brainerce';
8
+ import { useStoreInfo } from '@/providers/store-provider';
9
+ import { useTranslations } from '@/lib/translations';
10
+ import { cn } from '@/lib/utils';
11
+
12
+ interface CartUpgradeBannerProps {
13
+ suggestion: CartUpgradeSuggestion;
14
+ cartItem: CartItemType;
15
+ onUpgrade: () => void;
16
+ className?: string;
17
+ }
18
+
19
+ export function CartUpgradeBanner({
20
+ suggestion,
21
+ cartItem,
22
+ onUpgrade,
23
+ className,
24
+ }: CartUpgradeBannerProps) {
25
+ const { storeInfo } = useStoreInfo();
26
+ const t = useTranslations('cart');
27
+ const currency = storeInfo?.currency || 'USD';
28
+ const [upgrading, setUpgrading] = useState(false);
29
+ const [dismissed, setDismissed] = useState(false);
30
+
31
+ const storageKey = `dismissed_upgrade_${suggestion.sourceProductId}`;
32
+
33
+ useEffect(() => {
34
+ try {
35
+ if (sessionStorage.getItem(storageKey)) {
36
+ setDismissed(true);
37
+ }
38
+ } catch {
39
+ /* ignore */
40
+ }
41
+ }, [storageKey]);
42
+
43
+ if (dismissed) return null;
44
+
45
+ const target = suggestion.targetProduct;
46
+ const firstImage = target.images?.[0];
47
+ const imageUrl = firstImage
48
+ ? typeof firstImage === 'string'
49
+ ? firstImage
50
+ : firstImage.url
51
+ : null;
52
+ const formattedDelta = formatPrice(parseFloat(suggestion.priceDelta), { currency }) as string;
53
+
54
+ function handleDismiss() {
55
+ try {
56
+ sessionStorage.setItem(storageKey, '1');
57
+ } catch {
58
+ /* ignore */
59
+ }
60
+ setDismissed(true);
61
+ }
62
+
63
+ async function handleUpgrade() {
64
+ if (upgrading) return;
65
+ try {
66
+ setUpgrading(true);
67
+ const client = getClient();
68
+ await client.smartRemoveFromCart(cartItem.productId, cartItem.variantId || undefined);
69
+ await client.smartAddToCart({ productId: target.id, quantity: cartItem.quantity });
70
+ onUpgrade();
71
+ } catch (err) {
72
+ console.error('Failed to upgrade cart item:', err);
73
+ } finally {
74
+ setUpgrading(false);
75
+ }
76
+ }
77
+
78
+ return (
79
+ <div
80
+ className={cn(
81
+ 'bg-primary/5 border-primary/20 relative flex items-center gap-3 rounded-lg border px-4 py-3',
82
+ className
83
+ )}
84
+ >
85
+ {/* Dismiss button */}
86
+ <button
87
+ type="button"
88
+ onClick={handleDismiss}
89
+ className="text-muted-foreground hover:text-foreground absolute end-2 top-2 text-xs"
90
+ aria-label={t('dismissUpgrade')}
91
+ >
92
+ <svg
93
+ className="h-4 w-4"
94
+ fill="none"
95
+ viewBox="0 0 24 24"
96
+ stroke="currentColor"
97
+ strokeWidth={2}
98
+ >
99
+ <path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
100
+ </svg>
101
+ </button>
102
+
103
+ {/* Product image */}
104
+ <div className="bg-muted relative h-12 w-12 flex-shrink-0 overflow-hidden rounded">
105
+ {imageUrl ? (
106
+ <Image src={imageUrl} alt={target.name} fill sizes="48px" className="object-cover" />
107
+ ) : (
108
+ <div className="text-muted-foreground flex h-full w-full items-center justify-center">
109
+ <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
110
+ <path
111
+ strokeLinecap="round"
112
+ strokeLinejoin="round"
113
+ strokeWidth={1.5}
114
+ 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"
115
+ />
116
+ </svg>
117
+ </div>
118
+ )}
119
+ </div>
120
+
121
+ {/* Text */}
122
+ <div className="min-w-0 flex-1">
123
+ <p className="text-foreground text-sm font-medium">
124
+ {t('upgradeFor', { name: target.name, amount: formattedDelta })}
125
+ </p>
126
+ </div>
127
+
128
+ {/* Upgrade button */}
129
+ <button
130
+ type="button"
131
+ onClick={handleUpgrade}
132
+ disabled={upgrading}
133
+ className={cn(
134
+ 'bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1.5 text-xs font-medium transition-opacity hover:opacity-90',
135
+ 'disabled:cursor-not-allowed disabled:opacity-50'
136
+ )}
137
+ >
138
+ {upgrading ? t('upgrading') : t('upgrade')}
139
+ </button>
140
+ </div>
141
+ );
142
+ }