UNPKG

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.

80 lines (62 loc) 2.1 kB
import constants from '../constants'; import { unauthorized } from './generic'; import { getLastOrganizations, current, getById } from '../data/organization'; import fake from '../../iso/entity/fake'; var requestGenericLastOrganizations = () => { return { type: constants.organization.REQUEST_GENERIC_LAST_ORGANIZATIONS }; }; var receiveGenericLastOrganizations = ( orgs, page, fake ) => { if( !page ) { page = 0; } return { type: constants.organization.RECEIVE_GENERIC_LAST_ORGANIZATIONS, data: { organizations: orgs, fake: fake, nextPage: (page + 1 ) } }; }; var invalidGenericLastOrganizations = () => { return { type: constants.organization.INVALID_GENERIC_LAST_ORGANIZATIONS }; }; var requestCurrentOrganization = () => { return { type: constants.organization.REQUEST_CURRENT_ORGANIZATION }; }; var receiveCurrentOrganization = ( org ) => { return { type: constants.organization.RECEIVE_CURRENT_ORGANIZATION, data: { org: org } }; }; export function fetchCurrentOrganization() { return function( dispatch ) { dispatch( requestCurrentOrganization() ); current().then( ( org ) => { getById( org.Id ).then( ( orgEntity ) => { org.entity = orgEntity; dispatch( receiveCurrentOrganization( org ) ); } ); } ); }; } export function fetchGenericLastOrganizations( pageNumber ) { return function( dispatch ) { dispatch( requestGenericLastOrganizations() ); return getLastOrganizations( pageNumber || 0 ).then( function( resp ) { if( !resp || resp.length === 0 && ( !pageNumber || pageNumber === 0 ) ) { return dispatch( receiveGenericLastOrganizations( fake.organization, pageNumber, true ) ); } dispatch( receiveGenericLastOrganizations( resp, pageNumber ) ); } ).catch( unauthorized( dispatch, invalidGenericLastOrganizations ) ); }; }