Fakultas Ilmu Komputer UI

VacancyList.jsx 2.6 KB
Newer Older
1
import React from 'react';
sirinbaisa's avatar
sirinbaisa committed
2
import { Item, Button, Grid, Segment } from 'semantic-ui-react';
3
import { Link } from 'react-router';
4
import Vacancy from './Vacancy';
5
import CompanyVacancy from './CompanyVacancy';
6
import Server from '../lib/Server';
7
8
9
10

export default class VacancyList extends React.Component {

  static propTypes = {
11
    user: React.PropTypes.object.isRequired,
12
    userId: React.PropTypes.number.isRequired,
13
    items: React.PropTypes.array,
14
15
16
  };

  static defaultProps = {
17
    items: [],
18
19
  };

20
21
  constructor(props) {
    super(props);
M. Reza Qorib's avatar
M. Reza Qorib committed
22
    /* istanbul ignore next */
23
24
25
26
27
28
    this.state = {
      vacancies: this.props.items,
      bookmarkList: [],
      appliedList: [],
      loading: true,
    };
29
    this.generateVacancies = this.generateVacancies.bind(this);
30
31
  }

32
33
34
35
36
37
38
39
40
  deleteVacancy = id => Server.delete(`/vacancies/${id}/`, this.state).then(() => {
    this.modalAlert.open('Hapus Lowongan', 'Lowongan berhasil dihapus');
    const newVacancies = [];
    this.state.vacancies.map(vacancy => vacancy.id !== id && newVacancies.push(vacancy));
    this.setState({ vacancies: newVacancies });
  }, error => error.then((r) => {
    this.modalAlert.open('Gagal Menghapus Lowongan', r.error);
  }));

41
  generateVacancies() {
42
    if (this.props.user.role === 'student') {
43
44
45
      return this.state.vacancies.map(vacancy =>
        (
          <Vacancy
46
47
48
49
50
            key={vacancy.id}
            status={vacancy.status}
            user={this.props.user}
            bookmarked={vacancy.bookmarked ? 1 : 0}
            data={vacancy}
51
            studentId={this.props.userId}
52
          />
53
54
55
56
        ),
      );
    }

sirinbaisa's avatar
sirinbaisa committed
57
58
    return this.state.vacancies.map(vacancy => (

59
60
61
62
63
64
65
      <Item.Group key={vacancy.id} relaxed style={{ width: '100%' }}>
        <CompanyVacancy
          key={vacancy.id}
          data={vacancy}
          deleteCallback={() => this.deleteVacancy(vacancy.id)}
        />
      </Item.Group>
sirinbaisa's avatar
sirinbaisa committed
66
67

        ),
68
69
70
    );
  }

71
  companyHeader() {
72
    if (this.props.user.role === 'company') {
73
      return (
Zamil Majdy's avatar
Zamil Majdy committed
74
        <Grid textAlign="center" style={{ paddingTop: '10px' }}>
75
          <Button size="tiny" as={Link} to="/pelamar" icon="eye" labelPosition="left" color="facebook" content="Lihat Semua Pendaftar" />
76
          <Button size="tiny" as={Link} to="/buat-lowongan" icon="add" labelPosition="left" content="Tambah Lowongan Baru" color="teal" />
77
        </Grid>
78
79
80
81
82
      );
    }

    return '';
  }
83

84
  render = () => (
85
    <div>
86
87
      <Grid container columns="eleven" doubling>
        { this.companyHeader() }
88
89
90
        <Item.Group relaxed style={{ width: '100%' }}>
          { this.generateVacancies() }
        </Item.Group>
91
      </Grid>
92
    </div>
93
  );
94
}