Fakultas Ilmu Komputer UI

TopMenu.jsx 1.21 KB
Newer Older
1
2
import React from 'react';
import { Menu, Image } from 'semantic-ui-react';
3
4
import { Link, browserHistory } from 'react-router';

5
import Server from '../lib/Server';
6
import Storage from '../lib/Storage';
7
8

export default class TopMenu extends React.Component {
sirinbaisa's avatar
sirinbaisa committed
9

10
11
12
  constructor(props) {
    super(props);
    /* istanbul ignore next */
13
    this.state = { activeItem: 'home' };
14
15
    this.logout = this.logout.bind(this);
  }
sirinbaisa's avatar
sirinbaisa committed
16

17
18
  handleItemClick = (e, { name }) => this.setState({ activeItem: name });

19
20
21
22
23
24
  logout = () => {
    Server.get('/api-auth/logout/?next=/', true).then(() => {
      Storage.clear();
      browserHistory.push('/login');
    });
  };
25

26
  render() {
sirinbaisa's avatar
sirinbaisa committed
27
    const { activeItem } = this.state;
28
    return (
29
      <Menu color="blue" pointing secondary>
30
31
        <Image as="a" size="small" src="/assets/img/logo.png" href="/" />
        <Menu.Menu position="right">
Zamil Majdy's avatar
Zamil Majdy committed
32
          <Menu.Item as={Link} to="/home" name="home" active={activeItem === 'home'} onClick={this.handleItemClick} />
sirinbaisa's avatar
sirinbaisa committed
33
          <Menu.Item as={Link} to="/profile" name="profil" active={activeItem === 'profil'} onClick={this.handleItemClick} />
Zamil Majdy's avatar
Zamil Majdy committed
34
          <Menu.Item as={Link} onClick={this.logout} name="logout" />
35
36
37
38
39
        </Menu.Menu>
      </Menu>
    );
  }
}