Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit d3743a3

Browse files
committed
EOD checkin
1 parent ca0588e commit d3743a3

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

components/molecules/GravityForm/GravityForm.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,29 @@ export default function GravityForm({
2525
const formValidationSchema = getGfFormValidationSchema(fieldData)
2626
const fieldDefaults = getGfFormDefaults(fieldData)
2727

28+
// fetch('/api/wp/getWPUrl')
29+
// .then((result) => result.json)
30+
// .then((parsed) => {
31+
// wpBase = parsed.wpApiUrlBase
32+
// })
33+
2834
return (
2935
<Form
3036
className={cn(styles.gravityForm, cssClass)}
3137
formDefaults={fieldDefaults}
3238
id={formId && `gform-${formId}`}
3339
validationSchema={formValidationSchema}
34-
onSubmit={(values) => {
35-
const formApiUrl = `https://nextjswp.test/wp-json/gf/v2/forms/${formId}/submissions`
40+
onSubmit={async (values) => {
41+
const wpBaseRequest = await fetch('/api/wp/getWPUrl')
42+
const wpBaseObject = await wpBaseRequest.json()
43+
const wpBase = wpBaseObject.wpApiUrlBase
44+
45+
const formApiUrl = `${wpBase}wp-json/gf/v2/forms/${formId}/submissions`
3646
const formData = new FormData()
3747
const formKeys = Object.keys(values)
3848

49+
formData.append('form_id', formId)
50+
3951
formKeys.forEach((key) => {
4052
let fieldName = key.replaceAll('-', '_')
4153
if (fieldName.endsWith('_filedata')) {

pages/api/wp/getWPUrl.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {wpApiUrlBase} from '@/api/wordpress/connector'
2+
3+
/**
4+
* Load more posts for an archive.
5+
*
6+
* @author WebDevStudios
7+
* @param {object} req Instance of http.IncomingMessage.
8+
* @param {object} res Instance of http.ServerResponse.
9+
*/
10+
export default function getWPUrl(req, res) {
11+
res.status(200).send({wpApiUrlBase})
12+
}

0 commit comments

Comments
 (0)