Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: recaptcha added #227

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ STRIPE_SECRET_KEY = "sk_test_51JJ3vNLOlCyqSHKrp2vu93c9YzrXxDq7otphDYZqQTE10eZ0Gs
CANCEL_URL = "https://helpafamily.margaritahumanitarian.org/"
SUCCESS_URL = "https://helpafamily.margaritahumanitarian.org/thank-you"
NEXT_PUBLIC_GMAPS_JS_API_KEY = "<your Google Maps JavaScript API Key here>"

REACT_APP_SITE_KEY='6LeSv6ccAAAAAGL98cTakxdX_lvAUe-D3SR06bXw'
akshitarora921 marked this conversation as resolved.
Show resolved Hide resolved

// Generate these values in the Firebase console:
// PROJECT SETTINGS > Firebase Admin SDK > Generate new private key
Expand Down
13 changes: 13 additions & 0 deletions components/MainDonationForm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ReCaptchaV2 from 'react-google-recaptcha';
import React from 'react';
import clsx from 'clsx';

Expand Down Expand Up @@ -35,6 +36,7 @@ export default function MainDonationForm() {
const [selectedCauses, setSelectedCauses] = React.useState({});
const [isAnyoneInNeed, setIsAnyoneInNeed] = React.useState(true);
const [cause, setCause] = React.useState('');
const [reCaptchaToken, setReCaptchaToken] = React.useState('');
const [handleSubmit, isPending] = useStripeSession();

React.useEffect(() => {
Expand Down Expand Up @@ -79,6 +81,11 @@ export default function MainDonationForm() {
return;
}

if (reCaptchaToken === '') {
showModal('Please submit the captcha');
return;
}

handleSubmit({ amount, cause });
};

Expand Down Expand Up @@ -115,6 +122,12 @@ export default function MainDonationForm() {
options={AMOUNTS}
value={amount}
/>
<ReCaptchaV2
id="captcha"
onChange={(token) => setReCaptchaToken(token)}
onExpired={() => setReCaptchaToken('')}
sitekey={'6LcjyaccAAAAAAjE2z6vBhs2tOdhC-t0F2OCMj7z'} //need to use env variables process.env.REACT_APP_SITE_KEY
akshitarora921 marked this conversation as resolved.
Show resolved Hide resolved
/>
<button
className={clsx('btn btn-primary', { loading: isPending })}
type="submit"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-google-maps": "^9.4.5",
"react-google-recaptcha": "^2.1.0",
"react-icons": "^4.2.0",
"react-lottie": "^1.2.3",
"stripe": "^8.168.0"
Expand Down
27 changes: 25 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,13 @@ hoist-non-react-statics@^2.3.1:
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"
integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==

hoist-non-react-statics@^3.3.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

hosted-git-info@^2.1.4:
version "2.8.9"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
Expand Down Expand Up @@ -5414,7 +5421,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.5.8, prop-types@^15.7.2:
prop-types@^15.5.0, prop-types@^15.5.8, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -5575,6 +5582,14 @@ [email protected]:
iconv-lite "0.4.24"
unpipe "1.0.0"

react-async-script@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-async-script/-/react-async-script-1.2.0.tgz#ab9412a26f0b83f5e2e00de1d2befc9400834b21"
integrity sha512-bCpkbm9JiAuMGhkqoAiC0lLkb40DJ0HOEJIku+9JDjxX3Rcs+ztEOG13wbrOskt3n2DTrjshhaQ/iay+SnGg5Q==
dependencies:
hoist-non-react-statics "^3.3.0"
prop-types "^15.5.0"

react-dom@^17.0.2:
version "17.0.2"
resolved "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz"
Expand All @@ -5601,6 +5616,14 @@ react-google-maps@^9.4.5:
scriptjs "^2.5.8"
warning "^3.0.0"

react-google-recaptcha@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-google-recaptcha/-/react-google-recaptcha-2.1.0.tgz#9f6f4954ce49c1dedabc2c532347321d892d0a16"
integrity sha512-K9jr7e0CWFigi8KxC3WPvNqZZ47df2RrMAta6KmRoE4RUi7Ys6NmNjytpXpg4HI/svmQJLKR+PncEPaNJ98DqQ==
dependencies:
prop-types "^15.5.0"
react-async-script "^1.1.1"

react-icons@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.2.0.tgz#6dda80c8a8f338ff96a1851424d63083282630d0"
Expand All @@ -5611,7 +5634,7 @@ [email protected], "react-is@^16.12.0 || ^17.0.0", react-is@^17.0.1, react-is@^17.
resolved "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==

react-is@^16.8.1:
react-is@^16.7.0, react-is@^16.8.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
Expand Down