cluedin-widget
Version: 
This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.
50 lines (41 loc) • 1.33 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { getLastDeals } from '../data/deals';
import entityFake from '../../iso/entity/fake';
const requestGenericLastDeals = (timeStamp) => ({
  type: constants.deal.REQUEST_GENERIC_LAST_DEALS,
  data: {
    timeStamp,
  },
});
const receiveGenericLastDeals = (deals, page, fake, timeStamp) => {
  const pageResult = page || 0;
  return {
    type: constants.deal.RECEIVE_GENERIC_LAST_DEALS,
    data: {
      deals,
      isFake: fake,
      pageNumber: (pageResult + 1),
      timeStamp,
    },
  };
};
const invalidGenericLastDeals = () => ({
  type: constants.deal.INVALID_GENERIC_LAST_DEALS,
});
export function fetchGenericLastDeals(id, timeStamp) {
  return (dispatch, getState) => {
    dispatch(requestGenericLastDeals(timeStamp));
    const pageNumber = getState().deal.pageNumber;
    return getLastDeals(pageNumber || 0, id).then((resp) => {
      if (!resp || resp.length === 0 && (!pageNumber || pageNumber === 0)) {
        return dispatch(
          receiveGenericLastDeals(entityFake.deal || [],
            pageNumber,
            true,
            timeStamp));
      }
      return dispatch(receiveGenericLastDeals(resp, pageNumber, false, timeStamp));
    }).catch(unauthorized(dispatch, invalidGenericLastDeals));
  };
}