Newer
Older
import React from 'react'
import { get } from 'lodash'
import { connect } from 'react-redux'
import { actions } from 'pubsweet-client'
import styled, { css } from 'styled-components'
import { reduxForm, formValueSelector } from 'redux-form'
import { compose, setDisplayName, withProps } from 'recompose'
import { th, Icon, Button, RadioGroup, ValidatedField } from '@pubsweet/ui'
import { FormItems } from '../UIComponents'
import { createRecommendation } from '../../redux/recommendations'
const {
Row,
Title,
Label,
RowItem,
Textarea,
Subtitle,
RootContainer,
FormContainer,
} = FormItems
const Form = RootContainer.withComponent(FormContainer)
const decisionOptions = [
{ label: 'Publish', value: 'publish' },
{ label: 'Reject', value: 'reject' },
{ label: 'Return to Handling Editor', value: 'return-to-handling-editor' },
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
]
const DecisionForm = ({
decision,
hideModal,
handleSubmit,
heRecommendation: { reason, message = '' },
}) => (
<Form onSubmit={handleSubmit}>
<IconButton onClick={hideModal}>
<Icon primary>x</Icon>
</IconButton>
<Title>Make decision</Title>
<CustomSubtitle>
Recommended to<BoldSubtitle>{reason}</BoldSubtitle>
</CustomSubtitle>
<Row>
<RowItem vertical>
<Label>Message from Handling Editor</Label>
<span>{message}</span>
</RowItem>
</Row>
<Row>
<RowItem vertical>
<Label>Your Decision</Label>
<ValidatedField
component={input => (
<CustomRadioGroup>
<RadioGroup
name="decision"
options={decisionOptions}
{...input}
/>
</CustomRadioGroup>
)}
name="decision"
/>
</RowItem>
</Row>
{decision === 'return-to-handling-editor' && (
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
<Row>
<RowItem vertical>
<Label>Comments for Handling Editor</Label>
<ValidatedField
component={input => <Textarea {...input} height={70} />}
name="messageToHE"
/>
</RowItem>
</Row>
)}
<Row>
<RowItem centered>
<Button onClick={hideModal}>Cancel</Button>
</RowItem>
<RowItem centered>
<Button primary type="submit">
Submit
</Button>
</RowItem>
</Row>
</Form>
)
const subtitleParser = t => {
switch (t) {
case 'major':
return 'Revise(major)'
case 'minor':
return 'Revise(minor)'
case 'reject':
return 'Reject'
case 'publish':
default:
return 'Publish'
}
}
const selector = formValueSelector('eicDecision')
export default compose(
setDisplayName('DecisionForm'),
connect(
state => ({
decision: selector(state, 'decision'),
}),
{ createRecommendation, getCollections: actions.getCollections },
),
withProps(({ heRecommendation: { recommendation = '', comments = [] } }) => ({
heRecommendation: {
reason: subtitleParser(recommendation),
message: get(comments.find(c => c.public), 'content'),
},
})),
reduxForm({
form: 'eicDecision',
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
onSubmit: (
{ decision, messageToHE },
dispatch,
{
showModal,
fragmentId,
collectionId,
getCollections,
createRecommendation,
},
) => {
const recommendation = {
recommendation: decision,
recommendationType: 'editorRecommendation',
comments: [
{
public: false,
content: messageToHE,
},
],
}
createRecommendation(collectionId, fragmentId, recommendation).then(r => {
getCollections()
showModal({
title: 'Decision submitted',
cancelText: 'OK',
})
})
151
152
153
154
155
156
157
158
159
160
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
187
188
189
190
191
},
}),
)(DecisionForm)
// #region styled-components
const defaultText = css`
color: ${th('colorText')};
font-family: ${th('fontReading')};
font-size: ${th('fontSizeBaseSmall')};
`
const IconButton = styled.div`
align-self: flex-end;
cursor: pointer;
`
const CustomSubtitle = Subtitle.extend`
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
`
const BoldSubtitle = Subtitle.extend`
font-weight: bold;
margin-left: 5px;
`
const CustomRadioGroup = styled.div`
div {
flex-direction: row;
justify-content: space-between;
label {
span:last-child {
font-style: normal;
${defaultText};
}
}
}
`
// #endregion