Fakultas Ilmu Komputer UI

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

export default class ApplicantList extends React.Component {

  static propTypes = {
8
    items: React.PropTypes.array,
9
    status: React.PropTypes.number.isRequired,
10
11
  };

12
13
14
15
  static defaultProps = {
    items: [],
  };

16
17
18
  constructor(props) {
    super(props);
    /* istanbul ignore next */
19
    this.state = { applications: this.props.items };
20
    this.generateApplicants = this.generateApplicants.bind(this);
21
    this.updateStatus = this.updateStatus.bind(this);
22
23
  }

24
25
26
27
28
29
30
31
32
33
  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 });
  }
34
35
36

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

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