Fakultas Ilmu Komputer UI

VacancyPage.jsx 4.9 KB
Newer Older
1
import React from 'react';
Zamil Majdy's avatar
Zamil Majdy committed
2
import { Segment, Button } from 'semantic-ui-react';
3
import { Link } from 'react-router';
4
5
6
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import VacancyList from './components/VacancyList';
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;
M. Reza Qorib's avatar
M. Reza Qorib committed
21
    } else if (role === 'supervisor' || (role === 'admin' && user.data.supervisor != null)) {
22
      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
      return (
        <Tabs selected={0}>
42
          <Pane label="Lowongan" >
43
            <Pagination
44
              key={1}
45
              url="/vacancies/"
46
47
              child={
                <VacancyList
48
                  user={this.props.user}
49
50
51
52
                  key={1}
                  userId={this.state.id}
                />
              }
53
54
            />
          </Pane>
55
          <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
            />
          </Pane>
68
          <Pane label="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>
      );
M. Reza Qorib's avatar
M. Reza Qorib committed
83
84
    } else if ((this.props.user.role === 'admin' && this.props.user.data.company != null)
      || this.props.user.role === 'company') {
85
      return (
sirinbaisa's avatar
sirinbaisa committed
86
        <Segment className="paginationCompany">
87
          <Pagination
88
            key={1}
89
90
91
92
93
94
95
96
            url={`/companies/${this.state.id}/vacancies/`}
            child={
              <VacancyList
                key={1}
                user={this.props.user}
                userId={this.state.id}
              />
            }
Zamil Majdy's avatar
Zamil Majdy committed
97
            error="Akun anda belum terverifikasi. Harap hubungi pihak administrasi"
98
          />
sirinbaisa's avatar
sirinbaisa committed
99
        </Segment>
100
      );
101
    } else if (this.props.user.role === 'admin' || this.props.user.role === 'supervisor') {
sirinbaisa's avatar
sirinbaisa committed
102
      return (
103
        <Tabs selected={0}>
104
105
106
          <Pane label="Lowongan Belum Terverifikasi" >
            <Pagination
              key={1}
107
              url="/vacancies/?verified=false"
108
109
110
111
112
113
114
115
116
117
118
119
              child={
                <VacancyList
                  user={this.props.user}
                  key={1}
                  userId={this.state.id}
                />
              }
            />
          </Pane>
          <Pane label="Lowongan Terverifikasi" >
            <Pagination
              key={2}
M. Reza Qorib's avatar
M. Reza Qorib committed
120
              url="/vacancies/?verified=true"
121
122
123
124
125
126
127
128
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
            />
129
130
          </Pane>
        </Tabs>
131
132
      );
    }
133

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

144
145
146
147
148
149
150
151
152
153
154
155
156
  companyHeader() {
    if ((this.props.user.role === 'admin' && this.props.user.data.company != null) || this.props.user.role === 'company') {
      return (
        <div style={{ float: 'left' }}>
          <Button as={Link} to="/pelamar" icon="eye" labelPosition="left" color="facebook" content="Lihat Semua Pendaftar" />
          <Button as={Link} to="/buat-lowongan" icon="add" labelPosition="left" content="Tambah Lowongan Baru" color="teal" />
        </div>
      );
    }

    return '';
  }

157
  render() {
158
    return (
159
      <div className="applicant">
Zamil Majdy's avatar
Zamil Majdy committed
160
161
162
163
164
165
166
167
168
169
        {this.props.user.role === 'student' || (
          <div className="administrationButtons" style={{ display: 'inline-block' }}>
            { this.companyHeader() }
            {(this.props.user.role === 'admin' || this.props.user.role === 'supervisor') &&
            <Button
              as={Link} to="/rekap" icon="dashboard" labelPosition="left" color="facebook"
              content="Rekap Pendaftaran"
            />}
          </div>
        )}
170
171
        { this.generateVacancies() }
      </div>
172
    );
173
  }
174
}