Updated Toast alerts, progress mvp

• Updated:
- Toast alerts
This commit is contained in:
mgabdev
2020-12-07 23:39:13 -05:00
parent 5422c013e1
commit 05c5dcb581
28 changed files with 205 additions and 109 deletions

View File

@@ -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)
}
}

View File

@@ -1,3 +1,4 @@
import isObject from 'lodash.isobject'
import { showLoading, hideLoading } from 'react-redux-loading-bar'
const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED']
@@ -5,8 +6,8 @@ const defaultTypeSuffixes = ['PENDING', 'FULFILLED', 'REJECTED']
export default function loadingBarMiddleware(config = {}) {
const promiseTypeSuffixes = config.promiseTypeSuffixes || defaultTypeSuffixes
return ({ dispatch }) => next => (action) => {
if (action.type && action.type.indexOf('TIMELINE') > -1) {
return ({ dispatch }) => (next) => (action) => {
if (isObject(action) && action.type && action.type.indexOf('TIMELINE') > -1) {
const [PENDING, FULFILLED, REJECTED] = promiseTypeSuffixes
const isPending = new RegExp(`${PENDING}$`, 'g')