Refactor reducers to extra files

[MAILPOET-2450]
This commit is contained in:
Rostislav Wolny
2019-11-05 13:20:40 +01:00
committed by Jack Kitterhing
parent cd3f039958
commit 20d848132d
7 changed files with 48 additions and 43 deletions

View File

@@ -1,49 +1,18 @@
const addNotice = (state, action) => {
const notices = state.notices.filter((item) => item.id !== action.id);
const notice = {
id: action.id ? action.id : Math.random().toString(36).substr(2, 9),
content: action.content,
isDismissible: action.isDismissible,
status: action.status,
};
return {
...state,
notices: [...notices, notice],
};
};
import addNotice from './reducers/addNotice.jsx';
import toggleSidebar from './reducers/toggleSidebar.jsx';
import changeFormName from './reducers/changeFormName.jsx';
import saveFormStarted from './reducers/saveFormStarted.jsx';
import saveFormDone from './reducers/saveFormDone.jsx';
import removeNotice from './reducers/removeNotice.jsx';
export default (defaultState) => (state = defaultState, action) => {
switch (action.type) {
case 'TOGGLE_SIDEBAR':
return {
...state,
sidebarOpened: action.toggleTo,
};
case 'CHANGE_FORM_NAME':
return {
...state,
formData: {
...state.formData,
name: action.name,
},
};
case 'SAVE_FORM_STARTED':
return {
...state,
isFormSaving: true,
};
case 'SAVE_FORM_DONE':
return {
...state,
isFormSaving: false,
};
case 'ADD_NOTICE':
return addNotice(state, action);
case 'REMOVE_NOTICE':
return {
...state,
notices: [...state.notices].filter((item) => item.id !== action.id),
};
case 'ADD_NOTICE': return addNotice(state, action);
case 'CHANGE_FORM_NAME': return changeFormName(state, action);
case 'REMOVE_NOTICE': return removeNotice(state, action);
case 'SAVE_FORM_DONE': return saveFormDone(state);
case 'SAVE_FORM_STARTED': return saveFormStarted(state);
case 'TOGGLE_SIDEBAR': return toggleSidebar(state, action);
default:
return state;
}

View File

@@ -0,0 +1,13 @@
export default (state, action) => {
const notices = state.notices.filter((item) => item.id !== action.id);
const notice = {
id: action.id ? action.id : Math.random().toString(36).substr(2, 9),
content: action.content,
isDismissible: action.isDismissible,
status: action.status,
};
return {
...state,
notices: [...notices, notice],
};
};

View File

@@ -0,0 +1,7 @@
export default (state, action) => ({
...state,
formData: {
...state.formData,
name: action.name,
},
});

View File

@@ -0,0 +1,4 @@
export default (state, action) => ({
...state,
notices: [...state.notices].filter((item) => item.id !== action.id),
});

View File

@@ -0,0 +1,4 @@
export default (state) => ({
...state,
isFormSaving: false,
});

View File

@@ -0,0 +1,4 @@
export default (state) => ({
...state,
isFormSaving: true,
});

View File

@@ -0,0 +1,4 @@
export default (state, action) => ({
...state,
sidebarOpened: action.toggleTo,
});