edited some issues

This commit is contained in:
oriofir 2022-09-08 16:19:27 -07:00
parent 1cc6362528
commit 624bf7251e

View File

@ -57,10 +57,9 @@ const CustomForm = ({ data }: FormProps) => {
const [errorMsg, setErrorMsg] = useState('')
const [isFormSent, setIsFormSent] = useState(false)
const [isSending, setIsSending] = useState(false)
const [notification, setNotification] = useState('')
// const reRef = useRef<ReCAPTCHA>()
const { executeRecaptcha } = newFunction()
const { executeRecaptcha } = useGoogleReCaptcha()
const handleSubmitForm = useCallback(
(e) => {
@ -70,7 +69,7 @@ const CustomForm = ({ data }: FormProps) => {
console.log('Execute recaptcha not yet available')
return
}
executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken: string) => {
executeRecaptcha('enquiryFormSubmit').then((gReCaptchaToken) => {
// eslint-disable-next-line no-console
console.log(gReCaptchaToken, 'response Google reCaptcha server')
submitEnquiryForm(gReCaptchaToken)
@ -79,26 +78,19 @@ const CustomForm = ({ data }: FormProps) => {
[executeRecaptcha]
)
const submitEnquiryForm = (gReCaptchaToken: string) => {
fetch('/api/inquiry', {
const submitEnquiryForm = (gReCaptchaToken) => {
fetch('/api/enquiry', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({
_gRecaptchaToken: gReCaptchaToken,
get gRecaptchaToken() {
return this._gRecaptchaToken
},
set gRecaptchaToken(value) {
this._gRecaptchaToken = value
}
gRecaptchaToken: gReCaptchaToken
})
})
.then((res) => res.json())
.then((res) => {
// eslint-disable-next-line no-console
console.log(res, 'response from backend')
if (res?.status === 'success') {
setNotification(res?.message)
@ -108,7 +100,7 @@ const CustomForm = ({ data }: FormProps) => {
})
}
const handleSubmit = async (e: any) => {
async function handleSubmit(e: any) {
e.preventDefault()
try {
@ -132,7 +124,6 @@ const CustomForm = ({ data }: FormProps) => {
}
// const token = await reRef.current.executeAsync()
await fetch(`${process.env.NEXT_PUBLIC_API}/api/inquiry`, {
method: 'POST',
mode: 'no-cors',
@ -260,10 +251,6 @@ const CustomForm = ({ data }: FormProps) => {
</form>
</div>
)
function newFunction(): { executeRecaptcha: any } {
return useGoogleReCaptcha()
}
}
const Contact = ({ data }: DataProps) => {