2018-02-26 00:11:31 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-06-03 20:32:54 +00:00
|
|
|
import { Redirect, Route, Switch } from 'react-router';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
import AppRouting from './AppRouting';
|
2019-11-30 12:34:52 +00:00
|
|
|
import { PROJECT_NAME } from './constants/Env';
|
2018-05-18 22:29:14 +00:00
|
|
|
|
2019-11-30 12:34:52 +00:00
|
|
|
import { SnackbarProvider } from 'notistack';
|
2018-02-26 00:11:31 +00:00
|
|
|
import { create } from 'jss';
|
2019-11-30 12:34:52 +00:00
|
|
|
|
|
|
|
import { CssBaseline, IconButton, MuiThemeProvider, createMuiTheme } from '@material-ui/core';
|
2019-05-24 11:19:27 +00:00
|
|
|
import { StylesProvider, jssPreset } from '@material-ui/styles';
|
2019-11-30 12:34:52 +00:00
|
|
|
import { blueGrey, indigo, orange, red, green } from '@material-ui/core/colors';
|
|
|
|
import CloseIcon from '@material-ui/icons/Close';
|
2018-02-26 00:11:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Our theme
|
|
|
|
const theme = createMuiTheme({
|
|
|
|
palette: {
|
|
|
|
primary: indigo,
|
|
|
|
secondary: blueGrey,
|
|
|
|
highlight_idle: blueGrey[900],
|
|
|
|
highlight_warn: orange[500],
|
|
|
|
highlight_error: red[500],
|
|
|
|
highlight_success: green[500],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// JSS instance
|
|
|
|
const jss = create(jssPreset());
|
|
|
|
|
2019-06-03 20:32:54 +00:00
|
|
|
// this redirect forces a call to authenticationContext.refresh() which invalidates the JWT if it is invalid.
|
2019-08-04 17:42:58 +00:00
|
|
|
const unauthorizedRedirect = () => <Redirect to="/" />;
|
2019-06-03 20:32:54 +00:00
|
|
|
|
2019-08-04 17:42:58 +00:00
|
|
|
class App extends Component {
|
2019-11-30 12:34:52 +00:00
|
|
|
|
|
|
|
notistackRef = React.createRef();
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.title = PROJECT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickDismiss = (key) => () => {
|
|
|
|
this.notistackRef.current.closeSnackbar(key);
|
|
|
|
}
|
|
|
|
|
2019-06-03 20:32:54 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<StylesProvider jss={jss}>
|
|
|
|
<MuiThemeProvider theme={theme}>
|
2019-11-30 12:34:52 +00:00
|
|
|
<SnackbarProvider maxSnack={3} anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
|
|
|
|
ref={this.notistackRef}
|
|
|
|
action={(key) => (
|
|
|
|
<IconButton onClick={this.onClickDismiss(key)} size="small">
|
|
|
|
<CloseIcon />
|
|
|
|
</IconButton>
|
|
|
|
)}>
|
2019-06-03 20:32:54 +00:00
|
|
|
<CssBaseline />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path="/unauthorized" component={unauthorizedRedirect} />
|
|
|
|
<Route component={AppRouting} />
|
|
|
|
</Switch>
|
2019-08-04 17:42:58 +00:00
|
|
|
</SnackbarProvider>
|
2019-06-03 20:32:54 +00:00
|
|
|
</MuiThemeProvider>
|
|
|
|
</StylesProvider>
|
|
|
|
);
|
|
|
|
}
|
2018-02-26 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App
|