Render form teplates selection categories
[MAILPOET-2988]
This commit is contained in:
committed by
Veljko V
parent
85a729ed86
commit
6d1431b84a
@ -1,47 +1,72 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import Heading from 'common/typography/heading/heading';
|
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { Button } from '@wordpress/components';
|
import { Button } from '@wordpress/components';
|
||||||
|
import Categories from 'common/categories/categories';
|
||||||
import { TemplateType } from './store/types';
|
import Background from 'common/background/background';
|
||||||
|
import { TemplateData } from './store/types';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const templates: Array<TemplateType> = useSelect(
|
const [selectedCategory, setSelectedCategory] = useState('popup');
|
||||||
|
|
||||||
|
const categories = [
|
||||||
|
{
|
||||||
|
name: 'popup',
|
||||||
|
label: MailPoet.I18n.t('popupCategory'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'fixed_bar',
|
||||||
|
label: MailPoet.I18n.t('fixedBarCategory'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'below_posts',
|
||||||
|
label: MailPoet.I18n.t('belowPagesCategory'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'slide_in',
|
||||||
|
label: MailPoet.I18n.t('slideInCategory'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'others',
|
||||||
|
label: MailPoet.I18n.t('othersCategory'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const templates: TemplateData = useSelect(
|
||||||
(select) => select('mailpoet-form-editor-templates').getTemplates(),
|
(select) => select('mailpoet-form-editor-templates').getTemplates(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const selectTemplateFailed: boolean = useSelect(
|
|
||||||
(select) => select('mailpoet-form-editor-templates').getSelectTemplateFailed(),
|
// const selectTemplateFailed: boolean = useSelect(
|
||||||
[]
|
// (select) => select('mailpoet-form-editor-templates').getSelectTemplateFailed(),
|
||||||
);
|
// []
|
||||||
|
// );
|
||||||
|
|
||||||
const { selectTemplate } = useDispatch('mailpoet-form-editor-templates');
|
const { selectTemplate } = useDispatch('mailpoet-form-editor-templates');
|
||||||
return (
|
return (
|
||||||
<div className="template-selection" data-automation-id="template_selection_list">
|
<div className="template-selection" data-automation-id="template_selection_list">
|
||||||
<Heading level={1}>{MailPoet.I18n.t('heading')}</Heading>
|
<Background color="#fff" />
|
||||||
{selectTemplateFailed && (<div className="mailpoet_error">Failed</div>)}
|
<div className="mailpoet-templates">
|
||||||
<ol>
|
<Categories
|
||||||
<li>
|
categories={categories}
|
||||||
<Button
|
active={selectedCategory}
|
||||||
isLink
|
onSelect={setSelectedCategory}
|
||||||
data-automation-id="blank_template"
|
/>
|
||||||
onClick={() => selectTemplate()}
|
<ol>
|
||||||
>
|
{templates[selectedCategory].map((template, index) => (
|
||||||
{MailPoet.I18n.t('blankTemplate')}
|
<li key={template.id}>
|
||||||
</Button>
|
<Button
|
||||||
</li>
|
isLink
|
||||||
{templates.map((template, index) => (
|
onClick={() => selectTemplate(template.id)}
|
||||||
<li key={template.id}>
|
data-automation-id={`template_index_${index}`}
|
||||||
<Button
|
>
|
||||||
isLink
|
{template.name}
|
||||||
onClick={() => selectTemplate(template.id)}
|
</Button>
|
||||||
data-automation-id={`template_index_${index}`}
|
</li>
|
||||||
>
|
))}
|
||||||
{template.name}
|
</ol>
|
||||||
</Button>
|
</div>
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ol>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,3 +2,7 @@ export type TemplateType = {
|
|||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TemplateData = {
|
||||||
|
[formType: string]: Array<TemplateType>
|
||||||
|
}
|
||||||
|
@ -32,6 +32,11 @@
|
|||||||
<%= localize({
|
<%= localize({
|
||||||
'heading': __('Select form template'),
|
'heading': __('Select form template'),
|
||||||
'blankTemplate': _x('Blank template', 'the first item in the templates selection list'),
|
'blankTemplate': _x('Blank template', 'the first item in the templates selection list'),
|
||||||
|
'fixedBarCategory': _x('Fixed bar', 'This is a text on a widget that leads to settings for form placement - form type is fixed bar'),
|
||||||
|
'slideInCategory': _x('Slide–in', 'This is a text on a widget that leads to settings for form placement - form type is slide in'),
|
||||||
|
'popupCategory': _x('Pop up', 'This is a text on a widget that leads to settings for form placement - form type is pop up, it will be displayed on page in a small modal window'),
|
||||||
|
'belowPagesCategory': _x('Below pages', 'This is a text on a widget that leads to settings for form placement'),
|
||||||
|
'othersCategory': _x('Others (widget)', 'Placement of the form using theme widget'),
|
||||||
}) %>
|
}) %>
|
||||||
<% endblock %>
|
<% endblock %>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user