2016-09-13 03:59:48 -03:00
|
|
|
import React from 'react';
|
|
|
|
import { EDITORIAL_WORKFLOW } from '../../constants/publishModes';
|
|
|
|
import { selectUnpublishedEntry } from '../../reducers';
|
2016-09-13 14:31:18 -03:00
|
|
|
import { loadUnpublishedEntry, persistUnpublishedEntry } from '../../actions/editorialWorkflow';
|
2016-09-13 03:59:48 -03:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
export default function EntryPageHOC(EntryPage) {
|
|
|
|
class EntryPageHOC extends React.Component {
|
|
|
|
render() {
|
|
|
|
return <EntryPage {...this.props}/>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state, ownProps) {
|
|
|
|
const publish_mode = state.config.get('publish_mode');
|
|
|
|
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);
|
|
|
|
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
|
|
|
|
|
|
|
const returnObj = {};
|
|
|
|
if (isEditorialWorkflow && unpublishedEntry) {
|
|
|
|
const status = ownProps.params.status;
|
|
|
|
const slug = ownProps.params.slug;
|
|
|
|
const entry = selectUnpublishedEntry(state, status, slug);
|
|
|
|
returnObj.entry = entry;
|
|
|
|
}
|
|
|
|
return returnObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch, ownProps) {
|
|
|
|
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
|
|
|
const returnObj = {};
|
|
|
|
if (unpublishedEntry) {
|
|
|
|
// Overwrite loadEntry to loadUnpublishedEntry
|
2016-09-13 04:09:52 -03:00
|
|
|
const status = ownProps.params.status;
|
2016-09-13 03:59:48 -03:00
|
|
|
returnObj.loadEntry = (collection, slug) => {
|
2016-09-13 04:09:52 -03:00
|
|
|
dispatch(loadUnpublishedEntry(collection, status, slug));
|
2016-09-13 03:59:48 -03:00
|
|
|
};
|
2016-09-13 14:31:18 -03:00
|
|
|
|
|
|
|
returnObj.persistEntry = (collection, entryDraft) => {
|
|
|
|
dispatch(persistUnpublishedEntry(collection, status, entryDraft));
|
|
|
|
};
|
2016-09-13 03:59:48 -03:00
|
|
|
}
|
|
|
|
return returnObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return connect(mapStateToProps, mapDispatchToProps)(EntryPageHOC);
|
|
|
|
}
|