cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
49 lines (38 loc) • 1.26 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { getLastDeals } from '../data/deals';
import fake from '../../iso/entity/fake';
var requestGenericLastDeals = () => {
return {
type: constants.deal.REQUEST_GENERIC_LAST_DEALS
};
};
var receiveGenericLastDeals = ( deals, page, fake ) => {
if ( !page ) {
page = 0;
}
return {
type: constants.deal.RECEIVE_GENERIC_LAST_DEALS,
data: {
deals: deals,
isFake: fake,
nextPage: (page + 1 )
}
};
};
var invalidGenericLastDeals = () => {
return {
type: constants.deal.INVALID_GENERIC_LAST_DEALS
};
};
export function fetchGenericLastDeals( pageNumber ) {
return function( dispatch ) {
dispatch( requestGenericLastDeals() );
return getLastDeals( pageNumber || 0 ).then( function( resp ) {
if ( !resp || resp.length === 0 && ( !pageNumber || pageNumber === 0 ) ) {
return dispatch( receiveGenericLastDeals( fake.deal || [], pageNumber, true ) );
}
dispatch( receiveGenericLastDeals( resp, pageNumber ) );
} ).catch( unauthorized( dispatch, invalidGenericLastDeals ) );
};
}