0.1.3 • Published 6 years ago

bizly-status-notifications v0.1.3

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

bizly-status-notifications

  1. npm --save bizly-status-notifications
  2. in the root reducer import { bizlyStatusReducer } from 'bizly-status-notifications' and then add new store bizlyStatus: bizlyStatusReducer
  3. 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'
  4. in your app actions now you can import { pendingStatusNotification, successStatusNotification, failStatusNotification } from 'bizly-status-notifications' and then call dispatch(pendingStatusNotification()) or any other actions when needed.

Options

  • dispatch(pendingStatusNotification()) has no options, it should be dispatched for pending status
  • dispatch(successStatusNotification()) accepts either array of strings or just a string, default message is Your changes have been saved
  • dispatch(failStatusNotification()) accepts either array of strings or just a string, default message is Error sending data of strings or just a string, default message is Error 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;
    });
  };
}
0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago