create-brainerce-store 1.50.5 → 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 (230) hide show
  1. package/README.md +72 -0
  2. package/dist/index.js +146 -100
  3. package/messages/en.json +36 -1
  4. package/messages/he.json +36 -1
  5. package/package.json +1 -1
  6. package/templates/nextjs/base/.claude/commands/design.md +60 -0
  7. package/templates/nextjs/base/.env.local.ejs +5 -0
  8. package/templates/nextjs/base/.eslintrc.json +57 -3
  9. package/templates/nextjs/base/AGENTS.md +41 -0
  10. package/templates/nextjs/base/AI-GUIDE.md +143 -0
  11. package/templates/nextjs/base/CLAUDE.md +52 -0
  12. package/templates/nextjs/base/TRANSLATIONS.md +1 -1
  13. package/templates/nextjs/base/next.config.ts +2 -2
  14. package/templates/nextjs/base/package.json.ejs +52 -39
  15. package/templates/nextjs/base/src/app/account/page.tsx +5 -5
  16. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +1 -1
  17. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +2 -2
  18. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +1 -1
  19. package/templates/nextjs/base/src/app/auth/callback/page.tsx +4 -4
  20. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +4 -4
  21. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +2 -2
  22. package/templates/nextjs/base/src/app/cart/page.tsx +2 -173
  23. package/templates/nextjs/base/src/app/checkout/page.tsx +12 -11
  24. package/templates/nextjs/base/src/app/contact/page.tsx +3 -3
  25. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +2 -2
  26. package/templates/nextjs/base/src/app/forgot-password/page.tsx +4 -4
  27. package/templates/nextjs/base/src/app/globals.css +36 -30
  28. package/templates/nextjs/base/src/app/layout.tsx.ejs +12 -12
  29. package/templates/nextjs/base/src/app/login/page.tsx +4 -4
  30. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +19 -12
  31. package/templates/nextjs/base/src/app/page.tsx +4 -4
  32. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +3 -3
  33. package/templates/nextjs/base/src/app/payment-complete/page.tsx +1 -1
  34. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -6
  35. package/templates/nextjs/base/src/app/products/page.tsx +4 -623
  36. package/templates/nextjs/base/src/app/register/page.tsx +4 -4
  37. package/templates/nextjs/base/src/app/reset-password/page.tsx +5 -5
  38. package/templates/nextjs/base/src/app/sitemap.ts +1 -1
  39. package/templates/nextjs/base/src/app/verify-email/page.tsx +5 -5
  40. package/templates/nextjs/base/src/components/account/address-book.tsx +3 -3
  41. package/templates/nextjs/base/src/components/account/order-customizations.tsx +3 -3
  42. package/templates/nextjs/base/src/components/account/order-history.tsx +13 -5
  43. package/templates/nextjs/base/src/components/account/order-payment-block.tsx +2 -2
  44. package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +2 -2
  45. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +2 -2
  46. package/templates/nextjs/base/src/components/account/profile-section.tsx +3 -3
  47. package/templates/nextjs/base/src/components/auth/login-form.tsx +4 -4
  48. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +4 -4
  49. package/templates/nextjs/base/src/components/auth/register-form.tsx +4 -4
  50. package/templates/nextjs/base/src/components/brainerce-bot.tsx +2 -2
  51. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +24 -3
  52. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +2 -2
  53. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +2 -2
  54. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +4 -4
  55. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +20 -16
  56. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +3 -3
  57. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +3 -3
  58. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +3 -3
  59. package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +2 -2
  60. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +3 -3
  61. package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
  62. package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
  63. package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
  64. package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
  65. package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
  66. package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
  67. package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
  68. package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
  69. package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
  70. package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
  71. package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
  72. package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
  73. package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
  74. package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
  75. package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
  76. package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
  77. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +58 -0
  78. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +51 -0
  79. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +295 -0
  80. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +278 -0
  81. package/templates/nextjs/base/src/{hooks → core/hooks}/use-search.ts +1 -1
  82. package/templates/nextjs/base/src/{lib → core/lib}/brainerce.ts.ejs +1 -1
  83. package/templates/nextjs/base/src/core/lib/product-options.ts +121 -0
  84. package/templates/nextjs/base/src/{lib → core/lib}/resolve-currency.ts +1 -1
  85. package/templates/nextjs/base/src/{lib → core/lib}/safe-redirect.ts +1 -1
  86. package/templates/nextjs/base/src/{lib → core/lib}/sanitize.ts.ejs +1 -1
  87. package/templates/nextjs/base/src/{lib → core/lib}/use-currency.ts +1 -1
  88. package/templates/nextjs/base/src/{providers → core/providers}/store-provider.tsx.ejs +4 -4
  89. package/templates/nextjs/base/src/{components → ui}/cart/cart-bundle-offer.tsx +22 -16
  90. package/templates/nextjs/base/src/{components → ui}/cart/cart-item.tsx +8 -14
  91. package/templates/nextjs/base/src/{components → ui}/cart/cart-nudges.tsx +28 -39
  92. package/templates/nextjs/base/src/{components → ui}/cart/cart-summary.tsx +7 -5
  93. package/templates/nextjs/base/src/{components → ui}/cart/cart-upgrade-banner.tsx +13 -28
  94. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +140 -0
  95. package/templates/nextjs/base/src/{components → ui}/cart/coupon-input.tsx +14 -25
  96. package/templates/nextjs/base/src/{components → ui}/cart/free-shipping-bar.tsx +6 -7
  97. package/templates/nextjs/base/src/{components → ui}/cart/reservation-countdown.tsx +95 -103
  98. package/templates/nextjs/base/src/ui/home/discount-banner-strip.tsx +20 -0
  99. package/templates/nextjs/base/src/ui/home/featured-products-section.tsx +24 -0
  100. package/templates/nextjs/base/src/ui/home/hero-section.tsx +27 -0
  101. package/templates/nextjs/base/src/ui/home/home-client.tsx +29 -0
  102. package/templates/nextjs/base/src/{components/content → ui/layout}/announcement-bar.tsx.ejs +116 -125
  103. package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -0
  104. package/templates/nextjs/base/src/{components/content → ui/layout}/header-account.tsx +5 -20
  105. package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -0
  106. package/templates/nextjs/base/src/{components/content → ui/layout}/rich-text-block.tsx.ejs +1 -1
  107. package/templates/nextjs/base/src/{components/content → ui/layout}/site-footer.tsx.ejs +144 -164
  108. package/templates/nextjs/base/src/{components/content → ui/layout}/site-header.tsx.ejs +152 -182
  109. package/templates/nextjs/base/src/{components/products → ui/product}/customization-fields.tsx +457 -478
  110. package/templates/nextjs/base/src/{components/products → ui/product}/discount-badge.tsx +18 -22
  111. package/templates/nextjs/base/src/{components/products → ui/product}/frequently-bought-together.tsx +21 -33
  112. package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -0
  113. package/templates/nextjs/base/src/{components/shared → ui/product}/price-display.tsx +5 -4
  114. package/templates/nextjs/base/src/{components/products → ui/product}/product-card.tsx +238 -271
  115. package/templates/nextjs/base/src/{app/products/[slug] → ui/product}/product-client-section.tsx +455 -631
  116. package/templates/nextjs/base/src/{components/products → ui/product}/product-grid.tsx +3 -3
  117. package/templates/nextjs/base/src/ui/product/product-listing.tsx +446 -0
  118. package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx +102 -107
  119. package/templates/nextjs/base/src/{components/reviews → ui/product}/review-form.tsx +46 -45
  120. package/templates/nextjs/base/src/{components/reviews/reviews-section.tsx → ui/product/reviews-section.tsx.ejs} +38 -15
  121. package/templates/nextjs/base/src/{components/products → ui/product}/stock-badge.tsx +61 -63
  122. package/templates/nextjs/base/src/{components/products → ui/product}/variant-selector.tsx +3 -3
  123. package/templates/nextjs/base/src/{components → ui}/shared/cdn-image.tsx +1 -1
  124. package/templates/nextjs/base/src/{components → ui}/shared/loading-spinner.tsx +2 -2
  125. package/templates/nextjs/base/tailwind.config.ts +69 -30
  126. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +251 -0
  127. package/templates/nextjs/designs/atelier/globals.css +396 -0
  128. package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
  129. package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
  130. package/templates/nextjs/designs/atelier/ui/cart/cart-bundle-offer.tsx +110 -0
  131. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
  132. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
  133. package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
  134. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
  135. package/templates/nextjs/designs/atelier/ui/cart/cart-upgrade-banner.tsx +123 -0
  136. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
  137. package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
  138. package/templates/nextjs/designs/atelier/ui/cart/free-shipping-bar.tsx +77 -0
  139. package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +89 -0
  140. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
  141. package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
  142. package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
  143. package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
  144. package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
  145. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
  146. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
  147. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
  148. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
  149. package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
  150. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
  151. package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
  152. package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
  153. package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
  154. package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
  155. package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
  156. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
  157. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
  158. package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
  159. package/templates/nextjs/designs/atelier/ui/product/discount-badge.tsx +17 -0
  160. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +196 -0
  161. package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
  162. package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
  163. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
  164. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
  165. package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
  166. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
  167. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
  168. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +267 -0
  169. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
  170. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
  171. package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
  172. package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
  173. package/templates/nextjs/designs/atelier/ui/shared/fly-to-cart.ts +86 -0
  174. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
  175. package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
  176. package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
  177. package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
  178. package/templates/nextjs/themes/luxury/globals.css +405 -399
  179. package/templates/nextjs/themes/minimal/globals.css +36 -30
  180. package/templates/nextjs/themes/playful/globals.css +406 -400
  181. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +89 -0
  182. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +123 -0
  183. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +27 -0
  184. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +99 -0
  185. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +105 -0
  186. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +106 -0
  187. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +119 -0
  188. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +54 -0
  189. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +81 -0
  190. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +19 -0
  191. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +23 -0
  192. package/templates/nextjs/ui-canvas/home/hero-section.tsx +21 -0
  193. package/templates/nextjs/ui-canvas/home/home-client.tsx +26 -0
  194. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +101 -0
  195. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +71 -0
  196. package/templates/nextjs/ui-canvas/layout/header-account.tsx +31 -0
  197. package/templates/nextjs/{base/src/components → ui-canvas}/layout/language-switcher.tsx.ejs +76 -70
  198. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +36 -0
  199. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +82 -0
  200. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +119 -0
  201. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +445 -0
  202. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +19 -0
  203. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +168 -0
  204. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +165 -0
  205. package/templates/nextjs/ui-canvas/product/price-display.tsx +52 -0
  206. package/templates/nextjs/ui-canvas/product/product-card.tsx +197 -0
  207. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +352 -0
  208. package/templates/nextjs/ui-canvas/product/product-grid.tsx +27 -0
  209. package/templates/nextjs/ui-canvas/product/product-listing.tsx +224 -0
  210. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +99 -0
  211. package/templates/nextjs/ui-canvas/product/review-form.tsx +266 -0
  212. package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -0
  213. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +45 -0
  214. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +212 -0
  215. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +31 -0
  216. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +27 -0
  217. package/templates/nextjs/base/src/app/home-client.tsx +0 -98
  218. package/templates/nextjs/base/src/components/content/faq-section.tsx.ejs +0 -103
  219. package/templates/nextjs/base/src/components/products/modifier-group-selector.tsx +0 -238
  220. /package/templates/nextjs/base/src/{lib → core/lib}/auth.ts +0 -0
  221. /package/templates/nextjs/base/src/{lib → core/lib}/csrf.ts +0 -0
  222. /package/templates/nextjs/base/src/{lib → core/lib}/image-hosts.ts +0 -0
  223. /package/templates/nextjs/base/src/{lib → core/lib}/navigation.tsx.ejs +0 -0
  224. /package/templates/nextjs/base/src/{lib → core/lib}/nonce.ts +0 -0
  225. /package/templates/nextjs/base/src/{lib → core/lib}/sanitize-html.ts +0 -0
  226. /package/templates/nextjs/base/src/{lib → core/lib}/seo.ts +0 -0
  227. /package/templates/nextjs/base/src/{lib → core/lib}/store-info.ts +0 -0
  228. /package/templates/nextjs/base/src/{lib → core/lib}/translations.ts.ejs +0 -0
  229. /package/templates/nextjs/base/src/{lib → core/lib}/utils.ts +0 -0
  230. /package/templates/nextjs/base/src/{lib → core/lib}/validation.ts +0 -0
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import { formatPrice } from 'brainerce';
4
+ import { useTranslations } from '@/core/lib/translations';
5
+ import { useCart } from '@/core/providers/store-provider';
6
+ import { useCurrency } from '@/core/lib/use-currency';
7
+ import { cn } from '@/core/lib/utils';
8
+
9
+ interface CartSummaryProps {
10
+ className?: string;
11
+ }
12
+
13
+ /**
14
+ * Order summary (subtotal, rule/coupon discounts, shipping, tax note, total);
15
+ * all figures come from useCart().totals and useCart().cart. Every discount
16
+ * branch is kept — merchants rely on the per-rule breakdown.
17
+ */
18
+ export function CartSummary({ className }: CartSummaryProps) {
19
+ const t = useTranslations('cart');
20
+ const tc = useTranslations('common');
21
+ const { totals, cart } = useCart();
22
+ const currency = useCurrency();
23
+
24
+ const rules = cart?.appliedDiscounts;
25
+ const ruleAmt = cart?.ruleDiscountAmount ? parseFloat(cart.ruleDiscountAmount) : 0;
26
+ const couponAmt = totals.discount - ruleAmt;
27
+
28
+ return (
29
+ <section className={cn(className)}>
30
+ <h3 className="mb-4 font-sans text-base font-semibold">{t('orderSummary')}</h3>
31
+
32
+ <dl className="space-y-2.5 text-sm">
33
+ {/* Subtotal */}
34
+ <div className="flex items-center justify-between gap-4">
35
+ <dt className="text-muted-foreground">{tc('subtotal')}</dt>
36
+ <dd className="font-medium">{formatPrice(totals.subtotal, { currency }) as string}</dd>
37
+ </div>
38
+
39
+ {/* Rule discounts - show each rule by name */}
40
+ {rules && rules.length > 0
41
+ ? rules.map((rule) => (
42
+ <div key={rule.ruleId} className="flex items-center justify-between gap-4">
43
+ <dt className="text-primary">{rule.ruleName}</dt>
44
+ <dd className="font-medium text-primary">
45
+ -{formatPrice(parseFloat(rule.discountAmount), { currency }) as string}
46
+ </dd>
47
+ </div>
48
+ ))
49
+ : ruleAmt > 0 && (
50
+ <div className="flex items-center justify-between gap-4">
51
+ <dt className="text-primary">{tc('generalDiscount')}</dt>
52
+ <dd className="font-medium text-primary">
53
+ -{formatPrice(ruleAmt, { currency }) as string}
54
+ </dd>
55
+ </div>
56
+ )}
57
+
58
+ {/* Coupon discount */}
59
+ {cart?.couponCode && couponAmt > 0 && (
60
+ <div className="flex items-center justify-between gap-4">
61
+ <dt className="text-primary">
62
+ {tc('couponDiscount')} ({cart.couponCode})
63
+ </dt>
64
+ <dd className="font-medium text-primary">
65
+ -{formatPrice(couponAmt, { currency }) as string}
66
+ </dd>
67
+ </div>
68
+ )}
69
+
70
+ {/* Fallback: generic discount when no breakdown available */}
71
+ {totals.discount > 0 &&
72
+ ruleAmt <= 0 &&
73
+ !cart?.couponCode &&
74
+ (!rules || rules.length === 0) && (
75
+ <div className="flex items-center justify-between gap-4">
76
+ <dt className="text-primary">{tc('discount')}</dt>
77
+ <dd className="font-medium text-primary">
78
+ -{formatPrice(totals.discount, { currency }) as string}
79
+ </dd>
80
+ </div>
81
+ )}
82
+
83
+ {/* Shipping */}
84
+ {totals.shipping > 0 && (
85
+ <div className="flex items-center justify-between gap-4">
86
+ <dt className="text-muted-foreground">{tc('shipping')}</dt>
87
+ <dd className="font-medium">{formatPrice(totals.shipping, { currency }) as string}</dd>
88
+ </div>
89
+ )}
90
+
91
+ {/* Tax */}
92
+ <div className="flex items-center justify-between gap-4">
93
+ <dt className="text-muted-foreground">{tc('tax')}</dt>
94
+ <dd className="text-muted-foreground">{t('taxAtCheckout')}</dd>
95
+ </div>
96
+
97
+ {/* Total */}
98
+ <div className="flex items-center justify-between gap-4 border-t pt-3">
99
+ <dt className="text-base font-semibold text-foreground">{tc('total')}</dt>
100
+ <dd className="text-lg font-bold text-foreground">
101
+ {formatPrice(totals.total, { currency }) as string}
102
+ </dd>
103
+ </div>
104
+ </dl>
105
+ </section>
106
+ );
107
+ }
@@ -0,0 +1,123 @@
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import { CdnImage as Image } from '@/ui/shared/cdn-image';
5
+ import type { CartUpgradeSuggestion, CartItem as CartItemType } from 'brainerce';
6
+ import { formatPrice } from 'brainerce';
7
+ import { getClient } from '@/core/lib/brainerce';
8
+ import { useCurrency } from '@/core/lib/use-currency';
9
+ import { useTranslations } from '@/core/lib/translations';
10
+ import { cn } from '@/core/lib/utils';
11
+ import { IconX } from '@/ui/shared/icons';
12
+
13
+ interface CartUpgradeBannerProps {
14
+ suggestion: CartUpgradeSuggestion;
15
+ cartItem: CartItemType;
16
+ onUpgrade: () => void;
17
+ className?: string;
18
+ }
19
+
20
+ /**
21
+ * Per-line upgrade suggestion under a cart item ("upgrade to X for +Y");
22
+ * the suggestion comes from useCartPage().upgrades keyed by productId.
23
+ * Keeps the session-scoped dismiss and the swap logic.
24
+ */
25
+ export function CartUpgradeBanner({
26
+ suggestion,
27
+ cartItem,
28
+ onUpgrade,
29
+ className,
30
+ }: CartUpgradeBannerProps) {
31
+ const t = useTranslations('cart');
32
+ const currency = useCurrency();
33
+ const [upgrading, setUpgrading] = useState(false);
34
+ const [dismissed, setDismissed] = useState(false);
35
+
36
+ const storageKey = `dismissed_upgrade_${suggestion.sourceProductId}`;
37
+
38
+ useEffect(() => {
39
+ try {
40
+ if (sessionStorage.getItem(storageKey)) {
41
+ setDismissed(true);
42
+ }
43
+ } catch {
44
+ /* ignore */
45
+ }
46
+ }, [storageKey]);
47
+
48
+ if (dismissed) return null;
49
+
50
+ const target = suggestion.targetProduct;
51
+ const firstImage = target.images?.[0];
52
+ const imageUrl = firstImage
53
+ ? typeof firstImage === 'string'
54
+ ? firstImage
55
+ : firstImage.url
56
+ : null;
57
+ const formattedDelta = formatPrice(parseFloat(suggestion.priceDelta), { currency }) as string;
58
+
59
+ function handleDismiss() {
60
+ try {
61
+ sessionStorage.setItem(storageKey, '1');
62
+ } catch {
63
+ /* ignore */
64
+ }
65
+ setDismissed(true);
66
+ }
67
+
68
+ async function handleUpgrade() {
69
+ if (upgrading) return;
70
+ try {
71
+ setUpgrading(true);
72
+ const client = getClient();
73
+ await client.smartRemoveFromCart(cartItem.productId, cartItem.variantId || undefined);
74
+ await client.smartAddToCart({ productId: target.id, quantity: cartItem.quantity });
75
+ onUpgrade();
76
+ } catch (err) {
77
+ console.error('Failed to upgrade cart item:', err);
78
+ } finally {
79
+ setUpgrading(false);
80
+ }
81
+ }
82
+
83
+ return (
84
+ <div
85
+ className={cn(
86
+ 'flex items-center gap-3 rounded-lg border border-primary/25 bg-secondary/60 p-3',
87
+ className
88
+ )}
89
+ >
90
+ {/* Product image — `relative` + fixed box are layout-critical for next/image fill */}
91
+ <span className="relative block h-12 w-12 shrink-0 overflow-hidden rounded-lg border bg-background">
92
+ {imageUrl ? (
93
+ <Image src={imageUrl} alt={target.name} fill sizes="48px" className="object-cover" />
94
+ ) : null}
95
+ </span>
96
+
97
+ {/* Text */}
98
+ <p className="min-w-0 flex-1 text-sm text-foreground">
99
+ {t('upgradeFor', { name: target.name, amount: formattedDelta })}
100
+ </p>
101
+
102
+ {/* Upgrade button */}
103
+ <button
104
+ type="button"
105
+ onClick={handleUpgrade}
106
+ disabled={upgrading}
107
+ className="btn-primary btn-sm shrink-0"
108
+ >
109
+ {upgrading ? t('upgrading') : t('upgrade')}
110
+ </button>
111
+
112
+ {/* Dismiss button */}
113
+ <button
114
+ type="button"
115
+ onClick={handleDismiss}
116
+ aria-label={t('dismissUpgrade')}
117
+ className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
118
+ >
119
+ <IconX size={16} />
120
+ </button>
121
+ </div>
122
+ );
123
+ }
@@ -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
+ }
@@ -0,0 +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
+ 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
+ }
@@ -0,0 +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
+ 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
+ }