Skip to content

Commit 6991ed4

Browse files
committed
upload
1 parent acd1d7f commit 6991ed4

3 files changed

Lines changed: 177 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const ACCOUNT_REQUEST = 'ACCOUNT_REQUEST';
2+
export const ACCOUNT_RECEIVE = 'ACCOUNT_RECEIVE';
3+
4+
export const SERVICES_REQUEST = 'SERVICES_REQUEST';
5+
export const SERVICES_RECEIVE = 'SERVICES_RECEIVE';
6+
7+
export const SERVICE_REQUEST = 'SERVICE_REQUEST';
8+
export const SERVICE_RECEIVE = 'SERVICE_RECEIVE';
9+
10+
export const SERVICE_ENABLE_REQUEST = 'SERVICE_ENABLE_REQUEST';
11+
export const SERVICE_ENABLE_RECEIVE = 'SERVICE_ENABLE_RECEIVE';
12+
13+
export const SERVICE_SETTINGS_REQUEST = 'SERVICE_SETTINGS_REQUEST';
14+
export const SERVICE_SETTINGS_RECEIVE = 'SERVICE_SETTINGS_RECEIVE';
15+
16+
export const SERVICE_LOGS_REQUEST = 'SERVICE_LOGS_REQUEST';
17+
export const SERVICE_LOGS_RECEIVE = 'SERVICE_LOGS_RECEIVE';
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import * as t from './actionTypes';
2+
import api from 'lib/api';
3+
import messages from 'lib/text';
4+
5+
const receiveAccount = account => ({
6+
type: t.ACCOUNT_RECEIVE,
7+
account
8+
});
9+
10+
const receiveServices = services => ({
11+
type: t.SERVICES_RECEIVE,
12+
services
13+
});
14+
15+
const receiveService = service => ({
16+
type: t.SERVICE_RECEIVE,
17+
service
18+
});
19+
20+
const requestEnableDisableService = () => ({
21+
type: t.SERVICE_ENABLE_REQUEST
22+
});
23+
24+
const receiveEnableDisableService = () => ({
25+
type: t.SERVICE_ENABLE_RECEIVE
26+
});
27+
28+
const requestServiceSettings = () => ({
29+
type: t.SERVICE_SETTINGS_REQUEST
30+
});
31+
32+
const receiveServiceSettings = serviceSettings => ({
33+
type: t.SERVICE_SETTINGS_RECEIVE,
34+
serviceSettings
35+
});
36+
37+
const receiveServiceLogs = serviceLogs => ({
38+
type: t.SERVICE_LOGS_RECEIVE,
39+
serviceLogs
40+
});
41+
42+
export const fetchAccount = () => (dispatch, getState) => {
43+
return api.webstore.account.retrieve().then(({ status, json }) => {
44+
dispatch(receiveAccount(json));
45+
});
46+
};
47+
48+
export const updateAccount = account => (dispatch, getState) => {
49+
return api.webstore.account.update(account).then(({ status, json }) => {
50+
dispatch(receiveAccount(json));
51+
});
52+
};
53+
54+
export const updateDeveloperAccount = account => (dispatch, getState) => {
55+
return api.webstore.account
56+
.updateDeveloper(account)
57+
.then(({ status, json }) => {
58+
dispatch(receiveAccount(json));
59+
});
60+
};
61+
62+
export const fetchServices = () => (dispatch, getState) => {
63+
return api.webstore.services.list().then(({ status, json }) => {
64+
dispatch(receiveServices(json));
65+
});
66+
};
67+
68+
export const fetchService = serviceId => (dispatch, getState) => {
69+
return api.webstore.services.retrieve(serviceId).then(({ status, json }) => {
70+
const service = json;
71+
dispatch(receiveService(service));
72+
if (service.enabled) {
73+
dispatch(fetchServiceSettings(serviceId));
74+
dispatch(fetchServiceLogs(serviceId));
75+
}
76+
});
77+
};
78+
79+
export const enableService = serviceId => (dispatch, getState) => {
80+
dispatch(requestEnableDisableService());
81+
return api.webstore.services.enable(serviceId).then(({ status, json }) => {
82+
dispatch(receiveEnableDisableService());
83+
dispatch(fetchService(serviceId));
84+
});
85+
};
86+
87+
export const disableService = serviceId => (dispatch, getState) => {
88+
dispatch(requestEnableDisableService());
89+
return api.webstore.services.disable(serviceId).then(({ status, json }) => {
90+
dispatch(receiveEnableDisableService());
91+
dispatch(fetchService(serviceId));
92+
});
93+
};
94+
95+
export const fetchServiceSettings = serviceId => (dispatch, getState) => {
96+
dispatch(requestServiceSettings());
97+
return api.webstore.services.settings
98+
.retrieve(serviceId)
99+
.then(({ status, json }) => {
100+
const serviceSettings = json;
101+
dispatch(receiveServiceSettings(serviceSettings));
102+
})
103+
.catch(error => {});
104+
};
105+
106+
export const updateServiceSettings = (serviceId, settings) => (
107+
dispatch,
108+
getState
109+
) => {
110+
return api.webstore.services.settings
111+
.update(serviceId, settings)
112+
.then(({ status, json }) => {
113+
dispatch(fetchServiceSettings(serviceId));
114+
})
115+
.catch(error => {});
116+
};
117+
118+
export const fetchServiceLogs = serviceId => (dispatch, getState) => {
119+
return api.webstore.services.logs
120+
.list(serviceId)
121+
.then(({ status, json }) => {
122+
dispatch(receiveServiceLogs(json));
123+
})
124+
.catch(error => {});
125+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as t from './actionTypes';
2+
3+
const initialState = {
4+
account: null,
5+
services: [],
6+
service: null,
7+
serviceSettings: null,
8+
serviceLogs: null,
9+
loadingEnableDisableService: false
10+
};
11+
12+
export default (state = initialState, action) => {
13+
switch (action.type) {
14+
case t.ACCOUNT_RECEIVE:
15+
return Object.assign({}, state, { account: action.account });
16+
case t.SERVICES_RECEIVE:
17+
return Object.assign({}, state, { services: action.services });
18+
case t.SERVICE_RECEIVE:
19+
return Object.assign({}, state, { service: action.service });
20+
case t.SERVICE_SETTINGS_REQUEST:
21+
return Object.assign({}, state, { serviceSettings: null });
22+
case t.SERVICE_SETTINGS_RECEIVE:
23+
return Object.assign({}, state, {
24+
serviceSettings: action.serviceSettings
25+
});
26+
case t.SERVICE_LOGS_RECEIVE:
27+
return Object.assign({}, state, { serviceLogs: action.serviceLogs });
28+
case t.SERVICE_ENABLE_REQUEST:
29+
return Object.assign({}, state, { loadingEnableDisableService: true });
30+
case t.SERVICE_ENABLE_RECEIVE:
31+
return Object.assign({}, state, { loadingEnableDisableService: false });
32+
default:
33+
return state;
34+
}
35+
};

0 commit comments

Comments
 (0)