Persistence editorial workflow through own actions & reducer
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { EDITORIAL_WORKFLOW } from '../../constants/publishModes';
|
||||
import { selectUnpublishedEntry } from '../../reducers';
|
||||
import { loadUnpublishedEntry, persistUnpublishedEntry } from '../../actions/editorialWorkflow';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
|
||||
export default function EntryPageHOC(EntryPage) {
|
||||
class EntryPageHOC extends React.Component {
|
||||
@ -12,11 +13,10 @@ export default function EntryPageHOC(EntryPage) {
|
||||
}
|
||||
|
||||
function mapStateToProps(state, ownProps) {
|
||||
const publish_mode = state.config.get('publish_mode');
|
||||
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);
|
||||
const isEditorialWorkflow = (state.config.get('publish_mode') === EDITORIAL_WORKFLOW);
|
||||
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
||||
|
||||
const returnObj = {};
|
||||
const returnObj = { isEditorialWorkflow };
|
||||
if (isEditorialWorkflow && unpublishedEntry) {
|
||||
const status = ownProps.params.status;
|
||||
const slug = ownProps.params.slug;
|
||||
@ -26,22 +26,34 @@ export default function EntryPageHOC(EntryPage) {
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch, ownProps) {
|
||||
function mergeProps(stateProps, dispatchProps, ownProps) {
|
||||
const { isEditorialWorkflow } = stateProps;
|
||||
const { dispatch } = dispatchProps;
|
||||
|
||||
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
||||
const status = ownProps.params.status;
|
||||
|
||||
const returnObj = {};
|
||||
|
||||
if (unpublishedEntry) {
|
||||
// Overwrite loadEntry to loadUnpublishedEntry
|
||||
const status = ownProps.params.status;
|
||||
returnObj.loadEntry = (entry, collection, slug) => {
|
||||
dispatch(loadUnpublishedEntry(collection, status, slug));
|
||||
};
|
||||
}
|
||||
|
||||
if (isEditorialWorkflow) {
|
||||
// Overwrite persistEntry to persistUnpublishedEntry
|
||||
returnObj.persistEntry = (collection, entryDraft) => {
|
||||
dispatch(persistUnpublishedEntry(collection, entryDraft));
|
||||
dispatch(persistUnpublishedEntry(collection, entryDraft, unpublishedEntry));
|
||||
};
|
||||
}
|
||||
return returnObj;
|
||||
|
||||
return {
|
||||
...ownProps,
|
||||
...returnObj,
|
||||
};
|
||||
}
|
||||
|
||||
return connect(mapStateToProps, mapDispatchToProps)(EntryPageHOC);
|
||||
return connect(mapStateToProps, null, mergeProps)(EntryPageHOC);
|
||||
}
|
||||
|
Reference in New Issue
Block a user