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
116 lines (109 loc) · 3.14 KB
/
Organizations.js
File metadata and controls
116 lines (109 loc) · 3.14 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
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
import React from 'react'
import { number } from 'prop-types'
import { Trans, t } from '@lingui/macro'
import { Layout } from './Layout'
import { ListOf } from './ListOf'
import {
Button,
Heading,
Stack,
Box,
Divider,
InputGroup,
InputLeftElement,
Icon,
Input,
} from '@chakra-ui/core'
import {
PAGINATED_ORGANIZATIONS as FORWARD,
REVERSE_PAGINATED_ORGANIZATIONS as BACKWARD,
} from './graphql/queries'
import { useUserState } from './UserState'
import { OrganizationCard } from './OrganizationCard'
import { usePaginatedCollection } from './usePaginatedCollection'
import { ErrorBoundary } from 'react-error-boundary'
import { ErrorFallbackMessage } from './ErrorFallbackMessage'
import { LoadingMessage } from './LoadingMessage'
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,
relayRoot: 'findMyOrganizations',
})
if (error) return <ErrorFallbackMessage error={error} />
if (loading)
return (
<LoadingMessage>
<Trans>Organizations</Trans>
</LoadingMessage>
)
return (
<Layout>
<Heading as="h1" mb="4" textAlign={['center', 'left']}>
<Trans>Organizations</Trans>
</Heading>
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
<InputGroup width="100%" mb="8px">
<InputLeftElement>
<Icon name="search" color="gray.300" />
</InputLeftElement>
<Input type="text" placeholder={t`Search for an organization`} />
</InputGroup>
<ListOf
elements={nodes}
ifEmpty={() => <Trans>No Organizations</Trans>}
mb="4"
>
{(
{ name, slug, acronym, domainCount, verified, summaries },
index,
) => (
<ErrorBoundary
key={`${slug}:${index}`}
FallbackComponent={ErrorFallbackMessage}
>
<Box>
<OrganizationCard
slug={slug}
name={name}
acronym={acronym}
domainCount={domainCount}
verified={verified}
summaries={summaries}
/>
<Divider borderColor="gray.900" />
</Box>
</ErrorBoundary>
)}
</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>
<Trans>
*All data represented is mocked for demonstration purposes
</Trans>
</ErrorBoundary>
</Layout>
)
}
Organisations.propTypes = { orgsPerPage: number }