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.
46 lines (37 loc) • 1.3 kB
JavaScript
import constants from '../constants';
import { unauthorized } from './generic';
import { getLastGenericIssues } from '../data/issue';
import fake from '../../iso/entity/fake';
const requestGenericLastIssues = (timeStamp) => ({
type: constants.issue.REQUEST_GENERIC_LAST_ISSUES,
data: {
timeStamp,
},
});
const receiveGenericLastIssues = (issues, page, isFake, timeStamp) => {
const pageResult = page || 0;
return {
type: constants.issue.RECEIVE_GENERIC_LAST_ISSUES,
data: {
issues,
isFake,
pageNumber: (pageResult + 1),
timeStamp,
},
};
};
const invalidGenericLastIssues = () => ({
type: constants.issue.INVALID_GENERIC_LAST_ISSUES,
});
export function fetchGenericLastIssues(id, timeStamp) {
return (dispatch, getState) => {
dispatch(requestGenericLastIssues(timeStamp));
const pageNumber = getState().issue.pageNumber;
return getLastGenericIssues(pageNumber || 0, id).then((resp) => {
if (!resp || resp.length === 0 && (!pageNumber || pageNumber === 0)) {
return dispatch(receiveGenericLastIssues(fake.issue, pageNumber, true, timeStamp));
}
return dispatch(receiveGenericLastIssues(resp, pageNumber, false, timeStamp));
}).catch(unauthorized(dispatch, invalidGenericLastIssues));
};
}