Fakultas Ilmu Komputer UI

ApproveModal.jsx 2.83 KB
Newer Older
1
import React from 'react';
2
3
4
5
import { Modal, Button } from 'semantic-ui-react';
import Server from './../lib/Server';
import ConfirmationModal from './../components/ConfirmationModal';
import Applicant from './../components/Applicant';
6
7
8
9

export default class ApproveModal extends React.Component {
  static propTypes = {
    data: React.PropTypes.object.isRequired,
10
    updateStatus: React.PropTypes.func.isRequired,
11
12
13
14
15
16
17
  };

  constructor(props) {
    super(props);
    /* istanbul ignore next */
    this.state = {
      modalOpen: false,
18
19
      rejectLoading: false,
      acceptLoading: false,
20
21
    };
    this.handleOpen = this.handleOpen.bind(this);
22
23
    this.reject = this.reject.bind(this);
    this.accept = this.accept.bind(this);
24
25
  }

26
27
  handleOpen = () => this.setState({ modalOpen: true });
  handleClose = () => this.setState({ modalOpen: false });
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  rejectApplication = () => {
    const data = { status: Applicant.APPLICATION_STATUS.REJECTED };
    this.setState({ rejectLoading: true });
    Server.patch(`/applications/${this.props.data.id}/`, data).then((status) => {
      this.props.updateStatus(this.props.data.id, status.status);
    });
  };

  reject = () => {
    this.modal.open(
      'Tolak Lamaran?',
      'Apakah anda yakin untuk menolak lamaran ini?',
      'trash',
      this.rejectApplication,
    );
  };
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  acceptApplication = () => {
    const data = { status: Applicant.APPLICATION_STATUS.ACCEPTED };
    this.setState({ acceptLoading: true });
    Server.patch(`/applications/${this.props.data.id}/`, data).then((status) => {
      this.props.updateStatus(this.props.data.id, status.status);
    });
  };

  accept = () => {
    this.modal.open(
      'Terima Lamaran?',
      'Apakah anda yakin untuk menerima lamaran ini?',
      'checkmark',
      this.acceptApplication,
    );
  };
62
63
64

  render = () => (
    <Modal
65
      trigger={<Button primary onClick={this.handleOpen} floated="right">Detail</Button>}
66
67
68
69
      closeIcon="close"
      open={this.state.modalOpen}
      onClose={this.handleClose}
    >
70
71
      <ConfirmationModal ref={(modal) => { this.modal = modal; }} />
      <Modal.Header>Data Lamaran</Modal.Header>
72
      <Modal.Content>
73
74
75
76
77
        <h4> Cover Letter </h4>
        { this.props.data.cover_letter }
        <div style={{ float: 'right' }}>
          <a href={this.props.data.resume} >CV Pelamar </a>
        </div>
78
79
      </Modal.Content>
      <Modal.Actions>
80
81
82
83
84
        <Button.Group>
          <Button disabled={this.props.data.status === Applicant.APPLICATION_STATUS.REJECTED} loading={this.state.rejectLoading} color="red" onClick={this.reject}>Tolak Lamaran</Button>
          <Button.Or />
          <Button disabled={this.props.data.status === Applicant.APPLICATION_STATUS.ACCEPTED} loading={this.state.acceptLoading} color="green" onClick={this.accept}>Terima Lamaran</Button>
        </Button.Group>
85
86
87
88
89
      </Modal.Actions>
    </Modal>
    )
}