@@ -6,19 +6,9 @@ import FormError from './FormError'
66import MediaPreview from './MediaPreview'
77
88const CommentForm = ( props ) => {
9- const {
10- attachments,
11- setAttachments,
12- addCommentReply,
13- commentReply,
14- setCommentReply
15- } = props
9+ const { attachments, setAttachments, addComment, comment, setComment } = props
1610
17- const {
18- register : registerReply ,
19- errors : errorsReply ,
20- handleSubmit : handleSubmitReply
21- } = useForm ( )
11+ const { register, errors, handleSubmit } = useForm ( )
2212
2313 const handleFileChange = async ( event ) => {
2414 const newFiles = event . target . files
@@ -34,18 +24,15 @@ const CommentForm = (props) => {
3424 }
3525
3626 return (
37- < form
38- className = 'comment-form'
39- onSubmit = { handleSubmitReply ( addCommentReply ) }
40- >
27+ < form className = 'comment-form' onSubmit = { handleSubmit ( addComment ) } >
4128 < div className = 'comment-input' >
4229 < textarea
4330 rows = '5'
4431 cols = '25'
4532 name = 'Comments'
46- ref = { registerReply ( { required : true } ) }
47- value = { commentReply }
48- onChange = { ( e ) => setCommentReply ( e . target . value ) }
33+ value = { comment }
34+ ref = { register ( { required : true } ) }
35+ onChange = { ( e ) => setComment ( e . target . value ) }
4936 > </ textarea >
5037 < div className = 'file-input' >
5138 < input
@@ -60,7 +47,7 @@ const CommentForm = (props) => {
6047 </ label >
6148 </ div >
6249 </ div >
63- { errorsReply . Comments && < FormError message = 'Reply cannot be empty' /> }
50+ { errors . Comments && < FormError message = 'Reply cannot be empty' /> }
6451 < MediaPreview attachments = { attachments } setAttachments = { setAttachments } />
6552 < Button className = 'btn btn-default' > Add Reply</ Button >
6653 </ form >
0 commit comments