-
Notifications
You must be signed in to change notification settings - Fork 773
Expand file tree
/
Copy pathorganization.action.js
More file actions
78 lines (67 loc) · 2.26 KB
/
Copy pathorganization.action.js
File metadata and controls
78 lines (67 loc) · 2.26 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { createAction } from 'redux-actions';
import { v3 } from 'api';
import { fetchOrg, fetchOrgMembers } from './organization.api';
import {
GET_ORG,
GET_ORG_LOADING,
GET_ORG_ERROR,
GET_ORG_REPOS,
GET_ORG_REPOS_LOADING,
GET_ORG_REPOS_ERROR,
GET_ORG_MEMBERS,
GET_ORG_MEMBERS_LOADING,
GET_ORG_MEMBERS_ERROR,
} from './organization.constants';
export const getOrg = createAction(GET_ORG);
export const getOrgLoading = createAction(GET_ORG_LOADING);
export const getOrgError = createAction(GET_ORG_ERROR);
export const getOrgRepos = createAction(GET_ORG_REPOS);
export const getOrgReposLoading = createAction(GET_ORG_REPOS_LOADING);
export const getOrgReposError = createAction(GET_ORG_REPOS_ERROR);
export const getOrgMembers = createAction(GET_ORG_MEMBERS);
export const getOrgMembersLoading = createAction(GET_ORG_MEMBERS_LOADING);
export const getOrgMembersError = createAction(GET_ORG_MEMBERS_ERROR);
export const fetchOrganizations = orgName => (dispatch, getState) => {
// use a selector here
const accessToken = getState().auth.accessToken;
dispatch(getOrgLoading(true));
dispatch(getOrgError(''));
return fetchOrg(orgName, accessToken)
.then(data => {
dispatch(getOrgLoading(false));
dispatch(getOrg(data));
})
.catch(error => {
dispatch(getOrgLoading(false));
dispatch(getOrgError(error));
});
};
export const fetchOrganizationRepos = url => (dispatch, getState) => {
const accessToken = getState().auth.accessToken;
dispatch(getOrgReposLoading(true));
dispatch(getOrgReposError(''));
v3
.getJson(url, accessToken)
.then(data => {
dispatch(getOrgReposLoading(false));
dispatch(getOrgRepos(data));
})
.catch(error => {
dispatch(getOrgReposLoading(false));
dispatch(getOrgReposError(error));
});
};
export const fetchOrganizationMembers = orgName => (dispatch, getState) => {
const accessToken = getState().auth.accessToken;
dispatch(getOrgMembersLoading(true));
dispatch(getOrgMembersError(''));
return fetchOrgMembers(orgName, accessToken)
.then(data => {
dispatch(getOrgMembersLoading(false));
dispatch(getOrgMembers(data));
})
.catch(error => {
dispatch(getOrgMembersLoading(false));
dispatch(getOrgMembersError(error));
});
};