forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganizationDomains.js
More file actions
80 lines (75 loc) · 2.18 KB
/
OrganizationDomains.js
File metadata and controls
80 lines (75 loc) · 2.18 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 { Trans } from '@lingui/macro'
import { Box, Divider, Text } from '@chakra-ui/core'
import { PAGINATED_ORG_DOMAINS as FORWARD } from './graphql/queries'
import { ErrorBoundary } from 'react-error-boundary'
import { ErrorFallbackMessage } from './ErrorFallbackMessage'
import { LoadingMessage } from './LoadingMessage'
import { DomainCard } from './DomainCard'
import { ListOf } from './ListOf'
import { usePaginatedCollection } from './usePaginatedCollection'
import { number, string } from 'prop-types'
import { RelayPaginationControls } from './RelayPaginationControls'
export function OrganizationDomains({ domainsPerPage = 10, orgSlug }) {
const {
loading,
isLoadingMore,
error,
nodes,
next,
previous,
hasNextPage,
hasPreviousPage,
} = usePaginatedCollection({
fetchForward: FORWARD,
variables: { slug: orgSlug },
recordsPerPage: domainsPerPage,
relayRoot: 'findOrganizationBySlug.domains',
})
if (error) return <ErrorFallbackMessage error={error} />
if (loading)
return (
<LoadingMessage>
<Trans>Domains</Trans>
</LoadingMessage>
)
return (
<Box>
<ListOf
elements={nodes}
ifEmpty={() => (
<Text fontSize="xl" fontWeight="bold">
<Trans>No Domains</Trans>
</Text>
)}
mb="4"
>
{({ id, domain, lastRan, status, hasDMARCReport }, index) => (
<ErrorBoundary
key={`${id}:${index}`}
FallbackComponent={ErrorFallbackMessage}
>
<Box>
<DomainCard
url={domain}
lastRan={lastRan}
status={status}
hasDMARCReport={hasDMARCReport}
/>
<Divider borderColor="gray.900" />
</Box>
</ErrorBoundary>
)}
</ListOf>
<RelayPaginationControls
onlyPagination={true}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
next={next}
previous={previous}
isLoadingMore={isLoadingMore}
/>
</Box>
)
}
OrganizationDomains.propTypes = { domainsPerPage: number, orgSlug: string }