Newer
Older
import React from 'react'
import { withRouter } from 'react-router'
import { Mutation } from 'react-apollo'
import { Action, Button, H2, Icon, RadioGroup } from '@pubsweet/ui'
import { PreviewFooter, Notification, Buttons, Portal, CloseModal } from '../ui'
import SubmissionCancel from '../SubmissionCancel'
import { REVIEW_MANUSCRIPT, GET_REVIEWS, CURRENT_REVIEW } from './operations'
import ReviewInstructions from './ReviewInstructions'
import ListErrors from './ListErrors'
import SubmissionError from './SubmissionError'
class ReviewFooter extends React.Component {
state = {
report: false,
approve: false,
cancel: false,
const { currentUser, manuscript, previews, review, history } = this.props
const { report, approve, cancel, radio } = this.state
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
const { annotations } = review || []
const { status, teams } = manuscript
const submitter = teams.find(t => t.role === 'submitter').teamMembers[0]
return (
<PreviewFooter>
<div>
<Mutation
mutation={REVIEW_MANUSCRIPT}
refetchQueries={() => [
{
query: GET_REVIEWS,
variables: { manuscriptId: manuscript.id },
},
{
query: CURRENT_REVIEW,
variables: { manuscriptId: manuscript.id },
},
]}
>
{(reviewManuscript, { data }) => {
const setStatus = async newStatus => {
await reviewManuscript({
variables: { data: { id: manuscript.id, status: newStatus } },
})
}
if (status === 'tagging') {
return (
<Button
disabled={!previews}
onClick={() => setStatus('xml-qa')}
primary
>
Send for XML QA
</Button>
)
} else if (manuscript.status === 'xml-triage') {
const options = [
{
value: 'xml-qa',
label: 'XML QA',
},
{
value: 'xml-review',
label: 'Author review',
},
{
value: 'xml-complete',
label: 'PMC (skip review)',
},
]
<div>
<Button
onClick={() => this.setState({ approve: true })}
primary
>
</Button>
<Button onClick={() => this.setState({ report: true })}>
Ask for correction
</Button>
{approve && (
<Portal transparent>
<CloseModal
onClick={() => this.setState({ approve: false })}
/>
<RadioGroup
name="setstatus"
onChange={radio => this.setState({ radio })}
options={options}
/>
<Buttons right>
await setStatus(radio)
if (radio === 'xml-qa') {
this.setState({ approve: false })
} else {
history.push(
`/submission/${manuscript.id}/activity`,
)
}
<Button
onClick={() => this.setState({ approve: false })}
>
Cancel
</Button>
</Buttons>
</Portal>
)}
{report && (
<SubmissionError
annotations={annotations}
close={() => this.setState({ report: false })}
manuscript={manuscript}
/>
)}
</div>
)
} else if (status === 'xml-qa' || status === 'xml-review') {
return (
<React.Fragment>
<div>
<Button
onClick={() => this.setState({ approve: true })}
primary
>
Approve
</Button>
<Button onClick={() => this.setState({ report: true })}>
Report errors
</Button>
</div>
{currentUser.id === submitter.user.id && (
<Action
onClick={() => this.setState({ cancel: true })}
style={{ display: 'inline-flex', alignItems: 'center' }}
>
<Icon color="currentColor" size={2.5}>
trash-2
</Icon>
Cancel submission
</Action>
)}
{approve && (
<Portal style={{ width: '600px' }} transparent>
<p>
{status === 'xml-review'
? `Approve the final web versions of the manuscript for release to Europe PMC now?`
: `Confirm QA has been completed, and approve the web versons of the manuscript?`}
</p>
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<Notification type="warning">
{`Errors have been highlighted! Are you sure you want to approve the submission, rather than submitting your error report?`}
</Notification>
)}
<Buttons right>
<Button
onClick={async () => {
await setStatus(
status === 'xml-review'
? 'xml-complete'
: 'xml-review',
)
history.push('/')
}}
primary
>
Yes
</Button>
<Button
onClick={() => this.setState({ approve: false })}
>
No
</Button>
</Buttons>
</Portal>
)}
<CloseModal
onClick={() => this.setState({ report: false })}
/>
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<H2>Send the following errors?</H2>
<ListErrors annotations={annotations} />
<Buttons right>
<Button
onClick={async () => {
await setStatus('xml-triage')
history.push('/')
}}
primary
>
Send error report
</Button>
<Button
onClick={() => this.setState({ report: false })}
>
Cancel
</Button>
</Buttons>
</Portal>
) : (
<ReviewInstructions
close={() => this.setState({ report: false })}
/>
)}
</React.Fragment>
)}
</React.Fragment>
)
}
history.push('/')
return null
}}
</Mutation>
</div>
{cancel && (
<SubmissionCancel
cancel={() => this.props.cancel(true)}
close={() => this.setState({ cancel: false })}
/>
)}
</PreviewFooter>
)
}
}
export default withRouter(ReviewFooter)