DeleteCommentModal.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Button, Modal } from 'react-bootstrap';
  4. import moment from 'moment/src/moment';
  5. import ReactUtils from '../ReactUtils';
  6. import UserPicture from '../User/UserPicture';
  7. export default class DeleteCommentModal extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. }
  11. componentWillMount() {
  12. }
  13. render() {
  14. if (this.props.comment === undefined) {
  15. return <div></div>
  16. }
  17. const comment = this.props.comment;
  18. const commentDate = moment(comment.createdAt).format('YYYY/MM/DD HH:mm');
  19. // generate body
  20. let commentBody = comment.comment;
  21. if (commentBody.length > 200) { // omit
  22. commentBody = commentBody.substr(0,200) + '...';
  23. }
  24. commentBody = ReactUtils.nl2br(commentBody);
  25. return (
  26. <Modal show={this.props.isShown} onHide={this.props.cancel} className="page-comment-delete-modal">
  27. <Modal.Header closeButton>
  28. <Modal.Title>Delete comment?</Modal.Title>
  29. </Modal.Header>
  30. <Modal.Body>
  31. <UserPicture user={comment.creator} size="xs" /> <strong>{comment.creator.username}</strong> wrote on {commentDate}:
  32. <p className="comment-body">{commentBody}</p>
  33. </Modal.Body>
  34. <Modal.Footer>
  35. <Button onClick={this.props.cancel}>Cancel</Button>
  36. <Button onClick={this.props.confirmedToDelete} className="btn-danger">Delete</Button>
  37. </Modal.Footer>
  38. </Modal>
  39. );
  40. }
  41. }
  42. DeleteCommentModal.propTypes = {
  43. isShown: PropTypes.bool.isRequired,
  44. comment: PropTypes.object,
  45. cancel: PropTypes.func.isRequired, // for cancel evnet handling
  46. confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling
  47. };