overleaf/services/web/frontend/js/shared/components/recaptcha-2.tsx
Mathias Jakobsen af76768eb7 Merge pull request #13372 from overleaf/mj-captcha-add-email
[web] Add recaptcha to add-email

GitOrigin-RevId: 0540e0dbc3103dcaac87dd7fabeedbc5892c371c
2023-07-17 10:40:08 +00:00

27 lines
665 B
TypeScript

import { forwardRef } from 'react'
import ReCAPTCHA from 'react-google-recaptcha'
const siteKey = window.ExposedSettings.recaptchaSiteKey
const recaptchaDisabled = window.ExposedSettings.recaptchaDisabled
type Page = keyof typeof recaptchaDisabled
export const ReCaptcha2 = forwardRef<
ReCAPTCHA,
{ page: Page; onChange?: (token: string | null) => void }
>(function ReCaptcha2({ page: site, onChange }, ref) {
if (!siteKey) {
return null
}
if (site && recaptchaDisabled[site]) {
return null
}
return (
<ReCAPTCHA
ref={ref}
size="invisible"
sitekey={siteKey}
onChange={onChange}
badge="inline"
/>
)
})