recaptcha-2.tsx 757 B

1234567891011121314151617181920212223242526272829
  1. import { forwardRef } from 'react'
  2. import ReCAPTCHA from 'react-google-recaptcha'
  3. import getMeta from '@/utils/meta'
  4. import { ExposedSettings } from '../../../../types/exposed-settings'
  5. type Page = keyof ExposedSettings['recaptchaDisabled']
  6. export const ReCaptcha2 = forwardRef<
  7. ReCAPTCHA,
  8. { page: Page; onChange?: (token: string | null) => void }
  9. >(function ReCaptcha2({ page: site, onChange }, ref) {
  10. const { recaptchaSiteKey, recaptchaDisabled } = getMeta('ol-ExposedSettings')
  11. if (!recaptchaSiteKey) {
  12. return null
  13. }
  14. if (site && recaptchaDisabled[site]) {
  15. return null
  16. }
  17. return (
  18. <ReCAPTCHA
  19. ref={ref}
  20. size="invisible"
  21. sitekey={recaptchaSiteKey}
  22. onChange={onChange}
  23. badge="inline"
  24. />
  25. )
  26. })