import { useAuth, useSignInUp } from '@hooks/useAuth' import { Avatar, Badge, Box, Divider, Flex, Menu, NavLink } from '@mantine/core' import { notifications } from '@mantine/notifications' import { NAV_ITEM } from '@routes/nav-route' import { PathConstants } from '@routes/routes' import { IconAt, IconCircleXFilled, IconLogout, IconUserCircle, } from '@tabler/icons-react' import { useTranslation } from 'react-i18next' import { NavLink as Link } from 'react-router-dom' function NavLinkWithChildren(item) { const Icon = item.icon return ( }> {item.children.map((child) => { if (!child.show) return if (child.children) { return } else { return ( } label={child.text} component={Link} to={child.pathName} /> ) } })} ) } export default function Navbar() { const { auth, setAuth } = useAuth() const { t } = useTranslation() const { onLogout } = useSignInUp(setAuth) const logOut = async () => { try { await onLogout() } catch (error) { notifications.show({ color: 'red.5', icon: , withCloseButton: true, title: t('message_logout_fail'), }) } } return ( <> } size="sm" color="yellow.8" > {auth.userInfo?.name} } component={Link} to={PathConstants.PROFILE} > {t('ui_profile')} } fw="500" onClick={logOut} > {t('ui_logout')} {NAV_ITEM(t, auth?.userInfo?.isAdmin).map((item) => { if (!item.show) return null const Icon = item.icon if (item.children) { return } else { return ( } label={item.text} component={Link} to={item.pathName} className={({ isActive, isPending }) => isPending ? 'pending' : isActive ? 'active' : '' } color="red.8" /> ) } })} ) }