1
|
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
2
|
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
|
import { userController } from '../../controllers';
|
15
|
import { UserInfo } from '../../api';
|
16
|
|
17
|
const AdminNavBar = () => {
|
18
|
const router = useRouter();
|
19
|
const { logout } = useContext(LoggedUserContext);
|
20
|
const { SubMenu } = Menu;
|
21
|
const [name, setName] = useState<string>('');
|
22
|
|
23
|
const handleLogout = useCallback(() => {
|
24
|
logout();
|
25
|
router.push('/login');
|
26
|
}, [logout, router]);
|
27
|
|
28
|
async function fetchUsername() {
|
29
|
let usr = (await userController.usersMeGet()).data.name;
|
30
|
setName(usr ? usr : '');
|
31
|
}
|
32
|
|
33
|
useEffect(() => {
|
34
|
fetchUsername();
|
35
|
}, []);
|
36
|
|
37
|
return (
|
38
|
<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
|
<SubMenu icon={<FontAwesomeIcon icon={faUser} />} key="account" title={name}>
|
53
|
<Menu.Item key="setting:2" onClick={() => handleLogout()}>
|
54
|
Odhlásit se
|
55
|
</Menu.Item>
|
56
|
</SubMenu>
|
57
|
</Menu>
|
58
|
);
|
59
|
};
|
60
|
|
61
|
export default AdminNavBar;
|