move Recaptcha to element

This commit is contained in:
Hongbo Wu
2024-04-08 11:45:53 +08:00
parent 73877ed9e8
commit 7e812ab8b2
2 changed files with 23 additions and 24 deletions

View File

@ -0,0 +1,19 @@
import { GoogleReCaptchaCheckbox } from '@google-recaptcha/react'
type RecaptchaProps = {
setRecaptchaToken: (token: string) => void
}
export const Recaptcha = (props: RecaptchaProps): JSX.Element => {
return (
<>
<GoogleReCaptchaCheckbox
key="recaptcha"
onChange={(token) => {
console.log('recaptcha: ', token)
props.setRecaptchaToken(token)
}}
/>
</>
)
}

View File

@ -10,19 +10,17 @@ import { logoutMutation } from '../../../lib/networking/mutations/logoutMutation
import { useRouter } from 'next/router'
import { formatMessage } from '../../../locales/en/messages'
import { parseErrorCodes } from '../../../lib/queryParamParser'
import {
GoogleReCaptchaProvider,
GoogleReCaptchaCheckbox,
} from '@google-recaptcha/react'
import Link from 'next/link'
import { Recaptcha } from '../../elements/Recaptcha'
const SignUpForm = (): JSX.Element => {
const [email, setEmail] = useState<string | undefined>()
const [password, setPassword] = useState<string | undefined>()
const [fullname, setFullname] = useState<string | undefined>()
const [username, setUsername] = useState<string | undefined>()
const [debouncedUsername, setDebouncedUsername] =
useState<string | undefined>()
const [debouncedUsername, setDebouncedUsername] = useState<
string | undefined
>()
const { isUsernameValid, usernameErrorMessage } = useValidateUsernameQuery({
username: debouncedUsername ?? '',
@ -126,24 +124,6 @@ const SignUpForm = (): JSX.Element => {
)
}
type RecaptchaProps = {
setRecaptchaToken: (token: string) => void
}
const Recaptcha = (props: RecaptchaProps): JSX.Element => {
return (
<>
<GoogleReCaptchaCheckbox
key="recaptcha"
onChange={(token) => {
console.log('recaptcha: ', token)
props.setRecaptchaToken(token)
}}
/>
</>
)
}
export function EmailSignup(): JSX.Element {
const router = useRouter()
const recaptchaTokenRef = useRef<HTMLInputElement>(null)