DeleteCommentModal.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. let commentBody = comment.comment
  20. if (commentBody.length > 200) { // omit
  21. commentBody = commentBody.substr(0,200) + '...';
  22. }
  23. commentBody = ReactUtils.nl2br(commentBody);
  24. return (
  25. <Modal show={this.props.isShown} onHide={this.props.cancel} className="page-comment-delete-modal">
  26. <Modal.Header closeButton>
  27. <Modal.Title>Delete comment?</Modal.Title>
  28. </Modal.Header>
  29. <Modal.Body>
  30. <UserPicture user={comment.creator} size="xs" /> <strong>{comment.creator.username}</strong> wrote on {commentDate}:
  31. <p className="comment-body">{commentBody}</p>
  32. </Modal.Body>
  33. <Modal.Footer>
  34. <Button onClick={this.props.cancel}>Cancel</Button>
  35. <Button onClick={this.props.confirmedToDelete} className="btn-danger">Delete</Button>
  36. </Modal.Footer>
  37. </Modal>
  38. );
  39. }
  40. }
  41. DeleteCommentModal.propTypes = {
  42. isShown: PropTypes.bool.isRequired,
  43. comment: PropTypes.object,
  44. cancel: PropTypes.func.isRequired, // for cancel evnet handling
  45. confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling
  46. };