diff --git a/assets/js/src/post_editor_block/edit.jsx b/assets/js/src/post_editor_block/edit.jsx index 0f184001d6..0a63229ed9 100644 --- a/assets/js/src/post_editor_block/edit.jsx +++ b/assets/js/src/post_editor_block/edit.jsx @@ -1,18 +1,26 @@ /* eslint-disable react/react-in-jsx-scope */ -const wp = window.wp; -const { useState } = wp.element; +import PropTypes from 'prop-types'; const allForms = window.mailpoet_forms; -function Edit() { +function Edit({ attributes, setAttributes }) { function displayFormsSelect() { if (!Array.isArray(allForms)) return null; if (allForms.length === 0) return null; return ( - { + setAttributes({ + selectedForm: parseInt(event.target.value, 10), + }); + }} + defaultValue={attributes.selectedForm} + > {allForms.map((form) => ( - + ))} ); @@ -26,4 +34,11 @@ function Edit() { ); } +Edit.propTypes = { + attributes: PropTypes.shape({ + selectedForm: PropTypes.number, + }).isRequired, + setAttributes: PropTypes.func.isRequired, +}; + export default Edit; diff --git a/assets/js/src/post_editor_block/form_block.jsx b/assets/js/src/post_editor_block/form_block.jsx index 5f18e4eb60..3b34eeb0a4 100644 --- a/assets/js/src/post_editor_block/form_block.jsx +++ b/assets/js/src/post_editor_block/form_block.jsx @@ -9,6 +9,12 @@ registerBlockType('mailpoet/form-block', { icon: Icon, category: 'widgets', example: {}, + attributes: { + selectedForm: { + type: 'number', + default: null, + }, + }, edit: Edit, save() { return null;