-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnackbar.js
More file actions
66 lines (61 loc) · 1.74 KB
/
Snackbar.js
File metadata and controls
66 lines (61 loc) · 1.74 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import {
withStyles,
List,
Paper,
ListItem,
IconButton,
Avatar,
ListItemText,
ListSubheader,
ListItemAvatar,
} from '@material-ui/core';
import { Check as CheckIcon, Error as ErrorIcon, Close as CloseIcon } from '@material-ui/icons';
import { SnackbarContent, useSnackbar } from 'notistack';
const styles = () => ({
header: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
},
});
const Snackbar = React.forwardRef(({ response, classes }, ref) => {
const { closeSnackbar } = useSnackbar();
const title = React.useMemo(() => {
if (response.some(({ error }) => error)) return 'Some jobs failed';
return 'All jobs started successfully';
}, [response]);
return (
<SnackbarContent ref={ref}>
<Paper>
<List
subheader={
<ListSubheader className={classes.header}>
{title}
<IconButton onClick={() => closeSnackbar()} size="small">
<CloseIcon fontSize="small" />
</IconButton>
</ListSubheader>
}
>
{response.map(({ tag, error }) => (
<ListItem key={tag}>
<ListItemAvatar>
<Avatar>
{error && <ErrorIcon color="error" fontSize="small" />}
{!error && <CheckIcon color="action" fontSize="small" />}
</Avatar>
</ListItemAvatar>
<ListItemText
secondaryTypographyProps={{ color: 'error' }}
primary={tag}
secondary={error}
/>
</ListItem>
))}
</List>
</Paper>
</SnackbarContent>
);
});
export default withStyles(styles)(Snackbar);