forked from electerious/Ackee
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
45 lines (34 loc) · 1.21 KB
/
Main.js
File metadata and controls
45 lines (34 loc) · 1.21 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
import { createElement as h, Fragment } from 'react'
import { withErrorBoundary } from 'react-error-boundary'
import isUnknownError from '../utils/isUnknownError'
import useCustomScrollbar from '../hooks/useCustomScrollbar'
import useRouter from '../hooks/useRouter'
import OverlayFailure from './overlays/OverlayFailure'
import OverlayLogin from './overlays/OverlayLogin'
import ErrorFallback from './ErrorFallback'
import Filter from './Filter'
import Dashboard from './Dashboard'
const Main = (props) => {
useCustomScrollbar()
const [ setRoute, route ] = useRouter()
const enhancedProps = {
...props,
setRoute,
route
}
// Only handle errors not handled by other components
const unknownErrors = props.errors.filter(isUnknownError)
const hasError = unknownErrors.length !== 0
const hasToken = props.token.value != null
if (hasError === true) return h(OverlayFailure, { errors: unknownErrors })
if (hasToken === false && !window.env.authDisabled) {
return h(OverlayLogin, { token: props.token, addToken: props.addToken.bind(null, props) })
}
return h(Fragment, {},
h(Filter, enhancedProps),
h(Dashboard, enhancedProps)
)
}
export default withErrorBoundary(Main, {
FallbackComponent: ErrorFallback
})