import { useRouter } from 'next/router'; import Link from '../Link/Link'; import { HomeIcon, Bars3Icon, ShoppingCartIcon, ChevronLeftIcon, } from '@heroicons/react/24/outline'; import { useEffect, useState } from 'react'; import { getCart, getCountCart } from '@/core/utils/cart'; import useTransactions from '@/lib/transaction/hooks/useTransactions'; import { useCartStore } from '~/modules/cart/stores/useCartStore'; import useAuth from '@/core/hooks/useAuth'; /** * The AppBar component is a navigation component used to display a header or toolbar * in a web application. * * @param {Object} props - Props received by the component. * @param {string} props.title - The title to be displayed on the AppBar. * @returns {JSX.Element} - Rendered AppBar component. */ const AppBar = ({ title }) => { const router = useRouter(); const auth = useAuth(); const { cart } = useCartStore(); const query = { context: 'quotation', site: auth?.webRole === null && auth?.site ? auth.site : null, }; const [cartCount, setCartCount] = useState(0); const { transactions } = useTransactions({ query }); useEffect(() => { const handleCartChange = () => { const cart = async () => { const listCart = await getCountCart(); setCartCount(listCart); }; cart(); }; handleCartChange(); window.addEventListener('localStorageChange', handleCartChange); return () => { window.removeEventListener('localStorageChange', handleCartChange); }; }, [transactions.data, cart]); return ( ); }; export default AppBar;