Skip to content
Snippets Groups Projects
Commit 8bdb70e1 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

feat(admin-users): fix bugs and improve

parent e4c88ca2
No related branches found
No related tags found
1 merge request!43Sprint #19
...@@ -2,7 +2,7 @@ import React from 'react' ...@@ -2,7 +2,7 @@ import React from 'react'
import { Icon } from '@pubsweet/ui' import { Icon } from '@pubsweet/ui'
import styled from 'styled-components' import styled from 'styled-components'
import { positionHelper, marginHelper } from './styledHelpers' import { positionHelper, marginHelper, paddingHelper } from './styledHelpers'
const IconButton = styled.div` const IconButton = styled.div`
align-items: center; align-items: center;
...@@ -20,6 +20,7 @@ const IconButton = styled.div` ...@@ -20,6 +20,7 @@ const IconButton = styled.div`
} }
${marginHelper}; ${marginHelper};
${paddingHelper};
${positionHelper}; ${positionHelper};
` `
......
...@@ -106,17 +106,24 @@ export default compose( ...@@ -106,17 +106,24 @@ export default compose(
withFetching, withFetching,
withState('authors', 'setAuthors', ({ authors }) => authors), withState('authors', 'setAuthors', ({ authors }) => authors),
withHandlers({ withHandlers({
setFormAuthors: ({ changeForm, setAuthors, setFetching }) => authors => { setFormAuthors: ({
changeForm,
setAuthors,
setFetching,
onAuthorEdit,
}) => authors => {
setAuthors(authors) setAuthors(authors)
setFetching(false) setFetching(false)
onAuthorEdit(null)
changeForm('submission', 'authors', authors) changeForm('submission', 'authors', authors)
}, },
}), }),
withHandlers({ withHandlers({
addNewAuthor: ({ authors = [], setAuthors }) => () => { addNewAuthor: ({ authors = [], setAuthors, onAuthorEdit }) => () => {
if (authors.some(a => a.id === 'newAuthor')) { if (authors.some(a => a.id === 'newAuthor')) {
return return
} }
onAuthorEdit(0)
setAuthors([ setAuthors([
...authors, ...authors,
{ id: 'newAuthor', isCorresponding: false, isSubmitting: false }, { id: 'newAuthor', isCorresponding: false, isSubmitting: false },
......
...@@ -26,7 +26,7 @@ import { ...@@ -26,7 +26,7 @@ import {
const AddUserForm = ({ roles, countries, titles }) => ( const AddUserForm = ({ roles, countries, titles }) => (
<Fragment> <Fragment>
<Row alignItems="center" mb={2}> <Row alignItems="baseline" mb={1} mt={1}>
<Item mr={1} vertical> <Item mr={1} vertical>
<Label required>Email</Label> <Label required>Email</Label>
<ValidatedField <ValidatedField
...@@ -133,18 +133,18 @@ const EditForm = ({ titles, countries }) => ( ...@@ -133,18 +133,18 @@ const EditForm = ({ titles, countries }) => (
<Label>Roles</Label> <Label>Roles</Label>
</Item> </Item>
</Row> </Row>
<RowOverrideAlert mb={2} mt={1}> <RowOverrideAlert mb={3} mt={1}>
<Item> <Item>
<ValidatedField <ValidatedField
component={({ value, onChange }) => ( component={({ value, onChange }) => (
<Checkbox <Checkbox
checked={value} checked={value}
label="Author" label="Editor in Chief"
onChange={onChange} onChange={onChange}
value={value} value={value}
/> />
)} )}
name="author" name="editorInChief"
/> />
</Item> </Item>
<Item> <Item>
...@@ -174,21 +174,6 @@ const EditForm = ({ titles, countries }) => ( ...@@ -174,21 +174,6 @@ const EditForm = ({ titles, countries }) => (
/> />
</Item> </Item>
</RowOverrideAlert> </RowOverrideAlert>
<RowOverrideAlert mb={3}>
<Item>
<ValidatedField
component={({ value, onChange }) => (
<Checkbox
checked={value}
label="Editor in Chief"
onChange={onChange}
value={value}
/>
)}
name="editorInChief"
/>
</Item>
</RowOverrideAlert>
</Fragment> </Fragment>
) )
......
...@@ -22,7 +22,7 @@ const AddUser = ({ edit, journal, handleSubmit, ...rest }) => ( ...@@ -22,7 +22,7 @@ const AddUser = ({ edit, journal, handleSubmit, ...rest }) => (
> >
{showModal => {showModal =>
edit ? ( edit ? (
<IconButton icon="edit-2" iconSize={2} onClick={showModal} /> <IconButton icon="edit-2" iconSize={2} onClick={showModal} pt={1 / 2} />
) : ( ) : (
<ActionLink icon="plus" onClick={showModal}> <ActionLink icon="plus" onClick={showModal}>
ADD USER ADD USER
......
...@@ -41,7 +41,7 @@ const Users = ({ ...@@ -41,7 +41,7 @@ const Users = ({
...rest ...rest
}) => ( }) => (
<Fragment> <Fragment>
<Row alignItems="center" justify="space-between" mb={3}> <Row alignItems="center" justify="space-between" mb={1}>
<Item alignItems="center"> <Item alignItems="center">
<ActionLink icon="arrow-left" mr={2} onClick={history.goBack}> <ActionLink icon="arrow-left" mr={2} onClick={history.goBack}>
Admin Dashboard Admin Dashboard
...@@ -57,74 +57,85 @@ const Users = ({ ...@@ -57,74 +57,85 @@ const Users = ({
<Pagination {...rest} itemsPerPage={itemsPerPage} page={page} /> <Pagination {...rest} itemsPerPage={itemsPerPage} page={page} />
</Row> </Row>
<Row alignItems="center" mb={1} pl={2}> <Table>
<Item flex={2}> <thead>
<Label>Full name</Label> <tr>
</Item> <th>
<Item flex={4}> <Label>Full Name</Label>
<Label>Email</Label> </th>
</Item> <th colSpan={2}>
<Item flex={2}> <Label>Email</Label>
<Label>Affiliation</Label> </th>
</Item> <th>
<Item flex={2}> <Label>Affiliation</Label>
<Label>Roles</Label> </th>
</Item> <th>
<Item flex={1}> <Label>Roles</Label>
<Label>Status</Label> </th>
</Item> <th>
<Item /> <Label>Status</Label>
<Item /> </th>
</Row> <th>&nbsp;</th>
{paginatedItems.map(user => ( </tr>
<UserRow alignItems="center" key={user.id} pb={1 / 2} pl={2} pt={1 / 2}> </thead>
<Item flex={2}> <tbody>
<Text>{`${get(user, 'firstName', '')} ${get( {paginatedItems.map(user => (
user, <UserRow key={user.id}>
'lastName', <td>
'', <Text pl={1}>{`${get(user, 'firstName', '')} ${get(
)}`}</Text> user,
</Item> 'lastName',
<Item flex={4}> '',
<Text>{user.email}</Text> )}`}</Text>
</Item> </td>
<Item flex={2}> <td colSpan={2}>
<Text>{user.affiliation}</Text> <Text>{user.email}</Text>
</Item> </td>
<Item flex={2}> <td>
<Text customId>{getUserRoles(user)}</Text> <Text>{user.affiliation}</Text>
</Item> </td>
<Item flex={1} secondary> <td>
<Text>{getStatusLabel(user)}</Text> <Text customId>{getUserRoles(user)}</Text>
</Item> </td>
<HiddenItem justify="center"> <td>
<AddUser <Text secondary>{getStatusLabel(user)}</Text>
edit </td>
getUsers={getUsers}
modalKey={`edit-${user.id}`} <HiddenCell>
onSubmit={onSubmit} <Item alignItems="center" justify="flex-end">
user={user} <AddUser
/> edit
</HiddenItem> getUsers={getUsers}
<HiddenItem justify="justify" pl={1} pr={1}> modalKey={`edit-${user.id}`}
{!user.admin && ( onSubmit={onSubmit}
<OpenModal user={user}
isFetching={isFetching} />
modalKey={`deactivate-${user.id}`} <OpenModal
onConfirm={deactivateUser(user)} isFetching={isFetching}
subtitle={`${user.firstName} ${user.lastName}`} modalKey={`deactivate-${user.id}`}
title="Are you sure to deactivate user?" onConfirm={deactivateUser(user)}
> subtitle={`${user.firstName} ${user.lastName}`}
{showModal => ( title={`Are you sure to ${
<Button onClick={showModal} size="small"> !user.isActive ? 'activate' : 'deactivate'
{user.isActive ? 'DEACTIVATE' : 'ACTIVATE'} } user?`}
</Button> >
)} {showModal => (
</OpenModal> <ActivateButton
)} ml={1}
</HiddenItem> mr={1}
</UserRow> onClick={showModal}
))} size="small"
>
{!user.isActive ? 'ACTIVATE' : 'DEACTIVATE'}
</ActivateButton>
)}
</OpenModal>
</Item>
</HiddenCell>
</UserRow>
))}
</tbody>
</Table>
</Fragment> </Fragment>
) )
...@@ -162,27 +173,46 @@ export default compose( ...@@ -162,27 +173,46 @@ export default compose(
setModalError('Something went wrong...') setModalError('Something went wrong...')
}) })
}, },
getUserRoles: ({ journal: { roles = {} } }) => user => getUserRoles: ({ journal: { roles = {} } }) => user => {
Object.entries(roles) const parsedRoles = Object.entries(roles)
.reduce((acc, role) => (user[role[0]] ? [...acc, role[1]] : acc), []) .reduce((acc, role) => (user[role[0]] ? [...acc, role[1]] : acc), [])
.join(', '), .join(', ')
return parsedRoles || 'Author'
},
}), }),
)(Users) )(Users)
// #region styled-components // #region styled-components
const HiddenItem = styled(Item)` const Table = styled.table`
border-collapse: collapse;
& th,
& td {
border: none;
text-align: start;
vertical-align: middle;
height: calc(${th('gridUnit')} * 5);
}
`
const HiddenCell = styled.td`
opacity: 0; opacity: 0;
` `
const UserRow = styled(Row)` const UserRow = styled.tr`
background-color: ${th('colorBackgroundHue2')}; background-color: ${th('colorBackgroundHue2')};
border-bottom: 1px solid ${th('colorBorder')};
&:hover { &:hover {
background-color: #eeeeee; background-color: #eeeeee;
${HiddenItem} { ${HiddenCell} {
opacity: 1; opacity: 1;
} }
} }
` `
const ActivateButton = styled(Button)`
width: 90px;
`
// #endregion // #endregion
...@@ -140,7 +140,6 @@ module.exports = { ...@@ -140,7 +140,6 @@ module.exports = {
country: Joi.string().allow(''), country: Joi.string().allow(''),
title: Joi.string().allow(''), title: Joi.string().allow(''),
teams: Joi.array(), teams: Joi.array(),
author: Joi.boolean(),
editorInChief: Joi.boolean(), editorInChief: Joi.boolean(),
handlingEditor: Joi.boolean(), handlingEditor: Joi.boolean(),
invitationToken: Joi.string().allow(''), invitationToken: Joi.string().allow(''),
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment