-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (62 loc) · 1.76 KB
/
index.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
import { Notify } from "quasar";
export default (config = {}) => {
const positiveConfig = {
progress: true,
type: "positive",
icon: "fa fa-check-circle",
actions: [{ icon: "fa fa-xmark", color: "white" }],
};
if (config.hasOwnProperty("positive")) {
Object.assign(positiveConfig, config.positive);
}
const warningConfig = {
progress: true,
type: "warning",
icon: "fa fa-circle-info",
actions: [{ icon: "fa fa-xmark", color: "black" }],
};
if (config.hasOwnProperty("warning")) {
Object.assign(warningConfig, config.warning);
}
const negativeConfig = {
progress: true,
type: "negative",
icon: "fa fa-circle-exclamation",
actions: [{ icon: "fa fa-xmark", color: "white" }],
};
if (config.hasOwnProperty("negative")) {
Object.assign(negativeConfig, config.negative);
}
const errorConfig = {
progress: true,
type: "negative",
icon: "fa fa-circle-exclamation",
actions: [{ icon: "fa fa-xmark", color: "white" }],
messageInProduction: "Server error!",
};
if (config.hasOwnProperty("error")) {
Object.assign(errorConfig, config.error);
}
return {
positive(message) {
Notify.create({ ...positiveConfig, ...{ message } });
},
warning(message) {
Notify.create({ ...warningConfig, ...{ message } });
},
negative(message) {
Notify.create({ ...negativeConfig, ...{ message } });
},
error(err) {
let message = errorConfig.messageInProduction;
if (process.env.DEV) {
if (err.hasOwnProperty("response")) {
message = err.response.data.message ?? err.response.statusText;
} else {
message = err.message;
}
}
Notify.create({ ...errorConfig, ...{ message } });
},
};
};