Newer
Older
import React, { Fragment } from 'react'
import { get } from 'lodash'
import { connect } from 'react-redux'
import styled from 'styled-components'
import { Link } from 'react-router-dom'
import { th } from '@pubsweet/ui-toolkit'
import { actions } from 'pubsweet-client'
import { ConnectPage } from 'xpub-connect'
import { withJournal } from 'xpub-journal'
import { Icon, Button } from '@pubsweet/ui'
import { compose, withHandlers, withProps } from 'recompose'
import {
Row,
Text,
Item,
Label,
OpenModal,
Pagination,
ActionLink,
IconButton,
withPagination,
} from 'pubsweet-component-faraday-ui'
const NavLink = styled.div`
align-items: center;
cursor: auto;
display: flex;
justify-content: flex-start;
`
getUserRoles,
itemsPerPage,
getStatusLabel,
toggleUserStatus,
paginatedItems,
...rest
}) => (
<Fragment>
<Row alignItems="center" justify="space-between" mb={3}>
<Item alignItems="center">
<NavLink>
<Icon secondary size={2}>
arrow-left
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
<Link to="/admin">Admin Dashboard</Link>
</NavLink>
<ActionLink icon="plus" ml={2}>
ADD USER
</ActionLink>
</Item>
<Pagination {...rest} itemsPerPage={itemsPerPage} page={page} />
</Row>
<Row alignItems="center" mb={1} pl={2}>
<Item flex={2}>
<Label>Full name</Label>
</Item>
<Item flex={4}>
<Label>Email</Label>
</Item>
<Item flex={2}>
<Label>Affiliation</Label>
</Item>
<Item flex={2}>
<Label>Roles</Label>
</Item>
<Item flex={1}>
<Label>Status</Label>
</Item>
<Item />
<Item />
</Row>
{paginatedItems.map(u => (
<UserRow alignItems="center" key={u.id} pb={1 / 2} pl={2} pt={1 / 2}>
<Item flex={2}>
<Text>{`${u.firstName} ${u.lastName}`}</Text>
</Item>
<Item flex={4}>
<Text>{u.email}</Text>
</Item>
<Item flex={2}>
<Text>{u.affiliation}</Text>
</Item>
<Item flex={2}>
<Text customId>{getUserRoles(u)}</Text>
</Item>
<Item flex={1} secondary>
<Text>{getStatusLabel(u)}</Text>
</Item>
<HiddenItem justify="center">
<IconButton icon="edit-2" iconSize={2} onClick={() => {}} />
</HiddenItem>
<HiddenItem justify="justify" pl={1} pr={1}>
<OpenModal
modalKey={u.id}
subtitle="Gica Hagi"
title="Are you sure to deactivate user?"
>
{showModal => (
<Button onClick={showModal} size="small">
DEACTIVATE
</Button>
)}
</OpenModal>
</HiddenItem>
</UserRow>
))}
</Fragment>
)
export default compose(
ConnectPage(() => [actions.getUsers()]),
connect(state => ({ items: get(state, 'users.users') })),
withPagination,
withProps(({ journal: { roles = {} } }) => ({
roles: Object.keys(roles),
getStatusLabel: () => ({ isConfirmed, isActive = true }) => {
return 'INACTIVE'
return isConfirmed ? 'ACTIVE' : 'INVITED'
getUserRoles: ({ journal: { roles = {} } }) => user =>
Object.entries(roles)
.reduce((acc, role) => (user[role[0]] ? [...acc, role[1]] : acc), [])
.join(', '),
}),
)(Users)
// #region styled-components
const HiddenItem = styled(Item)`
opacity: 0;
const UserRow = styled(Row)`
background-color: ${th('colorBackgroundHue2')};
background-color: #eeeeee;
${HiddenItem} {
opacity: 1;