Add action, reducer and selector for blocks

[MAILPOET-2451]
This commit is contained in:
Rostislav Wolny
2019-12-02 17:22:06 +01:00
committed by Jack Kitterhing
parent d9295569a2
commit 3efc103625
4 changed files with 24 additions and 0 deletions

View File

@ -6,6 +6,13 @@ export function toggleSidebar(toggleTo) {
};
}
export function changeFormBlocks(blocks) {
return {
type: 'CHANGE_FORM_BLOCKS',
blocks,
};
}
export function changeFormName(name) {
return {
type: 'CHANGE_FORM_NAME',

View File

@ -8,9 +8,11 @@ import saveFormStarted from './reducers/save_form_started.jsx';
import switchSidebarTab from './reducers/switch_sidebar_tab.jsx';
import toggleSidebar from './reducers/toggle_sidebar.jsx';
import toggleSidebarPanel from './reducers/toggle_sidebar_panel.jsx';
import changeFormBlocks from './reducers/change_form_blocks.jsx';
export default (defaultState) => (state = defaultState, action) => {
switch (action.type) {
case 'CHANGE_FORM_BLOCKS': return changeFormBlocks(state, action);
case 'CHANGE_FORM_NAME': return changeFormName(state, action);
case 'CHANGE_FORM_SETTINGS': return changeFormSettings(state, action);
case 'CHANGE_FORM_STYLES': return changeFormStyles(state, action);

View File

@ -0,0 +1,12 @@
import validateForm from '../form_validator.jsx';
export default (state, action) => {
const newState = {
...state,
formBlocks: action.blocks,
};
return {
...newState,
formErrors: validateForm(newState.formData, newState.formBlocks),
};
};

View File

@ -44,4 +44,7 @@ export default {
getSidebarOpenedPanels(state) {
return state.sidebar.openedPanels;
},
getFormBlocks(state) {
return state.formBlocks;
},
};