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 { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
6 |
|
|
import {
|
7 |
|
|
faUser,
|
8 |
|
|
faFileExport,
|
9 |
|
|
faFileLines,
|
10 |
|
|
faUsers,
|
11 |
|
|
faTags,
|
12 |
|
|
faBookmark,
|
13 |
|
|
} from '@fortawesome/free-solid-svg-icons';
|
14 |
db0f300f
|
Jaroslav Hrubý
|
import { userController } from '../../controllers';
|
15 |
|
|
import { UserInfo } from '../../api';
|
16 |
8c45ccb0
|
hrubyjar
|
|
17 |
7a32656e
|
Jaroslav Hrubý
|
const AdminNavBar = () => {
|
18 |
8c45ccb0
|
hrubyjar
|
const router = useRouter();
|
19 |
|
|
const { logout } = useContext(LoggedUserContext);
|
20 |
|
|
const { SubMenu } = Menu;
|
21 |
db0f300f
|
Jaroslav Hrubý
|
const [name, setName] = useState<string>('');
|
22 |
8c45ccb0
|
hrubyjar
|
|
23 |
|
|
const handleLogout = useCallback(() => {
|
24 |
|
|
logout();
|
25 |
|
|
router.push('/login');
|
26 |
|
|
}, [logout, router]);
|
27 |
|
|
|
28 |
db0f300f
|
Jaroslav Hrubý
|
async function fetchUsername() {
|
29 |
|
|
let usr = (await userController.usersMeGet()).data.name;
|
30 |
|
|
setName(usr ? usr : '');
|
31 |
|
|
}
|
32 |
|
|
|
33 |
|
|
useEffect(() => {
|
34 |
|
|
fetchUsername();
|
35 |
|
|
}, []);
|
36 |
|
|
|
37 |
6d10fe14
|
Dominik Poch
|
return (
|
38 |
8c45ccb0
|
hrubyjar
|
<Menu theme="dark" mode="horizontal">
|
39 |
|
|
<Menu.Item style={{}} key="1" onClick={() => router.push('/documents/admin')}>
|
40 |
|
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
41 |
|
|
</Menu.Item>
|
42 |
|
|
<Menu.Item style={{}} key="2" onClick={() => router.push('/users')}>
|
43 |
|
|
<FontAwesomeIcon icon={faUsers} /> Uživatelé
|
44 |
|
|
</Menu.Item>
|
45 |
|
|
<Menu.Item style={{}} key="3" onClick={() => router.push('/tags')}>
|
46 |
|
|
<FontAwesomeIcon icon={faTags} /> Značky
|
47 |
|
|
</Menu.Item>
|
48 |
|
|
<Menu.Item style={{}} key="5" onClick={() => router.push('/export')}>
|
49 |
|
|
<FontAwesomeIcon icon={faFileExport} /> Export
|
50 |
|
|
</Menu.Item>
|
51 |
|
|
|
52 |
db0f300f
|
Jaroslav Hrubý
|
<SubMenu icon={<FontAwesomeIcon icon={faUser} />} key="account" title={name}>
|
53 |
8c45ccb0
|
hrubyjar
|
<Menu.Item key="setting:2" onClick={() => handleLogout()}>
|
54 |
|
|
Odhlásit se
|
55 |
|
|
</Menu.Item>
|
56 |
|
|
</SubMenu>
|
57 |
|
|
</Menu>
|
58 |
6d10fe14
|
Dominik Poch
|
);
|
59 |
8c45ccb0
|
hrubyjar
|
};
|
60 |
|
|
|
61 |
7a32656e
|
Jaroslav Hrubý
|
export default AdminNavBar;
|