-
Notifications
You must be signed in to change notification settings - Fork 559
/
NotificationsContainer.js
112 lines (104 loc) · 3.08 KB
/
NotificationsContainer.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React from "react";
import { withStyles } from "@material-ui/core";
import { compose, withState, withHandlers } from "recompose";
import { toast } from "react-toastify";
import Notification from "../../components/Notification";
import NotificationsView from "./NotificationsView";
const positions = [
toast.POSITION.TOP_LEFT,
toast.POSITION.TOP_CENTER,
toast.POSITION.TOP_RIGHT,
toast.POSITION.BOTTOM_LEFT,
toast.POSITION.BOTTOM_CENTER,
toast.POSITION.BOTTOM_RIGHT
];
export default compose(
withStyles(theme => ({
/*progress: {
visibility: "hidden"
},
notification: {
display: "flex",
alignItems: "center",
background: "transparent",
boxShadow: "none",
overflow: "visible"
},
notificationComponent: {
paddingRight: theme.spacing.unit * 4
}*/
})),
withState("notificationsPosition", "setNotificationPosition", 2),
withState("errorToastId", "setErrorToastId", null),
withHandlers({
sendNotification: props => (componentProps, options) => {
return toast(
<Notification
{...componentProps}
className={props.classes.notificationComponent}
/>,
options
);
}
}),
withHandlers({
retryErrorNotification: props => () => {
const componentProps = {
type: "message",
message: "Message was sent successfully!",
variant: "contained",
color: "success",
};
toast.update(props.errorToastId, {
render: <Notification {...componentProps} />,
type: "success"
});
props.setErrorToastId(null);
}
}),
withHandlers({
handleNotificationCall: props => notificationType => {
let componentProps;
if (props.errorToastId && notificationType === "error") return;
switch (notificationType) {
case "info":
componentProps = {
type: "feedback",
message: "New user feedback received",
variant: "contained",
color: "primary"
};
break;
case "error":
componentProps = {
type: "message",
message: "Message was not sent!",
variant: "contained",
color: "secondary",
extraButton: "Resend",
extraButtonClick: props.retryErrorNotification
};
break;
default:
componentProps = {
type: "shipped",
message: "The item was shipped",
variant: "contained",
color: "success"
};
}
const toastId = props.sendNotification(componentProps, {
type: notificationType,
position: positions[props.notificationsPosition],
progressClassName: props.classes.progress,
onClose:
notificationType === "error" && (() => props.setErrorToastId(null)),
className: props.classes.notification
});
if (notificationType === "error") props.setErrorToastId(toastId);
},
changeNotificationPosition: props => positionId => {
props.setNotificationPosition(positionId);
}
})
)(NotificationsView);