-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this feature will enable users to delete articles they have authored [Finishes #161776758]
- Loading branch information
1 parent
021f645
commit ecc3984
Showing
12 changed files
with
262 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { Component } from 'react'; | ||
import { Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { bindActionCreators } from 'redux'; | ||
import { deleteArticle } from '../../actions/articleActions'; | ||
|
||
export class DeleteModal extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
redirect: false, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.confirmDelete) { | ||
this.setState({ | ||
redirect: true, | ||
}); | ||
} | ||
} | ||
|
||
handleClick = event => { | ||
event.preventDefault(); | ||
const { slug, deleteArticle } = this.props; | ||
deleteArticle(slug); | ||
}; | ||
|
||
render() { | ||
const { redirect } = this.state; | ||
if (redirect) { | ||
const to = { pathname: '/dashboard' }; | ||
return ( | ||
<Redirect to={to} /> | ||
); | ||
} | ||
return ( | ||
<div className="modal fade" id="exampleModal" tabIndex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> | ||
<div className="modal-dialog" role="document"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title" id="exampleModalLabel">Confirm Delete</h5> | ||
<button type="button" className="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div className="modal-body"> | ||
Are you sure you want to delete this article? | ||
</div> | ||
<div className="modal-footer"> | ||
<button type="button" className="btn-cancel" data-dismiss="modal">Cancel</button> | ||
<button type="button" className="btn-delete" onClick={this.handleClick} data-dismiss="modal">Yes, delete</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
confirmDelete: state.article.confirmDelete, | ||
}); | ||
|
||
const matchDispatchToProps = dispatch => bindActionCreators({ | ||
deleteArticle, | ||
}, dispatch); | ||
|
||
DeleteModal.propTypes = { | ||
confirmDelete: PropTypes.bool.isRequired, | ||
deleteArticle: PropTypes.func.isRequired, | ||
slug: PropTypes.string.isRequired, | ||
|
||
}; | ||
|
||
export default connect( | ||
mapStateToProps, | ||
matchDispatchToProps, | ||
)(DeleteModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.