create-brainerce-store 1.51.0 → 1.52.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 (170) hide show
  1. package/README.md +72 -0
  2. package/dist/index.js +9 -68
  3. package/messages/en.json +32 -0
  4. package/messages/he.json +32 -0
  5. package/package.json +1 -1
  6. package/templates/nextjs/base/.claude/commands/design.md +9 -0
  7. package/templates/nextjs/base/AI-GUIDE.md +52 -3
  8. package/templates/nextjs/base/CLAUDE.md +10 -0
  9. package/templates/nextjs/base/package.json.ejs +52 -39
  10. package/templates/nextjs/base/src/app/globals.css +36 -30
  11. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +14 -10
  12. package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
  13. package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
  14. package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
  15. package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
  16. package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
  17. package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
  18. package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
  19. package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
  20. package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
  21. package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
  22. package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
  23. package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
  24. package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
  25. package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
  26. package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
  27. package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
  28. package/templates/nextjs/base/src/ui/cart/cart-bundle-offer.tsx +17 -11
  29. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +2 -8
  30. package/templates/nextjs/base/src/ui/cart/cart-nudges.tsx +28 -39
  31. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +3 -1
  32. package/templates/nextjs/base/src/ui/cart/cart-upgrade-banner.tsx +8 -23
  33. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +18 -27
  34. package/templates/nextjs/base/src/ui/cart/coupon-input.tsx +10 -21
  35. package/templates/nextjs/base/src/ui/cart/free-shipping-bar.tsx +2 -3
  36. package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +95 -103
  37. package/templates/nextjs/base/src/ui/home/hero-section.tsx +4 -6
  38. package/templates/nextjs/base/src/ui/layout/announcement-bar.tsx.ejs +116 -125
  39. package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -103
  40. package/templates/nextjs/base/src/ui/layout/header-account.tsx +2 -17
  41. package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -70
  42. package/templates/nextjs/base/src/ui/layout/site-footer.tsx.ejs +144 -164
  43. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +152 -182
  44. package/templates/nextjs/base/src/ui/product/customization-fields.tsx +456 -444
  45. package/templates/nextjs/base/src/ui/product/discount-badge.tsx +18 -22
  46. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +15 -27
  47. package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -175
  48. package/templates/nextjs/base/src/ui/product/price-display.tsx +3 -2
  49. package/templates/nextjs/base/src/ui/product/product-card.tsx +238 -271
  50. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +455 -470
  51. package/templates/nextjs/base/src/ui/product/product-listing.tsx +96 -79
  52. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +102 -107
  53. package/templates/nextjs/base/src/ui/product/review-form.tsx +44 -43
  54. package/templates/nextjs/{designs/passepartout → base/src}/ui/product/reviews-section.tsx.ejs +108 -96
  55. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +61 -63
  56. package/templates/nextjs/base/tailwind.config.ts +69 -42
  57. package/templates/nextjs/designs/{passepartout → atelier}/app-overlay/layout.tsx.ejs +23 -25
  58. package/templates/nextjs/designs/atelier/globals.css +396 -0
  59. package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
  60. package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
  61. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-bundle-offer.tsx +110 -111
  62. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
  63. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
  64. package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
  65. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
  66. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/cart-upgrade-banner.tsx +123 -141
  67. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
  68. package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
  69. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/free-shipping-bar.tsx +77 -62
  70. package/templates/nextjs/designs/{passepartout → atelier}/ui/cart/reservation-countdown.tsx +89 -103
  71. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
  72. package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
  73. package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
  74. package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
  75. package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
  76. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
  77. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
  78. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
  79. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
  80. package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
  81. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
  82. package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
  83. package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
  84. package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
  85. package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
  86. package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
  87. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
  88. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
  89. package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
  90. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/discount-badge.tsx +17 -22
  91. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/frequently-bought-together.tsx +196 -205
  92. package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
  93. package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
  94. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
  95. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
  96. package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
  97. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
  98. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
  99. package/templates/nextjs/designs/{passepartout → atelier}/ui/product/review-form.tsx +267 -294
  100. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
  101. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
  102. package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
  103. package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
  104. package/templates/nextjs/designs/{passepartout → atelier}/ui/shared/fly-to-cart.ts +86 -85
  105. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
  106. package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
  107. package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
  108. package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
  109. package/templates/nextjs/themes/luxury/globals.css +405 -399
  110. package/templates/nextjs/themes/minimal/globals.css +36 -30
  111. package/templates/nextjs/themes/playful/globals.css +406 -400
  112. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +2 -0
  113. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +2 -0
  114. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +2 -0
  115. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +2 -0
  116. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +2 -0
  117. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +2 -2
  118. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +2 -0
  119. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +2 -0
  120. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +2 -0
  121. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +1 -1
  122. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +1 -1
  123. package/templates/nextjs/ui-canvas/home/hero-section.tsx +1 -1
  124. package/templates/nextjs/ui-canvas/home/home-client.tsx +1 -1
  125. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +1 -1
  126. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +2 -2
  127. package/templates/nextjs/ui-canvas/layout/header-account.tsx +1 -1
  128. package/templates/nextjs/ui-canvas/layout/language-switcher.tsx.ejs +2 -0
  129. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +2 -0
  130. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +2 -2
  131. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +2 -2
  132. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +2 -0
  133. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +2 -0
  134. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +2 -0
  135. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +2 -0
  136. package/templates/nextjs/ui-canvas/product/price-display.tsx +2 -0
  137. package/templates/nextjs/ui-canvas/product/product-card.tsx +1 -1
  138. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +1 -1
  139. package/templates/nextjs/ui-canvas/product/product-grid.tsx +1 -1
  140. package/templates/nextjs/ui-canvas/product/product-listing.tsx +1 -1
  141. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +4 -0
  142. package/templates/nextjs/ui-canvas/product/review-form.tsx +29 -32
  143. package/templates/nextjs/ui-canvas/product/{reviews-section.tsx → reviews-section.tsx.ejs} +26 -8
  144. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +2 -0
  145. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +2 -0
  146. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +2 -0
  147. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +2 -0
  148. package/templates/nextjs/base/src/ui/product/reviews-section.tsx +0 -85
  149. package/templates/nextjs/designs/passepartout/globals.css +0 -412
  150. package/templates/nextjs/designs/passepartout/messages-patch/en.json +0 -87
  151. package/templates/nextjs/designs/passepartout/messages-patch/he.json +0 -87
  152. package/templates/nextjs/designs/passepartout/ui/cart/cart-nudges.tsx +0 -39
  153. package/templates/nextjs/designs/passepartout/ui/cart/cart-view.tsx +0 -149
  154. package/templates/nextjs/designs/passepartout/ui/home/home-client.tsx +0 -401
  155. package/templates/nextjs/designs/passepartout/ui/layout/announcement-bar.tsx +0 -139
  156. package/templates/nextjs/designs/passepartout/ui/layout/cart-link.tsx +0 -45
  157. package/templates/nextjs/designs/passepartout/ui/layout/faq-section.tsx +0 -103
  158. package/templates/nextjs/designs/passepartout/ui/layout/site-footer.tsx +0 -159
  159. package/templates/nextjs/designs/passepartout/ui/layout/site-header.tsx.ejs +0 -155
  160. package/templates/nextjs/designs/passepartout/ui/layout/trust-icons.tsx +0 -60
  161. package/templates/nextjs/designs/passepartout/ui/layout/whatsapp-button.tsx +0 -34
  162. package/templates/nextjs/designs/passepartout/ui/product/price-display.tsx +0 -111
  163. package/templates/nextjs/designs/passepartout/ui/product/product-card.tsx +0 -265
  164. package/templates/nextjs/designs/passepartout/ui/product/product-client-section.tsx +0 -667
  165. package/templates/nextjs/designs/passepartout/ui/product/product-grid.tsx +0 -35
  166. package/templates/nextjs/designs/passepartout/ui/product/product-listing.tsx +0 -427
  167. package/templates/nextjs/designs/passepartout/ui/product/recommendation-section.tsx +0 -113
  168. package/templates/nextjs/designs/passepartout/ui/product/stock-badge.tsx +0 -52
  169. package/templates/nextjs/designs/passepartout/ui/product/variant-selector.tsx +0 -307
  170. package/templates/nextjs/designs/passepartout/ui/shared/loading-spinner.tsx +0 -33
@@ -0,0 +1,147 @@
1
+ 'use client';
2
+
3
+ import { Link } from '@/core/lib/navigation';
4
+ import { useCartPage } from '@/core/hooks/use-cart-page';
5
+ import { CartItem } from '@/ui/cart/cart-item';
6
+ import { CartUpgradeBanner } from '@/ui/cart/cart-upgrade-banner';
7
+ import { CartBundleOfferCard } from '@/ui/cart/cart-bundle-offer';
8
+ import { CartSummary } from '@/ui/cart/cart-summary';
9
+ import { CouponInput } from '@/ui/cart/coupon-input';
10
+ import { CartNudges } from '@/ui/cart/cart-nudges';
11
+ import { FreeShippingBar } from '@/ui/cart/free-shipping-bar';
12
+ import { ReservationCountdown } from '@/ui/cart/reservation-countdown';
13
+ import { CartRecommendationSection } from '@/ui/product/recommendation-section';
14
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
15
+ import { useTranslations } from '@/core/lib/translations';
16
+ import { IconBag, IconArrowEnd, IconShield } from '@/ui/shared/icons';
17
+
18
+ export function CartView() {
19
+ const t = useTranslations('cart');
20
+ const tc = useTranslations('common');
21
+ const { cart, cartLoading, refreshCart, itemCount, cartRecs, upgrades, bundles } = useCartPage();
22
+
23
+ if (cartLoading) {
24
+ return <LoadingSpinner size="lg" className="min-h-[60vh]" />;
25
+ }
26
+
27
+ // Empty cart state — designed, never a bare sentence in blank space.
28
+ if (!cart || cart.items.length === 0) {
29
+ return (
30
+ <section className="container-narrow flex min-h-[60vh] items-center justify-center py-16">
31
+ <div className="card flex w-full max-w-md flex-col items-center gap-3 px-8 py-14 text-center">
32
+ <span className="flex h-16 w-16 items-center justify-center rounded-full bg-secondary text-primary">
33
+ <IconBag size={32} />
34
+ </span>
35
+ <h1 className="text-2xl sm:text-3xl">{t('emptyTitle')}</h1>
36
+ <p className="text-muted-foreground">{t('emptySubtitle')}</p>
37
+ <Link href="/products" className="btn-primary btn-md mt-3">
38
+ {tc('continueShopping')}
39
+ <IconArrowEnd size={18} className="rtl-flip" />
40
+ </Link>
41
+ </div>
42
+ </section>
43
+ );
44
+ }
45
+
46
+ return (
47
+ <section className="container-narrow py-8 lg:py-12">
48
+ <h1 className="text-3xl sm:text-4xl">
49
+ {t('title')}{' '}
50
+ <span className="font-sans text-base font-normal text-muted-foreground">
51
+ ({itemCount} {itemCount === 1 ? tc('item') : tc('items')})
52
+ </span>
53
+ </h1>
54
+
55
+ {/* Reservation countdown */}
56
+ {cart.reservation?.hasReservation && (
57
+ <ReservationCountdown reservation={cart.reservation} className="mt-4" />
58
+ )}
59
+
60
+ <div className="mt-6 grid grid-cols-1 items-start gap-8 lg:grid-cols-3 lg:gap-10">
61
+ {/* Cart Items */}
62
+ <div className="lg:col-span-2">
63
+ {/* Nudges */}
64
+ {cart.nudges && cart.nudges.length > 0 && (
65
+ <CartNudges nudges={cart.nudges} className="mb-4" />
66
+ )}
67
+
68
+ {/* Cart items */}
69
+ <ul className="card divide-y overflow-hidden">
70
+ {cart.items.map((item) => (
71
+ <li key={item.id} className="p-4 sm:p-5">
72
+ <CartItem item={item} onUpdate={refreshCart} />
73
+ {upgrades?.upgrades?.[item.productId] && (
74
+ <CartUpgradeBanner
75
+ suggestion={upgrades.upgrades[item.productId]}
76
+ cartItem={item}
77
+ onUpgrade={refreshCart}
78
+ className="mt-4"
79
+ />
80
+ )}
81
+ </li>
82
+ ))}
83
+ </ul>
84
+
85
+ {/* Bundle offers */}
86
+ {bundles?.bundles && bundles.bundles.length > 0 && (
87
+ <section className="mt-6">
88
+ <h3 className="mb-3 text-xl">{t('bundleOffers')}</h3>
89
+ <div className="space-y-4">
90
+ {bundles.bundles.map((offer) => (
91
+ <CartBundleOfferCard
92
+ key={offer.id}
93
+ offer={offer}
94
+ cartId={cart.id}
95
+ onAdd={refreshCart}
96
+ />
97
+ ))}
98
+ </div>
99
+ </section>
100
+ )}
101
+
102
+ {/* Coupon input */}
103
+ <div className="mt-6">
104
+ <p className="mb-2 text-sm font-semibold text-foreground">{t('couponTitle')}</p>
105
+ <CouponInput cart={cart} onUpdate={refreshCart} />
106
+ </div>
107
+ </div>
108
+
109
+ {/* Summary sidebar */}
110
+ <aside className="lg:sticky lg:top-24">
111
+ <div className="card space-y-5 p-5 sm:p-6">
112
+ <FreeShippingBar />
113
+ <CartSummary />
114
+
115
+ <Link href="/checkout" className="btn-primary btn-lg w-full">
116
+ {t('proceedToCheckout')}
117
+ <IconArrowEnd size={20} className="rtl-flip" />
118
+ </Link>
119
+
120
+ <p className="flex items-center justify-center gap-1.5 text-xs text-muted-foreground">
121
+ <IconShield size={16} />
122
+ {t('secureCheckoutNote')}
123
+ </p>
124
+ </div>
125
+
126
+ <p className="mt-4 text-center">
127
+ <Link
128
+ href="/products"
129
+ className="text-sm font-medium text-primary underline-offset-2 hover:underline"
130
+ >
131
+ {tc('continueShopping')}
132
+ </Link>
133
+ </p>
134
+ </aside>
135
+ </div>
136
+
137
+ {/* Cross-sell recommendations */}
138
+ {cartRecs?.recommendations && cartRecs.recommendations.length > 0 && (
139
+ <CartRecommendationSection
140
+ title={t('youMightAlsoNeed')}
141
+ items={cartRecs.recommendations}
142
+ className="mt-12"
143
+ />
144
+ )}
145
+ </section>
146
+ );
147
+ }
@@ -0,0 +1,142 @@
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import type { Cart } from 'brainerce';
5
+ import { getClient } from '@/core/lib/brainerce';
6
+ import { useTranslations } from '@/core/lib/translations';
7
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
8
+ import { cn } from '@/core/lib/utils';
9
+ import { IconTag, IconX } from '@/ui/shared/icons';
10
+
11
+ interface CouponInputProps {
12
+ cart: Cart;
13
+ /** When provided, uses applyCheckoutCoupon/removeCheckoutCoupon instead of
14
+ * applyCoupon/removeCoupon. Always pass this when a checkout session exists. */
15
+ checkoutId?: string;
16
+ onUpdate: () => void;
17
+ className?: string;
18
+ }
19
+
20
+ /**
21
+ * Coupon apply/remove control used on the cart page AND the checkout page
22
+ * (via `checkoutId`); the `cart` prop comes from useCartPage(). Keeps the
23
+ * applied-coupon state and the error message.
24
+ */
25
+ export function CouponInput({ cart, checkoutId, onUpdate, className }: CouponInputProps) {
26
+ const t = useTranslations('coupon');
27
+ const tc = useTranslations('common');
28
+ const [code, setCode] = useState('');
29
+ const [applying, setApplying] = useState(false);
30
+ const [removing, setRemoving] = useState(false);
31
+ const [error, setError] = useState<string | null>(null);
32
+
33
+ const appliedCoupon = cart.couponCode || null;
34
+
35
+ async function handleApply() {
36
+ const trimmed = code.trim();
37
+ if (!trimmed || applying) return;
38
+
39
+ try {
40
+ setApplying(true);
41
+ setError(null);
42
+ const client = getClient();
43
+ if (checkoutId) {
44
+ await client.applyCheckoutCoupon(checkoutId, trimmed);
45
+ } else {
46
+ await client.applyCoupon(cart.id, trimmed);
47
+ }
48
+ setCode('');
49
+ onUpdate();
50
+ } catch (err) {
51
+ const message = err instanceof Error ? err.message : t('invalidCode');
52
+ setError(message);
53
+ } finally {
54
+ setApplying(false);
55
+ }
56
+ }
57
+
58
+ async function handleRemove() {
59
+ if (removing) return;
60
+
61
+ try {
62
+ setRemoving(true);
63
+ setError(null);
64
+ const client = getClient();
65
+ if (checkoutId) {
66
+ await client.removeCheckoutCoupon(checkoutId);
67
+ } else {
68
+ await client.removeCoupon(cart.id);
69
+ }
70
+ onUpdate();
71
+ } catch (err) {
72
+ console.error('Failed to remove coupon:', err);
73
+ } finally {
74
+ setRemoving(false);
75
+ }
76
+ }
77
+
78
+ // Show applied coupon
79
+ if (appliedCoupon) {
80
+ return (
81
+ <div
82
+ className={cn(
83
+ 'inline-flex items-center gap-2 rounded-full bg-secondary py-1.5 pe-2 ps-4',
84
+ className
85
+ )}
86
+ >
87
+ <span aria-hidden="true" className="text-primary">
88
+ <IconTag size={16} />
89
+ </span>
90
+ <span className="text-sm font-semibold text-foreground">{appliedCoupon}</span>
91
+ <button
92
+ type="button"
93
+ onClick={handleRemove}
94
+ disabled={removing}
95
+ aria-label={tc('remove')}
96
+ className="flex h-7 w-7 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:opacity-50"
97
+ >
98
+ {removing ? <LoadingSpinner size="sm" /> : <IconX size={16} />}
99
+ </button>
100
+ </div>
101
+ );
102
+ }
103
+
104
+ return (
105
+ <div className={cn(className)}>
106
+ <div className="flex max-w-sm gap-2">
107
+ <input
108
+ type="text"
109
+ value={code}
110
+ onChange={(e) => {
111
+ setCode(e.target.value);
112
+ if (error) setError(null);
113
+ }}
114
+ onKeyDown={(e) => {
115
+ if (e.key === 'Enter') {
116
+ e.preventDefault();
117
+ handleApply();
118
+ }
119
+ }}
120
+ placeholder={t('placeholder')}
121
+ aria-label={t('placeholder')}
122
+ aria-invalid={error ? true : undefined}
123
+ className="input"
124
+ />
125
+ <button
126
+ type="button"
127
+ onClick={handleApply}
128
+ disabled={applying || !code.trim()}
129
+ className="btn-soft btn-md shrink-0"
130
+ >
131
+ {applying ? <LoadingSpinner size="sm" /> : tc('apply')}
132
+ </button>
133
+ </div>
134
+
135
+ {error && (
136
+ <p role="alert" className="mt-2 text-sm font-medium text-destructive">
137
+ {error}
138
+ </p>
139
+ )}
140
+ </div>
141
+ );
142
+ }
@@ -1,62 +1,77 @@
1
- 'use client';
2
-
3
- import { formatPrice } from 'brainerce';
4
- import { useStoreInfo, useCart } from '@/core/providers/store-provider';
5
- import { useCurrency } from '@/core/lib/use-currency';
6
- import { useTranslations } from '@/core/lib/translations';
7
- import { cn } from '@/core/lib/utils';
8
-
9
- interface FreeShippingBarProps {
10
- className?: string;
11
- }
12
-
13
- export function FreeShippingBar({ className }: FreeShippingBarProps) {
14
- // Hooks must be called unconditionally and in the same order on every
15
- // render — keep all of them above any early `return null` branch.
16
- const t = useTranslations('cart');
17
- const { storeInfo } = useStoreInfo();
18
- const { totals } = useCart();
19
- const currency = useCurrency();
20
-
21
- const upsell = storeInfo?.upsell;
22
- const threshold = upsell?.freeShippingThreshold;
23
- const enabled = upsell?.freeShippingBarEnabled !== false;
24
-
25
- // Don't render if disabled or no threshold configured
26
- if (!enabled || !threshold || threshold <= 0) return null;
27
-
28
- const subtotal = totals.subtotal;
29
- const remaining = Math.max(0, threshold - subtotal);
30
- const progress = Math.min(100, (subtotal / threshold) * 100);
31
- const qualified = remaining <= 0;
32
-
33
- // Don't show if already qualified
34
- if (qualified) {
35
- return (
36
- <div className={cn('rounded-none border border-green-200 bg-green-50 p-3', className)}>
37
- <div className="flex items-center gap-2 text-sm font-medium text-green-700">
38
- <svg className="h-4 w-4 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
39
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
40
- </svg>
41
- {t('freeShippingQualified')}
42
- </div>
43
- </div>
44
- );
45
- }
46
-
47
- return (
48
- <div className={cn('rounded-none border border-amber-200 bg-amber-50 p-3', className)}>
49
- <p className="mb-2 text-sm text-amber-800">
50
- {t('freeShippingRemaining', {
51
- amount: formatPrice(remaining, { currency }) as string,
52
- })}
53
- </p>
54
- <div className="h-2 w-full overflow-hidden rounded-full bg-amber-200">
55
- <div
56
- className="h-full rounded-full bg-amber-500 transition-all duration-500 ease-out"
57
- style={{ width: `${progress}%` }}
58
- />
59
- </div>
60
- </div>
61
- );
62
- }
1
+ 'use client';
2
+
3
+ import { formatPrice } from 'brainerce';
4
+ import { useStoreInfo, useCart } from '@/core/providers/store-provider';
5
+ import { useCurrency } from '@/core/lib/use-currency';
6
+ import { useTranslations } from '@/core/lib/translations';
7
+ import { cn } from '@/core/lib/utils';
8
+ import { IconTruck, IconCheck } from '@/ui/shared/icons';
9
+
10
+ interface FreeShippingBarProps {
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * Free-shipping progress on the cart page ("add X more for free shipping");
16
+ * threshold from useStoreInfo().upsell, subtotal from useCart().totals.
17
+ * Custom meter (track + forest fill) instead of the semantic <progress>.
18
+ */
19
+ export function FreeShippingBar({ className }: FreeShippingBarProps) {
20
+ // Hooks must be called unconditionally and in the same order on every
21
+ // render — keep all of them above any early `return null` branch.
22
+ const t = useTranslations('cart');
23
+ const { storeInfo } = useStoreInfo();
24
+ const { totals } = useCart();
25
+ const currency = useCurrency();
26
+
27
+ const upsell = storeInfo?.upsell;
28
+ const threshold = upsell?.freeShippingThreshold;
29
+ const enabled = upsell?.freeShippingBarEnabled !== false;
30
+
31
+ // Don't render if disabled or no threshold configured
32
+ if (!enabled || !threshold || threshold <= 0) return null;
33
+
34
+ const subtotal = totals.subtotal;
35
+ const remaining = Math.max(0, threshold - subtotal);
36
+ const qualified = remaining <= 0;
37
+ const percent = Math.min(100, Math.round((subtotal / threshold) * 100));
38
+
39
+ if (qualified) {
40
+ return (
41
+ <p
42
+ className={cn(
43
+ 'flex items-center gap-2 rounded-lg bg-secondary px-3.5 py-2.5 text-sm font-semibold text-primary',
44
+ className
45
+ )}
46
+ >
47
+ <IconCheck size={18} />
48
+ {t('freeShippingQualified')}
49
+ </p>
50
+ );
51
+ }
52
+
53
+ return (
54
+ <div className={cn('rounded-lg bg-secondary px-3.5 py-3', className)}>
55
+ <p className="flex items-center gap-2 text-sm font-medium text-foreground">
56
+ <span aria-hidden="true" className="text-primary">
57
+ <IconTruck size={18} />
58
+ </span>
59
+ {t('freeShippingRemaining', {
60
+ amount: formatPrice(remaining, { currency }) as string,
61
+ })}
62
+ </p>
63
+ <div
64
+ role="progressbar"
65
+ aria-valuenow={percent}
66
+ aria-valuemin={0}
67
+ aria-valuemax={100}
68
+ className="mt-2.5 h-2 overflow-hidden rounded-full bg-background"
69
+ >
70
+ <div
71
+ className="h-full rounded-full bg-primary transition-[width] duration-500"
72
+ style={{ width: `${percent}%` }}
73
+ />
74
+ </div>
75
+ </div>
76
+ );
77
+ }
@@ -1,103 +1,89 @@
1
- 'use client';
2
-
3
- import { useState, useEffect, useCallback } from 'react';
4
- import type { ReservationInfo } from 'brainerce';
5
- import { useTranslations } from '@/core/lib/translations';
6
- import { cn } from '@/core/lib/utils';
7
-
8
- interface ReservationCountdownProps {
9
- reservation: ReservationInfo;
10
- className?: string;
11
- }
12
-
13
- export function ReservationCountdown({ reservation, className }: ReservationCountdownProps) {
14
- const t = useTranslations('reservation');
15
- const [remainingSeconds, setRemainingSeconds] = useState<number>(0);
16
-
17
- const calculateRemaining = useCallback(() => {
18
- if (!reservation.expiresAt) return 0;
19
- const expiresAtMs = new Date(reservation.expiresAt).getTime();
20
- const nowMs = Date.now();
21
- return Math.max(0, Math.floor((expiresAtMs - nowMs) / 1000));
22
- }, [reservation.expiresAt]);
23
-
24
- useEffect(() => {
25
- setRemainingSeconds(calculateRemaining());
26
-
27
- const interval = setInterval(() => {
28
- const remaining = calculateRemaining();
29
- setRemainingSeconds(remaining);
30
-
31
- if (remaining <= 0) {
32
- clearInterval(interval);
33
- }
34
- }, 1000);
35
-
36
- return () => clearInterval(interval);
37
- }, [calculateRemaining]);
38
-
39
- if (!reservation.hasReservation) return null;
40
-
41
- const minutes = Math.floor(remainingSeconds / 60);
42
- const seconds = remainingSeconds % 60;
43
- const isExpired = remainingSeconds <= 0;
44
- const isUrgent = remainingSeconds > 0 && remainingSeconds < 120;
45
-
46
- const displayMessage = reservation.countdownMessage
47
- ? reservation.countdownMessage.replace(
48
- '{time}',
49
- `${minutes}:${seconds.toString().padStart(2, '0')}`
50
- )
51
- : null;
52
-
53
- return (
54
- <div
55
- className={cn(
56
- 'flex items-center gap-3 rounded-none px-4 py-3 text-sm',
57
- isExpired
58
- ? 'bg-destructive/10 border-destructive/20 text-destructive border'
59
- : isUrgent
60
- ? 'border border-orange-200 bg-orange-50 text-orange-800 dark:border-orange-800 dark:bg-orange-950/30 dark:text-orange-300'
61
- : 'bg-primary/5 border-primary/20 text-foreground border',
62
- className
63
- )}
64
- >
65
- <svg
66
- className={cn(
67
- 'h-5 w-5 flex-shrink-0',
68
- isExpired
69
- ? 'text-destructive'
70
- : isUrgent
71
- ? 'text-orange-600 dark:text-orange-400'
72
- : 'text-primary'
73
- )}
74
- fill="none"
75
- viewBox="0 0 24 24"
76
- stroke="currentColor"
77
- >
78
- <path
79
- strokeLinecap="round"
80
- strokeLinejoin="round"
81
- strokeWidth={2}
82
- d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
83
- />
84
- </svg>
85
-
86
- <div className="flex-1">
87
- {isExpired ? (
88
- <p className="font-medium">{t('expired')}</p>
89
- ) : displayMessage ? (
90
- <p>{displayMessage}</p>
91
- ) : (
92
- <p>
93
- {isUrgent ? `${t('hurry')} ` : ''}
94
- {t('reservedFor')}{' '}
95
- <span className="font-semibold tabular-nums">
96
- {minutes}:{seconds.toString().padStart(2, '0')}
97
- </span>
98
- </p>
99
- )}
100
- </div>
101
- </div>
102
- );
103
- }
1
+ 'use client';
2
+
3
+ import { useState, useEffect, useCallback } from 'react';
4
+ import type { ReservationInfo } from 'brainerce';
5
+ import { useTranslations } from '@/core/lib/translations';
6
+ import { cn } from '@/core/lib/utils';
7
+ import { IconClock } from '@/ui/shared/icons';
8
+
9
+ interface ReservationCountdownProps {
10
+ reservation: ReservationInfo;
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * Stock-reservation countdown on the cart/checkout pages; the `reservation`
16
+ * prop comes from useCartPage().cart.reservation. Keeps the ticking logic
17
+ * and the expired/urgent states (exposed via data-state).
18
+ */
19
+ export function ReservationCountdown({ reservation, className }: ReservationCountdownProps) {
20
+ const t = useTranslations('reservation');
21
+ const [remainingSeconds, setRemainingSeconds] = useState<number>(0);
22
+
23
+ const calculateRemaining = useCallback(() => {
24
+ if (!reservation.expiresAt) return 0;
25
+ const expiresAtMs = new Date(reservation.expiresAt).getTime();
26
+ const nowMs = Date.now();
27
+ return Math.max(0, Math.floor((expiresAtMs - nowMs) / 1000));
28
+ }, [reservation.expiresAt]);
29
+
30
+ useEffect(() => {
31
+ setRemainingSeconds(calculateRemaining());
32
+
33
+ const interval = setInterval(() => {
34
+ const remaining = calculateRemaining();
35
+ setRemainingSeconds(remaining);
36
+
37
+ if (remaining <= 0) {
38
+ clearInterval(interval);
39
+ }
40
+ }, 1000);
41
+
42
+ return () => clearInterval(interval);
43
+ }, [calculateRemaining]);
44
+
45
+ if (!reservation.hasReservation) return null;
46
+
47
+ const minutes = Math.floor(remainingSeconds / 60);
48
+ const seconds = remainingSeconds % 60;
49
+ const isExpired = remainingSeconds <= 0;
50
+ const isUrgent = remainingSeconds > 0 && remainingSeconds < 120;
51
+
52
+ const displayMessage = reservation.countdownMessage
53
+ ? reservation.countdownMessage.replace(
54
+ '{time}',
55
+ `${minutes}:${seconds.toString().padStart(2, '0')}`
56
+ )
57
+ : null;
58
+
59
+ return (
60
+ <div
61
+ role="timer"
62
+ data-state={isExpired ? 'expired' : isUrgent ? 'urgent' : 'active'}
63
+ className={cn(
64
+ 'flex items-center gap-2.5 rounded-lg px-4 py-3 text-sm font-medium',
65
+ isExpired || isUrgent
66
+ ? 'bg-destructive/10 text-destructive'
67
+ : 'bg-secondary text-foreground',
68
+ className
69
+ )}
70
+ >
71
+ <span aria-hidden="true" className="shrink-0">
72
+ <IconClock size={18} />
73
+ </span>
74
+ {isExpired ? (
75
+ <p>{t('expired')}</p>
76
+ ) : displayMessage ? (
77
+ <p>{displayMessage}</p>
78
+ ) : (
79
+ <p>
80
+ {isUrgent ? `${t('hurry')} ` : ''}
81
+ {t('reservedFor')}{' '}
82
+ <span className="font-bold tabular-nums">
83
+ {minutes}:{seconds.toString().padStart(2, '0')}
84
+ </span>
85
+ </p>
86
+ )}
87
+ </div>
88
+ );
89
+ }
@@ -0,0 +1,34 @@
1
+ 'use client';
2
+
3
+ import { useTranslations } from '@/core/lib/translations';
4
+ import { IconTruck, IconShield, IconGem, IconReturn } from '@/ui/shared/icons';
5
+
6
+ const BENEFITS = [
7
+ { icon: IconTruck, titleKey: 'benefit1Title', descKey: 'benefit1Desc' },
8
+ { icon: IconShield, titleKey: 'benefit2Title', descKey: 'benefit2Desc' },
9
+ { icon: IconGem, titleKey: 'benefit3Title', descKey: 'benefit3Desc' },
10
+ { icon: IconReturn, titleKey: 'benefit4Title', descKey: 'benefit4Desc' },
11
+ ] as const;
12
+
13
+ /** Trust/benefits row under the hero — icons + short promises. */
14
+ export function BenefitsBand() {
15
+ const t = useTranslations('home');
16
+
17
+ return (
18
+ <section aria-label={t('benefit2Title')}>
19
+ <ul className="container-page grid grid-cols-2 gap-x-6 gap-y-8 pb-10 pt-16 lg:grid-cols-4">
20
+ {BENEFITS.map(({ icon: Icon, titleKey, descKey }) => (
21
+ <li key={titleKey} className="flex items-start gap-3.5">
22
+ <span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-secondary text-primary">
23
+ <Icon size={24} />
24
+ </span>
25
+ <div>
26
+ <p className="text-sm font-semibold text-foreground">{t(titleKey)}</p>
27
+ <p className="mt-0.5 text-[13px] leading-5 text-muted-foreground">{t(descKey)}</p>
28
+ </div>
29
+ </li>
30
+ ))}
31
+ </ul>
32
+ </section>
33
+ );
34
+ }