cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
46 lines (37 loc) • 1.19 kB
JavaScript
import constants from '../constants';
import providerApi from '../data/provider';
import { unauthorized } from './generic';
var invalidActiveProviders = () => {
return {
type: constants.provider.INVALID_PROVIDER
};
};
var requestActiveProviders = () => {
return {
type: constants.provider.REQUEST_ACTIVE_PROVIDERS
}
};
var receiveActiveProviders = ( providers ) => {
return {
type: constants.provider.RECEIVE_ACTIVE_PROVIDERS,
data: providers
};
};
var fetchActiveProviders = () => {
return function( dispatch ) {
dispatch( requestActiveProviders() );
return providerApi.getCurrentProvider().then( function( resp ) {
dispatch( receiveActiveProviders( resp.body ) );
} ).catch( unauthorized( dispatch, invalidActiveProviders ) );
};
};
function shouldFetchActiveProviders( state ) {
return !( state.provider.providers && state.provider.providers.length > 0);
}
export function fetchActiveProvidersIfNeeded() {
return ( dispatch, getState ) => {
if ( shouldFetchActiveProviders( getState() ) ) {
return dispatch( fetchActiveProviders() )
}
}
}