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.
145 lines (132 loc) • 5.23 kB
JavaScript
import constants from '../constants';
import { storage } from '../config';
const initialState = {
users: [],
isFetching: false,
potentialUsers: [],
isFetchingPotentialUsers: false,
currentUser: void 0,
isFetchingCurrentUser: false,
isBoardingFinishedCached: storage.isBoardingFinished(),
};
export default function update(state = initialState, action = {}) {
switch (action.type) {
case constants.user.RECEIVE_REMOVE_ON_BOARDING:
const newCurrentUser = state.currentUser;
newCurrentUser.userProfile.isOnBoardingFinished = true;
return Object.assign({}, state, {
currentUser: Object.assign({}, newCurrentUser),
isBoardingFinishedCached: true,
});
case constants.user.RECEIVE_REMOVE_WIDGET_TO_USER_PROFILE:
const newCurrentUserForWidgetToRemove = state.currentUser;
if (!newCurrentUserForWidgetToRemove.userProfile.widgetConfiguration) {
newCurrentUserForWidgetToRemove.userProfile.widgetConfiguration = [{
entityType: action.data.widgetToRemove.entityType,
widgets: [{
place: action.data.widgetToRemove.place,
name: action.data.widgetToRemove.name,
isDeleted: true,
}],
}];
} else {
const hadConfigForWidget = newCurrentUserForWidgetToRemove.userProfile.widgetConfiguration.find((configPerType) => {
return configPerType.entityType.toLowerCase() === action.data.widgetToRemove.entityType.toLowerCase();
});
if (hadConfigForWidget) {
hadConfigForWidget.widgets = hadConfigForWidget.widgets || [];
hadConfigForWidget.widgets = hadConfigForWidget.widgets.filter((w) => {
return w.name.toLowerCase() !== action.data.widgetToRemove.name.toLowerCase();
});
hadConfigForWidget.widgets.push({
place: action.data.widgetToRemove.place,
name: action.data.widgetToRemove.name,
isDeleted: true,
});
} else {
newCurrentUserForWidgetToRemove.userProfile.widgetConfiguration.push({
entityType: action.data.widgetToRemove.entityType,
widgets: [{
place: action.data.widgetToRemove.place,
name: action.data.widgetToRemove.name,
isDeleted: true,
}],
});
}
}
return Object.assign({}, state, {
currentUser: Object.assign({}, newCurrentUserForWidgetToRemove),
});
case constants.user.RECEIVE_ADD_WIDGET_CONFIGURATION_TO_USER_PROFILE:
const newCurrentUserForWidgetToAdd = state.currentUser;
if (!newCurrentUserForWidgetToAdd.userProfile.widgetConfiguration) {
newCurrentUserForWidgetToAdd.userProfile.widgetConfiguration = [{
entityType: action.data.widgetToAdd.entityType,
widgets: [{
place: action.data.widgetToAdd.place,
name: action.data.widgetToAdd.name,
parameters: action.data.widgetToAdd.values,
}],
}];
} else {
const hadConfigForWidget = newCurrentUserForWidgetToAdd.userProfile.widgetConfiguration.find((configPerType) => {
return configPerType.entityType.toLowerCase() === action.data.widgetToAdd.entityType.toLowerCase();
});
if (hadConfigForWidget) {
hadConfigForWidget.widgets = hadConfigForWidget.widgets || [];
hadConfigForWidget.widgets.push({
place: action.data.widgetToAdd.place,
name: action.data.widgetToAdd.name,
parameters: action.data.widgetToAdd.values,
});
} else {
newCurrentUserForWidgetToAdd.userProfile.widgetConfiguration.push({
entityType: action.data.widgetToAdd.entityType,
widgets: [{
place: action.data.widgetToAdd.place,
name: action.data.widgetToAdd.name,
parameters: action.data.widgetToAdd.values,
}],
});
}
}
return Object.assign({}, state, {
currentUser: Object.assign({}, newCurrentUserForWidgetToAdd),
});
case constants.user.REQUEST_USERS:
return Object.assign({}, state, {
users: [],
isFetching: true,
});
case constants.user.RECEIVE_USERS:
return Object.assign({}, state, {
users: action.data.users,
isFetching: false,
});
case constants.user.REQUEST_POTENTIAL_USERS:
return Object.assign({}, state, {
potentialUsers: [],
isFetchingPotentialUsers: true,
});
case constants.user.INVALID_POTENTIAL_USERS:
return Object.assign({}, state, {
isFetchingPotentialUsers: false,
});
case constants.user.RECEIVE_POTENTIAL_USERS:
return Object.assign({}, state, {
potentialUsers: action.data,
isFetchingPotentialUsers: false,
});
case constants.user.REQUEST_CURRENT_USER:
return Object.assign({}, state, {
isFetchingCurrentUser: true,
});
case constants.user.RECEIVE_CURRENT_USER:
return Object.assign({}, state, {
currentUser: action.data.user,
isFetchingCurrentUser: false,
});
default:
return state;
}
};