-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
index.js
43 lines (39 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* WordPress dependencies
*/
import { Notice, Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
function TemplateValidationNotice( { isValid, ...props } ) {
if ( isValid ) {
return null;
}
const confirmSynchronization = () => {
// eslint-disable-next-line no-alert
if ( window.confirm( __( 'Resetting the template may result in loss of content, do you want to continue?' ) ) ) {
props.synchronizeTemplate();
}
};
return (
<Notice className="editor-template-validation-notice" isDismissible={ false } status="warning">
<p>{ __( 'The content of your post doesn’t match the template assigned to your post type.' ) }</p>
<div>
<Button isDefault onClick={ props.resetTemplateValidity }>{ __( 'Keep it as is' ) }</Button>
<Button onClick={ confirmSynchronization } isPrimary>{ __( 'Reset the template' ) }</Button>
</div>
</Notice>
);
}
export default compose( [
withSelect( ( select ) => ( {
isValid: select( 'core/editor' ).isValidTemplate(),
} ) ),
withDispatch( ( dispatch ) => {
const { setTemplateValidity, synchronizeTemplate } = dispatch( 'core/editor' );
return {
resetTemplateValidity: () => setTemplateValidity( true ),
synchronizeTemplate,
};
} ),
] )( TemplateValidationNotice );