Refactor reducers to extra files
[MAILPOET-2450]
This commit is contained in:
committed by
Jack Kitterhing
parent
cd3f039958
commit
20d848132d
@@ -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;
|
||||
}
|
||||
|
13
assets/js/src/form_editor/store/reducers/addNotice.jsx
Normal file
13
assets/js/src/form_editor/store/reducers/addNotice.jsx
Normal 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],
|
||||
};
|
||||
};
|
@@ -0,0 +1,7 @@
|
||||
export default (state, action) => ({
|
||||
...state,
|
||||
formData: {
|
||||
...state.formData,
|
||||
name: action.name,
|
||||
},
|
||||
});
|
@@ -0,0 +1,4 @@
|
||||
export default (state, action) => ({
|
||||
...state,
|
||||
notices: [...state.notices].filter((item) => item.id !== action.id),
|
||||
});
|
@@ -0,0 +1,4 @@
|
||||
export default (state) => ({
|
||||
...state,
|
||||
isFormSaving: false,
|
||||
});
|
@@ -0,0 +1,4 @@
|
||||
export default (state) => ({
|
||||
...state,
|
||||
isFormSaving: true,
|
||||
});
|
@@ -0,0 +1,4 @@
|
||||
export default (state, action) => ({
|
||||
...state,
|
||||
sidebarOpened: action.toggleTo,
|
||||
});
|
Reference in New Issue
Block a user