Fakultas Ilmu Komputer UI

VacancyPage.jsx 3.88 KB
Newer Older
1
import React from 'react';
2
import { Container, Item } from 'semantic-ui-react';S
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
            />
          </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
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
96
97
98
        <Container className="vacancies">
          <Pagination
            key={1}
            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"
          />
        </Container>
99
      );
100
    } else if (this.props.user.role === 'admin' || this.props.user.role === 'supervisor') {
101
102
      return (
        <Tabs selected={0}>
103
104
105
          <Pane label="Lowongan Belum Terverifikasi" >
            <Pagination
              key={1}
106
              url="/vacancies/?verified=false"
107
108
109
110
111
112
113
114
115
116
117
118
              child={
                <VacancyList
                  user={this.props.user}
                  key={1}
                  userId={this.state.id}
                />
              }
            />
          </Pane>
          <Pane label="Lowongan Terverifikasi" >
            <Pagination
              key={2}
119
              url={`/vacancies/?verified=true`}
120
121
122
123
124
125
126
127
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
            />
128
129
130
          </Pane>
        </Tabs>
      );
131
    }
132

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

  render() {
144
    return (
145
146
147
      <div className="applicant">
        { this.generateVacancies() }
      </div>
148
    );
149
  }
150
}