cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
133 lines (105 loc) • 3.23 kB
JavaScript
import constants from '../constants';
import { getBoarding, hasVisited, hasSearched, allInvitations } 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
};
};
var requestAllInvitations = () => {
return {
type: constants.boarding.REQUEST_INVITATIONS
}
};
var invalidAllInvitations = () => {
return {
type: constants.boarding.INVALID_INVITATIONS
};
};
var receiveAllInvitations = ( invitations ) => {
return {
type: constants.boarding.RECEIVE_INVITATIONS,
data: {
invitations: invitations
}
};
};
export function fetchAllInvitations( org ) {
return function( dispatch ) {
dispatch( requestAllInvitations() );
return allInvitations( org ).then( function( invitations ) {
dispatch( receiveAllInvitations( invitations ) );
} ).catch( unauthorized( dispatch, invalidAllInvitations ) );
};
}
export function fetchBoarding( org ) {
return function( dispatch ) {
dispatch( requestBoarding() );
return getBoarding( org ).then( function( resp ) {
dispatch( receiveBoarding( resp ) );
} ).catch( unauthorized( dispatch, invalidBoarding ) );
};
}
var receiveMarkAsVisited = () => {
return {
type: constants.boarding.RECEIVE_MARK_AS_VISITED
};
};
var invalidMarkAsVisited = () => {
return {
type: constants.boarding.INVALID_MARK_AS_VISITED
};
};
export function markAsVisited( org ) {
return function( dispatch ) {
dispatch( requestBoarding() );
return getBoarding( org ).then( function( boarding ) {
dispatch( receiveBoarding( boarding ) );
return hasVisited( boarding ).then( function( resp ) {
dispatch( receiveMarkAsVisited( resp ) );
} ).catch( unauthorized( dispatch, invalidMarkAsVisited ) );
} );
};
}
var receiveMarkAsSearched = () => {
return {
type: constants.boarding.RECEIVE_MARK_AS_SEARCHED
};
};
var invalidMarkAsSearched = () => {
return {
type: constants.boarding.INVALID_MARK_AS_SEARCHED
};
};
export function markAsSearched( org ) {
return function( dispatch ) {
dispatch( requestBoarding() );
return getBoarding( org ).then( function( boarding ) {
dispatch( receiveBoarding( boarding ) );
return hasSearched( boarding ).then( function( resp ) {
dispatch( receiveMarkAsSearched( resp ) );
} ).catch( unauthorized( dispatch, invalidMarkAsSearched ) );
} );
};
}
export function shouldFetchBoardingIfNeeded( org ) {
return ( dispatch, getState ) => {
if ( shouldFetchBoarding( getState() ) ) {
return dispatch( fetchBoarding( org ) );
}
};
}