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.
48 lines (39 loc) • 1.38 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { getLastDocuments } from '../data/document';
import entityFake from '../../iso/entity/fake';
const requestGenericLastDocuments = (timeStamp) => ({
type: constants.document.REQUEST_GENERIC_LAST_DOCUMENTS,
data: {
timeStamp,
},
});
const receiveGenericLastDocuments = (documents, page, fake, timeStamp) => {
const pageResult = page || 0;
return {
type: constants.document.RECEIVE_GENERIC_LAST_DOCUMENTS,
data: {
documents,
isFake: fake,
pageNumber: (pageResult + 1),
timeStamp,
},
};
};
const invalidGenericLastDocuments = () => ({
type: constants.document.INVALID_GENERIC_LAST_DOCUMENTS,
});
export function fetchGenericLastDocuments(id, timeStamp) {
return (dispatch, getState) => {
dispatch(requestGenericLastDocuments(timeStamp));
const pageNumber = getState().document.pageNumber;
return getLastDocuments(pageNumber || 0, id).then((resp) => {
if (!resp || resp.length === 0 && (!pageNumber || pageNumber === 0)) {
return dispatch(
receiveGenericLastDocuments(entityFake.document, pageNumber, true, timeStamp)
);
}
return dispatch(receiveGenericLastDocuments(resp, pageNumber, false, timeStamp));
}).catch(unauthorized(dispatch, invalidGenericLastDocuments));
};
}