Skip to content

Commit

Permalink
Allow transitioning status from scheduled to draft (#8332)
Browse files Browse the repository at this point in the history
* Replaces Save Draft button with Switch to Draft button on scheduled posts

* Fixes issue where a scheduled post would get published on save when the date was changed to the past
  • Loading branch information
earnjam committed Aug 3, 2018
1 parent c1c4c7e commit 33f7475
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +59,7 @@ export class PostSavedState extends Component {
);
}

if ( isPublished ) {
if ( isPublished || isScheduled ) {
return <PostSwitchToDraftButton />;
}

Expand Down Expand Up @@ -94,6 +94,7 @@ export default compose( [
const {
isEditedPostNew,
isCurrentPostPublished,
isCurrentPostScheduled,
isEditedPostDirty,
isSavingPost,
isEditedPostSaveable,
Expand All @@ -104,6 +105,7 @@ export default compose( [
post: getCurrentPost(),
isNew: isEditedPostNew(),
isPublished: isCurrentPostPublished(),
isScheduled: isCurrentPostScheduled(),
isDirty: forceIsDirty || isEditedPostDirty(),
isSaving: forceIsSaving || isSavingPost(),
isSaveable: isEditedPostSaveable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand All @@ -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 ) => {
Expand Down

0 comments on commit 33f7475

Please sign in to comment.