forked from topcoder-platform/community-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
64 lines (56 loc) · 1.53 KB
/
errors.js
File metadata and controls
64 lines (56 loc) · 1.53 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
/* eslint-env browser */
import actions from 'actions/errors';
import { isomorphy } from 'topcoder-react-utils';
export const ERROR_ICON_TYPES = {
NETWORK: 'network',
API: 'api',
};
let store; // Will be set only when rendering client-side
export function setErrorsStore(s) {
store = s;
}
/**
* The function behaves similarly to javascript alert()
* it will show a modal error diaglog with styling until the user clicks OK.
*/
export function fireErrorMessage(title, details) {
if (isomorphy.isClientSide() && store) {
setImmediate(() => {
store.dispatch(actions.errors.newError(title, details));
});
}
}
/**
* clear all error icons
*/
export function clearAllErrorIcons() {
if (isomorphy.isClientSide() && store) {
setImmediate(() => {
store.dispatch(actions.errors.clearAllErrorIcons());
});
}
}
/**
* add error message to error icon in bottom left in the screen.
* @param id id of error icon type (ERROR_ICON_TYPES.NETWORK or ERROR_ICON_TYPES.API)
* @param title icon hover title
* @param message icon hover message
*/
export function setErrorIcon(id, title, message) {
if (isomorphy.isClientSide() && store) {
setImmediate(() => {
store.dispatch(actions.errors.setErrorIcon(id, title, message));
});
}
}
/**
* clear all error message for an error icon.
* @param id id of error icon type to clear
*/
export function clearErrorIcon(id) {
if (isomorphy.isClientSide() && store) {
setImmediate(() => {
store.dispatch(actions.errors.clearErrorIcon(id));
});
}
}