navigation: show badge for validation tab

This commit is contained in:
vchikalkin 2024-07-02 18:34:13 +03:00
parent 2ea1b1bd69
commit dcf93644c8
3 changed files with 14 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import { Component as Validation } from './Validation';
import { Notification } from '@/Components/Common'; import { Notification } from '@/Components/Common';
import { NavigationBar, Tabs } from '@/Components/Layout/Navigation'; import { NavigationBar, Tabs } from '@/Components/Layout/Navigation';
import { NavigationProvider } from '@/context/navigation'; import { NavigationProvider } from '@/context/navigation';
import { useErrors } from '@/stores/hooks';
import { Media } from '@/styles/media'; import { Media } from '@/styles/media';
import { getPageTitle } from '@/utils/page'; import { getPageTitle } from '@/utils/page';
import Head from 'next/head'; import Head from 'next/head';
@ -42,6 +43,11 @@ export const tabs = [
icon: <WarningOutlined style={defaultIconStyle} />, icon: <WarningOutlined style={defaultIconStyle} />,
key: 'errors', key: 'errors',
title: 'Ошибки', title: 'Ошибки',
useShowBadge: () => {
const { hasErrors } = useErrors();
return hasErrors;
},
}, },
]; ];

View File

@ -1,6 +1,7 @@
import { NavigationContext } from '@/context/navigation'; import { NavigationContext } from '@/context/navigation';
import { useContext, useEffect } from 'react'; import { useContext, useEffect } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Badge } from 'ui/elements';
import { Flex } from 'ui/grid'; import { Flex } from 'ui/grid';
const Container = styled.div` const Container = styled.div`
@ -28,15 +29,19 @@ const TabButton = styled.button`
font-size: 0.75rem; font-size: 0.75rem;
`; `;
const StyledBadge = styled(Badge)`
color: unset !important;
`;
export function NavigationBar() { export function NavigationBar() {
const { currentTab, setCurrentTab, tabsList } = useContext(NavigationContext); const { currentTab, setCurrentTab, tabsList } = useContext(NavigationContext);
return ( return (
<Container> <Container>
{tabsList.map(({ icon, key, title }) => ( {tabsList.map(({ icon, key, title, useShowBadge }) => (
<TabButton key={key} active={key === currentTab} onClick={() => setCurrentTab(key)}> <TabButton key={key} active={key === currentTab} onClick={() => setCurrentTab(key)}>
<Flex flexDirection="column" alignItems="center"> <Flex flexDirection="column" alignItems="center">
{icon} <StyledBadge dot={useShowBadge?.call()}>{icon}</StyledBadge>
{title} {title}
</Flex> </Flex>
</TabButton> </TabButton>

View File

@ -4,6 +4,7 @@ type Tab = {
icon: JSX.Element; icon: JSX.Element;
key: string; key: string;
title: string; title: string;
useShowBadge?: () => boolean;
}; };
type NavigationContextType = { type NavigationContextType = {