Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.32 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
8
9

export default class VacancyPage extends React.Component {

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

  static getId(user) {
    const role = user.role;
    if (role === 'student') {
      return user.data.student.id;
    } else if (role === 'company') {
      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
39
40
      return (
        <Tabs selected={0}>
          <Pane label="Semua Lowongan" >
            <VacancyList
              key={1}
41
              userId={this.state.id}
42
43
44
45
46
47
              url="/vacancies/"
            />
          </Pane>
          <Pane label="Lamaran saya" >
            <VacancyList
              key={2}
48
              userId={this.state.id}
49
50
51
52
53
54
              url={`/students/${this.state.id}/applied-vacancies/`}
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
            <VacancyList
              key={3}
55
              userId={this.state.id}
56
57
58
59
60
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
            />
          </Pane>
        </Tabs>
      );
61
    } else if (this.props.user.role === 'company') {
62
      return (
63
        <VacancyList key={1} userId={this.state.id} url={`/companies/${this.state.id}/vacancies/`} type="company" />
64
      );
65
66
67
68
69
70
71
72
73
74
75
    } else if (this.props.user.role === 'admin') {
      return (
        <Tabs selected={0}>
          <Pane label="Lowongan Belum Terferivikasi" >
            <Item.Group>
              <AdminVacancy />
            </Item.Group>
          </Pane>
          <Pane label=" Semua Lamaran" />
        </Tabs>
      );
76
    }
77

78
79
80
81
82
83
84
85
86
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
87
88

  render() {
89
    return (
90
91
92
      <div className="applicant">
        { this.generateVacancies() }
      </div>
93
    );
94
  }
95
}