Skip to content

Commit

Permalink
New Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nachat-ayoub committed Feb 21, 2024
1 parent 07bc35c commit 831a097
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function App() {
const [error, setError] = useState<null | string>(null);
const { sendEmail } = useForm();

const captchaRef = useRef<null | ReCAPTCHA>(null);
// const captchaRef = useRef<null | ReCAPTCHA>(null);

async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
Expand All @@ -28,31 +28,39 @@ export default function App() {
return;
}

if (captchaRef?.current && typeof captchaRef.current !== 'string') {
const token = captchaRef.current.getValue();
if (!token) return setError('Please complete the captcha.');
captchaRef.current.reset();
sendEmail(e, (error) => {
if (error) {
setSendStatus('error');
} else {
setSendStatus('success');
}
});

await axios
.post('https://dummy-api-phi.vercel.app/api/reCaptcha', { token })
.then((res) => {
if (res.status === 200) {
sendEmail(e, (error) => {
if (error) {
setSendStatus('error');
} else {
setSendStatus('success');
}
});
} else {
setError('Failed to send email. Please try again.');
}
})
.catch((error) => {
console.log(error);
setError('Failed to send email. Please try again.');
});
}
// if (captchaRef?.current && typeof captchaRef.current !== 'string') {
// const token = captchaRef.current.getValue();
// if (!token) return setError('Please complete the captcha.');
// captchaRef.current.reset();

// await axios
// .post('https://dummy-api-phi.vercel.app/api/reCaptcha', { token })
// .then((res) => {
// if (res.status === 200) {
// sendEmail(e, (error) => {
// if (error) {
// setSendStatus('error');
// } else {
// setSendStatus('success');
// }
// });
// } else {
// setError('Failed to send email. Please try again.');
// }
// })
// .catch((error) => {
// console.log(error);
// setError('Failed to send email. Please try again.');
// });
// }
}

return (
Expand Down Expand Up @@ -151,10 +159,10 @@ export default function App() {
)}
</div>

<ReCAPTCHA
{/* <ReCAPTCHA
ref={captchaRef}
sitekey={import.meta.env.VITE_RECAPTCHA_SITE_KEY}
/>
/> */}
</form>
</section>
</main>
Expand Down

0 comments on commit 831a097

Please sign in to comment.