Add Manage subscription page

[MAILPOET-2677]
This commit is contained in:
Amine Ben hammou
2020-03-11 23:31:13 +01:00
committed by Veljko V
parent 48c6fcce37
commit 6026327b1f
10 changed files with 114 additions and 4 deletions

View File

@@ -3,3 +3,4 @@ export { default as Label } from './label';
export { default as Inputs } from './inputs';
export { default as SaveButton } from './save_button';
export { default as SegmentsSelect } from './segments_select';
export { default as PagesSelect } from './pages_select';

View File

@@ -1,8 +1,8 @@
import React from 'react';
import React, { ReactNode } from 'react';
type Props = {
title: string
description: string
description: ReactNode
htmlFor: string
}

View File

@@ -0,0 +1,39 @@
import React from 'react';
import { onChange, t } from 'settings/utils';
import { useSelector } from 'settings/store/hooks';
type Props = {
id?: string
value: string
linkAutomationId?: string
setValue: (x: string) => any
preview: 'manage' | 'unsubscribe' | 'confirm'
}
export default (props: Props) => {
const pages = useSelector('getPages')();
const selectedPage = props.value
? pages.find((x) => x.id === parseInt(props.value, 10))
: pages[0];
return (
<>
<select id={props.id} value={props.value} onChange={onChange(props.setValue)}>
{pages.map((page) => (
<option key={page.id} value={page.id}>
{`${page.title}`}
</option>
))}
</select>
{' '}
<a
target="_blank"
title={t`previewPage`}
rel="noopener noreferrer"
href={selectedPage.url[props.preview]}
data-automation-id={props.linkAutomationId}
>
{t`preview`}
</a>
</>
);
};

View File

@@ -4,7 +4,7 @@ import 'select2';
import { useSelector } from 'settings/store/hooks';
type Props = {
id?: string
id: string
value: string[]
placeholder?: string
setValue: (x: string[]) => any

View File

@@ -3,6 +3,7 @@ import { SaveButton } from 'settings/components';
import { t } from 'settings/utils';
import DefaultSender from './default_sender';
import SubscribeOn from './subscribe_on';
import ManageSubscription from './manage_subscription';
export default function Basics() {
return (
@@ -18,6 +19,7 @@ export default function Basics() {
title={t`subscribeInRegistrationTitle`}
description={t`subscribeInRegistrationDescription`}
/>
<ManageSubscription />
<SaveButton />
</div>
);

View File

@@ -0,0 +1,44 @@
import React from 'react';
import { t } from 'settings/utils';
import { useSetting } from 'settings/store/hooks';
import {
Label, Inputs, SegmentsSelect, PagesSelect,
} from 'settings/components';
export default function ManageSubscription() {
const [page, setPage] = useSetting('subscription', 'pages', 'manage');
const [segments, setSegments] = useSetting('subscription', 'segments');
return (
<>
<Label
title={t`manageSubTitle`}
description={(
<>
{t`manageSubDescription1`}
<br />
{t`manageSubDescription2`}
</>
)}
htmlFor="subscription-pages-manage"
/>
<Inputs>
<PagesSelect
value={page}
preview="manage"
setValue={setPage}
id="subscription-pages-manage"
linkAutomationId="preview_manage_subscription_page_link"
/>
<br />
<label htmlFor="subscription-segments">{t`subscribersCanChooseFrom`}</label>
<br />
<SegmentsSelect
id="subscription-segments"
value={segments}
setValue={setSegments}
placeholder={t`leaveEmptyToDisplayAll`}
/>
</Inputs>
</>
);
}

View File

@@ -12,5 +12,6 @@ export default function makeDefaultState(window: any): State {
},
data: window.mailpoet_settings,
segments: window.mailpoet_segments,
pages: window.mailpoet_pages,
};
}

View File

@@ -36,3 +36,7 @@ export function isMssActive(state: State) {
export function getSegments(state: State) {
return state.segments;
}
export function getPages(state: State) {
return state.pages;
}

View File

@@ -45,10 +45,19 @@ type Segment = {
name: string
subscribers: string
}
type Page = {
id: number
title: string
url: {
unsubscribe: string
manage: string
confirm: string
}
}
export type State = {
data: Settings
segments: Segment[]
pages: Page[]
flags: {
woocommerce: boolean
newUser: boolean