feat: Fix axios interceptors.

This commit is contained in:
Ahmed Bouhuolia
2020-05-26 17:51:00 +02:00
parent dd49774f93
commit 72ba394c53
15 changed files with 369 additions and 223 deletions

View File

@@ -66,7 +66,6 @@ function Login({
crediential: values.crediential,
password: values.password,
}).then(() => {
history.go('/homepage');
setSubmitting(false);
}).catch((errors) => {
const toastBuilders = [];

View File

@@ -0,0 +1,11 @@
import { isAuthenticated } from 'store/authentication/authentication.reducer'
import { connect } from 'react-redux';
const mapStateToProps = (state) => {
return {
isAuthorized: isAuthenticated(state),
};
};
export default connect(mapStateToProps);

View File

@@ -0,0 +1,47 @@
import { Intent } from '@blueprintjs/core';
import { useIntl } from 'react-intl';
import AppToaster from 'components/AppToaster';
import withGlobalErrors from './withGlobalErrors';
import withGlobalErrorsActions from './withGlobalErrorsActions';
import { compose } from 'utils';
let toastKeySessionExpired;
let toastKeySomethingWrong;
function GlobalErrors({
// #withGlobalErrors
globalErrors,
// #withGlobalErrorsActions
globalErrorsSet,
}) {
const { formatMessage } = useIntl();
if (globalErrors.something_wrong) {
toastKeySessionExpired = AppToaster.show({
message: formatMessage({ id: 'ops_something_went_wrong' }),
intent: Intent.DANGER,
onDismiss: () => {
globalErrorsSet({ something_wrong: false });
}
}, toastKeySessionExpired);
}
if (globalErrors.session_expired) {
toastKeySomethingWrong = AppToaster.show({
message: formatMessage({ id: 'session_expired' }),
intent: Intent.DANGER,
onDismiss: () => {
globalErrorsSet({ session_expired: false });
}
}, toastKeySomethingWrong);
}
return null;
}
export default compose(
withGlobalErrors,
withGlobalErrorsActions,
)(GlobalErrors);

View File

@@ -0,0 +1,10 @@
import { connect } from 'react-redux';
const mapStateToProps = (state) => {
return {
globalErrors: state.globalErrors.data,
};
};
export default connect(mapStateToProps);

View File

@@ -0,0 +1,9 @@
import {connect} from 'react-redux';
import { setGlobalErrors } from 'store/globalErrors/globalErrors.actions';
import t from 'store/types';
export const mapDispatchToProps = (dispatch) => ({
globalErrorsSet: (errors) => dispatch(setGlobalErrors(errors)),
});
export default connect(null, mapDispatchToProps);