-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotificationService.js
78 lines (70 loc) · 1.71 KB
/
NotificationService.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
/* eslint-disable prefer-destructuring */
import Vue from 'vue';
const vueInstance = new Vue();
function showError(error) {
vueInstance.$notify({
duration: 10000,
type: 'error',
title: 'Error',
text: error
});
}
const notificationService = {
success: (message) => {
vueInstance.$notify({
duration: 5000,
type: 'success',
title: 'Success',
text: message
});
},
warning: (message) => {
vueInstance.$notify({
duration: 5000,
type: 'warn',
title: 'Warning',
text: message
});
},
info: (message) => {
vueInstance.$notify({
duration: 5000,
title: 'Info',
text: message
});
},
chat: (title, message, data) => {
vueInstance.$notify({
title,
duration: 15000,
text: message,
data
});
},
error: (error) => {
if (typeof error === 'string') {
showError(error);
return;
}
if (error.body) {
error = error.body.error;
}
if (error.data) {
error = error.data;
}
if (typeof error.message === 'string') {
showError(error.message);
return;
}
Object.keys(error.message).forEach((key) => {
if (typeof error.message[key] === 'string') {
showError(error.message[key]);
} else {
error.message[key].forEach((message) => {
showError(message);
});
}
});
}
};
export default notificationService;