-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathPortalHome.tsx
163 lines (154 loc) · 4.85 KB
/
PortalHome.tsx
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import {useState, useEffect, useMemo} from 'react'
import {Box, Grid, Typography, Divider, Button} from '@mui/material'
import green from '@mui/material/colors/green'
import {useSnackbar} from 'notistack'
import {Settings} from '@mui/icons-material'
import EmptyState from '../EmptyState/EmptyState'
import AppsShelfSkeleton from '../AppsShelfSkeleton/AppsShelfSkeleton'
import AppsShelf from '../AppsShelf/AppsShelf'
import {fetchApps} from '@jembi/openhim-core-api'
const preloadedPortalApps = [
{
_id: '66f6ab7dd13af5ffa0d8aef7',
name: 'OpenHIM Docs',
description: 'Documentation for the OpenHIM',
icon: 'https://fonts.gstatic.com/s/i/materialicons/cloud/v12/24px.svg',
type: 'external',
category: 'Documentation',
access_roles: ['admin'],
url: 'https://openhim.org/docs/introduction/about',
showInPortal: true,
showInSideBar: false,
__v: 0
},
{
_id: '671621d593a136387ce3048c',
name: 'OpenHIM Platform Docs',
description: 'Documentation for the OpenHIM Platform',
icon: 'https://fonts.gstatic.com/s/i/materialicons/dashboard/v12/24px.svg',
type: 'external',
category: 'Documentation',
access_roles: ['admin'],
url: `https://jembi.gitbook.io/openhim-platform`,
showInPortal: true,
showInSideBar: false,
__v: 0
},
{
_id: '671621d593a136387ce3048c',
name: 'Transactions',
description: 'View incoming API requests',
icon: 'https://fonts.gstatic.com/s/i/materialicons/dashboard/v12/24px.svg',
type: 'internal',
category: 'OpenHIM',
access_roles: ['admin'],
url: `${window.location.origin}/#!/transactions`,
showInPortal: true,
showInSideBar: false,
__v: 0
},
{
_id: '671621d593a136387ce3048c',
name: 'Manage Channels',
description: 'View and manage channels',
icon: 'https://fonts.gstatic.com/s/i/materialicons/dashboard/v12/24px.svg',
type: 'internal',
category: 'OpenHIM',
access_roles: ['admin'],
url: `${window.location.origin}/#!/channels`,
showInPortal: true,
showInSideBar: false,
__v: 0
},
{
_id: '671621d593a136387ce3048c',
name: 'Manage Clients',
description: 'View and manage clients',
icon: 'https://fonts.gstatic.com/s/i/materialicons/dashboard/v12/24px.svg',
type: 'internal',
category: 'OpenHIM',
access_roles: ['admin'],
url: `${window.location.origin}/#!/clients`,
showInPortal: true,
showInSideBar: false,
__v: 0
},
{
_id: '671621d593a136387ce3048c',
name: 'Manage Users',
description: 'View and manage users',
icon: 'https://fonts.gstatic.com/s/i/materialicons/dashboard/v12/24px.svg',
type: 'internal',
category: 'OpenHIM',
access_roles: ['admin'],
url: `${window.location.origin}/#!/users`,
showInPortal: true,
showInSideBar: false,
__v: 0
}
]
function PortalHome() {
const [isLoading, setLoading] = useState(true)
const [portalApps, setApps] = useState([])
const {enqueueSnackbar} = useSnackbar()
/* extract unique categories */
const uniqueCategories = useMemo(
() => Array.from(new Set(portalApps.map(app => app.category))),
[portalApps]
)
/* group apps by category */
const appsGroupedByCat = useMemo(
() =>
uniqueCategories.reduce((acc: {[key: string]: any}, category) => {
const appsToDisplay = portalApps.filter(
app => app.category === category
)
return {...acc, [category.toString()]: appsToDisplay}
}, {}),
[uniqueCategories, portalApps]
)
async function loadContent() {
try {
const updatedPortalApps = await fetchApps()
setApps([...preloadedPortalApps, ...updatedPortalApps])
} catch (error) {
enqueueSnackbar('Unable to fetch apps', {variant: 'error'})
setApps([...preloadedPortalApps]) // Clear the apps list on error
} finally {
setLoading(false)
}
}
useEffect(() => {
loadContent()
}, [])
return (
<Box mt={'5%'} ml={'10%'} mr={'10%'}>
<section id="PortalHeader">
<Grid sx={{ml: 0, mt: 0}}>
<Box width="100%" display="flex" justifyContent="space-between">
<Typography variant="h2" color={green[700]}>
Portal
</Typography>
<Button href="#!/portal-admin" startIcon={<Settings />}>
Manage
</Button>
</Box>
</Grid>
<Divider sx={{mb: 3, borderBlockColor: 'rgba(0, 0, 0, 0.50)'}} />
</section>
<section id="CategoriesSection">
{isLoading ? (
<AppsShelfSkeleton />
) : Object.keys(appsGroupedByCat).length === 0 ? (
<EmptyState
header="You don't have any registered apps to display yet"
description="Start by adding a new app to your portal."
/>
) : (
<AppsShelf appsGroupedByCat={appsGroupedByCat} />
)}
</section>
</Box>
)
}
export default PortalHome