Fakultas Ilmu Komputer UI

ApplicantPage.jsx 3.9 KB
Newer Older
1
import React from 'react';
2
import { Grid, Dropdown } from 'semantic-ui-react';
3
import Tabs from './components/Tabs';
4
import ApplicantList from './components/ApplicantList';
5
import Applicant from './components/Applicant';
6
import Pagination from './components/Pagination';
7
import Server from './lib/Server';
8

9
export default class ApplicantPage extends React.Component {
Zamil Majdy's avatar
Zamil Majdy committed
10
11
12
13
14

  static propTypes = {
    user: React.PropTypes.object.isRequired,
  };

15
16
17
18
19
20
21
  constructor(props) {
    super(props);
    /* istanbul ignore next */
    this.state = {
      email: '',
      password: '',
      errorFlag: false,
22
      company: { id: 1 },
23
24
25
      urls: [],
      selected: `/companies/${this.props.user.data.company.id}/applications/`,
      refresh: 0,
26
    };
27
28
29
    this.getVacancyList = this.getVacancyList.bind(this);
    this.handleChange = this.handleChange.bind(this);
    this.getVacancyList();
30
31
  }

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  handleChange = (e, data) => {
    this.setState({ selected: data.value, refresh: this.state.refresh + 5 });
  };

  getVacancyList= () => Server.get(`/companies/${this.props.user.data.company.id}/vacancies/`, false).then((data) => {
    const results = data.results;
    const names = ['Semua Lowongan'];
    const urls = [{
      key: 0,
      value: `/companies/${this.props.user.data.company.id}/applications/`,
      text: 'Semua Lowongan',
    }];
    results.map( (vacancy) => {
      names.push(vacancy.name);
      const url = `/companies/${this.props.user.data.company.id}/applications/${vacancy.id}/by_vacancy/`;
      const info = {
        key: vacancy.id,
        value: url,
        text: vacancy.name,
      };
      urls.push(info);
      return urls;
    } );
    this.setState({ urls });
    console.log('hasil');
    console.log(this.state.urls);
  }, error => error.then((r) => {
    this.modalAlert.open('Gagal mendapatkan daftar lowongan', r.detail);
  }));

62
  render() {
Zamil Majdy's avatar
Zamil Majdy committed
63
    const company = this.props.user.data.company;
64
    return (
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      <Grid>
        <div>
          <Dropdown placeholder="Semua Lowongan" search selection options={this.state.urls} onChange={this.handleChange} />
        </div>
        <Tabs selected={0}>
          <Pagination
            key={1 + this.state.refresh}
            url={`${this.state.selected}?status=${Applicant.APPLICATION_STATUS.NEW}`}
            label="Lamaran Baru"
            child={
              <ApplicantList companyId={company.id} status={Applicant.APPLICATION_STATUS.NEW} />
            }
          />
          <Pagination
            key={2 + this.state.refresh}
            url={`${this.state.selected}?status=${Applicant.APPLICATION_STATUS.READ}`}
            label="Lamaran Dibaca"
            child={
              <ApplicantList companyId={company.id} status={Applicant.APPLICATION_STATUS.READ} />
            }
          />
          <Pagination
            key={3 + this.state.refresh}
            url={`${this.state.selected}?status=${Applicant.APPLICATION_STATUS.BOOKMARKED}`}
            label="Lamaran Ditandai"
            child={
              <ApplicantList
                companyId={company.id}
                status={Applicant.APPLICATION_STATUS.BOOKMARKED}
              />
            }
          />
          <Pagination
            key={4 + this.state.refresh}
            url={`${this.state.selected}?status=${Applicant.APPLICATION_STATUS.ACCEPTED}`}
            label="Lamaran Diterima"
            child={
              <ApplicantList
                companyId={company.id}
                status={Applicant.APPLICATION_STATUS.ACCEPTED}
              />
            }
          />
          <Pagination
            key={5 + this.state.refresh}
            url={`${this.state.selected}?status=${Applicant.APPLICATION_STATUS.REJECTED}`}
            label="Lamaran Ditolak"
            child={
              <ApplicantList
                companyId={company.id}
                status={Applicant.APPLICATION_STATUS.REJECTED}
              />
            }
          />
        </Tabs>
      </Grid>
121
122
    );
  }
123
}