diff --git a/src/pages/authentication/BusRegister.js b/src/pages/authentication/BusRegister.js index e224cb0..ad248a5 100644 --- a/src/pages/authentication/BusRegister.js +++ b/src/pages/authentication/BusRegister.js @@ -10,7 +10,7 @@ import { Stack, Typography, Button, StepLabel, - + CircularProgress, } from '@mui/material'; import VisibilityIcon from '@mui/icons-material/Visibility'; @@ -32,9 +32,11 @@ const BusRegister = () => { const [completed, setCompleted] = useState([false]); const [updateValid, setUpdateValid] = useState(false); const step0GuardRef = useRef(null); + const nextBusyRef = useRef(false); const [username, setUsername] = useState("") const [base64Url, setBase64Url] = useState("") const [checkCode, setCheckCode] = useState("") + const [isNextBusy, setIsNextBusy] = useState(false); const intl = useIntl(); const steps = [ intl.formatMessage({id: 'personalInformation'}), @@ -98,30 +100,38 @@ const BusRegister = () => { } const handleNext = async () => { - if (activeStep === 0 && step0GuardRef.current) { - const step0Ok = await Promise.resolve(step0GuardRef.current()); - if (!step0Ok) { + if (nextBusyRef.current) return; + nextBusyRef.current = true; + setIsNextBusy(true); + try { + if (activeStep === 0 && step0GuardRef.current) { + const step0Ok = await Promise.resolve(step0GuardRef.current()); + if (!step0Ok) { + return; + } + } + const captchaTest = await handleCaptcha(); + if (!captchaTest) { + notifyActionError(intl.formatMessage({id: 'validVerify'})) return; } - } - const captchaTest = await handleCaptcha(); - if (!captchaTest) { - notifyActionError(intl.formatMessage({id: 'validVerify'})) - return; - } - const test = await handleCheckUsername() - if (test) { - notifyActionError(intl.formatMessage({id: 'usernameTaken'})) - } else { - const newActiveStep = - isLastStep() && !allStepsCompleted() - ? // It's the last step, but not all steps have been completed, - // find the first step that has been completed - steps.findIndex((step, i) => !(i in completed)) - : activeStep + 1; - setActiveStep(newActiveStep); - scrollToTop(); + const test = await handleCheckUsername() + if (test) { + notifyActionError(intl.formatMessage({id: 'usernameTaken'})) + } else { + const newActiveStep = + isLastStep() && !allStepsCompleted() + ? // It's the last step, but not all steps have been completed, + // find the first step that has been completed + steps.findIndex((step, i) => !(i in completed)) + : activeStep + 1; + setActiveStep(newActiveStep); + scrollToTop(); + } + } finally { + nextBusyRef.current = false; + setIsNextBusy(false); } }; @@ -224,7 +234,7 @@ const BusRegister = () => { ) : ( ) : (activeStep === totalSteps() - 1 ? ( @@ -254,7 +274,7 @@ const BusRegister = () => { ) : ( // ) : (activeStep === totalSteps() - 1 ? ( @@ -243,7 +264,7 @@ const Register = () => { ) : ( // ) : (activeStep === totalSteps() - 1 ? ( @@ -259,7 +280,7 @@ const Register = () => { ) : ( //