2017-08-25 14:54:32 +08:00
|
|
|
import React, { Component } from "react";
|
2017-08-25 22:40:23 +08:00
|
|
|
import PropTypes, { bool, number, string, func } from "prop-types";
|
|
|
|
import { Modal, Button, Alert, Glyphicon } from "react-bootstrap";
|
|
|
|
import { FormattedMessage, FormattedHTMLMessage } from "react-intl";
|
2017-08-25 14:54:32 +08:00
|
|
|
import { connect } from "react-redux";
|
2017-08-28 23:05:09 +08:00
|
|
|
import axios from "../../../app/axios";
|
2017-08-25 14:54:32 +08:00
|
|
|
|
2017-08-28 23:05:09 +08:00
|
|
|
import { LEAVE_TEAM_PATH } from "../../../app/routes";
|
2017-08-25 22:40:23 +08:00
|
|
|
import { leaveTeamModalShow } from "../../actions/LeaveTeamActions";
|
2017-08-28 23:05:09 +08:00
|
|
|
import { addTeamsData, setCurrentTeam } from "../../actions/TeamsActions";
|
2017-08-25 22:40:23 +08:00
|
|
|
|
2017-08-25 14:54:32 +08:00
|
|
|
class LeaveTeamModal extends Component {
|
2017-08-25 22:40:23 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.onCloseModal = this.onCloseModal.bind(this);
|
2017-08-28 15:36:21 +08:00
|
|
|
this.leaveTeam = this.leaveTeam.bind(this);
|
2017-08-25 22:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onCloseModal() {
|
|
|
|
this.props.leaveTeamModalShow(false);
|
|
|
|
}
|
2017-08-25 22:07:37 +08:00
|
|
|
|
2017-08-28 15:36:21 +08:00
|
|
|
leaveTeam() {
|
2017-08-28 23:05:09 +08:00
|
|
|
const teamUrl = `${LEAVE_TEAM_PATH}?team=${this.props.teamId}`;
|
|
|
|
axios
|
|
|
|
.delete(teamUrl, {
|
|
|
|
withCredentials: true
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
console.log(response);
|
|
|
|
const teams = response.data.teams.collection;
|
|
|
|
this.props.addTeamsData(teams);
|
|
|
|
const currentTeam = _.find(teams, team => team.current_team);
|
|
|
|
this.props.setCurrentTeam(currentTeam);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log("error: ", error.response.data.message);
|
|
|
|
});
|
|
|
|
this.props.leaveTeamModalShow(false);
|
2017-08-28 15:36:21 +08:00
|
|
|
}
|
|
|
|
|
2017-08-25 14:54:32 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2017-08-25 22:40:23 +08:00
|
|
|
<Modal show={this.props.showModal} onHide={this.onCloseModal}>
|
2017-08-25 14:54:32 +08:00
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>
|
2017-08-25 22:07:37 +08:00
|
|
|
<FormattedMessage
|
|
|
|
id="settings_page.leave_team_modal.title"
|
|
|
|
values={{ teamName: this.props.teamName }}
|
|
|
|
/>
|
2017-08-25 14:54:32 +08:00
|
|
|
</Modal.Title>
|
|
|
|
</Modal.Header>
|
2017-08-25 22:40:23 +08:00
|
|
|
<Modal.Body>
|
|
|
|
<p>
|
|
|
|
<FormattedMessage id="settings_page.leave_team_modal.subtitle" />
|
|
|
|
</p>
|
|
|
|
<Alert bsStyle="danger">
|
2017-08-28 15:36:21 +08:00
|
|
|
<Glyphicon glyph="exclamation-sign" />
|
2017-08-25 22:40:23 +08:00
|
|
|
<FormattedMessage id="settings_page.leave_team_modal.warnings" />
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<FormattedMessage id="settings_page.leave_team_modal.warning_message_one" />
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<FormattedHTMLMessage id="settings_page.leave_team_modal.warning_message_two" />
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<FormattedMessage id="settings_page.leave_team_modal.warning_message_three" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</Alert>
|
|
|
|
</Modal.Body>
|
2017-08-25 14:54:32 +08:00
|
|
|
<Modal.Footer>
|
2017-08-25 22:40:23 +08:00
|
|
|
<Button onClick={this.onCloseModal}>
|
2017-08-25 14:54:32 +08:00
|
|
|
<FormattedMessage id="general.close" />
|
|
|
|
</Button>
|
2017-08-28 15:36:21 +08:00
|
|
|
<Button bsStyle="success" onClick={this.leaveTeam}>
|
2017-08-28 23:05:09 +08:00
|
|
|
<FormattedMessage id="settings_page.leave_team_modal.leave_team" />
|
2017-08-28 15:36:21 +08:00
|
|
|
</Button>
|
2017-08-25 14:54:32 +08:00
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-25 22:07:37 +08:00
|
|
|
LeaveTeamModal.propTypes = {
|
|
|
|
showModal: bool.isRequired,
|
|
|
|
teamId: number.isRequired,
|
|
|
|
teamName: string.isRequired,
|
2017-08-28 23:05:09 +08:00
|
|
|
addTeamsData: func.isRequired,
|
|
|
|
leaveTeamModalShow: func.isRequired
|
2017-08-25 22:07:37 +08:00
|
|
|
};
|
2017-08-25 14:54:32 +08:00
|
|
|
const mapStateToProps = ({ showLeaveTeamModal }) => ({
|
|
|
|
showModal: showLeaveTeamModal.show,
|
2017-08-25 22:07:37 +08:00
|
|
|
teamId: showLeaveTeamModal.id,
|
|
|
|
teamName: showLeaveTeamModal.teamName
|
2017-08-25 14:54:32 +08:00
|
|
|
});
|
|
|
|
|
2017-08-28 23:05:09 +08:00
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
leaveTeamModalShow,
|
|
|
|
addTeamsData,
|
|
|
|
setCurrentTeam
|
|
|
|
})(LeaveTeamModal);
|