Fakultas Ilmu Komputer UI

index.jsx 1.83 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 ProfilePage from './ProfilePage';
9
import Server from './lib/Server';
10
import Storage from './lib/Storage';
11
12
13
14
15
16
17
18

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


19
20
21
22
23
24
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
25
    this.handleHome = this.handleHome.bind(this);
26
27
28
29
30
31
  }

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

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

  render = () => (
    <Router history={browserHistory}>
      <Route path="/login" component={Login} />
      <Route component={Dashboard} onEnter={this.handleAuth}>
44
        <Route path="/" component={VacancyPage} />
45
46
        <Route path="/profile" component={ProfilePage} data={Storage.get('user-data')} own={true} />
        <Route path="/mahasiswa/:id" component={ProfilePage} data={Storage.get('user-data')} own={false} />
47
48
        <Route path="/lowongan" component={VacancyPage} />
        <Route path="/users" component={Profile} />
49
      </Route>
Zamil Majdy's avatar
Zamil Majdy committed
50
51
      <Route path="/home" onEnter={this.handleHome} />
      <Redirect from="*" to="/home" />
52
53
54
    </Router>
  );
}
55
56

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