DeleteCommentModal.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. <span className="text-danger">{this.props.errorMessage}</span>&nbsp;
  36. <Button onClick={this.props.cancel}>Cancel</Button>
  37. <Button onClick={this.props.confirmedToDelete} className="btn-danger">Delete</Button>
  38. </Modal.Footer>
  39. </Modal>
  40. );
  41. }
  42. }
  43. DeleteCommentModal.propTypes = {
  44. isShown: PropTypes.bool.isRequired,
  45. comment: PropTypes.object,
  46. errorMessage: PropTypes.string,
  47. cancel: PropTypes.func.isRequired, // for cancel evnet handling
  48. confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling
  49. };