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) => {
|
import addNotice from './reducers/addNotice.jsx';
|
||||||
const notices = state.notices.filter((item) => item.id !== action.id);
|
import toggleSidebar from './reducers/toggleSidebar.jsx';
|
||||||
const notice = {
|
import changeFormName from './reducers/changeFormName.jsx';
|
||||||
id: action.id ? action.id : Math.random().toString(36).substr(2, 9),
|
import saveFormStarted from './reducers/saveFormStarted.jsx';
|
||||||
content: action.content,
|
import saveFormDone from './reducers/saveFormDone.jsx';
|
||||||
isDismissible: action.isDismissible,
|
import removeNotice from './reducers/removeNotice.jsx';
|
||||||
status: action.status,
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
notices: [...notices, notice],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default (defaultState) => (state = defaultState, action) => {
|
export default (defaultState) => (state = defaultState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'TOGGLE_SIDEBAR':
|
case 'ADD_NOTICE': return addNotice(state, action);
|
||||||
return {
|
case 'CHANGE_FORM_NAME': return changeFormName(state, action);
|
||||||
...state,
|
case 'REMOVE_NOTICE': return removeNotice(state, action);
|
||||||
sidebarOpened: action.toggleTo,
|
case 'SAVE_FORM_DONE': return saveFormDone(state);
|
||||||
};
|
case 'SAVE_FORM_STARTED': return saveFormStarted(state);
|
||||||
case 'CHANGE_FORM_NAME':
|
case 'TOGGLE_SIDEBAR': return toggleSidebar(state, action);
|
||||||
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),
|
|
||||||
};
|
|
||||||
default:
|
default:
|
||||||
return state;
|
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