Skip to content

Commit 5e27420

Browse files
author
Osman
committed
Merge branch 'master' of github.com:CodeForPhilly/paws-data-pipeline into 564-nginx-logging
2 parents a0280c8 + a04783e commit 5e27420

33 files changed

+1831
-1077
lines changed

src/client/package-lock.json

Lines changed: 1236 additions & 691 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@testing-library/user-event": "^7.2.1",
1414
"jsonwebtoken": "^8.5.1",
1515
"lodash": "^4.17.20",
16-
"moment": "^2.29.1",
16+
"moment-timezone": "^0.5.43",
1717
"react": "^16.13.1",
1818
"react-dom": "^16.13.1",
1919
"react-hook-form": "^7.43.9",

src/client/src/App.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Header from "./components/Header";
77
import Login from './pages/Login/Login';
88
import Logout from './pages/Login/Logout';
99
import HomePage from './pages/Home';
10-
import Admin from './pages/Admin';
10+
import Admin from './pages/Admin/Admin';
1111
import {Search360} from './pages/DataView360/Search/Search';
1212
import View360 from './pages/DataView360/View/View360';
1313
import About from './pages/About';
@@ -19,6 +19,7 @@ import useToken from './pages/Login/useToken';
1919
import Box from "@material-ui/core/Box";
2020
import {RFM} from "./pages/RFM/RFM";
2121
import UserManagement from './pages/UserManagement/UserManagement';
22+
import AlertBanner from './components/AlertBanner';
2223

2324
let jwt = require('jsonwebtoken');
2425

@@ -94,9 +95,12 @@ function AuthenticatedApp() {
9495
return (
9596
<Router>
9697

97-
<Box pb={4}>
98+
<Box>
9899
{!jwtExpired ? <Header headerType={headerType}/> : <Header headerType={'Login'}/>}
99100
</Box>
101+
<Box minHeight="84px">
102+
<AlertBanner />
103+
</Box>
100104
{popRefreshAlert &&
101105
<RefreshDlg shouldOpen={true} setToken={setToken}/>} {/* Pop up the refresh dialog */}
102106

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
3+
import { Alert, AlertTitle } from "@material-ui/lab";
4+
import useAlert from "../hooks/useAlert";
5+
import { Typography } from "@material-ui/core";
6+
import _ from "lodash";
7+
8+
const AlertBanner = () => {
9+
const { text, type, clearAlert } = useAlert();
10+
11+
if (text && type) {
12+
return (
13+
<Alert onClose={() => clearAlert()} severity={type} spacing={2} >
14+
<AlertTitle>
15+
<Typography variant="h6">{_.startCase(type)}</Typography>
16+
</AlertTitle>
17+
<Typography>{text}</Typography>
18+
</Alert>
19+
);
20+
} else {
21+
return <></>;
22+
}
23+
};
24+
25+
export default AlertBanner;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react';
2+
3+
const ALERT_TIME = 6000;
4+
const initialState = {
5+
text: "",
6+
type: "",
7+
};
8+
9+
const AlertContext = React.createContext({
10+
...initialState,
11+
setAlert: () => {},
12+
});
13+
14+
export const AlertProvider = ({ children }) => {
15+
const [text, setText] = React.useState("");
16+
const [type, setType] = React.useState("");
17+
const timerRef = React.useRef(null);
18+
19+
const setAlert = ({ type, text }) => {
20+
setType(type);
21+
setText(text);
22+
23+
if (timerRef.current) {
24+
clearTimeout(timerRef.current);
25+
}
26+
27+
if (type !== "error") {
28+
timerRef.current = setTimeout(() => {
29+
setText("");
30+
setType("");
31+
}, ALERT_TIME);
32+
}
33+
};
34+
35+
const clearAlert = () => {
36+
if (timerRef.current) {
37+
clearTimeout(timerRef.current);
38+
}
39+
40+
setType("");
41+
setText("");
42+
}
43+
44+
return (
45+
<AlertContext.Provider
46+
value={{
47+
text,
48+
type,
49+
setAlert,
50+
clearAlert,
51+
}}
52+
>
53+
{children}
54+
</AlertContext.Provider>
55+
);
56+
};
57+
58+
export default AlertContext;

src/client/src/hooks/useAlert.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useContext } from "react";
2+
import AlertContext from "../contexts/AlertContext";
3+
4+
const useAlert = () => useContext(AlertContext);
5+
6+
export default useAlert;

src/client/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { ThemeProvider } from '@material-ui/core/styles';
55
import * as serviceWorker from './serviceWorker';
66
import "./assets/font/font.css";
77
import defaultTheme from './theme/defaultTheme';
8+
import { AlertProvider } from './contexts/AlertContext';
89

910

1011
ReactDOM.render(
1112
<React.StrictMode>
1213
<ThemeProvider theme={defaultTheme}>
13-
<App/>
14+
<AlertProvider>
15+
<App/>
16+
</AlertProvider>
1417
</ThemeProvider>
1518
</React.StrictMode>,
1619
document.getElementById('root')

0 commit comments

Comments
 (0)