Просмотр исходного кода

avoid double click from changing password form

web_access_fix
Jason Chuang 21 часов назад
Родитель
Сommit
40dd3d56ec
1 измененных файлов: 15 добавлений и 4 удалений
  1. +15
    -4
      src/pages/User/ChangePasswordPage/index.js

+ 15
- 4
src/pages/User/ChangePasswordPage/index.js Просмотреть файл

@@ -51,6 +51,8 @@ const Index = () => {
const [expiryErr, setExpiryErr] = React.useState(false); const [expiryErr, setExpiryErr] = React.useState(false);
const [expiryErrText, setExpiryErrText] = React.useState(""); const [expiryErrText, setExpiryErrText] = React.useState("");
const [changePasswordValues, setChangePasswordValues] = React.useState(); const [changePasswordValues, setChangePasswordValues] = React.useState();
const [isChangingPassword, setIsChangingPassword] = React.useState(false);
const changePwdInFlightRef = React.useRef(false);


const intl = useIntl(); const intl = useIntl();
@@ -59,8 +61,12 @@ const Index = () => {
}, []); }, []);


const goLogin = (values) =>{ const goLogin = (values) =>{
// console.log(values)
setComfirmChangeMessage(false)
if (changePwdInFlightRef.current) {
return;
}
changePwdInFlightRef.current = true;
setIsChangingPassword(true);
setComfirmChangeMessage(false);
HttpUtils.post({ HttpUtils.post({
url: UrlUtils.PATCH_CHANGE_PASSWORD, url: UrlUtils.PATCH_CHANGE_PASSWORD,
params:{ params:{
@@ -69,11 +75,15 @@ const Index = () => {
}, },
onSuccess: function (){ onSuccess: function (){
setIsChanged(true); setIsChanged(true);
changePwdInFlightRef.current = false;
setIsChangingPassword(false);
}, },
onError:function (error) { onError:function (error) {
// console.log(error.response.data); // console.log(error.response.data);
setExpiryErrText(intl.formatMessage({ id: error.response.data.error })) setExpiryErrText(intl.formatMessage({ id: error.response.data.error }))
setExpiryErr(true) setExpiryErr(true)
changePwdInFlightRef.current = false;
setIsChangingPassword(false);
// window.location.assign("/iamsmart/loginFail"); // window.location.assign("/iamsmart/loginFail");
} }
}); });
@@ -395,6 +405,7 @@ const Index = () => {
aria-label={intl.formatMessage({id: 'confirm'})} aria-label={intl.formatMessage({id: 'confirm'})}
variant="contained" variant="contained"
type="submit" type="submit"
disabled={isChangingPassword}
// onClick={()=>goLogin()} // onClick={()=>goLogin()}
> >
<FormattedMessage id="confirm"/> <FormattedMessage id="confirm"/>
@@ -423,12 +434,12 @@ const Index = () => {
</Stack> </Stack>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={() => setComfirmChangeMessage(false)}>
<Button disabled={isChangingPassword} onClick={() => setComfirmChangeMessage(false)}>
<Typography variant="h5"> <Typography variant="h5">
<FormattedMessage id="close"/> <FormattedMessage id="close"/>
</Typography> </Typography>
</Button> </Button>
<Button onClick={() => goLogin(changePasswordValues)}>
<Button disabled={isChangingPassword} onClick={() => goLogin(changePasswordValues)}>
<Typography variant="h5"> <Typography variant="h5">
<FormattedMessage id="confirm"/> <FormattedMessage id="confirm"/>
</Typography> </Typography>


Загрузка…
Отмена
Сохранить