From f0a169c7b2f192abfedd02e1f41e0c5effd51283 Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Fri, 5 Jan 2018 12:01:39 -0500 Subject: [PATCH] fix lost unsaved changes when updating status or publishing --- src/components/Editor/Editor.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/Editor/Editor.js b/src/components/Editor/Editor.js index 2348f0c14a74..2d870ceb23a8 100644 --- a/src/components/Editor/Editor.js +++ b/src/components/Editor/Editor.js @@ -180,7 +180,11 @@ class Editor extends React.Component { }; handleChangeStatus = (newStatusName) => { - const { updateUnpublishedEntryStatus, collection, slug, currentStatus } = this.props; + const { entryDraft, updateUnpublishedEntryStatus, collection, slug, currentStatus } = this.props; + if (entryDraft.get('hasChanged')) { + window.alert('You have unsaved changes, please save before updating status.'); + return; + } const newStatus = status.get(newStatusName); this.props.updateUnpublishedEntryStatus(collection.get('name'), slug, currentStatus, newStatus); } @@ -206,14 +210,11 @@ class Editor extends React.Component { if (currentStatus !== status.last()) { window.alert('Please update status to "Ready" before publishing.'); return; + } else if (entryDraft.get('hasChanged')) { + window.alert('You have unsaved changes, please save before publishing.'); + return; } else if (!window.confirm('Are you sure you want to publish this entry?')) { return; - } else if (entryDraft.get('hasChanged')) { - if (window.confirm('Your unsaved changes will be saved before publishing. Are you sure you want to publish?')) { - await persistEntry(collection); - } else { - return; - } } await publishUnpublishedEntry(collection.get('name'), slug);