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',

Anca Ursachi
committed
collection: { visibleStatus = 'Draft', customId, handlingEditor },
}) => {
const { authors = [], metadata = {}, submitted = null } = fragment
const { title = 'No title', journal = '', type = '' } = metadata
return (
<Fragment>
<Row
alignItems="baseline"
data-test-id="manuscript-title"
justify="space-between"
>

Sinzeanu Demetriad
committed
<Tag data-test-id="fragment-status" status>
{visibleStatus}
</Tag>
) : (
<Tag oldStatus>Viewing an Older Version</Tag>
)}
<Row
alignItems="center"
data-test-id="authors-row"
justify="flex-start"
mb={1}
>
<AuthorTagList authors={authors} withAffiliations withTooltip />
</Row>
)}
<Row alignItems="center" justify="flex-start" mb={1}>
{customId && (
<Text
customId
data-test-id="manuscript-id"
mr={1}
>{`ID ${customId}`}</Text>
)}
{submitted && (
<DateParser durationThreshold={0} timestamp={submitted}>
{timestamp => <Text mr={3}>Submitted on {timestamp}</Text>}
<Text>{manuscriptType.label || type}</Text>
<Text journal ml={1}>
{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(
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 }) => (email, props) =>
resendInvitation(email, props),
revokeInvitation: ({ revokeInvitation }) => (id, props) =>
revokeInvitation(id, props),
}),
withHandlers({
renderHE: ({
inviteHE,
heInvitation,
resendInvitation,
revokeInvitation,
pendingInvitation = {},
handlingEditors = [],

Anca Ursachi
committed
isLatestVersion,

Anca Ursachi
committed
currentUser: {
permissions: { canAssignHE },
id: currentUserId,
admin,
editorInChief,
},
collection: { handlingEditor },

Anca Ursachi
committed
collection,

Anca Ursachi
committed
currentUser,
if (pendingInvitation.userId === currentUserId) {
return <Text ml={1}>Invited</Text>
}
if (
(get(pendingInvitation, 'userId', false) ||
get(heInvitation, 'userId', false)) &&
(admin || editorInChief)
) {
const person = chain(handlingEditors)

Anca Ursachi
committed
.filter(
he =>
he.id ===
(get(heInvitation, 'userId', false) ||
get(pendingInvitation, 'userId', false)),
)
.map(he => ({ ...he, name: `${he.firstName} ${he.lastName}` }))
.first()
.value()

Anca Ursachi
committed
let invitedPerson = {}
if (get(pendingInvitation, 'userId', false)) {
invitedPerson = pendingInvitation
} else if (get(heInvitation, 'userId', false)) {
invitedPerson = heInvitation
}
return (
<PersonInvitation
isFetching={isFetching}

Anca Ursachi
committed
isLatestVersion={isLatestVersion}
{...invitedPerson}
onResend={resendInvitation}
onRevoke={revokeInvitation}
person={person}
/>
)
}

Anca Ursachi
committed
if (heInvitation) {
return <Text ml={1}>{handlingEditor.name}</Text>
}
<Button
data-test-id="manuscript-invite-he-button"
ml={1}
onClick={inviteHE}
primary
size="small"
>

Tania Fecheta
committed
return <Text ml={1}>{handlingEditor.name}</Text>
},
}),
setDisplayName('ManuscriptHeader'),