@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
55 lines (53 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = TemplateValidationNotice;
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _data = require("@wordpress/data");
var _element = require("@wordpress/element");
var _blockEditor = require("@wordpress/block-editor");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
function TemplateValidationNotice() {
const [showConfirmDialog, setShowConfirmDialog] = (0, _element.useState)(false);
const isValid = (0, _data.useSelect)(select => {
return select(_blockEditor.store).isValidTemplate();
}, []);
const {
setTemplateValidity,
synchronizeTemplate
} = (0, _data.useDispatch)(_blockEditor.store);
if (isValid) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Notice, {
className: "editor-template-validation-notice",
isDismissible: false,
status: "warning",
actions: [{
label: (0, _i18n.__)('Keep it as is'),
onClick: () => setTemplateValidity(true)
}, {
label: (0, _i18n.__)('Reset the template'),
onClick: () => setShowConfirmDialog(true)
}],
children: (0, _i18n.__)('The content of your post doesn’t match the template assigned to your post type.')
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalConfirmDialog, {
isOpen: showConfirmDialog,
confirmButtonText: (0, _i18n.__)('Reset'),
onConfirm: () => {
setShowConfirmDialog(false);
synchronizeTemplate();
},
onCancel: () => setShowConfirmDialog(false),
size: "medium",
children: (0, _i18n.__)('Resetting the template may result in loss of content, do you want to continue?')
})]
});
}
//# sourceMappingURL=index.js.map