-
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.
- update comments on articles [Delivers #161959254]
- Loading branch information
1 parent
7a73f18
commit c60d186
Showing
15 changed files
with
414 additions
and
14 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
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,129 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import ReactQuill from 'react-quill'; | ||
import PropTypes from 'prop-types'; | ||
import Loader from 'react-loader'; | ||
import { | ||
Modal, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
} from 'reactstrap'; | ||
import { editComment } from '../../actions/articleActions'; | ||
|
||
export class UpdateComment extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
body: '', | ||
modal: false, | ||
}; | ||
} | ||
|
||
componentDidMount = () => { | ||
const { comment } = this.props; | ||
this.setState({ body: comment.body }); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.updateCommentSuccess === true) { | ||
window.location.reload(); | ||
} | ||
if (nextProps.isLoggedIn === false) { | ||
const { history } = this.props; | ||
history.push('/login'); | ||
} | ||
} | ||
|
||
toggle = () => { | ||
const { modal } = this.state; | ||
this.setState({ | ||
modal: !modal, | ||
}); | ||
} | ||
|
||
handleChange = value => { | ||
this.setState({ body: value }); | ||
} | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
const { editComment, slug, comment: { id } } = this.props; | ||
const { body, modal } = this.state; | ||
const payload = { | ||
comment: { | ||
body, | ||
}, | ||
}; | ||
editComment(payload, slug, id); | ||
this.setState({ | ||
modal: !modal, | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
body, | ||
modal, | ||
} = this.state; | ||
const { | ||
loading, | ||
className, | ||
buttonLabel, | ||
} = this.props; | ||
return ( | ||
<React.Fragment> | ||
<Loader loaded={!loading}> | ||
<i className="far fa-edit icon" onClick={this.toggle} role="button" tabIndex={0}>{buttonLabel}</i> | ||
<Modal isOpen={modal} toggle={this.toggle} className={className}> | ||
<ModalHeader>Edit comment</ModalHeader> | ||
<ModalBody> | ||
<ReactQuill | ||
id="text-editor" | ||
theme="" | ||
placeholder="Please add a comment" | ||
className="quill-height-comments" | ||
value={body} | ||
onChange={this.handleChange} | ||
required | ||
/> | ||
</ModalBody> | ||
<ModalFooter> | ||
<button type="button" className="btn btn-outline-primary m-r-10" onClick={this.handleSubmit}>Submit</button> | ||
<button type="button" className="btn btn-outline-warning m-r-10" onClick={this.toggle}>Close</button> | ||
</ModalFooter> | ||
</Modal> | ||
</Loader> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
isLoggedIn: state.user.isLoggedIn, | ||
loading: state.user.loading, | ||
updateCommentSuccess: state.article.updateCommentSuccess, | ||
}); | ||
|
||
const matchDispatchToProps = (dispatch) => bindActionCreators({ | ||
editComment, | ||
}, dispatch); | ||
|
||
UpdateComment.propTypes = { | ||
updateCommentSuccess: PropTypes.bool, | ||
comment: PropTypes.object.isRequired, | ||
slug: PropTypes.string.isRequired, | ||
editComment: PropTypes.func.isRequired, | ||
className: PropTypes.string.isRequired, | ||
buttonLabel: PropTypes.string.isRequired, | ||
history: PropTypes.object.isRequired, | ||
loading: PropTypes.bool.isRequired, | ||
isLoggedIn: PropTypes.object.isRequired, | ||
}; | ||
|
||
UpdateComment.defaultProps = { | ||
updateCommentSuccess: false, | ||
}; | ||
|
||
export default connect(mapStateToProps, matchDispatchToProps)(UpdateComment); |
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.