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
66 lines (61 loc) · 1.73 KB
/
AdminPanel.js
File metadata and controls
66 lines (61 loc) · 1.73 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
import React from 'react'
import { Stack, SimpleGrid, useToast } from '@chakra-ui/core'
import UserList from './UserList'
import { string } from 'prop-types'
import { slugify } from './slugify'
import { ADMIN_PANEL } from './graphql/queries'
import { useQuery } from '@apollo/client'
import { useUserState } from './UserState'
import { AdminDomains } from './AdminDomains'
export default function AdminPanel({ orgName, permission }) {
const { currentUser } = useUserState()
const toast = useToast()
// TODO: combine these queries into a single request
const { loading, error, data, refetch } = useQuery(ADMIN_PANEL, {
variables: { slug: slugify(orgName) },
context: {
headers: {
authorization: currentUser.jwt,
},
},
onError: error => {
const [_, message] = error.message.split(': ')
toast({
title: 'Error',
description: message,
status: 'failure',
duration: 9000,
isClosable: true,
})
},
})
if (loading) {
return <p>Loading...</p>
}
// Current api returns an error if no domains found
// TODO: Remove includes check when api is ready
if (error && !error.includes('Error, unable to find domains')) {
return <p>{String(error)}</p>
}
return (
<Stack spacing={10}>
<SimpleGrid columns={{ lg: 2 }} spacing="60px" width="100%">
<AdminDomains
domainsData={data.domains}
orgName={orgName}
refetchFunc={refetch}
/>
<UserList
permission={permission}
userListData={data.userList}
orgName={orgName}
orgSlug={slugify(orgName)}
/>
</SimpleGrid>
</Stack>
)
}
AdminPanel.propTypes = {
orgName: string,
permission: string,
}