Newer
Older
1
2
3
4
5
6
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
import React from 'react'
import { includes } from 'lodash'
import { Alert } from 'react-bootstrap'
import BookBuilderModal from './BookBuilderModal'
import styles from './styles/bookBuilder.local.scss'
export class ProgressIndicator extends React.Component {
constructor (props) {
super(props)
this._isAllowedToChange = this._isAllowedToChange.bind(this)
this._onClick = this._onClick.bind(this)
this._toggleModal = this._toggleModal.bind(this)
this._changeWorkflowState = this._changeWorkflowState.bind(this)
this.progressValues = {
style: ['To Style', 'Styling', 'Styled'],
edit: ['To Edit', 'Editing', 'Edited'],
review: ['To Review', 'Reviewing', 'Reviewed'],
clean: ['To Clean', 'Cleaning', 'Cleaned']
}
this.state = {
showWarning: false,
showError: false
}
}
_isAllowedToChange () {
const { type, roles, chapter } = this.props
if (includes(roles, 'production-editor')) return true
const isOne = (chapter.progress[type] === 1)
if (chapter.progress[type] === 1 && type === 'edit' && includes(roles, 'copy-editor')) return true
if (isOne && type === 'review' && includes(roles, 'author')) return true
return false
}
_onClick () {
const { roles } = this.props
if (!this._isAllowedToChange()) {
this.setState({ showError: true })
setTimeout(() => { this.setState({showError: false}) }, 3000)
return
} else if (includes(roles, 'production-editor')) {
this._changeWorkflowState()
} else {
this._toggleModal()
}
}
_toggleModal () {
this.setState({ showWarning: !this.state.showWarning })
}
_changeWorkflowState () {
const { chapter, update, type, viewOrEdit } = this.props
const { progressValues } = this
const list = progressValues[type]
let position = chapter.progress[type]
position += 1 // move up a level
if (position >= list.length) {
position = 0 // or cycle back to the beginning
}
chapter.progress[type] = position
update(chapter)
this.setState({ showWarning: false })
viewOrEdit()
}
render () {
const { type, chapter, hasIcon, outerContainer } = this.props
const { progressValues } = this
let ErrorMsg = this.state.showError
? (
<Alert bsStyle='warning' className={styles.noWritesError}>
You don't have access to perfom this action. Please contact your Production Editor.
</Alert>
)
: null
let icon = ''
if (hasIcon) {
icon = <i className='fa fa-angle-right' />
}
const warningModal = (
<BookBuilderModal
title='Change of workflow status'
action='workflow-warning'
successText='OK'
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
successAction={this._changeWorkflowState}
show={this.state.showWarning}
toggle={this._toggleModal}
container={outerContainer}
/>
)
return (
<span>
{ ErrorMsg }
<li className={'progress' + chapter.progress[type]}
onClick={this._onClick}>
{ progressValues[type][chapter.progress[type]] }
{ icon }
{ warningModal }
</li>
</span>
)
}
}
ProgressIndicator.propTypes = {
type: React.PropTypes.string.isRequired,
chapter: React.PropTypes.object.isRequired,
hasIcon: React.PropTypes.bool,
update: React.PropTypes.func.isRequired,
roles: React.PropTypes.array.isRequired,
outerContainer: React.PropTypes.object.isRequired,
viewOrEdit: React.PropTypes.func
}
export default ProgressIndicator