1 |
db0f300f
|
Jaroslav Hrubý
|
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
2 |
8c45ccb0
|
hrubyjar
|
import { Menu } from 'antd';
|
3 |
|
|
import { useRouter } from 'next/router';
|
4 |
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
5 |
|
|
import { faFileLines, faUser } from '@fortawesome/free-solid-svg-icons';
|
6 |
|
|
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
7 |
db0f300f
|
Jaroslav Hrubý
|
import { userController } from '../../controllers';
|
8 |
8c45ccb0
|
hrubyjar
|
|
9 |
|
|
const UserNavBar = () => {
|
10 |
|
|
const router = useRouter();
|
11 |
|
|
const { logout } = useContext(LoggedUserContext);
|
12 |
|
|
const { SubMenu } = Menu;
|
13 |
db0f300f
|
Jaroslav Hrubý
|
const [name, setName] = useState<string>('');
|
14 |
8c45ccb0
|
hrubyjar
|
|
15 |
|
|
const handleLogout = useCallback(() => {
|
16 |
|
|
logout();
|
17 |
|
|
router.push('/login');
|
18 |
|
|
}, [logout, router]);
|
19 |
|
|
|
20 |
db0f300f
|
Jaroslav Hrubý
|
async function fetchUsername() {
|
21 |
|
|
let usr = (await userController.usersMeGet()).data.name;
|
22 |
|
|
setName(usr ? usr : '');
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
useEffect(() => {
|
26 |
|
|
fetchUsername();
|
27 |
|
|
}, []);
|
28 |
|
|
|
29 |
ac59aec1
|
Dominik Poch
|
return (
|
30 |
6a250c18
|
Lukáš Vlček
|
<div className={'navbar-wrapper'}>
|
31 |
|
|
<Menu theme="dark" mode="horizontal" style={{ flexGrow: 1 }}>
|
32 |
|
|
<Menu.Item key="1" onClick={() => router.push('/documents/annotator')}>
|
33 |
|
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
34 |
8c45ccb0
|
hrubyjar
|
</Menu.Item>
|
35 |
6a250c18
|
Lukáš Vlček
|
</Menu>
|
36 |
|
|
<Menu theme="dark" mode="horizontal">
|
37 |
|
|
<SubMenu
|
38 |
|
|
key="account"
|
39 |
|
|
icon={<FontAwesomeIcon icon={faUser} />}
|
40 |
|
|
title={name}
|
41 |
|
|
>
|
42 |
|
|
<Menu.Item key="setting:2" onClick={() => handleLogout()}>
|
43 |
|
|
Odhlásit se
|
44 |
|
|
</Menu.Item>
|
45 |
|
|
</SubMenu>
|
46 |
|
|
</Menu>
|
47 |
|
|
</div>
|
48 |
ac59aec1
|
Dominik Poch
|
);
|
49 |
8c45ccb0
|
hrubyjar
|
};
|
50 |
|
|
|
51 |
|
|
export default UserNavBar;
|