Add position to fixed bar form

[MAILPOET-2740]
This commit is contained in:
Pavel Dohnal
2020-04-02 11:19:06 +02:00
committed by Veljko V
parent 08656a3991
commit 8155480089
8 changed files with 49 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import MailPoet from 'mailpoet'; import MailPoet from 'mailpoet';
import { SelectControl } from '@wordpress/components'; import { SelectControl, RadioControl } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data'; import { useSelect, useDispatch } from '@wordpress/data';
import FormPlacementSettings from './form_placement_settings'; import FormPlacementSettings from './form_placement_settings';
@@ -14,6 +14,10 @@ const FixedBar = () => {
(select) => select('mailpoet-form-editor').getFixedBarFormDelay(), (select) => select('mailpoet-form-editor').getFixedBarFormDelay(),
[] []
); );
const fixedBarFormPosition = useSelect(
(select) => select('mailpoet-form-editor').getFixedBarFormPosition(),
[]
);
const placeFixedBarFormOnAllPages = useSelect( const placeFixedBarFormOnAllPages = useSelect(
(select) => select('mailpoet-form-editor').placeFixedBarFormOnAllPages(), (select) => select('mailpoet-form-editor').placeFixedBarFormOnAllPages(),
@@ -28,6 +32,7 @@ const FixedBar = () => {
setPlaceFixedBarFormOnAllPages, setPlaceFixedBarFormOnAllPages,
setPlaceFixedBarFormOnAllPosts, setPlaceFixedBarFormOnAllPosts,
setFixedBarFormDelay, setFixedBarFormDelay,
setFixedBarFormPosition,
} = useDispatch('mailpoet-form-editor'); } = useDispatch('mailpoet-form-editor');
const [ const [
@@ -42,11 +47,16 @@ const FixedBar = () => {
localDelay, localDelay,
setLocalDelay, setLocalDelay,
] = useState(fixedBarFormDelay === undefined ? 15 : fixedBarFormDelay); ] = useState(fixedBarFormDelay === undefined ? 15 : fixedBarFormDelay);
const [
localPosition,
setLocalPosition,
] = useState(fixedBarFormPosition === undefined ? 'top' : fixedBarFormPosition);
const save = () => { const save = () => {
setPlaceFixedBarFormOnAllPages(localPlaceFixedBarFormOnAllPages); setPlaceFixedBarFormOnAllPages(localPlaceFixedBarFormOnAllPages);
setPlaceFixedBarFormOnAllPosts(localPlaceFixedBarFormOnAllPosts); setPlaceFixedBarFormOnAllPosts(localPlaceFixedBarFormOnAllPosts);
setFixedBarFormDelay(localDelay); setFixedBarFormDelay(localDelay);
setFixedBarFormPosition(localPosition);
}; };
return ( return (
@@ -88,6 +98,15 @@ const FixedBar = () => {
label: MailPoet.I18n.t('formPlacementDelaySeconds').replace('%1s', delayValue), label: MailPoet.I18n.t('formPlacementDelaySeconds').replace('%1s', delayValue),
}))} }))}
/> />
<RadioControl
label={MailPoet.I18n.t('formPlacementPlacementPosition')}
selected={localPosition}
options={[
{ label: MailPoet.I18n.t('formPlacementPlacementPositionTop'), value: 'top' },
{ label: MailPoet.I18n.t('formPlacementPlacementPositionBottom'), value: 'bottom' },
]}
onChange={setLocalPosition}
/>
</FormPlacementSettings> </FormPlacementSettings>
); );
}; };

View File

@@ -76,6 +76,13 @@ export function setFixedBarFormDelay(delay) {
}; };
} }
export function setFixedBarFormPosition(position) {
return {
type: 'SET_FIXED_BAR_FORM_POSITION',
position,
};
}
export function deleteCustomFieldStarted() { export function deleteCustomFieldStarted() {
return { return {
type: 'DELETE_CUSTOM_FIELD_STARTED', type: 'DELETE_CUSTOM_FIELD_STARTED',

View File

@@ -20,6 +20,7 @@ export default function mapFormDataAfterLoading(data) {
placeFixedBarFormOnAllPages: data.settings.place_fixed_bar_form_on_all_pages === '1', placeFixedBarFormOnAllPages: data.settings.place_fixed_bar_form_on_all_pages === '1',
placeFixedBarFormOnAllPosts: data.settings.place_fixed_bar_form_on_all_posts === '1', placeFixedBarFormOnAllPosts: data.settings.place_fixed_bar_form_on_all_posts === '1',
fixedBarFormDelay, fixedBarFormDelay,
fixedBarFormPosition: data.settings.fixed_bar_form_position,
}, },
}; };
} }

View File

@@ -11,6 +11,7 @@ export default function mapFormDataBeforeSaving(data) {
place_fixed_bar_form_on_all_pages: data.settings.placeFixedBarFormOnAllPages === true ? '1' : '', place_fixed_bar_form_on_all_pages: data.settings.placeFixedBarFormOnAllPages === true ? '1' : '',
place_fixed_bar_form_on_all_posts: data.settings.placeFixedBarFormOnAllPosts === true ? '1' : '', place_fixed_bar_form_on_all_posts: data.settings.placeFixedBarFormOnAllPosts === true ? '1' : '',
fixed_bar_form_delay: data.settings.fixedBarFormDelay, fixed_bar_form_delay: data.settings.fixedBarFormDelay,
fixed_bar_form_position: data.settings.fixedBarFormPosition,
}, },
}; };
} }

View File

@@ -13,6 +13,7 @@ import {
placeFixedBarFormOnAllPosts, placeFixedBarFormOnAllPosts,
placeFixedBarFormOnAllPages, placeFixedBarFormOnAllPages,
setFixedBarFormDelay, setFixedBarFormDelay,
setFixedBarFormPosition,
} from './reducers/form_placement.jsx'; } from './reducers/form_placement.jsx';
import changeFormSettings from './reducers/change_form_settings.jsx'; import changeFormSettings from './reducers/change_form_settings.jsx';
import changeFormStyles from './reducers/change_form_styles.jsx'; import changeFormStyles from './reducers/change_form_styles.jsx';
@@ -70,6 +71,7 @@ export default (defaultState) => (state = defaultState, action) => {
case 'PLACE_FIXED_BAR_FORM_ON_ALL_PAGES': return placeFixedBarFormOnAllPages(state, action); case 'PLACE_FIXED_BAR_FORM_ON_ALL_PAGES': return placeFixedBarFormOnAllPages(state, action);
case 'PLACE_FIXED_BAR_FORM_ON_ALL_POSTS': return placeFixedBarFormOnAllPosts(state, action); case 'PLACE_FIXED_BAR_FORM_ON_ALL_POSTS': return placeFixedBarFormOnAllPosts(state, action);
case 'SET_FIXED_BAR_FORM_DELAY': return setFixedBarFormDelay(state, action); case 'SET_FIXED_BAR_FORM_DELAY': return setFixedBarFormDelay(state, action);
case 'SET_FIXED_BAR_FORM_POSITION': return setFixedBarFormPosition(state, action);
default: default:
return state; return state;
} }

View File

@@ -39,3 +39,15 @@ export const formPlacementDelay = curry((delayFormName, state, action) => ({
export const setPopupFormDelay = formPlacementDelay('popupFormDelay'); export const setPopupFormDelay = formPlacementDelay('popupFormDelay');
export const setFixedBarFormDelay = formPlacementDelay('fixedBarFormDelay'); export const setFixedBarFormDelay = formPlacementDelay('fixedBarFormDelay');
export const setFixedBarFormPosition = (state, action) => ({
...state,
hasUnsavedChanges: true,
formData: {
...state.formData,
settings: {
...state.formData.settings,
fixedBarFormPosition: action.position,
},
},
});

View File

@@ -58,6 +58,9 @@ export default {
getFixedBarFormDelay(state) { getFixedBarFormDelay(state) {
return state.formData.settings.fixedBarFormDelay; return state.formData.settings.fixedBarFormDelay;
}, },
getFixedBarFormPosition(state) {
return state.formData.settings.fixedBarFormPosition;
},
getAllAvailableSegments(state) { getAllAvailableSegments(state) {
return state.segments; return state.segments;
}, },

View File

@@ -68,6 +68,9 @@
'placeFormBellowAllPages': _x('Display on all pages', 'This is a text on a switch if a form should be displayed bellow all pages'), 'placeFormBellowAllPages': _x('Display on all pages', 'This is a text on a switch if a form should be displayed bellow all pages'),
'placeFormBellowAllPosts': _x('Display on all posts', 'This is a text on a switch if a form should be displayed bellow all posts'), 'placeFormBellowAllPosts': _x('Display on all posts', 'This is a text on a switch if a form should be displayed bellow all posts'),
'formPlacementDelay': _x('Display with a delay of', 'Label on a selection of different times'), 'formPlacementDelay': _x('Display with a delay of', 'Label on a selection of different times'),
'formPlacementPlacementPosition': _x('Position', 'Placement of a fixed bar form, on top of the page or on the bottom'),
'formPlacementPlacementPositionTop': _x('top', 'Placement of a fixed bar form, on top of the page or on the bottom'),
'formPlacementPlacementPositionBottom': _x('bottom', 'Placement of a fixed bar form, on top of the page or on the bottom'),
'formPlacementDelaySeconds': _x('%1s sec', 'times selection should be in the end "30 sec"'), 'formPlacementDelaySeconds': _x('%1s sec', 'times selection should be in the end "30 sec"'),
'formPlacementSave': _x('Save', 'Text on a button to save a form'), 'formPlacementSave': _x('Save', 'Text on a button to save a form'),
'addFormWidgetHint': __('Add this form to a [link]widget area[/link].'), 'addFormWidgetHint': __('Add this form to a [link]widget area[/link].'),