@@ -6,6 +6,9 @@ import getArchivePosts from '@/api/frontend/wp/archive/getArchivePosts'
6
6
import postComment from '@/api/frontend/wp/comments/postComment'
7
7
import getPagePropTypes from '@/functions/getPagePropTypes'
8
8
import Blocks from '@/components/molecules/Blocks'
9
+ import Form from '@/components/molecules/Form'
10
+ import { Field , ErrorMessage } from 'formik'
11
+ import * as Yup from 'yup'
9
12
10
13
// Define route post type.
11
14
const postType = 'post'
@@ -30,20 +33,6 @@ export default function BlogPost({post, archive, posts, pagination}) {
30
33
await getArchivePosts ( postType , pagination ?. endCursor )
31
34
}
32
35
33
- /**
34
- * Post a comment back to the blog
35
- */
36
- async function postTestComment ( ) {
37
- // TODO: get form data and post the comment
38
- await postComment (
39
- 'Test Testerson' ,
40
-
41
- 'https://nextjswp.test' ,
42
- post . databaseId ,
43
- 'This is a test comment.'
44
- )
45
- }
46
-
47
36
// Check for post archive.
48
37
// TODO create generic archive component and move this check to `_app.js`.
49
38
if ( archive ) {
@@ -84,7 +73,60 @@ export default function BlogPost({post, archive, posts, pagination}) {
84
73
__html : JSON . stringify ( post ?. comments ?? [ ] )
85
74
} }
86
75
/>
87
- < button onClick = { postTestComment } > Post test comment</ button >
76
+
77
+ < Form
78
+ className = "sample-form"
79
+ id = "form-1"
80
+ title = "Add a comment"
81
+ validationSchema = { Yup . object ( ) . shape ( {
82
+ author : Yup . string ( ) . required ( 'This field is required.' ) ,
83
+ authorEmail : Yup . string ( ) . required ( 'This field is required.' )
84
+ } ) }
85
+ onSubmit = { async ( values , { setSubmitting} ) => {
86
+ const { author, authorEmail, authorUrl, content} = values
87
+ await postComment (
88
+ author ,
89
+ authorEmail ,
90
+ authorUrl ,
91
+ post . databaseId ,
92
+ content
93
+ )
94
+ setSubmitting ( false )
95
+ } }
96
+ >
97
+ < label htmlFor = "author" > Author</ label >
98
+ < Field
99
+ id = "author"
100
+ name = "author"
101
+ placeholder = "Test Testerson"
102
+ type = "text"
103
+ />
104
+ < ErrorMessage name = "author" />
105
+ < label htmlFor = "authorEmail" > Email</ label >
106
+ < Field
107
+ id = "authorEmail"
108
+ name = "authorEmail"
109
+
110
+ type = "email"
111
+ />
112
+ < ErrorMessage name = "authorEmail" />
113
+ < label htmlFor = "authorUrl" > Website</ label >
114
+ < Field
115
+ id = "authorUrl"
116
+ name = "authorUrl"
117
+ placeholder = "https://nextjswp.local"
118
+ type = "url"
119
+ />
120
+ < ErrorMessage name = "authorUrl" />
121
+ < label htmlFor = "content" > Comment</ label >
122
+ < Field
123
+ id = "content"
124
+ name = "content"
125
+ placeholder = "This is a test comment"
126
+ type = "textarea"
127
+ />
128
+ < ErrorMessage name = "content" />
129
+ </ Form >
88
130
</ article >
89
131
</ Layout >
90
132
)
0 commit comments