Merge 3f06711501
into fdd7bf41c0
This commit is contained in:
commit
2849908c91
@ -3,13 +3,13 @@ import { useSelector } from 'react-redux';
|
|||||||
import useRegister from 'hooks/useRegister';
|
import useRegister from 'hooks/useRegister';
|
||||||
import Turnstile from 'react-turnstile';
|
import Turnstile from 'react-turnstile';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
// import { useSelector } from 'react-redux';
|
|
||||||
|
|
||||||
// material-ui
|
// material-ui
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
Grid,
|
Grid,
|
||||||
@ -50,6 +50,9 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
const [strength, setStrength] = useState(0);
|
const [strength, setStrength] = useState(0);
|
||||||
const [level, setLevel] = useState();
|
const [level, setLevel] = useState();
|
||||||
|
|
||||||
|
const [timer, setTimer] = useState(0);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const handleClickShowPassword = () => {
|
const handleClickShowPassword = () => {
|
||||||
setShowPassword(!showPassword);
|
setShowPassword(!showPassword);
|
||||||
};
|
};
|
||||||
@ -74,11 +77,17 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setLoading(true); // Start loading
|
||||||
|
|
||||||
const { success, message } = await sendVerificationCode(email, turnstileToken);
|
const { success, message } = await sendVerificationCode(email, turnstileToken);
|
||||||
|
setLoading(false); // Stop loading
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
showError(message);
|
showError(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimer(60); // Start the 60-second timer
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -94,6 +103,17 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
}
|
}
|
||||||
}, [siteInfo]);
|
}, [siteInfo]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let interval;
|
||||||
|
if (timer > 0) {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
setTimer((prevTimer) => prevTimer - 1);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [timer]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Formik
|
<Formik
|
||||||
@ -240,8 +260,13 @@ const RegisterForm = ({ ...others }) => {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
endAdornment={
|
endAdornment={
|
||||||
<InputAdornment position="end">
|
<InputAdornment position="end">
|
||||||
<Button variant="contained" color="primary" onClick={() => handleSendCode(values.email)}>
|
<Button
|
||||||
发送验证码
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={() => handleSendCode(values.email)}
|
||||||
|
disabled={timer > 0 || loading}
|
||||||
|
>
|
||||||
|
{loading ? <CircularProgress size={24} /> : timer > 0 ? `${timer}s` : '发送验证码'}
|
||||||
</Button>
|
</Button>
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user