Updated Toast alerts, progress mvp
• Updated: - Toast alerts
This commit is contained in:
@@ -1,18 +1,27 @@
|
||||
// import { showAlertForError } from '../actions/alerts';
|
||||
import isObject from 'lodash.isobject'
|
||||
import { showToast } from '../actions/toasts'
|
||||
import {
|
||||
TOAST_TYPE_ERROR,
|
||||
TOAST_TYPE_SUCCESS,
|
||||
} from '../constants'
|
||||
|
||||
const defaultFailSuffix = 'FAIL';
|
||||
const defaultSuccessSuffix = 'SUCCESS'
|
||||
const defaultFailSuffix = 'FAIL'
|
||||
|
||||
export default function errorsMiddleware() {
|
||||
return ({ dispatch }) => next => action => {
|
||||
// : todo : use skipAlert!
|
||||
if (action.type && !action.skipAlert) {
|
||||
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
|
||||
return ({ dispatch }) => (next) => (action) => {
|
||||
if (isObject(action) && action.type && action.showToast) {
|
||||
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g')
|
||||
const isSuccess = new RegExp(`${defaultSuccessSuffix}$`, 'g')
|
||||
|
||||
|
||||
if (action.type.match(isFail)) {
|
||||
// dispatch(showAlertForError(action.error));
|
||||
}
|
||||
dispatch(showToast(TOAST_TYPE_ERROR, action))
|
||||
} else if (action.type.match(isSuccess)) {
|
||||
dispatch(showToast(TOAST_TYPE_SUCCESS, action))
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
};
|
||||
return next(action)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user