diff --git a/src/components/sections/partners/contact/index.tsx b/src/components/sections/partners/contact/index.tsx index 02a6a4d..28b6988 100644 --- a/src/components/sections/partners/contact/index.tsx +++ b/src/components/sections/partners/contact/index.tsx @@ -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() - 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) => { ) - - function newFunction(): { executeRecaptcha: any } { - return useGoogleReCaptcha() - } } const Contact = ({ data }: DataProps) => {