Newer
Older
import React from 'react'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { Action, H2, CheckboxGroup } from '@pubsweet/ui'
import { Portal, CloseModal, Loading, LoadingIcon, Toggle } from '../ui'
import SubmissionErrorReport, {
adminOptions,
Fieldset,
} from '../SubmissionErrorReport'
export const Option = styled.div`
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: space-between;
min-height: calc(${th('gridUnit')} * 6);
padding: ${th('gridUnit')} calc(${th('gridUnit')} * 3);
& > * {
margin: ${th('gridUnit')} auto;
}
@media screen and (max-width: 870px) {
padding: ${th('gridUnit')} calc(${th('gridUnit')} * 4);
}
`
const CheckList = styled(Fieldset)`
div {
flex-direction: row;
flex-wrap: wrap;
label {
width: 50%;
}
}
`
const options = adminOptions
.filter(o => !['title', 'english', 'grants'].includes(o.value))
const submissionMessage = async (url, annotations) => {
if (url && annotations) {
const response = await fetch(url)
const html = await response.text()
const outer = document.createElement('div')
const test = document.createElement('div')
test.innerHTML = html
outer.appendChild(test)
const locate = annotations.map(a => {
const loc = a.ranges[0].start
const result = document.evaluate(
loc,
outer,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
)
location: result.singleNodeValue
? `#${result.singleNodeValue.id}`
: '[PDF?]',
quote: a.quote,
text: a.text,
}
})
return locate
}
}
if (
this.state.error !== prevState.error &&
this.state.error === 'tagging'
) {
this.withLocations()
}
}
async withLocations() {
const { annotations, manuscript } = this.props
const html = manuscript.files.find(file => file.type === 'tempHTML')
const locate = await submissionMessage(html && html.url, annotations)
this.setState({ formData: locate })
}
const { annotations, manuscript, close } = this.props
const html = manuscript.files.find(file => file.type === 'tempHTML')
<H2>Report Errors</H2>
<Toggle>
<Action
className={error === 'submission' && 'current'}
onClick={() => this.setState({ error: 'submission' })}
>
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
135
136
137
138
139
140
141
142
</Action>
<Action
className={error === 'tagging' && 'current'}
onClick={() => this.setState({ error: 'tagging' })}
>
Return for tagging correction
</Action>
</Toggle>
{(() => {
switch (error) {
case 'submission':
return (
<React.Fragment>
<p>
{`The submission will be routed back for triage when the requested changes are made.`}
</p>
<CheckList>
<label>Missing items</label>
<CheckboxGroup
onChange={c => this.setState({ checkedBoxes: c })}
options={options}
value={checkedBoxes}
/>
</CheckList>
<SubmissionErrorReport
checkedBoxes={checkedBoxes}
close={close}
manuscript={manuscript}
teams={manuscript.teams}
/>
</React.Fragment>
)
case 'tagging':
if (html && annotations) {
return (
<React.Fragment>
{!formData ? (
<Loading>
<LoadingIcon />
</Loading>
) : (
<TaggerError
manuscript={manuscript}
/>
return (
<React.Fragment>
<p>No errors reported.</p>
<TaggerError
close={close}
formData={[]}
manuscript={manuscript}
/>
</React.Fragment>
)
default:
return null
}
})()}
</Portal>