Redux changes and refactoring
This commit is contained in:
45
src/redux/actions/error_actions.js
Normal file
45
src/redux/actions/error_actions.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import {showWindow, shutdownApplication} from './common_actions';
|
||||
|
||||
let ErrorActions = [];
|
||||
|
||||
export const CLEAR_ERROR = 'error/clearError';
|
||||
export const clearError = () => {
|
||||
return {
|
||||
type: CLEAR_ERROR,
|
||||
payload: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const dismissError = () => {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(clearError());
|
||||
const errorAction = ErrorActions[0];
|
||||
ErrorActions = ErrorActions.splice(1);
|
||||
if (errorAction) {
|
||||
errorAction();
|
||||
}
|
||||
if (getState().error.ErrorCritical) {
|
||||
dispatch(shutdownApplication());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const notifyError = (msg, critical, callback) => {
|
||||
return dispatch => {
|
||||
ErrorActions = [callback, ...ErrorActions];
|
||||
msg = msg.toString();
|
||||
dispatch(setErrorInfo(msg, critical));
|
||||
dispatch(showWindow());
|
||||
};
|
||||
};
|
||||
|
||||
export const SET_ERROR_INFO = 'error/setErrorInfo';
|
||||
export const setErrorInfo = (msg, critical) => {
|
||||
return {
|
||||
type: SET_ERROR_INFO,
|
||||
payload: {
|
||||
msg,
|
||||
critical
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user