DeleteCommentModal.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Button from 'react-bootstrap/es/Button';
  4. import Modal from 'react-bootstrap/es/Modal';
  5. import dateFnsFormat from 'date-fns/format';
  6. import ReactUtils from '../ReactUtils';
  7. import UserPicture from '../User/UserPicture';
  8. export default class DeleteCommentModal extends React.Component {
  9. /*
  10. * the threshold for omitting body
  11. */
  12. static get OMIT_BODY_THRES() { return 400 }
  13. constructor(props) {
  14. super(props);
  15. }
  16. componentWillMount() {
  17. }
  18. render() {
  19. if (this.props.comment === undefined) {
  20. return <div></div>;
  21. }
  22. const comment = this.props.comment;
  23. const commentDate = dateFnsFormat(comment.createdAt, 'YYYY/MM/DD HH:mm');
  24. // generate body
  25. let commentBody = comment.comment;
  26. if (commentBody.length > DeleteCommentModal.OMIT_BODY_THRES) { // omit
  27. commentBody = commentBody.substr(0, DeleteCommentModal.OMIT_BODY_THRES) + '...';
  28. }
  29. commentBody = ReactUtils.nl2br(commentBody);
  30. return (
  31. <Modal show={this.props.isShown} onHide={this.props.cancel} className="page-comment-delete-modal">
  32. <Modal.Header closeButton>
  33. <Modal.Title>
  34. <i className="icon-fw icon-fire text-danger"></i>
  35. Delete comment?
  36. </Modal.Title>
  37. </Modal.Header>
  38. <Modal.Body>
  39. <UserPicture user={comment.creator} size="xs" /> <strong>{comment.creator.username}</strong> wrote on {commentDate}:
  40. <p className="well well-sm comment-body m-t-5">{commentBody}</p>
  41. </Modal.Body>
  42. <Modal.Footer>
  43. <span className="text-danger">{this.props.errorMessage}</span>&nbsp;
  44. <Button onClick={this.props.cancel} bsClass="btn btn-sm">Cancel</Button>
  45. <Button onClick={this.props.confirmedToDelete} bsClass="btn btn-sm btn-danger">
  46. <i className="icon icon-fire"></i>
  47. Delete
  48. </Button>
  49. </Modal.Footer>
  50. </Modal>
  51. );
  52. }
  53. }
  54. DeleteCommentModal.propTypes = {
  55. isShown: PropTypes.bool.isRequired,
  56. comment: PropTypes.object,
  57. errorMessage: PropTypes.string,
  58. cancel: PropTypes.func.isRequired, // for cancel evnet handling
  59. confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling
  60. };