Skip to content

Commit 625011b

Browse files
committed
Refresh dialog component and App.js support
1 parent dca3811 commit 625011b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/client/src/App.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import Admin from './pages/Admin';
88
import DataView from './pages/DataView360/DataView360';
99
import About from './pages/About';
1010
import Login from './components/Login/Login';
11+
import CDialog from './components/CDialog';
1112
import Check from './pages/Check/Check';
13+
14+
1215
import useToken from './components/Login/useToken';
1316
var jwt = require('jsonwebtoken');
1417

@@ -76,6 +79,8 @@ function AuthenticatedApp() {
7679

7780
const jwtExpired = expTime <= 0
7881

82+
const popRefreshAlert = expTime < 30;
83+
7984
const hdr = userRole === 'admin' ? <AdminHeader /> : <Header /> // If we're going to display a header, which one?
8085

8186
return (
@@ -84,6 +89,9 @@ function AuthenticatedApp() {
8489

8590
{ !jwtExpired && hdr ? hdr : '' /* Above-chosen header, or if logged out, no header */ }
8691

92+
{popRefreshAlert && <CDialog /> }
93+
94+
8795
{ /* If not logged in, show login screen */
8896
(!access_token | jwtExpired) ? <Login setToken={setToken} /> : <Switch>
8997

src/client/src/components/CDialog.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import Button from '@material-ui/core/Button';
3+
import Dialog from '@material-ui/core/Dialog';
4+
import DialogActions from '@material-ui/core/DialogActions';
5+
import DialogContent from '@material-ui/core/DialogContent';
6+
import DialogContentText from '@material-ui/core/DialogContentText';
7+
import DialogTitle from '@material-ui/core/DialogTitle';
8+
9+
export default function CDialog() {
10+
const [open, setOpen] = React.useState(true);
11+
12+
const handleClickOpen = () => {
13+
setOpen(true);
14+
};
15+
16+
const handleClose = (shouldRefresh) => {
17+
setOpen(false);
18+
console.log("Refresh? " + String(shouldRefresh));
19+
};
20+
21+
22+
23+
return (
24+
<div>
25+
{/* <Button variant="outlined" color="primary" onClick={handleClickOpen}>
26+
Open alert dialog
27+
</Button> */}
28+
<Dialog
29+
open={open}
30+
onClose={handleClose}
31+
aria-labelledby="alert-dialog-title"
32+
aria-describedby="alert-dialog-description"
33+
>
34+
<DialogTitle id="alert-dialog-title">{"You are about to be logged out!"}</DialogTitle>
35+
<DialogContent>
36+
<DialogContentText id="alert-dialog-description">
37+
Stay logged in to keep working?
38+
</DialogContentText>
39+
</DialogContent>
40+
<DialogActions>
41+
<Button onClick={() => handleClose(false)} color="primary">
42+
No
43+
</Button>
44+
<Button onClick={() => handleClose(true)} color="primary" autoFocus>
45+
Yes
46+
</Button>
47+
</DialogActions>
48+
</Dialog>
49+
</div>
50+
);
51+
}

0 commit comments

Comments
 (0)