recaptcha-2.tsx 928 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import ReCAPTCHA from 'react-google-recaptcha'
  2. import getMeta from '@/utils/meta'
  3. import { ExposedSettings } from '../../../../types/exposed-settings'
  4. interface ReCaptcha2Props extends Pick<
  5. React.ComponentProps<typeof ReCAPTCHA>,
  6. 'onChange'
  7. > {
  8. page: keyof ExposedSettings['recaptchaDisabled']
  9. recaptchaRef: React.LegacyRef<ReCAPTCHA>
  10. }
  11. export function ReCaptcha2({
  12. page: site,
  13. onChange,
  14. recaptchaRef,
  15. }: ReCaptcha2Props) {
  16. const { recaptchaSiteKey, recaptchaDisabled } = getMeta('ol-ExposedSettings')
  17. if (!recaptchaSiteKey) {
  18. return null
  19. }
  20. if (site && recaptchaDisabled[site]) {
  21. return null
  22. }
  23. if (process.env.NODE_ENV === 'development' && window.Cypress) {
  24. return null // Disable captcha for E2E tests in dev-env.
  25. }
  26. return (
  27. <ReCAPTCHA
  28. ref={recaptchaRef}
  29. size="invisible"
  30. sitekey={recaptchaSiteKey}
  31. onChange={onChange}
  32. badge="inline"
  33. />
  34. )
  35. }