mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
53 lines (52 loc) • 1.68 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.errors = errors;
const redux_1 = require("redux");
const action_types_1 = require("mattermost-redux/action_types");
const initialProducts = {
products: {},
productsLoaded: false,
};
function products(state = initialProducts, action) {
switch (action.type) {
case action_types_1.HostedCustomerTypes.RECEIVED_SELF_HOSTED_PRODUCTS: {
const productList = action.data;
const productDict = productList.reduce((map, obj) => {
map[obj.id] = obj;
return map;
}, {});
return {
...state,
products: {
...state.products,
...productDict,
},
productsLoaded: true,
};
}
default:
return state;
}
}
const emptyErrors = {};
function errors(state = emptyErrors, action) {
switch (action.type) {
case action_types_1.HostedCustomerTypes.SELF_HOSTED_PRODUCTS_FAILED: {
return { ...state, products: true };
}
case action_types_1.HostedCustomerTypes.SELF_HOSTED_PRODUCTS_REQUEST:
case action_types_1.HostedCustomerTypes.RECEIVED_SELF_HOSTED_PRODUCTS: {
const newState = Object.assign({}, state);
delete newState.products;
return newState;
}
default:
return state;
}
}
exports.default = (0, redux_1.combineReducers)({
products,
errors,
});