Render more filters in the form
[MAILPOET-3469]
This commit is contained in:
@@ -14,9 +14,12 @@ import { isFormValid } from './validator';
|
|||||||
import plusIcon from '../../common/button/icon/plus';
|
import plusIcon from '../../common/button/icon/plus';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AnyFormItem,
|
FilterRow,
|
||||||
FilterValue,
|
FilterValue,
|
||||||
GroupFilterValue,
|
GroupFilterValue,
|
||||||
|
Segment,
|
||||||
|
SegmentTypes,
|
||||||
|
SubscriberActionTypes,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -26,7 +29,7 @@ interface Props {
|
|||||||
export const Form: React.FunctionComponent<Props> = ({
|
export const Form: React.FunctionComponent<Props> = ({
|
||||||
segmentId,
|
segmentId,
|
||||||
}) => {
|
}) => {
|
||||||
const segment: AnyFormItem = useSelect(
|
const segment: Segment = useSelect(
|
||||||
(select) => select('mailpoet-dynamic-segments-form').getSegment(),
|
(select) => select('mailpoet-dynamic-segments-form').getSegment(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -36,12 +39,12 @@ export const Form: React.FunctionComponent<Props> = ({
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const filterValue: FilterValue | undefined = useSelect(
|
const filterRows: FilterRow[] = useSelect(
|
||||||
(select) => select('mailpoet-dynamic-segments-form').findFilterValueForSegment(segment),
|
(select) => select('mailpoet-dynamic-segments-form').findFiltersValueForSegment(segment),
|
||||||
[segment]
|
[segment]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { updateSegment, handleSave } = useDispatch('mailpoet-dynamic-segments-form');
|
const { updateSegment, updateSegmentFilter, handleSave } = useDispatch('mailpoet-dynamic-segments-form');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className="mailpoet_form">
|
<form className="mailpoet_form">
|
||||||
@@ -92,31 +95,46 @@ export const Form: React.FunctionComponent<Props> = ({
|
|||||||
{MailPoet.I18n.t('formPageTitle')}
|
{MailPoet.I18n.t('formPageTitle')}
|
||||||
</label>
|
</label>
|
||||||
</Heading>
|
</Heading>
|
||||||
|
{Array.isArray(filterRows) && filterRows.map((filterRow, index) => (
|
||||||
|
<>
|
||||||
<Grid.ThreeColumns>
|
<Grid.ThreeColumns>
|
||||||
<Select
|
<Select
|
||||||
dimension="small"
|
dimension="small"
|
||||||
placeholder={MailPoet.I18n.t('selectActionPlaceholder')}
|
placeholder={MailPoet.I18n.t('selectActionPlaceholder')}
|
||||||
options={segmentFilters}
|
options={segmentFilters}
|
||||||
value={filterValue}
|
value={filterRow.filterValue}
|
||||||
onChange={(newValue: FilterValue): void => {
|
onChange={(newValue: FilterValue): void => {
|
||||||
updateSegment({
|
updateSegmentFilter({
|
||||||
segmentType: newValue.group,
|
segmentType: newValue.group,
|
||||||
action: newValue.value,
|
action: newValue.value,
|
||||||
});
|
}, index);
|
||||||
}}
|
}}
|
||||||
automationId="select-segment-action"
|
automationId="select-segment-action"
|
||||||
isFullWidth
|
isFullWidth
|
||||||
/>
|
/>
|
||||||
{segment.segmentType !== undefined && (
|
{filterRow.index !== undefined && (
|
||||||
<FormFilterFields />
|
<FormFilterFields filterIndex={filterRow.index} />
|
||||||
)}
|
)}
|
||||||
</Grid.ThreeColumns>
|
</Grid.ThreeColumns>
|
||||||
<div className="mailpoet-gap" />
|
<div className="mailpoet-gap" />
|
||||||
|
</>
|
||||||
|
))}
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
dimension="small"
|
dimension="small"
|
||||||
variant="link"
|
variant="link"
|
||||||
iconStart={plusIcon}
|
iconStart={plusIcon}
|
||||||
|
onClick={(e): void => {
|
||||||
|
e.preventDefault();
|
||||||
|
const filters = segment.filters;
|
||||||
|
filters.push({
|
||||||
|
segmentType: SegmentTypes.WordPressRole,
|
||||||
|
action: SubscriberActionTypes.WORDPRESS_ROLE,
|
||||||
|
});
|
||||||
|
updateSegment({
|
||||||
|
filters,
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{MailPoet.I18n.t('addCondition')}
|
{MailPoet.I18n.t('addCondition')}
|
||||||
</Button>
|
</Button>
|
||||||
|
@@ -35,10 +35,14 @@ export interface FilterValue extends SelectOption {
|
|||||||
group: SegmentTypes;
|
group: SegmentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FilterRow {
|
||||||
|
filterValue: FilterValue;
|
||||||
|
index: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FormItem {
|
export interface FormItem {
|
||||||
|
id?: number;
|
||||||
segmentType?: string;
|
segmentType?: string;
|
||||||
name?: string;
|
|
||||||
description?: string;
|
|
||||||
action?: string;
|
action?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +79,13 @@ export interface EmailFormItem extends FormItem {
|
|||||||
days?: string;
|
days?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Segment = {
|
||||||
|
id?: number;
|
||||||
|
name?: string;
|
||||||
|
description?: string;
|
||||||
|
filters?: AnyFormItem[];
|
||||||
|
}
|
||||||
|
|
||||||
export type AnyFormItem =
|
export type AnyFormItem =
|
||||||
WordpressRoleFormItem |
|
WordpressRoleFormItem |
|
||||||
WooCommerceFormItem |
|
WooCommerceFormItem |
|
||||||
@@ -145,7 +156,7 @@ export interface StateType {
|
|||||||
wooCurrencySymbol: string;
|
wooCurrencySymbol: string;
|
||||||
wooCountries: WindowWooCommerceCountries;
|
wooCountries: WindowWooCommerceCountries;
|
||||||
customFieldsList: WindowCustomFields;
|
customFieldsList: WindowCustomFields;
|
||||||
segment: AnyFormItem,
|
segment: Segment,
|
||||||
errors: string[],
|
errors: string[],
|
||||||
allAvailableFilters: GroupFilterValue[],
|
allAvailableFilters: GroupFilterValue[],
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user