2016-05-02 13:36:25 +05:30
|
|
|
import React, { PropTypes } from 'react';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2016-05-02 13:34:23 +05:30
|
|
|
import errorsDict from 'services/errorsDict';
|
2016-02-13 20:58:47 +05:30
|
|
|
import { PanelBodyHeader } from 'components/ui/Panel';
|
|
|
|
|
2016-05-22 19:31:31 +05:30
|
|
|
let autoHideTimer;
|
|
|
|
function resetTimer() {
|
|
|
|
if (autoHideTimer) {
|
|
|
|
clearTimeout(autoHideTimer);
|
|
|
|
autoHideTimer = null;
|
|
|
|
}
|
|
|
|
}
|
2016-05-02 13:36:25 +05:30
|
|
|
export default function AuthError({error, onClose = function() {}}) {
|
2016-05-22 19:31:31 +05:30
|
|
|
resetTimer();
|
|
|
|
|
2016-05-22 20:46:51 +05:30
|
|
|
if (error.payload && error.payload.canRepeatIn) {
|
2016-05-22 19:31:31 +05:30
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 13:36:25 +05:30
|
|
|
return (
|
2016-05-22 19:31:31 +05:30
|
|
|
<PanelBodyHeader type="error" onClose={() => {
|
|
|
|
resetTimer();
|
|
|
|
onClose();
|
|
|
|
}}>
|
2016-05-02 13:36:25 +05:30
|
|
|
{errorsDict.resolve(error)}
|
|
|
|
</PanelBodyHeader>
|
|
|
|
);
|
2016-02-13 20:58:47 +05:30
|
|
|
}
|
2016-05-02 13:36:25 +05:30
|
|
|
|
|
|
|
AuthError.displayName = 'AuthError';
|
|
|
|
AuthError.propTypes = {
|
2016-05-22 19:31:31 +05:30
|
|
|
error: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
|
|
type: PropTypes.string,
|
|
|
|
payload: PropTypes.object
|
|
|
|
})]).isRequired,
|
2016-05-02 13:36:25 +05:30
|
|
|
onClose: PropTypes.func
|
|
|
|
};
|