Fakultas Ilmu Komputer UI

ApplicantList.jsx 1.4 KB
Newer Older
1
import React from 'react';
2
import { Item, Grid } from 'semantic-ui-react';
3
4
5
6
7
8
9
import Applicant from './Applicant';
import Server from '../lib/Server';

export default class ApplicantList extends React.Component {

  static propTypes = {
    url: React.PropTypes.string.isRequired,
10
    status: React.PropTypes.number.isRequired,
11
12
13
14
15
  };

  constructor(props) {
    super(props);
    /* istanbul ignore next */
16
    this.state = { applications: [] };
17
18
19
    Server.get(this.props.url, false).then((data) => {
      this.setState({ applications: data });
    });
20

21
    this.generateApplicants = this.generateApplicants.bind(this);
22
    this.updateStatus = this.updateStatus.bind(this);
23
24
  }

25
26
27
28
29
30
31
32
33
34
  updateStatus(id, status) {
    const obj = [];
    this.state.applications.map((application) => {
      const clonedObj = {};
      Object.assign(clonedObj, application);
      if (application.id === id) clonedObj.status = status;
      return obj.push(clonedObj);
    });
    this.setState({ applications: obj });
  }
35
36
37

  generateApplicants() {
    return this.state.applications.map(application =>
38
39
40
41
      application.status === this.props.status && (<Applicant
        key={application.id} data={application}
        updateStatus={this.updateStatus}
      />),
42
43
44
45
    );
  }

  render = () => (
46
47
48
49
50
    <Grid container doubling>
      <Item.Group relaxed style={{ width: '100%' }}>
        { this.generateApplicants() }
      </Item.Group>
    </Grid>
51
52
  );
}