Add delay settings

[MAILPOET-2741]
This commit is contained in:
Pavel Dohnal
2020-03-24 14:40:16 +01:00
committed by Veljko V
parent c38f6febd6
commit b5ce2a97c9
8 changed files with 60 additions and 1 deletions

View File

@@ -1,12 +1,20 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import MailPoet from 'mailpoet'; import MailPoet from 'mailpoet';
import { SelectControl } 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';
import Toggle from '../../../../common/toggle'; import Toggle from '../../../../common/toggle';
import Icon from './popup_icon'; import Icon from './popup_icon';
const delayValues = [0, 15, 30, 60, 120, 180, 240];
const Popup = () => { const Popup = () => {
const popupFormDelay = useSelect(
(select) => select('mailpoet-form-editor').getPopupFormDelay(),
[]
);
const placePopupFormOnAllPages = useSelect( const placePopupFormOnAllPages = useSelect(
(select) => select('mailpoet-form-editor').placePopupFormOnAllPages(), (select) => select('mailpoet-form-editor').placePopupFormOnAllPages(),
[] []
@@ -16,7 +24,11 @@ const Popup = () => {
(select) => select('mailpoet-form-editor').placePopupFormOnAllPosts(), (select) => select('mailpoet-form-editor').placePopupFormOnAllPosts(),
[] []
); );
const { setPlacePopupFormOnAllPages, setPlacePopupFormOnAllPosts } = useDispatch('mailpoet-form-editor'); const {
setPlacePopupFormOnAllPages,
setPlacePopupFormOnAllPosts,
setPopupFormDelay,
} = useDispatch('mailpoet-form-editor');
const [ const [
localPlacePopupFormOnAllPages, localPlacePopupFormOnAllPages,
@@ -26,10 +38,15 @@ const Popup = () => {
localPlacePopupFormOnAllPosts, localPlacePopupFormOnAllPosts,
setLocalPlacePopupFormOnAllPosts, setLocalPlacePopupFormOnAllPosts,
] = useState(placePopupFormOnAllPosts); ] = useState(placePopupFormOnAllPosts);
const [
localDelay,
setLocalDelay,
] = useState(popupFormDelay === undefined ? 15 : popupFormDelay);
const save = () => { const save = () => {
setPlacePopupFormOnAllPages(localPlacePopupFormOnAllPages); setPlacePopupFormOnAllPages(localPlacePopupFormOnAllPages);
setPlacePopupFormOnAllPosts(localPlacePopupFormOnAllPosts); setPlacePopupFormOnAllPosts(localPlacePopupFormOnAllPosts);
setPopupFormDelay(localDelay);
}; };
return ( return (
@@ -62,6 +79,15 @@ const Popup = () => {
/> />
</div> </div>
</div> </div>
<SelectControl
label={MailPoet.I18n.t('formPlacementDelay')}
value={localDelay}
onChange={setLocalDelay}
options={delayValues.map((delayValue) => ({
value: delayValue,
label: MailPoet.I18n.t('formPlacementDelaySeconds').replace('%1s', delayValue),
}))}
/>
</FormPlacementSettings> </FormPlacementSettings>
); );
}; };

View File

@@ -48,6 +48,13 @@ export function setPlacePopupFormOnAllPosts(place) {
}; };
} }
export function setPopupFormDelay(delay) {
return {
type: 'SET_POPUP_FORM_DELAY',
delay,
};
}
export function deleteCustomFieldStarted() { export function deleteCustomFieldStarted() {
return { return {
type: 'DELETE_CUSTOM_FIELD_STARTED', type: 'DELETE_CUSTOM_FIELD_STARTED',

View File

@@ -1,4 +1,9 @@
export default function mapFormDataAfterLoading(data) { export default function mapFormDataAfterLoading(data) {
let popupFormDelay = parseInt(data.settings.popup_form_delay, 10);
if (Number.isNaN(popupFormDelay)) {
popupFormDelay = undefined;
}
return { return {
...data, ...data,
settings: { settings: {
@@ -7,6 +12,7 @@ export default function mapFormDataAfterLoading(data) {
placeFormBellowAllPosts: data.settings.place_form_bellow_all_posts === '1', placeFormBellowAllPosts: data.settings.place_form_bellow_all_posts === '1',
placePopupFormOnAllPages: data.settings.place_popup_form_on_all_pages === '1', placePopupFormOnAllPages: data.settings.place_popup_form_on_all_pages === '1',
placePopupFormOnAllPosts: data.settings.place_popup_form_on_all_posts === '1', placePopupFormOnAllPosts: data.settings.place_popup_form_on_all_posts === '1',
popupFormDelay,
}, },
}; };
} }

View File

@@ -7,6 +7,7 @@ export default function mapFormDataBeforeSaving(data) {
place_form_bellow_all_posts: data.settings.placeFormBellowAllPosts === 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_pages: data.settings.placePopupFormOnAllPages === true ? '1' : '',
place_popup_form_on_all_posts: data.settings.placePopupFormOnAllPosts === true ? '1' : '', place_popup_form_on_all_posts: data.settings.placePopupFormOnAllPosts === true ? '1' : '',
popup_form_delay: data.settings.popupFormDelay,
}, },
}; };
} }

View File

@@ -9,6 +9,7 @@ import {
placeFormBellowAllPosts, placeFormBellowAllPosts,
placePopupFormOnAllPages, placePopupFormOnAllPages,
placePopupFormOnAllPosts, placePopupFormOnAllPosts,
setPopupFormDelay,
} 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';
@@ -62,6 +63,7 @@ export default (defaultState) => (state = defaultState, action) => {
case 'PLACE_FORM_BELLOW_ALL_POSTS': return placeFormBellowAllPosts(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_PAGES': return placePopupFormOnAllPages(state, action);
case 'PLACE_POPUP_FORM_ON_ALL_POSTS': return placePopupFormOnAllPosts(state, action); case 'PLACE_POPUP_FORM_ON_ALL_POSTS': return placePopupFormOnAllPosts(state, action);
case 'SET_POPUP_FORM_DELAY': return setPopupFormDelay(state, action);
default: default:
return state; return state;
} }

View File

@@ -19,3 +19,15 @@ export const placeFormBellowAllPages = formPlacement('placeFormBellowAllPages');
export const placePopupFormOnAllPages = formPlacement('placePopupFormOnAllPages'); export const placePopupFormOnAllPages = formPlacement('placePopupFormOnAllPages');
export const placePopupFormOnAllPosts = formPlacement('placePopupFormOnAllPosts'); export const placePopupFormOnAllPosts = formPlacement('placePopupFormOnAllPosts');
export const setPopupFormDelay = (state, action) => ({
...state,
hasUnsavedChanges: true,
formData: {
...state.formData,
settings: {
...state.formData.settings,
popupFormDelay: action.delay,
},
},
});

View File

@@ -46,6 +46,9 @@ export default {
placePopupFormOnAllPosts(state) { placePopupFormOnAllPosts(state) {
return state.formData.settings.placePopupFormOnAllPosts || false; return state.formData.settings.placePopupFormOnAllPosts || false;
}, },
getPopupFormDelay(state) {
return state.formData.settings.popupFormDelay;
},
getAllAvailableSegments(state) { getAllAvailableSegments(state) {
return state.segments; return state.segments;
}, },

View File

@@ -65,6 +65,8 @@
'placeFormBellowPagesDescription': __('This form placement allows you to add this form at the end of all the pages or posts, below the content.'), 'placeFormBellowPagesDescription': __('This form placement allows you to add this form at the end of all the pages or posts, below the content.'),
'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'),
'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].'),
'addFormShortcodeHint': __('[link]Use Gutenberg block[/link] available on any page or post. Or use the shortcode [shortcode].'), 'addFormShortcodeHint': __('[link]Use Gutenberg block[/link] available on any page or post. Or use the shortcode [shortcode].'),