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