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.
125 lines (99 loc) • 3.43 kB
JavaScript
import constants from '../constants';
import { getBoarding, hasVisited, hasSearched, allInvitations } from '../data/boarding';
import { unauthorized } from './generic';
import { storage } from '../config';
const shouldFetchBoarding = (state) => (!state.user.isBoardingFinishedCached && !state.boarding.boardingInfo);
const requestBoarding = () => ({
type: constants.boarding.REQUEST_BOARDING,
});
const receiveBoarding = (boarding) => ({
type: constants.boarding.RECEIVE_BOARDING,
data: boarding,
});
const invalidBoarding = () => ({
type: constants.boarding.INVALID_BOARDING,
});
const requestAllInvitations = () => ({
type: constants.boarding.REQUEST_INVITATIONS,
});
const invalidAllInvitations = () => ({
type: constants.boarding.INVALID_INVITATIONS,
});
const receiveAllInvitations = (invitations) => ({
type: constants.boarding.RECEIVE_INVITATIONS,
data: {
invitations,
},
});
export function fetchAllInvitations(org) {
return (dispatch) => {
dispatch(requestAllInvitations());
return allInvitations(org).then((invitations) => {
dispatch(receiveAllInvitations(invitations));
}).catch(unauthorized(dispatch, invalidAllInvitations));
};
}
export function fetchBoarding(org) {
return function fetchBoardingTransation(dispatch) {
dispatch(requestBoarding());
return getBoarding(org).then((resp) => {
dispatch(receiveBoarding(resp));
}).catch(unauthorized(dispatch, invalidBoarding));
};
}
const receiveMarkAsVisited = () => ({
type: constants.boarding.RECEIVE_MARK_AS_VISITED,
});
const invalidMarkAsVisited = () => ({
type: constants.boarding.INVALID_MARK_AS_VISITED,
});
const requestMarkHasVisited = () => ({
type: constants.boarding.REQUEST_MARK_AS_VISISTED,
});
export function markAsVisited(org) {
return function markAsVisitedTransation(dispatch, getState) {
if (getState().boarding.boardingInfo) {
dispatch(requestMarkHasVisited());
return hasVisited(getState().boarding.boardingInfo).then((resp) => {
dispatch(receiveMarkAsVisited(resp));
}).catch(unauthorized(dispatch, invalidMarkAsVisited));
}
dispatch(requestBoarding());
return getBoarding(org).then((boarding) => {
dispatch(receiveBoarding(boarding));
dispatch(requestMarkHasVisited());
return hasVisited(boarding).then((resp) => {
storage.markEntityPageVisister();
dispatch(receiveMarkAsVisited(resp));
}).catch(unauthorized(dispatch, invalidMarkAsVisited));
});
};
}
const receiveMarkAsSearched = () => ({
type: constants.boarding.RECEIVE_MARK_AS_SEARCHED,
});
const invalidMarkAsSearched = () => ({
type: constants.boarding.INVALID_MARK_AS_SEARCHED,
});
const requestMarkAsSearched = () => ({
type: constants.boarding.REQUEST_MARK_AS_SEARCHED,
});
export function markAsSearched(org) {
return function markAsSearchedTransaction(dispatch) {
return getBoarding(org).then((boarding) => {
dispatch(receiveBoarding(boarding));
dispatch(requestMarkAsSearched());
return hasSearched(boarding).then((resp) => {
storage.markSearchAsDone();
dispatch(receiveMarkAsSearched(resp));
}).catch(unauthorized(dispatch, invalidMarkAsSearched));
});
};
}
export function shouldFetchBoardingIfNeeded(org) {
return (dispatch, getState) => {
if (shouldFetchBoarding(getState())) {
dispatch(fetchBoarding(org));
}
};
}