Fakultas Ilmu Komputer UI

VacancyPage.jsx 3.74 KB
Newer Older
1
import React from 'react';
2
import { Item } from 'semantic-ui-react';
3
4
5
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import VacancyList from './components/VacancyList';
6
import AdminVacancy from './components/AdminVacancy';
7
import Pagination from './components/Pagination';
8
9
10

export default class VacancyPage extends React.Component {

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

  static getId(user) {
    const role = user.role;
    if (role === 'student') {
      return user.data.student.id;
19
    } else if (role === 'company' || (role === 'admin' && user.data.company != null)) {
20
      return user.data.company.id;
21
22
    } else if (role === 'supervisor' || role === 'admin' && user.data.supervisor != null){
      return user.data.supervisor.id;
23
24
    }

25
    return 0;
26
27
  }

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

37

38
  generateVacancies() {
39
    if (this.props.user.role === 'student') {
40
41
42
      return (
        <Tabs selected={0}>
          <Pane label="Semua Lowongan" >
43
            <Pagination
44
45
              key={1}
              url="/vacancies/"
46
47
              child={
                <VacancyList
48
                  user={this.props.user}
49
50
51
52
                  key={1}
                  userId={this.state.id}
                />
              }
53
54
55
            />
          </Pane>
          <Pane label="Lamaran saya" >
56
            <Pagination
57
58
              key={2}
              url={`/students/${this.state.id}/applied-vacancies/`}
59
60
61
62
63
64
65
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
66
67
68
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
69
            <Pagination
70
71
              key={3}
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
72
73
74
75
76
77
78
              child={
                <VacancyList
                  key={3}
                  user={this.props.user}
                  userId={this.state.id}
                />
              }
79
80
81
82
            />
          </Pane>
        </Tabs>
      );
83
    } else if (this.props.user.role === 'company') {
84
      return (
85
86
87
88
89
90
91
92
93
94
95
        <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"
        />
96
      );
97
    } else if (this.props.user.role === 'admin' || this.props.user.role === 'supervisor') {
98
99
      return (
        <Tabs selected={0}>
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
          <Pane label="Lowongan Belum Terverifikasi" >
            <Pagination
              key={1}
              url="/vacancies/"
              child={
                <VacancyList
                  user={this.props.user}
                  key={1}
                  userId={this.state.id}
                />
              }
            />
          </Pane>
          <Pane label="Lowongan Terverifikasi" >
            <Pagination
              key={2}
              url={`/vacancies/`}
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
            />
125
126
127
          </Pane>
        </Tabs>
      );
128
    }
129

130
131
132
133
134
135
136
137
138
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
139
140

  render() {
141
    return (
142
143
144
      <div className="applicant">
        { this.generateVacancies() }
      </div>
145
    );
146
  }
147
}