Skip to content

Commit 4235f52

Browse files
committed
492: Update useAlert params and add clearAlert
1 parent 7fa500e commit 4235f52

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/client/src/components/AlertBanner.jsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import React from "react";
22

3-
import { Alert } from "@material-ui/lab";
3+
import { Alert, AlertTitle } from "@material-ui/lab";
44
import useAlert from "../hooks/useAlert";
5+
import { Typography } from "@material-ui/core";
6+
import _ from "lodash";
57

68
const AlertBanner = () => {
7-
const { text, type, setAlert } = useAlert();
9+
const { text, type, clearAlert } = useAlert();
810

911
if (text && type) {
1012
return (
11-
<Alert
12-
onClose={() => setAlert(null)}
13-
severity={type}
14-
sx={{
15-
position: "absolute",
16-
zIndex: 10,
17-
}}
18-
>
19-
{text}
13+
<Alert onClose={() => clearAlert()} severity={type} spacing={2} >
14+
<AlertTitle>
15+
<Typography variant="h6">{_.startCase(type)}</Typography>
16+
</AlertTitle>
17+
<Typography>{text}</Typography>
2018
</Alert>
2119
);
2220
} else {

src/client/src/contexts/AlertContext.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export const AlertProvider = ({ children }) => {
1515
const [text, setText] = React.useState("");
1616
const [type, setType] = React.useState("");
1717

18-
const setAlert = (text, type) => {
19-
setText(text);
18+
const setAlert = ({ type, text }) => {
2019
setType(type);
20+
setText(text);
2121

2222
if (type !== "error") {
2323
setTimeout(() => {
@@ -27,12 +27,18 @@ export const AlertProvider = ({ children }) => {
2727
}
2828
};
2929

30+
const clearAlert = () => {
31+
setType("");
32+
setText("");
33+
}
34+
3035
return (
3136
<AlertContext.Provider
3237
value={{
3338
text,
3439
type,
3540
setAlert,
41+
clearAlert,
3642
}}
3743
>
3844
{children}

0 commit comments

Comments
 (0)