Newer
Older
import React, { Fragment } from 'react'
import { get, chain } from 'lodash'
import { H2, H4, DateParser, Button } from '@pubsweet/ui'
import {
compose,
withProps,
defaultProps,
withHandlers,
setDisplayName,
} from 'recompose'
import {
Tag,
Row,
Text,
AuthorTagList,
PersonInvitation,
} from 'pubsweet-component-faraday-ui'
fragment = {},
manuscriptType = {},
editorInChief = 'Unassigned',
collection: { visibleStatus = 'Draft', handlingEditor, customId },
}) => {
const { authors = [], metadata = {}, submitted = null } = fragment
const { title = 'No title', journal = '', type = '' } = metadata
return (
<Fragment>
<Row alignItems="baseline" justify="space-between">
<H2 mb={1}>{title}</H2>
<Tag data-test-id="fragment-status" status>
{visibleStatus}
</Tag>
</Row>
{authors.length > 0 && (
<Row alignItems="center" justify="flex-start" mb={1}>
<AuthorTagList
affiliations
authors={authors}
withAffiliations
withTooltip
/>
</Row>
)}
<Row alignItems="center" justify="flex-start" mb={1}>
<Text customId mr={1}>{`ID ${customId}`}</Text>
{submitted && (
<DateParser durationThreshold={0} timestamp={submitted}>
{timestamp => (
<Text mr={3} secondary>
Submitted on {timestamp}
</Text>
)}
</DateParser>
)}
<H4>{manuscriptType.label || type}</H4>
<Text ml={1} secondary>
{journal}
</Text>
</Row>
<Row alignItems="center" justify="flex-start" mb={1}>
<H4>Editor in Chief</H4>
<Text ml={1} mr={3}>
{editorInChief}
</Text>
<H4>Handling editor</H4>
</Row>
</Fragment>
)
}
export default compose(
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
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
143
144
defaultProps({
inviteHE: () => {},
revokeInvitation: () => {},
resendInvitation: () => {},
}),
withProps(
({
journal = {},
fragment: { metadata },
collection: { invitations = [] },
}) => ({
manuscriptType: get(journal, 'manuscriptTypes', []).find(
t => t.value === get(metadata, 'type', ''),
),
heInvitation: invitations.find(
i => i.role === 'handlingEditor' && i.isAccepted,
),
pendingInvitation: invitations.find(
i => i.role === 'handlingEditor' && !i.hasAnswer,
),
}),
),
withHandlers({
resendInvitation: ({ resendInvitation }) => id => {
resendInvitation(id)
},
revokeInvitation: ({ revokeInvitation }) => id => {
revokeInvitation(id)
},
}),
withHandlers({
renderHE: ({
inviteHE,
revokeHE,
heInvitation,
resendInvitation,
revokeInvitation,
pendingInvitation,
handlingEditors = [],
collection: { handlingEditor, invitations = [] },
}) => () => {
if (pendingInvitation) {
const person = chain(handlingEditors)
.filter(he => he.id === pendingInvitation.userId)
.map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` }))
.first()
.value()
return (
<PersonInvitation
ml={1}
{...pendingInvitation}
onResend={resendInvitation}
onRevoke={revokeInvitation}
person={person}
/>
)
}
if (heInvitation) {
return <Text ml={1}>{handlingEditor.name}</Text>
}
return (
<Button ml={1} onClick={inviteHE} primary size="small">
Invite
</Button>
)
},
}),
setDisplayName('ManuscriptHeader'),