Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.82 KB
Newer Older
1
import React from 'react';
2
import { Container } from 'semantic-ui-react';
3
4
5
import Tabs from './components/Tabs';
import Pane from './components/Pane';
import VacancyList from './components/VacancyList';
6
import Pagination from './components/Pagination';
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
              key={1}
41
              url="/vacancies/"
42
43
              child={
                <VacancyList
44
                  user={this.props.user}
45
46
47
48
                  key={1}
                  userId={this.state.id}
                />
              }
49
50
51
            />
          </Pane>
          <Pane label="Lamaran saya" >
52
            <Pagination
53
54
              key={2}
              url={`/students/${this.state.id}/applied-vacancies/`}
55
56
57
58
59
60
61
              child={
                <VacancyList
                  user={this.props.user}
                  key={2}
                  userId={this.state.id}
                />
              }
62
63
64
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
65
            <Pagination
66
67
              key={3}
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
68
69
70
71
72
73
74
              child={
                <VacancyList
                  key={3}
                  user={this.props.user}
                  userId={this.state.id}
                />
              }
75
76
77
78
            />
          </Pane>
        </Tabs>
      );
79
    } else if (this.props.user.role === 'company' || this.props.user.role === 'admin') {
80
      return (
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        <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>
95
96
      );
    }
97

98
99
100
101
102
103
104
105
106
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
107
108

  render() {
109
    return (
110
111
112
      <div className="applicant">
        { this.generateVacancies() }
      </div>
113
    );
114
  }
115
}