This repository was archived by the owner on Feb 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 1
1
import PropTypes from 'prop-types'
2
- import React from 'react'
2
+ import React , { useState } from 'react'
3
3
import * as Yup from 'yup'
4
4
import Form from '@/components/molecules/Form'
5
5
import Text from '@/components/atoms/Inputs/Text'
@@ -15,6 +15,8 @@ import postComment from '@/api/frontend/wp/comments/postComment'
15
15
* @return {Element } The Comments component.
16
16
*/
17
17
export default function Comments ( { comments, postId} ) {
18
+ const [ message , setMessage ] = useState ( '' )
19
+
18
20
return (
19
21
< >
20
22
< h3 > Comments</ h3 >
@@ -66,12 +68,22 @@ export default function Comments({comments, postId}) {
66
68
postId ,
67
69
content
68
70
)
69
- response . error
70
- ? alert ( response . errorMessage )
71
- : alert ( JSON . stringify ( response ) )
71
+ if ( response . error ) {
72
+ setMessage ( response . errorMessage )
73
+ setSubmitting ( false )
74
+ return
75
+ }
76
+
77
+ // alert(JSON.stringify(response))
78
+ if ( response . success && ! response . comment ) {
79
+ setMessage (
80
+ 'Your comment was sent and will appear after moderation.'
81
+ )
82
+ }
72
83
setSubmitting ( false )
73
84
} }
74
85
>
86
+ { ! ! message && < div > { message } </ div > }
75
87
< Text id = "author" label = "Author" isRequired type = "text" />
76
88
< Text id = "authorEmail" label = "Email" isRequired type = "email" />
77
89
< Text id = "authorUrl" label = "Website" type = "url" />
You can’t perform that action at this time.
0 commit comments