badge for cart

This commit is contained in:
hamid zarghami
2025-12-02 10:55:56 +03:30
parent 4fca678230
commit ed05588533
+22 -1
View File
@@ -10,6 +10,7 @@ import HeartIcon from '../icons/HeartIcon'
import { useParams, usePathname } from 'next/navigation'
import HomeIcon from '../icons/HomeIcon'
import { useTranslation } from 'react-i18next';
import { useCart } from '@/app/[name]/(Dialogs)/cart/hook/useCart';
function BottomNavBar() {
const params = useParams();
@@ -19,6 +20,13 @@ function BottomNavBar() {
const { t } = useTranslation('common', {
keyPrefix: 'BottomNavbar'
});
const { items } = useCart();
const cartItemsCount = React.useMemo(() => {
return Object.values(items).reduce((total, item) => {
return total + (item?.quantity || 0);
}, 0);
}, [items]);
return (
<div className="fixed bottom-0 left-0 w-full bg-transparent pointer-events-none">
@@ -42,7 +50,20 @@ function BottomNavBar() {
<nav
className="h-full px-2 grid grid-cols-5 gap-x-2 text-[10px] items-end"
>
<BottomNavLink href={`/${name}/cart`} icon={<BagIcon width={20} height={20} />} value={t('Cart')} />
<BottomNavLink
href={`/${name}/cart`}
icon={
<div className="relative">
<BagIcon width={20} height={20} />
{cartItemsCount > 0 && (
<span className="absolute -top-2 -right-2 flex items-center justify-center min-w-[18px] h-[18px] px-1 text-[10px] font-medium text-white bg-primary rounded-full">
{cartItemsCount > 99 ? '99+' : cartItemsCount}
</span>
)}
</div>
}
value={t('Cart')}
/>
<BottomNavLink href={`/${name}/pager`} icon={<PagerIcon width={20} height={20} />} value={t('Pager')} />
<BottomNavHighlightLink
href={`/${name}`}