diff --git a/packages/edit-post/src/components/sidebar/post-schedule/index.js b/packages/edit-post/src/components/sidebar/post-schedule/index.js index cf644bc9a6ae1e..756c366de91adb 100644 --- a/packages/edit-post/src/components/sidebar/post-schedule/index.js +++ b/packages/edit-post/src/components/sidebar/post-schedule/index.js @@ -32,6 +32,7 @@ export function PostSchedule() { renderContent={ () => } /> + ); } diff --git a/packages/edit-post/src/components/sidebar/post-schedule/style.scss b/packages/edit-post/src/components/sidebar/post-schedule/style.scss index c19896af20ab63..5b4d0d92ec8169 100644 --- a/packages/edit-post/src/components/sidebar/post-schedule/style.scss +++ b/packages/edit-post/src/components/sidebar/post-schedule/style.scss @@ -12,3 +12,11 @@ .components-button.edit-post-post-schedule__toggle { text-align: right; } + +.edit-post-post-schedule-warning { + margin: 0; + + .edit-post-post-status & { + margin-top: $grid-unit; + } +} diff --git a/packages/editor/src/components/post-publish-panel/prepublish.js b/packages/editor/src/components/post-publish-panel/prepublish.js index 916f42239fe2e8..a9caf23283cc6f 100644 --- a/packages/editor/src/components/post-publish-panel/prepublish.js +++ b/packages/editor/src/components/post-publish-panel/prepublish.js @@ -80,6 +80,9 @@ function PostPublishPanelPrepublish( { > + + + ) } diff --git a/packages/editor/src/components/post-publish-panel/style.scss b/packages/editor/src/components/post-publish-panel/style.scss index b16226bd48fa5e..40565fa79d75a2 100644 --- a/packages/editor/src/components/post-publish-panel/style.scss +++ b/packages/editor/src/components/post-publish-panel/style.scss @@ -146,3 +146,12 @@ .post-publish-panel__tip { color: $alert-yellow; } + +.editor-post-publish-panel__warning { + margin: 0; +} + +.editor-post-publish-panel_warning.is-opened { + border-top: 0; + padding-top: $grid-unit-05; +} diff --git a/packages/editor/src/components/post-schedule/index.js b/packages/editor/src/components/post-schedule/index.js index 549a12074244bc..137e82f23368a8 100644 --- a/packages/editor/src/components/post-schedule/index.js +++ b/packages/editor/src/components/post-schedule/index.js @@ -2,13 +2,43 @@ * WordPress dependencies */ import { __experimentalGetSettings } from '@wordpress/date'; -import { withSelect, withDispatch } from '@wordpress/data'; -import { compose } from '@wordpress/compose'; -import { DateTimePicker } from '@wordpress/components'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { DateTimePicker, Notice } from '@wordpress/components'; +import { __ } from '@wordpress/i18n'; -export function PostSchedule( { date, onUpdateDate } ) { +export function Warning() { + const { date, isFloating } = useSelect( ( select ) => { + const { getEditedPostAttribute, isEditedPostDateFloating } = select( + 'core/editor' + ); + return { + date: getEditedPostAttribute( 'date' ), + isFloating: isEditedPostDateFloating(), + }; + } ); + + if ( isFloating || Date.parse( date ) >= Date.now() ) { + return null; + } + + return ( + + { __( 'Your post will be backdated.' ) } + + ); +} + +export function PostSchedule() { + const date = useSelect( ( select ) => + select( 'core/editor' ).getEditedPostAttribute( 'date' ) + ); + const { editPost } = useDispatch( 'core/editor' ); const onChange = ( newDate ) => { - onUpdateDate( newDate ); + editPost( { date: newDate } ); document.activeElement.blur(); }; const settings = __experimentalGetSettings(); @@ -33,17 +63,6 @@ export function PostSchedule( { date, onUpdateDate } ) { ); } -export default compose( [ - withSelect( ( select ) => { - return { - date: select( 'core/editor' ).getEditedPostAttribute( 'date' ), - }; - } ), - withDispatch( ( dispatch ) => { - return { - onUpdateDate( date ) { - dispatch( 'core/editor' ).editPost( { date } ); - }, - }; - } ), -] )( PostSchedule ); +PostSchedule.Warning = Warning; + +export default PostSchedule;