Projekt

Obecné

Profil

Stáhnout (2.21 KB) Statistiky
| Větev: | Tag: | Revize:
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 { faFileLines, faTags, faUser, faUsers } from '@fortawesome/free-solid-svg-icons';
7
import { userController } from '../../controllers';
8
import { COLOR_NAVBAR } from '../../constants';
9

    
10
const AdminNavBar = () => {
11
    const router = useRouter();
12
    const { logout } = useContext(LoggedUserContext);
13
    const { SubMenu } = Menu;
14
    const [name, setName] = useState<string>('');
15

    
16
    const handleLogout = useCallback(async () => {
17
        await logout();
18
        await router.push('/login');
19
    }, [logout, router]);
20

    
21
    async function fetchUsername() {
22
        let usr = (await userController.usersMeGet()).data.name;
23
        setName(usr ? usr : '');
24
    }
25

    
26
    useEffect(() => {
27
        fetchUsername();
28
    }, []);
29

    
30
    return (
31
        <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
                </Menu.Item>
46
            </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
    );
60
};
61

    
62
export default AdminNavBar;
(1-1/2)