File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
3
- import { Alert } from "@material-ui/lab" ;
3
+ import { Alert , AlertTitle } from "@material-ui/lab" ;
4
4
import useAlert from "../hooks/useAlert" ;
5
+ import { Typography } from "@material-ui/core" ;
6
+ import _ from "lodash" ;
5
7
6
8
const AlertBanner = ( ) => {
7
- const { text, type, setAlert } = useAlert ( ) ;
9
+ const { text, type, clearAlert } = useAlert ( ) ;
8
10
9
11
if ( text && type ) {
10
12
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 >
20
18
</ Alert >
21
19
) ;
22
20
} else {
Original file line number Diff line number Diff line change @@ -15,9 +15,9 @@ export const AlertProvider = ({ children }) => {
15
15
const [ text , setText ] = React . useState ( "" ) ;
16
16
const [ type , setType ] = React . useState ( "" ) ;
17
17
18
- const setAlert = ( text , type ) => {
19
- setText ( text ) ;
18
+ const setAlert = ( { type, text } ) => {
20
19
setType ( type ) ;
20
+ setText ( text ) ;
21
21
22
22
if ( type !== "error" ) {
23
23
setTimeout ( ( ) => {
@@ -27,12 +27,18 @@ export const AlertProvider = ({ children }) => {
27
27
}
28
28
} ;
29
29
30
+ const clearAlert = ( ) => {
31
+ setType ( "" ) ;
32
+ setText ( "" ) ;
33
+ }
34
+
30
35
return (
31
36
< AlertContext . Provider
32
37
value = { {
33
38
text,
34
39
type,
35
40
setAlert,
41
+ clearAlert,
36
42
} }
37
43
>
38
44
{ children }
You can’t perform that action at this time.
0 commit comments