UNPKG

@wordpress/editor

Version:
53 lines (48 loc) 1.5 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { Notice } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; import { store as blockEditorStore } from '@wordpress/block-editor'; function TemplateValidationNotice({ isValid, ...props }) { if (isValid) { return null; } const confirmSynchronization = () => { if ( // eslint-disable-next-line no-alert window.confirm(__('Resetting the template may result in loss of content, do you want to continue?'))) { props.synchronizeTemplate(); } }; return createElement(Notice, { className: "editor-template-validation-notice", isDismissible: false, status: "warning", actions: [{ label: __('Keep it as is'), onClick: props.resetTemplateValidity }, { label: __('Reset the template'), onClick: confirmSynchronization }] }, __('The content of your post doesn’t match the template assigned to your post type.')); } export default compose([withSelect(select => ({ isValid: select(blockEditorStore).isValidTemplate() })), withDispatch(dispatch => { const { setTemplateValidity, synchronizeTemplate } = dispatch(blockEditorStore); return { resetTemplateValidity: () => setTemplateValidity(true), synchronizeTemplate }; })])(TemplateValidationNotice); //# sourceMappingURL=index.js.map