-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALD-11 | Add reCAPTCHA component (#198)
* feat: remove stuff * chore: allow conditionally recaptcha and call submit when completes * feat: separate recaptcha into component and added tests * feat: get recaptcha key from question data * feat: add ReCAPTCHA usage info to readme * feat: add imports * fix: address comments --------- Co-authored-by: Jesus Sabroso <jesussabroso@one-beyonds.com>
- Loading branch information
1 parent
1499d19
commit d166e60
Showing
9 changed files
with
222 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
|
||
import QuestionRecaptcha from '..' | ||
|
||
const formDataValues = {} | ||
const recaptchaRef = React.createRef(null) | ||
const onSubmitForm = () => {} | ||
const question = { | ||
name: 'recaptcha', | ||
type: 'recaptcha', | ||
recaptchaKey: 'random' | ||
} | ||
|
||
test('renders a reCAPTCHA', () => { | ||
const { getByTestId } = render( | ||
<QuestionRecaptcha | ||
ref={recaptchaRef} | ||
formDataValues={formDataValues} | ||
onSubmitForm={onSubmitForm} | ||
question={question} | ||
/> | ||
) | ||
|
||
expect(getByTestId('recaptcha-test')).toBeTruthy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { forwardRef } from 'react' | ||
import ReCAPTCHA from 'react-google-recaptcha' | ||
|
||
/** @jsxRuntime classic */ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui' | ||
|
||
const QuestionRecaptcha = forwardRef(({ formDataValues, onSubmitForm, question }, ref) => { | ||
const onReCAPTCHAChange = async (captchaCode) => { | ||
if (!captchaCode) { | ||
return | ||
} | ||
|
||
ref?.current?.reset() | ||
onSubmitForm(formDataValues) | ||
} | ||
|
||
return ( | ||
<ReCAPTCHA | ||
ref={ref} | ||
size="invisible" | ||
sitekey={question.recaptchaKey} | ||
onChange={onReCAPTCHAChange} | ||
data-testid="recaptcha-test" | ||
/> | ||
) | ||
}) | ||
|
||
export default QuestionRecaptcha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.