2020-01-18 02:07:52 +05:30
|
|
|
import React, { ComponentType, useEffect } from 'react';
|
|
|
|
|
|
|
|
import { resolve as resolveError } from 'app/services/errorsDict';
|
|
|
|
import { PanelBodyHeader } from 'app/components/ui/Panel';
|
|
|
|
import { ValidationError } from 'app/components/ui/form/FormModel';
|
|
|
|
|
|
|
|
interface Props {
|
2020-05-24 04:38:24 +05:30
|
|
|
error: ValidationError;
|
|
|
|
onClose?: () => void;
|
2020-01-18 02:07:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
let autoHideTimer: number | null = null;
|
|
|
|
function resetTimeout(): void {
|
2020-05-24 04:38:24 +05:30
|
|
|
if (autoHideTimer) {
|
|
|
|
clearTimeout(autoHideTimer);
|
|
|
|
autoHideTimer = null;
|
|
|
|
}
|
2020-01-18 02:07:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
const AuthError: ComponentType<Props> = ({ error, onClose }) => {
|
2020-05-24 04:38:24 +05:30
|
|
|
useEffect(() => {
|
|
|
|
resetTimeout();
|
|
|
|
|
|
|
|
if (onClose && typeof error !== 'string' && error.payload && error.payload.canRepeatIn) {
|
|
|
|
const msLeft = error.payload.canRepeatIn * 1000;
|
|
|
|
// 1500 to let the user see, that time is elapsed
|
|
|
|
setTimeout(onClose, msLeft - Date.now() + 1500);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resetTimeout;
|
|
|
|
}, [error, onClose]);
|
|
|
|
|
|
|
|
return (
|
2024-12-18 03:41:39 +05:30
|
|
|
<PanelBodyHeader type="error" onClose={onClose} data-testid="auth-error">
|
2020-05-24 04:38:24 +05:30
|
|
|
{resolveError(error)}
|
|
|
|
</PanelBodyHeader>
|
|
|
|
);
|
2020-01-18 02:07:52 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export default AuthError;
|