Add subscribe in comments and registration
[MAILPOET-2677]
This commit is contained in:
committed by
Veljko V
parent
ecffd118af
commit
57e881dff5
@@ -30,6 +30,10 @@
|
|||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mailpoet-settings-inputs input.regular-text {
|
||||||
|
width: 25.5em;
|
||||||
|
}
|
||||||
|
|
||||||
.mailpoet-settings-inputs .regular-text p {
|
.mailpoet-settings-inputs .regular-text p {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,15 @@ import $ from 'jquery';
|
|||||||
import 'select2';
|
import 'select2';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string
|
id?: string
|
||||||
value: string[]
|
value: string[]
|
||||||
|
placeholder?: string
|
||||||
setValue: (x: string[]) => any
|
setValue: (x: string[]) => any
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ id, value, setValue }: Props) => {
|
export default ({
|
||||||
|
id, value, placeholder, setValue,
|
||||||
|
}: Props) => {
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
const idSelector = `#${id}`;
|
const idSelector = `#${id}`;
|
||||||
$(idSelector).select2();
|
$(idSelector).select2();
|
||||||
@@ -19,7 +22,7 @@ export default ({ id, value, setValue }: Props) => {
|
|||||||
}, [id, setValue]);
|
}, [id, setValue]);
|
||||||
const segments: any[] = (window as any).mailpoet_segments;
|
const segments: any[] = (window as any).mailpoet_segments;
|
||||||
return (
|
return (
|
||||||
<select id={id} defaultValue={value} multiple>
|
<select id={id} data-placeholder={placeholder} defaultValue={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})`}
|
||||||
|
@@ -1,11 +1,23 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SaveButton } from 'settings/components';
|
import { SaveButton } from 'settings/components';
|
||||||
|
import { t } from 'settings/utils';
|
||||||
import DefaultSender from './default_sender';
|
import DefaultSender from './default_sender';
|
||||||
|
import SubscribeOn from './subscribe_on';
|
||||||
|
|
||||||
export default function Basics() {
|
export default function Basics() {
|
||||||
return (
|
return (
|
||||||
<div className="mailpoet-settings-grid">
|
<div className="mailpoet-settings-grid">
|
||||||
<DefaultSender />
|
<DefaultSender />
|
||||||
|
<SubscribeOn
|
||||||
|
event="on_comment"
|
||||||
|
title={t`subscribeInCommentsTitle`}
|
||||||
|
description={t`subscribeInCommentsDescription`}
|
||||||
|
/>
|
||||||
|
<SubscribeOn
|
||||||
|
event="on_register"
|
||||||
|
title={t`subscribeInRegistrationTitle`}
|
||||||
|
description={t`subscribeInRegistrationDescription`}
|
||||||
|
/>
|
||||||
<SaveButton />
|
<SaveButton />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
48
assets/js/src/settings/pages/basics/subscribe_on.tsx
Normal file
48
assets/js/src/settings/pages/basics/subscribe_on.tsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { t, onChange, onToggle } from 'settings/utils';
|
||||||
|
import { useSetting } from 'settings/store/hooks';
|
||||||
|
import { Label, Inputs, SegmentsSelect } from 'settings/components';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
event: 'on_comment' | 'on_register'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SubscribeOn({ title, description, event }: Props) {
|
||||||
|
const [enabled, setEnabled] = useSetting('subscribe', event, 'enabled');
|
||||||
|
const [label, setLabel] = useSetting('subscribe', event, 'label');
|
||||||
|
const [segments, setSegments] = useSetting('subscribe', event, 'segments');
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Label
|
||||||
|
title={title}
|
||||||
|
description={description}
|
||||||
|
htmlFor={`subscribe-${event}-enabled`}
|
||||||
|
/>
|
||||||
|
<Inputs>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={`subscribe-${event}-enabled`}
|
||||||
|
checked={enabled === '1'}
|
||||||
|
onChange={onToggle(setEnabled)}
|
||||||
|
/>
|
||||||
|
{enabled === '1' && (
|
||||||
|
<>
|
||||||
|
<br />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="regular-text"
|
||||||
|
value={label || t`yesAddMe`}
|
||||||
|
onChange={onChange(setLabel)}
|
||||||
|
/>
|
||||||
|
<br />
|
||||||
|
<label htmlFor={`subscribe-${event}-segments`}>{t`usersWillBeSubscribedTo`}</label>
|
||||||
|
<br />
|
||||||
|
<SegmentsSelect id={`subscribe-${event}-segments`} placeholder={t`chooseList`} value={segments} setValue={setSegments} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Inputs>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
@@ -9,12 +9,12 @@ export type Settings = {
|
|||||||
}
|
}
|
||||||
subscribe: {
|
subscribe: {
|
||||||
on_comment: {
|
on_comment: {
|
||||||
enabled: boolean
|
enabled: '1' | '0'
|
||||||
label: string
|
label: string
|
||||||
segments: string[]
|
segments: string[]
|
||||||
}
|
}
|
||||||
on_register: {
|
on_register: {
|
||||||
enabled: boolean
|
enabled: '1' | '0'
|
||||||
label: string
|
label: string
|
||||||
segments: string[]
|
segments: string[]
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,10 @@ import MailPoet from 'mailpoet';
|
|||||||
import { ChangeEvent } from 'react';
|
import { ChangeEvent } from 'react';
|
||||||
|
|
||||||
type Setter = (value: string) => any
|
type Setter = (value: string) => any
|
||||||
type Event = ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
|
type Event = ChangeEvent<any>
|
||||||
|
|
||||||
export const onChange = (setter: Setter) => (e: Event) => setter(e.target.value);
|
export const onChange = (setter: Setter) => (e: Event) => setter(e.target.value);
|
||||||
|
|
||||||
|
export const onToggle = (setter: Setter) => (e: Event) => setter(e.target.checked ? '1' : '0');
|
||||||
|
|
||||||
export const t = ([word]: TemplateStringsArray) => MailPoet.I18n.t(word);
|
export const t = ([word]: TemplateStringsArray) => MailPoet.I18n.t(word);
|
||||||
|
@@ -41,6 +41,13 @@
|
|||||||
'yourName': __('Your name'),
|
'yourName': __('Your name'),
|
||||||
'replyTo': __('Reply-to'),
|
'replyTo': __('Reply-to'),
|
||||||
|
|
||||||
|
'subscribeInCommentsTitle': __('Subscribe in comments'),
|
||||||
|
'subscribeInCommentsDescription': __('Visitors that comment on a post can subscribe to your list via a checkbox.'),
|
||||||
|
'subscribeInRegistrationTitle': __('Subscribe in registration form'),
|
||||||
|
'subscribeInRegistrationDescription': __('Allow users who register as a WordPress user on your website to subscribe to a MailPoet list (in addition to the "WordPress Users" list). This also enables WordPress users to receive confirmation emails (if sign-up confirmation is enabled).'),
|
||||||
|
'usersWillBeSubscribedTo': __('Users will be subscribed to these lists:'),
|
||||||
|
'yesAddMe': __('Yes, add me to your mailing list'),
|
||||||
|
'chooseList': __('Choose a list'),
|
||||||
|
|
||||||
'reinstallConfirmation': __('Are you sure? All of your MailPoet data will be permanently erased (newsletters, statistics, subscribers, etc.).'),
|
'reinstallConfirmation': __('Are you sure? All of your MailPoet data will be permanently erased (newsletters, statistics, subscribers, etc.).'),
|
||||||
'announcementHeader': __('Get notified when someone subscribes'),
|
'announcementHeader': __('Get notified when someone subscribes'),
|
||||||
|
Reference in New Issue
Block a user