DeleteCommentModal.jsx 2.2 KB

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