DeleteCommentModal.jsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. componentWillMount() {
  14. }
  15. render() {
  16. if (this.props.comment === undefined) {
  17. return <div></div>;
  18. }
  19. const comment = this.props.comment;
  20. const commentDate = dateFnsFormat(comment.createdAt, 'YYYY/MM/DD HH:mm');
  21. // generate body
  22. let commentBody = comment.comment;
  23. if (commentBody.length > DeleteCommentModal.OMIT_BODY_THRES) { // omit
  24. commentBody = `${commentBody.substr(0, DeleteCommentModal.OMIT_BODY_THRES)}...`;
  25. }
  26. commentBody = ReactUtils.nl2br(commentBody);
  27. return (
  28. <Modal show={this.props.isShown} onHide={this.props.cancel} className="page-comment-delete-modal">
  29. <Modal.Header closeButton>
  30. <Modal.Title>
  31. <i className="icon-fw icon-fire text-danger"></i>
  32. Delete comment?
  33. </Modal.Title>
  34. </Modal.Header>
  35. <Modal.Body>
  36. <UserPicture user={comment.creator} size="xs" /> <strong>{comment.creator.username}</strong> wrote on {commentDate}:
  37. <p className="well well-sm comment-body m-t-5">{commentBody}</p>
  38. </Modal.Body>
  39. <Modal.Footer>
  40. <span className="text-danger">{this.props.errorMessage}</span>&nbsp;
  41. <Button onClick={this.props.cancel} bsClass="btn btn-sm">Cancel</Button>
  42. <Button onClick={this.props.confirmedToDelete} bsClass="btn btn-sm btn-danger">
  43. <i className="icon icon-fire"></i>
  44. Delete
  45. </Button>
  46. </Modal.Footer>
  47. </Modal>
  48. );
  49. }
  50. }
  51. DeleteCommentModal.propTypes = {
  52. isShown: PropTypes.bool.isRequired,
  53. comment: PropTypes.object,
  54. errorMessage: PropTypes.string,
  55. cancel: PropTypes.func.isRequired, // for cancel evnet handling
  56. confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling
  57. };