-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathactions.js
68 lines (60 loc) · 1.61 KB
/
actions.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
// Repositories
import {getAccount as apiGetAccount} from 'repositories/account';
import {AUTH_URL} from 'config';
// Types
export const APP_ACCOUNT_LOADING = 'APP_ACCOUNT_LOADING';
export const APP_ACCOUNT_LOADED = 'APP_ACCOUNT_LOADED';
export const APP_MENU_DRAWER_TOGGLE = 'APP_MENU_DRAWER_TOGGLE';
export const APP_SNACKBAR_SHOW = 'CORE_SNACKBAR_SHOW';
export const APP_SNACKBAR_HIDE = 'CORE_SNACKBAR_HIDE';
/**
* Loads the user's account into the application
* @returns {function(*)}
*/
export function loadAccount() {
return dispatch => {
dispatch({type: APP_ACCOUNT_LOADING});
apiGetAccount().then(account => {
dispatch({
type: APP_ACCOUNT_LOADED,
payload: account
});
}).catch((error) => {
if (error.hasOwnProperty(status) && error.status === 401) {
const returnUrl = window.btoa(window.location.href);
window.location.href = `${AUTH_URL}?return=${returnUrl}`;
} else {
throw(error);
}
});
};
}
/**
* Toggles the menu drawer
* @param open
* @returns {{type: string, payload: *}}
*/
export function toggleDrawer(open) {
return {
type: APP_MENU_DRAWER_TOGGLE,
payload: open
};
}
/**
* Shows the snack bar
* @param message
* @returns {{type: string, payload: *}}
*/
export function showSnackbar(message) {
return {
type: APP_SNACKBAR_SHOW,
payload: message
};
}
/**
* Hides the snack bar
* @returns {{type: string}}
*/
export function hideSnackbar() {
return {type: APP_SNACKBAR_HIDE};
}