diff --git a/packages/editor/src/components/post-saved-state/index.js b/packages/editor/src/components/post-saved-state/index.js index d72c0def526bc..42eed5d28736b 100644 --- a/packages/editor/src/components/post-saved-state/index.js +++ b/packages/editor/src/components/post-saved-state/index.js @@ -41,7 +41,7 @@ export class PostSavedState extends Component { } render() { - const { isNew, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props; + const { isNew, isScheduled, isPublished, isDirty, isSaving, isSaveable, onSave, isAutosaving } = this.props; const { forceSavedMessage } = this.state; if ( isSaving ) { // TODO: Classes generation should be common across all return @@ -59,7 +59,7 @@ export class PostSavedState extends Component { ); } - if ( isPublished ) { + if ( isPublished || isScheduled ) { return ; } @@ -94,6 +94,7 @@ export default compose( [ const { isEditedPostNew, isCurrentPostPublished, + isCurrentPostScheduled, isEditedPostDirty, isSavingPost, isEditedPostSaveable, @@ -104,6 +105,7 @@ export default compose( [ post: getCurrentPost(), isNew: isEditedPostNew(), isPublished: isCurrentPostPublished(), + isScheduled: isCurrentPostScheduled(), isDirty: forceIsDirty || isEditedPostDirty(), isSaving: forceIsSaving || isSavingPost(), isSaveable: isEditedPostSaveable(), diff --git a/packages/editor/src/components/post-switch-to-draft-button/index.js b/packages/editor/src/components/post-switch-to-draft-button/index.js index 8ea77f0f8a0d3..93895cb831f54 100644 --- a/packages/editor/src/components/post-switch-to-draft-button/index.js +++ b/packages/editor/src/components/post-switch-to-draft-button/index.js @@ -6,14 +6,20 @@ import { __ } from '@wordpress/i18n'; import { withSelect, withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) { - if ( ! isPublished ) { +function PostSwitchToDraftButton( { isSaving, isPublished, isScheduled, onClick } ) { + if ( ! isPublished && ! isScheduled ) { return null; } const onSwitch = () => { + let alertMessage; + if ( isPublished ) { + alertMessage = __( 'Are you sure you want to unpublish this post?' ); + } else if ( isScheduled ) { + alertMessage = __( 'Are you sure you want to unschedule this post?' ); + } // eslint-disable-next-line no-alert - if ( window.confirm( __( 'Are you sure you want to unpublish this post?' ) ) ) { + if ( window.confirm( alertMessage ) ) { onClick(); } }; @@ -32,10 +38,11 @@ function PostSwitchToDraftButton( { isSaving, isPublished, onClick } ) { export default compose( [ withSelect( ( select ) => { - const { isSavingPost, isCurrentPostPublished } = select( 'core/editor' ); + const { isSavingPost, isCurrentPostPublished, isCurrentPostScheduled } = select( 'core/editor' ); return { isSaving: isSavingPost(), isPublished: isCurrentPostPublished(), + isScheduled: isCurrentPostScheduled(), }; } ), withDispatch( ( dispatch ) => {