forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganizations.js
More file actions
80 lines (74 loc) · 1.98 KB
/
Organizations.js
File metadata and controls
80 lines (74 loc) · 1.98 KB
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
import React from 'react'
import { number } from 'prop-types'
import { Trans } from '@lingui/macro'
import { Layout } from './Layout'
import { ListOf } from './ListOf'
import { Button, Heading, Stack, Box, Divider } from '@chakra-ui/core'
import {
PAGINATED_ORGANIZATIONS as FORWARD,
REVERSE_PAGINATED_ORGANIZATIONS as BACKWARD,
} from './graphql/queries'
import { useUserState } from './UserState'
import { Organization } from './Organization'
import { usePaginatedCollection } from './usePaginatedCollection'
export default function Organisations({ orgsPerPage = 10 }) {
const { currentUser } = useUserState()
const {
loading,
error,
nodes,
next,
previous,
hasNextPage,
hasPreviousPage,
} = usePaginatedCollection({
fetchForward: FORWARD,
fetchBackward: BACKWARD,
fetchHeaders: { authorization: currentUser.jwt },
recordsPerPage: orgsPerPage,
})
if (error)
return (
<p>
<Trans>error {error.message}</Trans>
</p>
)
if (loading)
return (
<p>
<Trans>Loading...</Trans>
</p>
)
return (
<Layout>
<Heading as="h1" mb="4">
<Trans>Organizations</Trans>
</Heading>
<ListOf
elements={nodes}
ifEmpty={() => <Trans>No Organizations</Trans>}
mb="4"
>
{({ name, slug, domainCount }, index) => (
<Box key={`${slug}:${index}`}>
<Organization slug={slug} name={name} domainCount={domainCount} />
<Divider borderColor="gray.900" />
</Box>
)}
</ListOf>
<Stack isInline align="center" mb="4">
<Button
onClick={previous}
disable={!!hasPreviousPage}
aria-label="Previous page"
>
<Trans>Previous</Trans>
</Button>
<Button onClick={next} disable={!!hasNextPage} aria-label="Next page">
<Trans>Next</Trans>
</Button>
</Stack>
</Layout>
)
}
Organisations.propTypes = { orgsPerPage: number }