Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
68
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React from 'react'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { Button, TextField } from '@pubsweet/ui'
import { compose, withProps, withHandlers, 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>
<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>
))}
</Root>
)
export default compose(
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 }) => he => () => {
inviteHandlingEditor(he)
},
}),
)(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