UNPKG

cluedin-widget

Version:

This is the project for creating and managing widgets in CluedIn.

46 lines (37 loc) 1.06 kB
import constants from '../constants'; import { getBoarding } from '../data/boarding'; import { unauthorized } from './generic'; var shouldFetchBoarding = ( state ) => { return !(state.boardingInfo); }; var requestBoarding = () => { return { type: constants.boarding.REQUEST_BOARDING }; }; var receiveBoarding = ( boarding ) => { return { type: constants.boarding.RECEIVE_BOARDING, data: boarding }; }; var invalidBoarding = () => { return { type: constants.boarding.INVALID_BOARDING }; }; export function fetchBoarding( org ) { return function( dispatch ) { dispatch( requestBoarding() ); return getBoarding( org ).then( function( resp ) { dispatch( receiveBoarding( resp ) ); } ).catch( unauthorized( dispatch, invalidBoarding ) ); }; } export function shouldFetchBoardingIfNeeded( org ) { return ( dispatch, getState ) => { if ( shouldFetchBoarding( getState() ) ) { return dispatch( fetchBoarding( org ) ); } }; }