From 8ec820c383fa7d4b83d1206928150a366d30266a Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Tue, 23 Dec 2025 16:21:48 -0300 Subject: [PATCH] feat(marketplace): add cart hover dropdown preview - Add CartDropdownContent component showing cart items on hover - Show 'carrinho vazio' message when empty - Display up to 4 items with name, quantity, price - Add remove button for each item in dropdown - Show total and 'Ver carrinho completo' link - Badge only shows when cart has items (already implemented) --- marketplace/src/layouts/Shell.tsx | 102 +++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 10 deletions(-) diff --git a/marketplace/src/layouts/Shell.tsx b/marketplace/src/layouts/Shell.tsx index d7accf3..774a2e2 100644 --- a/marketplace/src/layouts/Shell.tsx +++ b/marketplace/src/layouts/Shell.tsx @@ -2,6 +2,66 @@ import { useEffect, useRef, useState } from 'react' import { Link } from 'react-router-dom' import { useAuth } from '../context/AuthContext' import { useCartStore, selectCartSummary } from '../stores/cartStore' +import { formatCurrency } from '../utils/format' + +// Cart dropdown content component +function CartDropdownContent() { + const items = useCartStore((state) => state.items) + const removeItem = useCartStore((state) => state.removeItem) + const { totalValue } = useCartStore(selectCartSummary) + + // Show max 4 items in preview + const displayItems = items.slice(0, 4) + const hiddenCount = items.length - displayItems.length + + return ( +
+
+

Carrinho

+
+
+ {displayItems.map((item) => ( +
+
+

{item.name}

+

{item.quantity}x • R$ {formatCurrency(item.unitPrice)}

+
+ +
+ ))} + {hiddenCount > 0 && ( +
+ +{hiddenCount} {hiddenCount === 1 ? 'item' : 'itens'} +
+ )} +
+
+
+ Total: + R$ {formatCurrency(totalValue)} +
+ + Ver carrinho completo + +
+
+ ) +} export function Shell({ children }: { children: React.ReactNode }) { const { user, logout } = useAuth() @@ -58,16 +118,38 @@ export function Shell({ children }: { children: React.ReactNode }) { )} - - - - - {cartCount > 0 && ( - - {cartCount > 99 ? '99+' : cartCount} - - )} - + {/* Cart with hover dropdown */} +
+ + + + + {cartCount > 0 && ( + + {cartCount > 99 ? '99+' : cartCount} + + )} + + + {/* Dropdown on hover */} +
+ {cartCount === 0 ? ( +
+ + + +

Seu carrinho está vazio

+

Adicione produtos para começar

+
+ ) : ( + + )} +
+
{user && (