@@ -2,14 +2,16 @@ import uuid from 'uuid/v4';
2
2
import { get } from 'lodash' ;
3
3
import { actions as notifActions } from 'redux-notifications' ;
4
4
import { BEGIN , COMMIT , REVERT } from 'redux-optimist' ;
5
+ import { Map } from 'immutable' ;
5
6
import { serializeValues } from 'Lib/serializeEntryValues' ;
6
7
import { currentBackend } from 'coreSrc/backend' ;
7
- import { selectPublishedSlugs , selectUnpublishedSlugs } from 'Reducers' ;
8
+ import { selectPublishedSlugs , selectUnpublishedSlugs , selectEntry } from 'Reducers' ;
8
9
import { selectFields } from 'Reducers/collections' ;
9
- import { EDITORIAL_WORKFLOW } from 'Constants/publishModes' ;
10
+ import { EDITORIAL_WORKFLOW , status } from 'Constants/publishModes' ;
10
11
import { EDITORIAL_WORKFLOW_ERROR } from 'netlify-cms-lib-util' ;
11
12
import {
12
13
loadEntry ,
14
+ entryDeleted ,
13
15
getMediaAssets ,
14
16
setDraftEntryMediaFiles ,
15
17
clearDraftEntryMediaFiles ,
@@ -525,3 +527,41 @@ export function publishUnpublishedEntry(collection, slug) {
525
527
} ) ;
526
528
} ;
527
529
}
530
+
531
+ export function unpublishPublishedEntry ( collection , slug ) {
532
+ return ( dispatch , getState ) => {
533
+ const state = getState ( ) ;
534
+ const backend = currentBackend ( state . config ) ;
535
+ const transactionID = uuid ( ) ;
536
+ const entry = selectEntry ( state , collection . get ( 'name' ) , slug ) ;
537
+ const entryDraft = Map ( ) . set ( 'entry' , entry ) ;
538
+ dispatch ( unpublishedEntryPersisting ( collection , entry , transactionID ) ) ;
539
+ return backend
540
+ . persistEntry ( state . config , collection , entryDraft , [ ] , state . integrations , [ ] , {
541
+ status : status . get ( 'PENDING_PUBLISH' ) ,
542
+ } )
543
+ . then ( ( ) => backend . deleteEntry ( state . config , collection , slug ) )
544
+ . then ( ( ) => {
545
+ dispatch ( unpublishedEntryPersisted ( collection , entryDraft , transactionID , slug ) ) ;
546
+ dispatch ( entryDeleted ( collection , slug ) ) ;
547
+ dispatch ( loadUnpublishedEntry ( collection , slug ) ) ;
548
+ dispatch (
549
+ notifSend ( {
550
+ message : { key : 'ui.toast.entryUnpublished' } ,
551
+ kind : 'success' ,
552
+ dismissAfter : 4000 ,
553
+ } ) ,
554
+ ) ;
555
+ } )
556
+ . catch ( error => {
557
+ dispatch (
558
+ notifSend ( {
559
+ message : { key : 'ui.toast.onFailToUnpublishEntry' , details : error } ,
560
+ kind : 'danger' ,
561
+ dismissAfter : 8000 ,
562
+ } ) ,
563
+ ) ;
564
+ dispatch ( unpublishedEntryPersistedFail ( error , transactionID ) ) ;
565
+ } ) ;
566
+ } ;
567
+ }
0 commit comments