mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#26: email resend count down for forgot-password
This commit is contained in:
@@ -3,9 +3,30 @@ import React, { PropTypes } from 'react';
|
||||
import errorsDict from 'services/errorsDict';
|
||||
import { PanelBodyHeader } from 'components/ui/Panel';
|
||||
|
||||
let autoHideTimer;
|
||||
function resetTimer() {
|
||||
if (autoHideTimer) {
|
||||
clearTimeout(autoHideTimer);
|
||||
autoHideTimer = null;
|
||||
}
|
||||
}
|
||||
export default function AuthError({error, onClose = function() {}}) {
|
||||
resetTimer();
|
||||
|
||||
if (error.type === 'error.email_frequency') {
|
||||
if (error.payload && error.payload.canRepeatIn) {
|
||||
error.payload.msLeft = error.payload.canRepeatIn * 1000;
|
||||
setTimeout(onClose, error.payload.msLeft - Date.now() + 1500); // 1500 to let the user see, that time is elapsed
|
||||
} else {
|
||||
// TODO: it would be greate to log this case, when we will setup frontend logging
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PanelBodyHeader type="error" onClose={onClose}>
|
||||
<PanelBodyHeader type="error" onClose={() => {
|
||||
resetTimer();
|
||||
onClose();
|
||||
}}>
|
||||
{errorsDict.resolve(error)}
|
||||
</PanelBodyHeader>
|
||||
);
|
||||
@@ -13,6 +34,9 @@ export default function AuthError({error, onClose = function() {}}) {
|
||||
|
||||
AuthError.displayName = 'AuthError';
|
||||
AuthError.propTypes = {
|
||||
error: PropTypes.string.isRequired,
|
||||
error: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
||||
type: PropTypes.string,
|
||||
payload: PropTypes.object
|
||||
})]).isRequired,
|
||||
onClose: PropTypes.func
|
||||
};
|
||||
|
Reference in New Issue
Block a user