Skip to content
Snippets Groups Projects
Commit ac874ad3 authored by Jure's avatar Jure
Browse files

refactor: update users manager to use shared table style

parent c2102d4e
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,10 @@ import gql from 'graphql-tag' ...@@ -3,7 +3,10 @@ import gql from 'graphql-tag'
import { useMutation } from '@apollo/react-hooks' import { useMutation } from '@apollo/react-hooks'
import { Action } from '@pubsweet/ui' import { Action } from '@pubsweet/ui'
import { UserAvatar } from '../../component-avatar/src' import { UserAvatar } from '../../component-avatar/src'
import { Row, Cell, LastCell, UserCombo, Primary, Secondary, UserInfo } from './style' import { Row, Cell, LastCell } from './style'
import { UserCombo, Primary, Secondary, UserInfo } from '../../shared'
import { convertTimestampToDate } from '../../../shared/time-formatting' import { convertTimestampToDate } from '../../../shared/time-formatting'
const DELETE_USER = gql` const DELETE_USER = gql`
......
import React, { useState } from 'react' import React, { useState } from 'react'
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { useQuery } from '@apollo/react-hooks' import { useQuery } from '@apollo/react-hooks'
import { Heading } from '@pubsweet/ui' // import { Heading } from '@pubsweet/ui'
import User from './User' import User from './User'
import { Container, Table, Header, Caret, Carets } from './style' import {
import Spinner from '../../shared/Spinner' Container,
import Pagination from '../../shared/Pagination' Table,
Header,
PageHeading,
Content,
Spinner,
Pagination,
CaretUp,
CaretDown,
Carets,
} from './style'
const GET_USERS = gql` const GET_USERS = gql`
query Users( query Users(
...@@ -15,7 +24,12 @@ const GET_USERS = gql` ...@@ -15,7 +24,12 @@ const GET_USERS = gql`
$offset: Int $offset: Int
$limit: Int $limit: Int
) { ) {
users(sort: $sort, filter: $filter, offset: $offset, limit: $limit) { paginatedUsers(
sort: $sort
filter: $filter
offset: $offset
limit: $limit
) {
totalCount totalCount
users { users {
id id
...@@ -30,38 +44,6 @@ const GET_USERS = gql` ...@@ -30,38 +44,6 @@ const GET_USERS = gql`
} }
` `
const CaretUp = ({ active }) => (
<Caret
aria-hidden="true"
className=""
data-icon="caret-up"
fill="currentColor"
focusable="false"
height="1em"
viewBox="0 0 100 100"
width="1em"
active={active}
>
<path d="M50 17L100.229 67.25H-0.229473L50 17Z" />
</Caret>
)
const CaretDown = ({ active }) => (
<Caret
active={active}
aria-hidden="true"
className=""
data-icon="caret-down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="0 0 100 100"
width="1em"
>
<path d="M50 84L-0.229473 33.75L100.229 33.75L50 84Z" />
</Caret>
)
const UsersManager = () => { const UsersManager = () => {
const SortHeader = ({ thisSortName, children }) => { const SortHeader = ({ thisSortName, children }) => {
...@@ -113,32 +95,34 @@ const UsersManager = () => { ...@@ -113,32 +95,34 @@ const UsersManager = () => {
if (loading) return <Spinner /> if (loading) return <Spinner />
if (error) return `Error! ${error.message}` if (error) return `Error! ${error.message}`
const { users, totalCount } = data.users const { users, totalCount } = data.paginatedUsers
return ( return (
<Container> <Container>
<Heading level={1}>Users</Heading> <PageHeading level={1}>Users</PageHeading>
<Table> <Content>
<Header> <Table>
<tr> <Header>
<SortHeader thisSortName="username">Name</SortHeader> <tr>
<SortHeader thisSortName="created">Created</SortHeader> <SortHeader thisSortName="username">Name</SortHeader>
<SortHeader thisSortName="admin">Admin</SortHeader> <SortHeader thisSortName="created">Created</SortHeader>
<th /> <SortHeader thisSortName="admin">Admin</SortHeader>
</tr> <th />
</Header> </tr>
<tbody> </Header>
{users.map((user, key) => ( <tbody>
<User key={user.id} number={key + 1} user={user} /> {users.map((user, key) => (
))} <User key={user.id} number={key + 1} user={user} />
</tbody> ))}
</Table> </tbody>
<Pagination </Table>
limit={limit} <Pagination
page={page} limit={limit}
setPage={setPage} page={page}
totalCount={totalCount} setPage={setPage}
/> totalCount={totalCount}
/>
</Content>
</Container> </Container>
) )
} }
......
import styled, { css } from 'styled-components' // import styled, { css } from 'styled-components'
import { Action } from '@pubsweet/ui' // import { Action } from '@pubsweet/ui'
import { th, grid } from '@pubsweet/ui-toolkit' // import { th, grid } from '@pubsweet/ui-toolkit'
export const Table = styled.table` export {
width: 100%; Row,
border-radius: ${th('borderRadius')}; Cell,
border-collapse: collapse; LastCell,
font-size: ${th('fontSizeBaseSmall')}; UserCombo,
Primary,
td { Secondary,
width: 33%; UserInfo,
} Container,
` Table,
export const Header = styled.thead` Header,
text-align: left; Content,
font-variant: all-small-caps; PageHeading,
border-bottom: 1px solid ${th('colorFurniture')}; Carets,
CaretUp,
background-color: ${th('colorBackgroundHue')}; CaretDown,
Spinner,
th { Pagination,
padding: ${grid(1)} ${grid(3)}; } from '../../shared'
}
`
export const Container = styled.div`
padding: ${grid(2)};
`
export const Row = styled.tr`
max-height: ${grid(8)};
border-bottom: 1px solid ${th('colorFurniture')};
&:hover {
background-color: ${th('colorBackgroundHue')};
}
`
export const Cell = styled.td`
padding-bottom: ${grid(2)};
padding-top: calc(${grid(2)} - 1px);
padding-left: ${grid(3)};
padding-right: ${grid(3)};
button {
font-size: ${th('fontSizeBaseSmall')};
}
`
export const UserCombo = styled.div`
display: flex;
line-height: ${grid(2.5)};
align-items: center;
`
export const LastCell = styled(Cell)`
text-align: right;
`
export const Primary = styled.div`
font-weight: 500;
`
export const Secondary = styled.div`
color: ${th('colorTextPlaceholder')};
`
export const UserInfo = styled.div`
margin-left: ${grid(1)};
`
export const Caret = styled.svg`
${props =>
props.active
? css`
color: ${th('colorPrimary')};
`
: css`
color: ${th('colorSecondary')};
`}
`
export const Carets = styled.span`
display: inline-flex;
flex-direction: column;
align-items: center;
vertical-align: middle;
margin-left: ${grid(0.5)};
svg {
height: ${grid(1.5)};
}
svg:nth-of-type(2) {
margin-top: ${grid(-0.5)};
}
`
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