Projekt

Obecné

Profil

Stáhnout (1.43 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
        <Menu theme="dark" mode="horizontal">
31
            <Menu.Item key="1" onClick={() => router.push('/documents/annotator')}>
32
                <FontAwesomeIcon icon={faFileLines} /> Dokumenty
33
            </Menu.Item>
34

    
35
            <SubMenu key="account" icon={<FontAwesomeIcon icon={faUser} />} title={name}>
36
                <Menu.Item key="setting:2" onClick={() => handleLogout()}>
37
                    Odhlásit se
38
                </Menu.Item>
39
            </SubMenu>
40
        </Menu>
41
    );
42
};
43

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