0.1.3 • Published 6 years ago
bizly-status-notifications v0.1.3
bizly-status-notifications
- npm --save
bizly-status-notifications
- in the root reducer
import { bizlyStatusReducer } from 'bizly-status-notifications'
and then add new storebizlyStatus: bizlyStatusReducer
- in the main layout add the
<StatusBanner />
component (it will be hidden until one of the actions trigger it).import StatusBanner from 'bizly-status-notifications'
- in your app actions now you can
import { pendingStatusNotification, successStatusNotification, failStatusNotification } from 'bizly-status-notifications'
and then calldispatch(pendingStatusNotification())
or any other actions when needed.
Options
dispatch(pendingStatusNotification())
has no options, it should be dispatched for pending statusdispatch(successStatusNotification())
accepts either array of strings or just a string, default message isYour changes have been saved
dispatch(failStatusNotification())
accepts either array of strings or just a string, default message isError sending data
of strings or just a string, default message isError sending data
Example
export function createCardStart(values) {
return (dispatch) => {
dispatch({ type: 'CREATE_CARD_START' });
dispatch(pendingStatusNotification());
return axios({
url: '/api/creditcards',
method: 'post',
data: values,
})
.then((response) => {
dispatch(createCardSuccess({
data: response.data.data,
}));
dispatch(successStatusNotification('Card successfully added'));
return response.data;
})
.catch((error) => {
dispatch(createCardFail(error.response));
dispatch(failStatusNotification(['There was an error', 'Please check your card and try again']));
return error;
});
};
}