Fakultas Ilmu Komputer UI

VacancyPage.jsx 2 KB
Newer Older
1
2
3
4
5
6
7
import React from 'react';
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import VacancyList from './components/VacancyList';

export default class VacancyPage extends React.Component {

8
9
10
11
12
13
14
15
  static propTypes = {
    user: React.PropTypes.object.isRequired,
  };

  static getId(user) {
    const role = user.role;
    if (role === 'student') {
      return user.data.student.id;
16
    } else if (role === 'company' || role === 'admin') {
17
      return user.data.company.id;
18
19
    }

20
    return 0;
21
22
  }

23
24
25
  constructor(props) {
    super(props);
    /* istanbul ignore next */
26
    this.state = {
27
      vacancies: [],
28
      id: VacancyPage.getId(this.props.user),
29
    };
30
31
  }

32
  generateVacancies() {
33
    if (this.props.user.role === 'student') {
34
35
36
37
38
      return (
        <Tabs selected={0}>
          <Pane label="Semua Lowongan" >
            <VacancyList
              key={1}
39
              userId={this.state.id}
40
41
42
43
44
45
              url="/vacancies/"
            />
          </Pane>
          <Pane label="Lamaran saya" >
            <VacancyList
              key={2}
46
              userId={this.state.id}
M. Reza Qorib's avatar
M. Reza Qorib committed
47
              status="applied"
48
49
50
51
52
53
              url={`/students/${this.state.id}/applied-vacancies/`}
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
            <VacancyList
              key={3}
54
              userId={this.state.id}
55
56
57
58
59
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
            />
          </Pane>
        </Tabs>
      );
60
    } else if (this.props.user.role === 'company' || this.props.user.role === 'admin') {
61
      return (
62
        <VacancyList key={1} userId={this.state.id} url={`/companies/${this.state.id}/vacancies/`} type="company" />
63
64
      );
    }
65

66
67
68
69
70
71
72
73
74
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
75
76

  render() {
77
    return (
78
79
80
      <div className="applicant">
        { this.generateVacancies() }
      </div>
81
    );
82
  }
83
}