Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.22 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
6
import Pagination from './components/Pagination';
import { Menu, Icon } from 'semantic-ui-react';
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
              url="/vacancies/"
41
42
43
44
45
46
47
              child={
                <VacancyList
                  key={1}
                  userId={this.state.id}
                  url="/vacancies/"
                />
              }
48
49
50
51
52
            />
          </Pane>
          <Pane label="Lamaran saya" >
            <VacancyList
              key={2}
53
              userId={this.state.id}
M. Reza Qorib's avatar
M. Reza Qorib committed
54
              status="applied"
55
56
57
58
59
60
              url={`/students/${this.state.id}/applied-vacancies/`}
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
            <VacancyList
              key={3}
61
              userId={this.state.id}
62
63
64
65
66
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
            />
          </Pane>
        </Tabs>
      );
67
    } else if (this.props.user.role === 'company' || this.props.user.role === 'admin') {
68
      return (
69
        <VacancyList key={1} userId={this.state.id} url={`/companies/${this.state.id}/vacancies/`} type="company" />
70
71
      );
    }
72

73
74
75
76
77
78
79
80
81
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
82
83

  render() {
84
    return (
85
86
87
      <div className="applicant">
        { this.generateVacancies() }
      </div>
88
    );
89
  }
90
}