Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.67 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';
6
7
8

export default class VacancyPage extends React.Component {

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

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

21
    return 0;
22
23
  }

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

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

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

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