Add reducer for popup form

[MAILPOET-2741]
This commit is contained in:
Pavel Dohnal
2020-03-24 12:09:20 +01:00
committed by Veljko V
parent 893d0e7ac1
commit ff1f979218
5 changed files with 35 additions and 15 deletions

View File

@@ -34,6 +34,20 @@ export function setPlaceFormBellowAllPosts(place) {
};
}
export function setPlacePopupFormOnAllPages(place) {
return {
type: 'PLACE_POPUP_FORM_ON_ALL_PAGES',
place,
};
}
export function setPlacePopupFormOnAllPosts(place) {
return {
type: 'PLACE_POPUP_FORM_ON_ALL_POSTS',
place,
};
}
export function deleteCustomFieldStarted() {
return {
type: 'DELETE_CUSTOM_FIELD_STARTED',

View File

@@ -5,6 +5,8 @@ export default function mapFormDataAfterLoading(data) {
...data.settings,
placeFormBellowAllPages: data.settings.place_form_bellow_all_pages === '1',
placeFormBellowAllPosts: data.settings.place_form_bellow_all_posts === '1',
placePopupFormOnAllPages: data.settings.place_popup_form_on_all_pages === '1',
placePopupFormOnAllPosts: data.settings.place_popup_form_on_all_posts === '1',
},
};
}

View File

@@ -5,6 +5,8 @@ export default function mapFormDataBeforeSaving(data) {
...data.settings,
place_form_bellow_all_pages: data.settings.placeFormBellowAllPages === true ? '1' : '',
place_form_bellow_all_posts: data.settings.placeFormBellowAllPosts === true ? '1' : '',
place_popup_form_on_all_pages: data.settings.placePopupFormOnAllPages === true ? '1' : '',
place_popup_form_on_all_posts: data.settings.placePopupFormOnAllPosts === true ? '1' : '',
},
};
}

View File

@@ -7,6 +7,8 @@ import changeFormName from './reducers/change_form_name.jsx';
import {
placeFormBellowAllPages,
placeFormBellowAllPosts,
placePopupFormOnAllPages,
placePopupFormOnAllPosts,
} from './reducers/form_placement.jsx';
import changeFormSettings from './reducers/change_form_settings.jsx';
import changeFormStyles from './reducers/change_form_styles.jsx';
@@ -58,6 +60,8 @@ export default (defaultState) => (state = defaultState, action) => {
case 'DELETE_CUSTOM_FIELD_FAILED': return customFieldDeleteFailed(state, action);
case 'PLACE_FORM_BELLOW_ALL_PAGES': return placeFormBellowAllPages(state, action);
case 'PLACE_FORM_BELLOW_ALL_POSTS': return placeFormBellowAllPosts(state, action);
case 'PLACE_POPUP_FORM_ON_ALL_PAGES': return placePopupFormOnAllPages(state, action);
case 'PLACE_POPUP_FORM_ON_ALL_POSTS': return placePopupFormOnAllPosts(state, action);
default:
return state;
}

View File

@@ -1,23 +1,21 @@
export const placeFormBellowAllPosts = (state, action) => ({
...state,
formData: {
...state.formData,
hasUnsavedChanges: true,
settings: {
...state.formData.settings,
placeFormBellowAllPosts: action.place,
},
},
});
import { curry } from 'lodash';
export const placeFormBellowAllPages = (state, action) => ({
const formPlacement = curry((placement, state, action) => ({
...state,
hasUnsavedChanges: true,
formData: {
...state.formData,
hasUnsavedChanges: true,
settings: {
...state.formData.settings,
placeFormBellowAllPages: action.place,
[placement]: action.place,
},
},
});
}));
export const placeFormBellowAllPosts = formPlacement('placeFormBellowAllPosts');
export const placeFormBellowAllPages = formPlacement('placeFormBellowAllPages');
export const placePopupFormOnAllPages = formPlacement('placePopupFormOnAllPages');
export const placePopupFormOnAllPosts = formPlacement('placePopupFormOnAllPosts');