Fakultas Ilmu Komputer UI

VacancyPage.jsx 2.03 KB
Newer Older
1
2
3
import React from 'react';
import Tabs from './components/Tabs';
import Pane from './components/Pane';
4
import Storage from './lib/Storage';
5
6
7
8
import VacancyList from './components/VacancyList';

export default class VacancyPage extends React.Component {

9
10
11
12
13
14
15
16
17
18
19
20
  static getRole() {
    const student = Storage.get('user-data').student;
    const company = Storage.get('user-data').company;
    if (student) {
      return { id: student.id, type: 'student' };
    } else if (company) {
      return { id: company.id, type: 'company' };
    }

    return { id: '0', type: 'error' };
  }

21
22
23
  constructor(props) {
    super(props);
    /* istanbul ignore next */
24
    const role = VacancyPage.getRole();
25
    this.state = {
26
      vacancies: [],
27
      id: role.id,
28
      role: role.type,
29
    };
30
31
  }

32
33
34
35
36
37
38
  generateVacancies() {
    if (this.state.role === 'student') {
      return (
        <Tabs selected={0}>
          <Pane label="Semua Lowongan" >
            <VacancyList
              key={1}
39
              userId={this.state.id}
40
41
42
43
44
45
46
              url="/vacancies/"
            />
          </Pane>
          <Pane label="Lamaran saya" >
            <VacancyList
              key={2}
              status="Batal"
47
              userId={this.state.id}
48
49
50
51
52
53
              url={`/students/${this.state.id}/applied-vacancies/`}
            />
          </Pane>
          <Pane label="Lamaran Ditandai" >
            <VacancyList
              key={3}
54
              userId={this.state.id}
55
56
57
58
59
60
61
              url={`/students/${this.state.id}/bookmarked-vacancies/`}
            />
          </Pane>
        </Tabs>
      );
    } else if (this.state.role === 'company') {
      return (
62
        <VacancyList key={1} userId={this.state.id} url="/vacancies/?verified=false" type="company" />
63
64
      );
    }
65

66
67
68
69
70
71
72
73
74
    return (
      <div>
        <h3>
          Anda tidak terautentifikasi. Harap logout dan login
          kembali dengan akun yang benar
        </h3>
      </div>
    );
  }
75
76

  render() {
77
    return (
78
79
80
      <div className="applicant">
        { this.generateVacancies() }
      </div>
81
    );
82
  }
83
}