Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.75 KB
Newer Older
1
2
3
4
import React from 'react';
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import VacancyList from './components/VacancyList';
5
import Pagination from './components/Pagination';
sirinbaisa's avatar
sirinbaisa committed
6
import Applicants from './components/Applicants';
7
8
9

export default class VacancyPage extends React.Component {

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

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

22
    return 0;
23
24
  }

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

34
  generateVacancies() {
35
    if (this.props.user.role === 'student') {
36
37
38
      return (
        <Tabs selected={0}>
          <Pane label="Semua Lowongan" >
39
            <Pagination
40
              key={1}
41
              url="/vacancies/"
42
43
              child={
                <VacancyList
44
                  user={this.props.user}
45
46
47
48
                  key={1}
                  userId={this.state.id}
                />
              }
49
            />
sirinbaisa's avatar
sirinbaisa committed
50
              <Applicants />
51
52
          </Pane>
          <Pane label="Lamaran saya" >
53
            <Pagination
54
55
              key={2}
              url={`/students/${this.state.id}/applied-vacancies/`}
56
57
58
59
60
61
62
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
63
64
65
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
66
            <Pagination
67
68
              key={3}
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
69
70
71
72
73
74
75
              child={
                <VacancyList
                  key={3}
                  user={this.props.user}
                  userId={this.state.id}
                />
              }
76
77
78
79
            />
          </Pane>
        </Tabs>
      );
80
    } else if (this.props.user.role === 'company' || this.props.user.role === 'admin') {
81
      return (
82
83
84
85
86
87
88
89
90
91
92
        <Pagination
          url={`/companies/${this.state.id}/vacancies/`}
          child={
            <VacancyList
              key={1}
              user={this.props.user}
              userId={this.state.id}
            />
          }
          error="Anda belum diverifikasi. Harap hubungi admin"
        />
93
94
      );
    }
95

96
97
98
99
100
101
102
103
104
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
105
106

  render() {
107
    return (
108
109
110
      <div className="applicant">
        { this.generateVacancies() }
      </div>
111
    );
112
  }
113
}