overleaf/services/web/frontend/js/shared/components/recaptcha-2.tsx
Jakob Ackermann aa480a2663 Merge pull request #18898 from overleaf/jpa-no-window
[web] migrate from window attributes to getMeta

GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
2024-06-19 08:04:21 +00:00

29 lines
757 B
TypeScript

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