Allow only selected pages or all pages
[MAILPOET-3120]
This commit is contained in:
@@ -2,7 +2,13 @@ import React from 'react';
|
|||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { ToggleControl } from '@wordpress/components';
|
import { ToggleControl } from '@wordpress/components';
|
||||||
import { assocPath, compose, __ } from 'lodash/fp';
|
import {
|
||||||
|
assocPath,
|
||||||
|
compose,
|
||||||
|
__,
|
||||||
|
cond,
|
||||||
|
identity,
|
||||||
|
} from 'lodash/fp';
|
||||||
import Selection from 'form/fields/selection.jsx';
|
import Selection from 'form/fields/selection.jsx';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -25,28 +31,34 @@ const PlacementSettings = ({ settingsPlacementKey }: Props) => {
|
|||||||
<ToggleControl
|
<ToggleControl
|
||||||
label={MailPoet.I18n.t('placeFormOnAllPages')}
|
label={MailPoet.I18n.t('placeFormOnAllPages')}
|
||||||
checked={formSettings.formPlacement[settingsPlacementKey].pages.all}
|
checked={formSettings.formPlacement[settingsPlacementKey].pages.all}
|
||||||
onChange={compose([changeFormSettings, assocPath(`formPlacement.${settingsPlacementKey}.pages.all`, __, formSettings)])}
|
onChange={(newValue) => {
|
||||||
|
compose([
|
||||||
|
changeFormSettings,
|
||||||
|
assocPath(`formPlacement.${settingsPlacementKey}.pages.all`, newValue),
|
||||||
|
cond([
|
||||||
|
[() => newValue, assocPath(`formPlacement.${settingsPlacementKey}.pages.selected`, [])], // if enabled clear selected pages
|
||||||
|
[() => !newValue, identity], // if disabled do nothing
|
||||||
|
]),
|
||||||
|
])(formSettings);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Selection
|
<Selection
|
||||||
item={{
|
item={{
|
||||||
pages: formSettings.formPlacement[settingsPlacementKey].pages.selected,
|
id: formSettings.formPlacement[settingsPlacementKey].pages.selected.join(),
|
||||||
}}
|
|
||||||
onValueChange={(e) => {
|
|
||||||
changeFormSettings(
|
|
||||||
assocPath(
|
|
||||||
`formPlacement.${settingsPlacementKey}.pages.selected`,
|
|
||||||
e.target.value,
|
|
||||||
formSettings
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
|
onValueChange={(e) => compose([
|
||||||
|
changeFormSettings,
|
||||||
|
assocPath(`formPlacement.${settingsPlacementKey}.pages.selected`, e.target.value),
|
||||||
|
assocPath(`formPlacement.${settingsPlacementKey}.pages.all`, false), // disable all if some pages are selected
|
||||||
|
])(formSettings)}
|
||||||
field={{
|
field={{
|
||||||
id: 'pages',
|
id: 'pages',
|
||||||
name: 'pages',
|
name: 'pages',
|
||||||
values: pages,
|
values: pages,
|
||||||
multiple: true,
|
multiple: true,
|
||||||
placeholder: MailPoet.I18n.t('selectPage'),
|
placeholder: MailPoet.I18n.t('selectPage'),
|
||||||
getLabel: (seg) => seg.name,
|
getLabel: (page) => page.name,
|
||||||
|
selected: () => formSettings.formPlacement[settingsPlacementKey].pages.selected,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
|
Reference in New Issue
Block a user