Set content pattern when selecting template from select tempate modal
[MAILPOET-6014]
This commit is contained in:
committed by
Mike Jolley
parent
f159a23a8a
commit
4becea02ff
@@ -1,6 +1,8 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
// @ts-expect-error No types available for this component
|
// @ts-expect-error No types available for this component
|
||||||
import { BlockPreview } from '@wordpress/block-editor';
|
import { BlockPreview } from '@wordpress/block-editor';
|
||||||
|
import { store as editorStore } from '@wordpress/editor';
|
||||||
|
import { dispatch } from '@wordpress/data';
|
||||||
import { Modal } from '@wordpress/components';
|
import { Modal } from '@wordpress/components';
|
||||||
import { Async } from 'email-editor/engine/components/sidebar/template-select/async';
|
import { Async } from 'email-editor/engine/components/sidebar/template-select/async';
|
||||||
import { getTemplatesForPreview } from './templates-data';
|
import { getTemplatesForPreview } from './templates-data';
|
||||||
@@ -10,6 +12,12 @@ export function SelectTemplateModal({ isOpen, setIsOpen }) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const templates = getTemplatesForPreview();
|
const templates = getTemplatesForPreview();
|
||||||
|
|
||||||
|
const handleTemplateSelection = (template) => {
|
||||||
|
setIsOpen(false);
|
||||||
|
void dispatch(editorStore).resetEditorBlocks(template.patternParsed);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||||
<Modal title="Select a template" onRequestClose={() => setIsOpen(false)}>
|
<Modal title="Select a template" onRequestClose={() => setIsOpen(false)}>
|
||||||
@@ -17,11 +25,22 @@ export function SelectTemplateModal({ isOpen, setIsOpen }) {
|
|||||||
<div key={template.id}>
|
<div key={template.id}>
|
||||||
<h2>{`Template ${template.id}`}</h2>
|
<h2>{`Template ${template.id}`}</h2>
|
||||||
<div
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
style={{
|
style={{
|
||||||
width: '450px',
|
width: '450px',
|
||||||
border: '1px solid #000',
|
border: '1px solid #000',
|
||||||
padding: '20px',
|
padding: '20px',
|
||||||
display: 'block',
|
display: 'block',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
handleTemplateSelection(template);
|
||||||
|
}}
|
||||||
|
onKeyPress={(event) => {
|
||||||
|
if (event.key === 'Enter' || event.key === ' ') {
|
||||||
|
handleTemplateSelection(template);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Async placeholder={<p>rendering template</p>}>
|
<Async placeholder={<p>rendering template</p>}>
|
||||||
|
@@ -54,8 +54,8 @@ export function getTemplatesForPreview() {
|
|||||||
return {
|
return {
|
||||||
id: template.id,
|
id: template.id,
|
||||||
contentParsed: parse(fullContent),
|
contentParsed: parse(fullContent),
|
||||||
|
patternParsed: parse(contentPattern),
|
||||||
template,
|
template,
|
||||||
pattern: contentPattern,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user