Add Form preview rudimentary component
[MAILPOET-2602]
This commit is contained in:
committed by
Jack Kitterhing
parent
8439b8cb2e
commit
176ecef4f7
19
assets/js/src/common/preview.jsx
Normal file
19
assets/js/src/common/preview.jsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
|
||||||
|
function Preview({
|
||||||
|
children,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{children}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Preview.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Preview;
|
48
assets/js/src/form_editor/components/preview.jsx
Normal file
48
assets/js/src/form_editor/components/preview.jsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Modal, Spinner } from '@wordpress/components';
|
||||||
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
|
|
||||||
|
import Preview from '../../common/preview.jsx';
|
||||||
|
|
||||||
|
const FormPreview = () => {
|
||||||
|
const [form, setForm] = useState(null);
|
||||||
|
|
||||||
|
const { hidePreview } = useDispatch('mailpoet-form-editor');
|
||||||
|
const isPreview = useSelect(
|
||||||
|
(select) => select('mailpoet-form-editor').getIsPreviewShown(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
function loadFormPreviewFromServer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isPreview) {
|
||||||
|
loadFormPreviewFromServer();
|
||||||
|
}
|
||||||
|
}, [isPreview]);
|
||||||
|
|
||||||
|
if (!isPreview) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
isDismissible
|
||||||
|
shouldCloseOnEsc
|
||||||
|
shouldCloseOnClickOutside
|
||||||
|
title="Form Preview"
|
||||||
|
onRequestClose={hidePreview}
|
||||||
|
>
|
||||||
|
<Preview>
|
||||||
|
{form === null && (
|
||||||
|
<Spinner />
|
||||||
|
)}
|
||||||
|
{form !== null && (
|
||||||
|
<div dangerouslySetInnerHTML={form} />
|
||||||
|
)}
|
||||||
|
</Preview>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FormPreview;
|
Reference in New Issue
Block a user