Update navbar component

This commit is contained in:
Hazem Krimi
2021-05-02 03:58:47 +01:00
parent 5edf5ea55e
commit 8739df0bd7
2 changed files with 28 additions and 41 deletions
+27 -38
View File
@@ -5,60 +5,49 @@ import { Wrapper } from './styles';
import { Avatar, Link, Menu, Text } from '..'; import { Avatar, Link, Menu, Text } from '..';
import { Settings, Logout, Logo } from '../../assets'; import { Settings, Logout, Logo } from '../../assets';
type NavbarProps = { const Navbar = () => {
withSidebar: boolean;
};
const Navbar = ({ withSidebar }: NavbarProps) => {
const user = useReactiveVar(userVar); const user = useReactiveVar(userVar);
const role = useReactiveVar(roleVar); const role = useReactiveVar(roleVar);
const history = useHistory(); const history = useHistory();
return ( return (
<Wrapper color={role} withSidebar={withSidebar}> <Wrapper color={role}>
<Link href='/'> <Link href='/'>
<Logo /> <Logo />
</Link> </Link>
<div className='menu'></div> <div className='menu'></div>
<div className='user' id='user'> <div className='user' id='user'>
<Avatar text='H' color={role} /> <Avatar
text={
(user?.firstName && user?.firstName[0].toLocaleUpperCase()) ||
(role && role[0].toLocaleUpperCase()) ||
'C'
}
color={role}
/>
<Text variant='body' weight='bold'> <Text variant='body' weight='bold'>
{user?.firstName} {user?.lastName} {user?.firstName} {user?.lastName}
</Text> </Text>
</div> </div>
<Menu <Menu
component='user' component='user'
items={ items={[
role !== 'admin' {
? [ icon: <Settings />,
{ label: 'Settings',
icon: <Settings />, action: () => history.push('/settings'),
label: 'Settings', },
action: () => history.push('/settings'), {
}, icon: <Logout />,
{ label: 'Logout',
icon: <Logout />, action: () => {
label: 'Logout', tokenVar(undefined);
action: () => { localStorage.removeItem('token');
tokenVar(undefined); history.push('/login');
localStorage.removeItem('token'); },
history.push('/login'); avoid: true,
}, },
avoid: true, ]}
},
]
: [
{
icon: <Logout />,
label: 'Logout',
action: () => {
tokenVar(undefined);
history.push('/login');
},
avoid: true,
},
]
}
/> />
</Wrapper> </Wrapper>
); );
+1 -3
View File
@@ -2,7 +2,6 @@ import styled from 'styled-components';
type WrapperProps = { type WrapperProps = {
color?: 'client' | 'productOwner' | 'developer' | 'admin'; color?: 'client' | 'productOwner' | 'developer' | 'admin';
withSidebar: boolean;
}; };
export const Wrapper = styled.div<WrapperProps>` export const Wrapper = styled.div<WrapperProps>`
@@ -11,8 +10,7 @@ export const Wrapper = styled.div<WrapperProps>`
display: grid; display: grid;
grid-template-columns: auto 1fr auto; grid-template-columns: auto 1fr auto;
align-items: center; align-items: center;
padding: ${({ withSidebar }) => padding: 15px 45px 15px 120px;
withSidebar ? '15px 45px 15px 120px' : '15px 45px'};
user-select: none; user-select: none;
position: sticky; position: sticky;
top: 0; top: 0;