Newer
Older
import React, { Fragment } from 'react'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { Button, TextField } from '@pubsweet/ui'
import {
compose,
withProps,
defaultProps,
withHandlers,
setDisplayName,
withStateHandlers,
} from 'recompose'
import {
Row,
Item,
Text,
Label,
OpenModal,
IconButton,
paddingHelper,
} from '../'
const AssignHE = ({
clearSearch,
searchValue,
changeSearch,
handlingEditors,
inviteHandlingEditor,
}) => (
<Root pb={2}>
<TextContainer>
<TextField onChange={changeSearch} value={searchValue} />
<IconButton
icon="x-circle"
iconSize={2}
onClick={clearSearch}
right={8}
top={12}
/>
</TextContainer>
{handlingEditors.length > 0 && (
<Fragment>
<Row alignItems="center" height={4} pl={1}>
<Item flex={1}>
<Label>Name</Label>
</Item>
<Item flex={2}>
<Label>Email</Label>
</Item>
<Item flex={1} />
</Row>
{handlingEditors.map((he, index) => (
<CustomRow
alignItems="center"
height={4}
isFirst={index === 0}
key={he.id}
pl={1}
<Item flex={1}>
<Text secondary>{he.name}</Text>
</Item>
<Item flex={2}>
<Text secondary>{he.email}</Text>
</Item>
<Item flex={1}>
<OpenModal
onConfirm={inviteHandlingEditor(he)}
title="Are you sure you want to invite this HE?"
>
{showModal => (
<CustomButton onClick={showModal} size="small">
INVITE
</CustomButton>
)}
</OpenModal>
</Item>
</CustomRow>
))}
</Fragment>
)}
</Root>
)
export default compose(
defaultProps({
inviteHandlingEditor: he => {},
}),
withProps(({ handlingEditors = [] }) => ({
handlingEditors: handlingEditors.map(he => ({
...he,
name: `${he.firstName} ${he.lastName}`,
})),
})),
withStateHandlers(
{ searchValue: '' },
{
changeSearch: ({ searchValue }) => e => ({
searchValue: e.target.value.toLowerCase(),
}),
clearSearch: () => () => ({
searchValue: '',
}),
},
),
withProps(({ searchValue, handlingEditors = [] }) => ({
handlingEditors: handlingEditors.filter(he =>
he.name.toLowerCase().startsWith(searchValue),
),
})),
withHandlers({
inviteHandlingEditor: ({ inviteHandlingEditor }) => ({
email = '',
}) => () => {
inviteHandlingEditor(email)
},
}),
setDisplayName('AssignHandlingEditor'),
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
145
146
147
148
149
150
)(AssignHE)
// #region styles
const Root = styled.div`
background-color: ${th('colorBackgroundHue2')};
${paddingHelper};
`
const TextContainer = styled.div`
padding: ${th('gridUnit')};
position: relative;
width: calc(${th('gridUnit')} * 40);
`
const CustomButton = styled(Button)`
opacity: 0;
`
const CustomRow = styled(Row)`
border-top: ${props => props.isFirst && '1px solid #e7e7e7'};
border-bottom: 1px solid #e7e7e7;
&:hover {
background-color: #eee;
${CustomButton} {
opacity: 1;
}
}
`
// #endregion