File size: 1,502 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import { get } from 'lodash';
import PropTypes from 'prop-types';
import { useState } from 'react';
import PostCommentForm from './form';
import './post-comment.scss'; // intentional, shares styles
import './post-comment-with-error.scss';
function PostCommentWithError( {
activeReplyCommentId,
commentId,
commentsTree,
post,
repliesList,
} ) {
const commentParentId = get( commentsTree, [ commentId, 'data', 'parent', 'ID' ], null );
const commentText = get( commentsTree, [ commentId, 'data', 'content' ] );
const placeholderError = get( commentsTree, [ commentId, 'data', 'placeholderError' ] );
const placeholderErrorType = get( commentsTree, [ commentId, 'data', 'placeholderErrorType' ] );
const [ comment, setComment ] = useState( commentText );
if ( activeReplyCommentId !== commentParentId ) {
return null;
}
return (
<li className="comments__comment is-error">
<PostCommentForm
commentText={ comment }
error={ placeholderError }
errorType={ placeholderErrorType }
onUpdateCommentText={ setComment }
parentCommentId={ commentParentId }
placeholderId={ commentId }
post={ post }
/>
{ repliesList }
</li>
);
}
PostCommentWithError.propTypes = {
commentId: PropTypes.oneOfType( [ PropTypes.string, PropTypes.number ] ).isRequired,
commentsTree: PropTypes.object.isRequired,
onUpdateCommentText: PropTypes.func.isRequired,
post: PropTypes.object.isRequired,
repliesList: PropTypes.object,
};
export default PostCommentWithError;
|