Projekt

Obecné

Profil

Stáhnout (1.69 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 { faFileLines, faUser } from '@fortawesome/free-solid-svg-icons';
6
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
7
import { userController } from '../../controllers';
8

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

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

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

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

    
29
    return (
30
        <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
                </Menu.Item>
35
            </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
    );
49
};
50

    
51
export default UserNavBar;
(2-2/2)