Add segments to the state
[MAILPOET-2677]
This commit is contained in:
committed by
Veljko V
parent
57e881dff5
commit
48c6fcce37
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import 'select2';
|
import 'select2';
|
||||||
|
import { useSelector } from 'settings/store/hooks';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id?: string
|
id?: string
|
||||||
@@ -9,9 +10,9 @@ type Props = {
|
|||||||
setValue: (x: string[]) => any
|
setValue: (x: string[]) => any
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({
|
export default (props: Props) => {
|
||||||
id, value, placeholder, setValue,
|
const { id, setValue } = props;
|
||||||
}: Props) => {
|
const segments = useSelector('getSegments')();
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
const idSelector = `#${id}`;
|
const idSelector = `#${id}`;
|
||||||
$(idSelector).select2();
|
$(idSelector).select2();
|
||||||
@@ -20,9 +21,9 @@ export default ({
|
|||||||
});
|
});
|
||||||
return () => $(idSelector).select2('destroy');
|
return () => $(idSelector).select2('destroy');
|
||||||
}, [id, setValue]);
|
}, [id, setValue]);
|
||||||
const segments: any[] = (window as any).mailpoet_segments;
|
|
||||||
return (
|
return (
|
||||||
<select id={id} data-placeholder={placeholder} defaultValue={value} multiple>
|
<select id={id} data-placeholder={props.placeholder} defaultValue={props.value} multiple>
|
||||||
{segments.map((seg) => (
|
{segments.map((seg) => (
|
||||||
<option key={seg.id} value={seg.id}>
|
<option key={seg.id} value={seg.id}>
|
||||||
{`${seg.name} (${seg.subscribers})`}
|
{`${seg.name} (${seg.subscribers})`}
|
||||||
|
@@ -11,5 +11,6 @@ export default function makeDefaultState(window: any): State {
|
|||||||
newUser: !!window.mailpoet_is_new_user,
|
newUser: !!window.mailpoet_is_new_user,
|
||||||
},
|
},
|
||||||
data: window.mailpoet_settings,
|
data: window.mailpoet_settings,
|
||||||
|
segments: window.mailpoet_segments,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -32,3 +32,7 @@ export function isNewUser(state: State) {
|
|||||||
export function isMssActive(state: State) {
|
export function isMssActive(state: State) {
|
||||||
return _.get(state, 'mta.method') === 'MailPoet';
|
return _.get(state, 'mta.method') === 'MailPoet';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSegments(state: State) {
|
||||||
|
return state.segments;
|
||||||
|
}
|
||||||
|
@@ -40,8 +40,15 @@ export type Settings = {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Segment = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
subscribers: string
|
||||||
|
}
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
data: Settings
|
data: Settings
|
||||||
|
segments: Segment[]
|
||||||
flags: {
|
flags: {
|
||||||
woocommerce: boolean
|
woocommerce: boolean
|
||||||
newUser: boolean
|
newUser: boolean
|
||||||
|
Reference in New Issue
Block a user