diff --git a/packages/editor/src/components/template-validation-notice/index.js b/packages/editor/src/components/template-validation-notice/index.js
index 64e2227e30febe..4aa1faac4bd9ce 100644
--- a/packages/editor/src/components/template-validation-notice/index.js
+++ b/packages/editor/src/components/template-validation-notice/index.js
@@ -1,63 +1,61 @@
/**
* WordPress dependencies
*/
-import { Notice } from '@wordpress/components';
+import {
+ Notice,
+ __experimentalConfirmDialog as ConfirmDialog,
+} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
-import { withSelect, withDispatch } from '@wordpress/data';
-import { compose } from '@wordpress/compose';
+import { useDispatch, useSelect } from '@wordpress/data';
+import { useState } from '@wordpress/element';
import { store as blockEditorStore } from '@wordpress/block-editor';
-function TemplateValidationNotice( { isValid, ...props } ) {
+export default function TemplateValidationNotice() {
+ const [ showConfirmDialog, setShowConfirmDialog ] = useState( false );
+ const isValid = useSelect( ( select ) => {
+ return select( blockEditorStore ).isValidTemplate();
+ }, [] );
+ const { setTemplateValidity, synchronizeTemplate } =
+ useDispatch( blockEditorStore );
+
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 (
-
- { __(
- 'The content of your post doesn’t match the template assigned to your post type.'
- ) }
-
+ <>
+ setTemplateValidity( true ),
+ },
+ {
+ label: __( 'Reset the template' ),
+ onClick: () => setShowConfirmDialog( true ),
+ },
+ ] }
+ >
+ { __(
+ 'The content of your post doesn’t match the template assigned to your post type.'
+ ) }
+
+ {
+ setShowConfirmDialog( false );
+ synchronizeTemplate();
+ } }
+ onCancel={ () => setShowConfirmDialog( false ) }
+ >
+ { __(
+ 'Resetting the template may result in loss of content, do you want to continue?'
+ ) }
+
+ >
);
}
-
-export default compose( [
- withSelect( ( select ) => ( {
- isValid: select( blockEditorStore ).isValidTemplate(),
- } ) ),
- withDispatch( ( dispatch ) => {
- const { setTemplateValidity, synchronizeTemplate } =
- dispatch( blockEditorStore );
- return {
- resetTemplateValidity: () => setTemplateValidity( true ),
- synchronizeTemplate,
- };
- } ),
-] )( TemplateValidationNotice );
diff --git a/packages/editor/src/components/template-validation-notice/style.scss b/packages/editor/src/components/template-validation-notice/style.scss
deleted file mode 100644
index dde63f7e36b14c..00000000000000
--- a/packages/editor/src/components/template-validation-notice/style.scss
+++ /dev/null
@@ -1,9 +0,0 @@
-.editor-template-validation-notice {
- display: flex;
- justify-content: space-between;
- align-items: center;
-
- .components-button {
- margin-left: 5px;
- }
-}
diff --git a/packages/editor/src/style.scss b/packages/editor/src/style.scss
index f0593f4bee2683..fd8f5821392c68 100644
--- a/packages/editor/src/style.scss
+++ b/packages/editor/src/style.scss
@@ -31,4 +31,3 @@
@import "./components/preview-dropdown/style.scss";
@import "./components/table-of-contents/style.scss";
@import "./components/template-areas/style.scss";
-@import "./components/template-validation-notice/style.scss";