import React from 'react'; import PropTypes from 'prop-types'; import { Button, Modal } from 'react-bootstrap'; import moment from 'moment'; import ReactUtils from '../ReactUtils'; import UserPicture from '../User/UserPicture'; export default class DeleteCommentModal extends React.Component { /* * the threshold for omitting body */ static get OMIT_BODY_THRES() { return 400 }; constructor(props) { super(props); } componentWillMount() { } render() { if (this.props.comment === undefined) { return
} const comment = this.props.comment; const commentDate = moment(comment.createdAt).format('YYYY/MM/DD HH:mm'); // generate body let commentBody = comment.comment; if (commentBody.length > DeleteCommentModal.OMIT_BODY_THRES) { // omit commentBody = commentBody.substr(0, DeleteCommentModal.OMIT_BODY_THRES) + '...'; } commentBody = ReactUtils.nl2br(commentBody); return ( Delete comment? {comment.creator.username} wrote on {commentDate}:

{commentBody}

{this.props.errorMessage} 
); } } DeleteCommentModal.propTypes = { isShown: PropTypes.bool.isRequired, comment: PropTypes.object, errorMessage: PropTypes.string, cancel: PropTypes.func.isRequired, // for cancel evnet handling confirmedToDelete: PropTypes.func.isRequired, // for confirmed event handling };