Fakultas Ilmu Komputer UI

TopMenu.jsx 1.1 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 {
9
10
11
12
13
  constructor(props) {
    super(props);
    /* istanbul ignore next */
    this.logout = this.logout.bind(this);
  }
14

15
16
17
18
19
20
  logout = () => {
    Server.get('/api-auth/logout/?next=/', true).then(() => {
      Storage.clear();
      browserHistory.push('/login');
    });
  };
21

22
23
  render() {
    return (
24
      <Menu color="blue" pointing secondary>
25
26
        <Image as="a" size="small" src="/assets/img/logo.png" href="/" />
        <Menu.Menu position="right">
27
28
          <Menu.Item as={Link} to="/lowongan" name="home" onClick={this.handleItemClick} />
          <Menu.Item as={Link} to="/profile" name="profil" onClick={this.handleItemClick} />
29
          {Server.isLoggedIn() ?
30
            <Menu.Item as={Link} onClick={this.logout} name="logout" /> :
31
            <Menu.Item as={Link} to="/login" name="login" />
32
          }
33
34
35
36
37
        </Menu.Menu>
      </Menu>
    );
  }
}