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 104b7a1 commit 8c907a3
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 9 deletions.
152 changes: 152 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@emailjs/browser": "^4.1.0",
"axios": "^1.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-google-recaptcha": "^3.1.0"
Expand Down
37 changes: 28 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ReCAPTCHA from 'react-google-recaptcha';
import { useState } from 'react';
import ReCAPTCHA, { ReCAPTCHAProps } from 'react-google-recaptcha';

Check failure on line 1 in src/App.tsx

View workflow job for this annotation

GitHub Actions / deploy

'ReCAPTCHAProps' is declared but its value is never read.
import { useRef, useState } from 'react';
import useForm from './useForm';
import axios from 'axios';

type TStatus = 'success' | 'error' | null;

Expand All @@ -10,9 +11,11 @@ export default function App() {
const [sendStatus, setSendStatus] = useState<TStatus>(null);
const [error, setError] = useState<null | string>(null);
const { sendEmail } = useForm();
const captchaRef = useRef<React.LegacyRef<ReCAPTCHA> | null>(null);

function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();

setError(null);
setEmail(email.trim());
if (email === '') {
Expand All @@ -24,13 +27,28 @@ export default function App() {
return;
}

sendEmail(e, (error) => {
if (error) {
setSendStatus('error');
} else {
setSendStatus('success');
}
});
if (captchaRef?.current && typeof captchaRef.current !== 'string') {
// @ts-ignore
const token = captchaRef.current.getValue();
// @ts-ignore
captchaRef.current.reset();

axios
.post('https://dummy-api-phi.vercel.app/api/reCaptcha', { token })
.then((res) => console.log(res))
.catch((error) => {
console.log(error);
});
return;

sendEmail(e, (error) => {
if (error) {
setSendStatus('error');
} else {
setSendStatus('success');
}
});
}
}

return (
Expand Down Expand Up @@ -103,6 +121,7 @@ export default function App() {
></textarea>

<ReCAPTCHA
ref={captchaRef}

Check failure on line 124 in src/App.tsx

View workflow job for this annotation

GitHub Actions / deploy

No overload matches this call.
sitekey={import.meta.env.VITE_RECAPTCHA_SITE_KEY}
onChange={(value) => {
console.log('Captcha value:', value);
Expand Down

0 comments on commit 8c907a3

Please sign in to comment.