cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
51 lines (38 loc) • 1.35 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { getLastDocuments } from '../data/document';
import fake from '../../iso/entity/fake';
var requestGenericLastDocuments = () => {
return {
type: constants.document.REQUEST_GENERIC_LAST_DOCUMENTS
};
};
var receiveGenericLastDocuments = ( documents, page, fake ) => {
if ( !page ) {
page = 0;
}
return {
type: constants.document.RECEIVE_GENERIC_LAST_DOCUMENTS,
data: {
documents: documents,
isFake: fake,
nextPage: (page + 1 )
}
};
};
var invalidGenericLastDocuments = () => {
return {
type: constants.document.INVALID_GENERIC_LAST_DOCUMENTS
};
};
export function fetchGenericLastDocuments( pageNumber, id ) {
return function( dispatch ) {
dispatch( requestGenericLastDocuments() );
return getLastDocuments( pageNumber || 0, id ).then( function( resp ) {
if ( !resp || resp.length === 0 && ( !pageNumber || pageNumber === 0 ) ) {
return dispatch( receiveGenericLastDocuments( fake.document, pageNumber, true ) );
}
dispatch( receiveGenericLastDocuments( resp, pageNumber ) );
} ).catch( unauthorized( dispatch, invalidGenericLastDocuments ) );
};
};