Newer
Older
import { find } from 'lodash'
import React from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// import { fragmentsOfCollection } from 'pubsweet-core/app/helpers/Utils'
import SimpleEditor from './SimpleEditor'
export class SimpleEditorWrapper extends React.Component {
constructor (props) {
super(props)
this.save = this.save.bind(this)
this.updateComments = this.updateComments.bind(this)
this._checkRights = this._checkRights.bind(this)
this.state = {
canEdit: false
}
}
componentWillMount () {
const { getCollections, getFragments } = this.props.actions
getCollections().then(result => {
getFragments(result.collections[0])
})
this._checkRights()
}
// componentDidUpdate () {
// this._checkRights()
// }
_checkRights () {
const { fragment, user } = this.props
if ((fragment.progress['review'] === 1 && user.teams[0].teamType.name === 'Author') ||
(fragment.progress['edit'] === 1 && user.teams[0].teamType.name === 'Copy Editor')) {
this.setState({ canEdit: true })
} else {
this.setState({ canEdit: false })
}
if (user.teams[0].teamType.name === 'Production Editor') {
this.setState({ canEdit: true })
}
}
save (source, callback) {
const { book, fragment } = this.props
const { updateFragment } = this.props.actions
fragment.source = source
updateFragment(book, fragment)
}
updateComments (newComments) {
const { book, fragment } = this.props
const { updateFragment } = this.props.actions
fragment.comments = newComments
updateFragment(book, fragment)
}
render () {
const { book, fragment, user } = this.props
return (
<SimpleEditor
book={book}
canEdit={this.state.canEdit}
fragment={fragment}
onSave={this.save}
updateComments={this.updateComments}
user={user}
/>
)
}
}
SimpleEditorWrapper.propTypes = {
book: React.PropTypes.object.isRequired,
fragment: React.PropTypes.object.isRequired,
actions: React.PropTypes.object.isRequired,
user: React.PropTypes.object.isRequired
}
function mapStateToProps (state, ownProps) {
const bookId = ownProps.params.bookId
let book = find(state.collections, function (c) {
return c.id === bookId
})
const fragmentId = ownProps.params.fragmentId
let fragment = state.fragments[fragmentId]
return {
fragment: fragment,
book: book,
user: state.currentUser.user
}
}
function mapDispatchToProps (dispatch) {
return {
actions: bindActionCreators(Actions, dispatch)
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(SimpleEditorWrapper)