forked from amand33p/bug-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToastNotification.tsx
More file actions
44 lines (37 loc) · 1021 Bytes
/
Copy pathToastNotification.tsx
File metadata and controls
44 lines (37 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { useDispatch, useSelector } from 'react-redux';
import {
clearNotification,
selectNotifState,
} from '../redux/slices/notificationSlice';
import { Snackbar } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import Alert from '@material-ui/lab/Alert';
const useStyles = makeStyles((theme) => ({
snackbar: {
[theme.breakpoints.down('xs')]: {
bottom: 75,
},
},
}));
const ToastNotification = () => {
const classes = useStyles();
const dispatch = useDispatch();
const { message, type } = useSelector(selectNotifState);
const clearNotif = () => {
dispatch(clearNotification());
};
if (!message || !type) return null;
return (
<Snackbar
open={!!message}
onClose={clearNotif}
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
className={classes.snackbar}
>
<Alert onClose={clearNotif} severity={type}>
{message}
</Alert>
</Snackbar>
);
};
export default ToastNotification;