Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v5.3.0 #4678

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matters-web",
"version": "5.2.0",
"version": "5.3.0",
"description": "codebase of Matters' website",
"author": "Matters <hi@matters.town>",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/EmailLoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ export const EmailLoginForm: React.FC<FormProps> = ({

const InnerForm = (
<>
<ReCaptcha action="email_login" setToken={setTurnstileToken} />

<Form id={formId} onSubmit={handleSubmit}>
<Form.Input
label={<FormattedMessage defaultMessage="Email" id="sy+pv5" />}
Expand Down Expand Up @@ -344,6 +342,8 @@ export const EmailLoginForm: React.FC<FormProps> = ({
disabled={sendingCode}
/>
)}

<ReCaptcha action="email_login" setToken={setTurnstileToken} />
</Form>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/Forms/EmailSignUpForm/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const Init: React.FC<FormProps> = ({

const InnerForm = (
<Form id={formId} onSubmit={handleSubmit}>
<ReCaptcha action="register" setToken={setTurnstileToken} />
<Form.Input
label={<FormattedMessage defaultMessage="Email" id="sy+pv5" />}
type="email"
Expand All @@ -163,6 +162,8 @@ const Init: React.FC<FormProps> = ({
spacingBottom="base"
autoFocus
/>

<ReCaptcha action="register" setToken={setTurnstileToken} />
</Form>
)

Expand Down
59 changes: 37 additions & 22 deletions src/components/ReCaptcha/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useContext, useRef } from 'react'
import classNames from 'classnames'
import { useContext, useRef, useState } from 'react'
import { FormattedMessage } from 'react-intl'

import { toast, ViewerContext } from '~/components'

import styles from './styles.module.css'
import { Turnstile, TurnstileInstance } from './Turnstile'

export * from './Turnstile/types'
Expand All @@ -22,6 +24,7 @@ export const ReCaptcha: React.FC<ReCaptchaProps> = ({
}) => {
const viewer = useContext(ViewerContext)
const turnstileRef = useRef<TurnstileInstance>(null)
const [interaction, setInteraction] = useState(false)

const onError = () => {
if (silence) return
Expand All @@ -36,27 +39,39 @@ export const ReCaptcha: React.FC<ReCaptchaProps> = ({
})
}

const containerClasses = classNames({
[styles.container]: true,
[styles.interaction]: interaction,
})

return (
<Turnstile
ref={turnstileRef}
siteKey={siteKey}
options={{
action,
cData: `user-group-${viewer.info.group}`,
size: 'invisible',
}}
scriptOptions={{
compat: 'recaptcha',
appendTo: 'body',
}}
onSuccess={(token) => {
if (setToken) {
setToken(token)
}
}}
onError={onError}
onUnsupported={onError}
onExpire={() => turnstileRef.current?.reset()}
/>
<div className={containerClasses}>
<Turnstile
ref={turnstileRef}
siteKey={siteKey}
options={{
action,
cData: `user-group-${viewer.info.group}`,
size: 'normal',
theme: 'light',
appearance: 'interaction-only',
}}
scriptOptions={{
compat: 'recaptcha',
appendTo: 'body',
}}
onBeforeInteractive={() => {
setInteraction(true)
}}
onSuccess={(token) => {
if (setToken) {
setToken(token)
}
}}
onError={onError}
onUnsupported={onError}
onExpire={() => turnstileRef.current?.reset()}
/>
</div>
)
}
9 changes: 9 additions & 0 deletions src/components/ReCaptcha/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.container {
@mixin flex-center-all;

margin-top: var(--sp12);

&:not(.interaction) {
display: none;
}
}
Loading