* fix(tracker): fix assist typings * fix(tracker): fix assist typings * change(ui) - preferences - removed old * change(ui) - preferences - wip * change(ui) - preferences - list * change(ui) - right box mardings * change(ui) - preferences - integration item paddings * change(ui) - preferences - integration icons * change(ui) - preferences - integration icons * change(ui) - preferences - integration - check status * change(ui) - preferences - integration - check status * change(ui) - preferences - metadata - move the delete button inside the modal * change(ui) - preferences - webhooks - modal and delete btn changes * change(ui) - preferences - modalContext updates * change(ui) - input field forward refs * change(ui) - metadata - modal * change(ui) - metadata - set deleting item to null * change(ui) - integrations * change(ui) - hoc withcopy * change(ui) - projects * change(ui) - users list modal * change(ui) - projects remove border for the last * change(ui) - integrations new api changes * change(ui) - github and jira changes * change(ui) - github and jira changes Co-authored-by: sylenien <nikita@openreplay.com>
52 lines
2 KiB
JavaScript
52 lines
2 KiB
JavaScript
import { List, Map } from 'immutable';
|
|
import { createRequestReducer } from '../funcTools/request';
|
|
import { fetchListType, saveType, removeType, editType, initType, fetchType } from '../funcTools/types';
|
|
import { createItemInListUpdater } from '../funcTools/tools';
|
|
|
|
const idKey = 'siteId';
|
|
const itemInListUpdater = createItemInListUpdater(idKey);
|
|
|
|
export const createIntegrationReducer = (name, Config) => {
|
|
const FETCH_LIST = fetchListType(name);
|
|
const SAVE = saveType(name);
|
|
const REMOVE = removeType(name);
|
|
const EDIT = editType(name);
|
|
const INIT = initType(name);
|
|
const FETCH = fetchType(name);
|
|
|
|
const initialState = Map({
|
|
instance: Config(),
|
|
list: List(),
|
|
fetched: false,
|
|
issuesFetched: false,
|
|
});
|
|
const reducer = (state = initialState, action = {}) => {
|
|
switch (action.type) {
|
|
case FETCH_LIST.success:
|
|
return state
|
|
.set('list', Array.isArray(action.data) ? List(action.data).map(Config) : List([new Config(action.data)]))
|
|
.set(action.name + 'Fetched', true);
|
|
case FETCH.success:
|
|
return state.set('instance', Config(action.data));
|
|
case SAVE.success:
|
|
const config = Config(action.data);
|
|
return state.update('list', itemInListUpdater(config)).set('instance', config);
|
|
case REMOVE.success:
|
|
return state.update('list', (list) => list.filter((site) => site.siteId !== action.siteId)).set('instance', Config());
|
|
case EDIT:
|
|
return state.mergeIn(['instance'], action.instance);
|
|
case INIT:
|
|
return state.set('instance', Config(action.instance));
|
|
}
|
|
return state;
|
|
};
|
|
return createRequestReducer(
|
|
{
|
|
// fetchRequest: FETCH_LIST,
|
|
fetchRequest: FETCH,
|
|
saveRequest: SAVE,
|
|
removeRequest: REMOVE,
|
|
},
|
|
reducer
|
|
);
|
|
};
|