Fakultas Ilmu Komputer UI

index.jsx 1.63 KB
Newer Older
1
2
import React from 'react';
import ReactDOM from 'react-dom';
3
4
import { Router, Route, browserHistory, Redirect } from 'react-router';
import { Segment } from 'semantic-ui-react';
5
6
import Dashboard from './Dashboard';
import Login from './Login';
7
import VacancyPage from './VacancyPage';
8
import Server from './lib/Server';
9
import Storage from './lib/Storage';
10
11
12
13
14
15
16
17

export const Profile = () => (
  <Segment>
    <img src="http://semantic-ui.com/images/wireframe/media-paragraph.png" alt="wire-frame" />
  </Segment>
);


18
19
20
21
22
23
export default class App extends React.Component {

  constructor(props) {
    super(props);
    /* istanbul ignore next */
    this.handleAuth = this.handleAuth.bind(this);
Zamil Majdy's avatar
Zamil Majdy committed
24
    this.handleHome = this.handleHome.bind(this);
25
26
27
28
29
30
  }

  handleAuth = (nextState, replace) => (
    Server.isLoggedIn() || replace({ pathname: '/login' })
  );

31
32
33
34
35
36
37
  handleHome= (nextState, replace) => {
    if (Server.isLoggedIn()) {
      Storage.get('user-data').student ? replace({pathname: '/lowongan'}) : replace({pathname: '/profile'});
    } else {
      replace({ pathname: '/login' });
    }
  };
38
39
40
41
42

  render = () => (
    <Router history={browserHistory}>
      <Route path="/login" component={Login} />
      <Route component={Dashboard} onEnter={this.handleAuth}>
43
        <Route path="/" component={VacancyPage} />
44
45
46
        <Route path="/profile" component={Profile} />
        <Route path="/lowongan" component={VacancyPage} />
        <Route path="/users" component={Profile} />
47
      </Route>
Zamil Majdy's avatar
Zamil Majdy committed
48
49
      <Route path="/home" onEnter={this.handleHome} />
      <Redirect from="*" to="/home" />
50
51
52
    </Router>
  );
}
53
54

ReactDOM.render(<App />, document.getElementById('react-app'));