2017-08-23 00:19:50 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React 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() {
|
2019-11-27 14:33:32 +05:30
|
|
|
if (autoHideTimer) {
|
|
|
|
clearTimeout(autoHideTimer);
|
|
|
|
autoHideTimer = null;
|
|
|
|
}
|
2016-05-22 19:31:31 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
export default function AuthError({ error, onClose = function() {} }) {
|
|
|
|
resetTimer();
|
2016-05-22 19:31:31 +05:30
|
|
|
|
2019-11-27 14:33:32 +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
|
|
|
|
}
|
2016-05-22 19:31:31 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<PanelBodyHeader
|
|
|
|
type="error"
|
|
|
|
onClose={() => {
|
|
|
|
resetTimer();
|
|
|
|
onClose();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{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 = {
|
2019-11-27 14:33:32 +05:30
|
|
|
error: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.shape({
|
|
|
|
type: PropTypes.string,
|
|
|
|
payload: PropTypes.object,
|
|
|
|
}),
|
|
|
|
]).isRequired,
|
|
|
|
onClose: PropTypes.func,
|
2016-05-02 13:36:25 +05:30
|
|
|
};
|