forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminPanel.js
More file actions
77 lines (72 loc) · 2.25 KB
/
AdminPanel.js
File metadata and controls
77 lines (72 loc) · 2.25 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
import React from 'react'
import { Stack, SimpleGrid, useToast } from '@chakra-ui/core'
import { string } from 'prop-types'
import { ADMIN_PANEL } from './graphql/queries'
import { useQuery } from '@apollo/client'
import { useUserState } from './UserState'
import { AdminDomains } from './AdminDomains'
import { ErrorBoundary } from 'react-error-boundary'
import { ErrorFallbackMessage } from './ErrorFallbackMessage'
import { LoadingMessage } from './LoadingMessage'
import { Trans } from '@lingui/macro'
import UserList from './UserList'
export default function AdminPanel({ orgSlug, permission }) {
const { currentUser } = useUserState()
const toast = useToast()
const { loading, error, data } = useQuery(ADMIN_PANEL, {
variables: { orgSlug: orgSlug, domainsFirst: 5, affiliationsFirst: 5 },
context: {
headers: {
authorization: currentUser.jwt,
},
},
onError: (error) => {
const [_, message] = error.message.split(': ')
toast({
title: 'Error',
description: message,
status: 'error',
duration: 9000,
isClosable: true,
position: 'top-left',
})
},
})
if (loading) {
return (
<LoadingMessage>
<Trans>Organization Info</Trans>
</LoadingMessage>
)
}
// Current api returns an error if no domains found
// TODO: Remove includes check when api is ready
if (error) {
return <ErrorFallbackMessage error={error} />
}
return (
<Stack spacing={10}>
<SimpleGrid columns={{ lg: 2 }} spacing="60px" width="100%">
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
<AdminDomains
domainsData={data.findOrganizationBySlug.domains}
orgId={data.findOrganizationBySlug.id}
orgSlug={orgSlug}
/>
</ErrorBoundary>
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
<UserList
permission={permission}
userListData={data.findOrganizationBySlug.affiliations}
orgId={data.findOrganizationBySlug.id}
orgName={data.findOrganizationBySlug.name}
/>
</ErrorBoundary>
</SimpleGrid>
</Stack>
)
}
AdminPanel.propTypes = {
orgSlug: string.isRequired,
permission: string.isRequired,
}