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 +15
-1
lines changed
components/molecules/GravityForm Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
import PropTypes from 'prop-types'
2
+ import React , { useState } from 'react'
2
3
import Form from '@/components/molecules/Form'
3
4
import Fields from './Fields'
4
5
import getGfFormValidationSchema from '@/functions/gravityForms/getGfFormValidationSchema'
@@ -25,6 +26,8 @@ export default function GravityForm({
25
26
const formValidationSchema = getGfFormValidationSchema ( fieldData )
26
27
const fieldDefaults = getGfFormDefaults ( fieldData )
27
28
29
+ const [ formFeedback , setFeedback ] = useState ( false )
30
+
28
31
return (
29
32
< Form
30
33
className = { cn ( styles . gravityForm , cssClass ) }
@@ -71,13 +74,24 @@ export default function GravityForm({
71
74
method : 'POST' ,
72
75
mimeType : 'multipart/form-data' ,
73
76
body : formData
74
- } ) . then ( ( response ) => response . json ( ) )
77
+ } )
78
+ . then ( ( response ) => response . json ( ) )
79
+ . then ( ( feedback ) => setFeedback ( feedback . confirmation_message ) )
80
+ . catch ( ( error ) => {
81
+ setFeedback ( `Error in form submission: ${ error . message } ` )
82
+ } )
75
83
} }
76
84
>
77
85
{ ( formikProps ) => (
78
86
< >
79
87
{ title && < h2 className = { styles . title } > { title } </ h2 > }
80
88
{ fieldData && < Fields fields = { fieldData } formikProps = { formikProps } /> }
89
+ { ! ! formFeedback && (
90
+ < div
91
+ className = "feedback"
92
+ dangerouslySetInnerHTML = { { __html : formFeedback } }
93
+ />
94
+ ) }
81
95
</ >
82
96
) }
83
97
</ Form >
You can’t perform that action at this time.
0 commit comments