Fakultas Ilmu Komputer UI

index.jsx 1.94 KB
Newer Older
1
2
import React from 'react';
import ReactDOM from 'react-dom';
3
import { Router, Route, browserHistory, Redirect } from 'react-router';
4
5
import Dashboard from './Dashboard';
import Login from './Login';
6
import VacancyPage from './VacancyPage';
7
import ProfilePage from './ProfilePage';
8
import CompanyProfile from './CompanyProfile';
Zamil Majdy's avatar
Zamil Majdy committed
9
10
import HomeCompany from './HomeCompany';
import CreateVacancy from './CreateVacancy';
11
import Server from './lib/Server';
12
import Storage from './lib/Storage';
13

14
15
16
17
18
19
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
20
    this.handleHome = this.handleHome.bind(this);
21
22
  }

Zamil Majdy's avatar
Zamil Majdy committed
23
24
25
26
  handleAuth = (nextState, replace) => {
    if (!Server.isLoggedIn()) replace({ pathname: '/login' });
    Storage.getUserData();
  };
27

28
  handleHome= (nextState, replace, cb) => {
29
    if (Server.isLoggedIn()) {
Zamil Majdy's avatar
Zamil Majdy committed
30
31
      Storage.getUserData().then(() => {
        replace({ pathname: '/lowongan' }); cb();
32
      });
33
    }
Zamil Majdy's avatar
Zamil Majdy committed
34
    return replace({ pathname: '/login' });
35
  };
36
37
38
39
40

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

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