-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acd1d7f
commit 6991ed4
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const ACCOUNT_REQUEST = 'ACCOUNT_REQUEST'; | ||
export const ACCOUNT_RECEIVE = 'ACCOUNT_RECEIVE'; | ||
|
||
export const SERVICES_REQUEST = 'SERVICES_REQUEST'; | ||
export const SERVICES_RECEIVE = 'SERVICES_RECEIVE'; | ||
|
||
export const SERVICE_REQUEST = 'SERVICE_REQUEST'; | ||
export const SERVICE_RECEIVE = 'SERVICE_RECEIVE'; | ||
|
||
export const SERVICE_ENABLE_REQUEST = 'SERVICE_ENABLE_REQUEST'; | ||
export const SERVICE_ENABLE_RECEIVE = 'SERVICE_ENABLE_RECEIVE'; | ||
|
||
export const SERVICE_SETTINGS_REQUEST = 'SERVICE_SETTINGS_REQUEST'; | ||
export const SERVICE_SETTINGS_RECEIVE = 'SERVICE_SETTINGS_RECEIVE'; | ||
|
||
export const SERVICE_LOGS_REQUEST = 'SERVICE_LOGS_REQUEST'; | ||
export const SERVICE_LOGS_RECEIVE = 'SERVICE_LOGS_RECEIVE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import * as t from './actionTypes'; | ||
import api from 'lib/api'; | ||
import messages from 'lib/text'; | ||
|
||
const receiveAccount = account => ({ | ||
type: t.ACCOUNT_RECEIVE, | ||
account | ||
}); | ||
|
||
const receiveServices = services => ({ | ||
type: t.SERVICES_RECEIVE, | ||
services | ||
}); | ||
|
||
const receiveService = service => ({ | ||
type: t.SERVICE_RECEIVE, | ||
service | ||
}); | ||
|
||
const requestEnableDisableService = () => ({ | ||
type: t.SERVICE_ENABLE_REQUEST | ||
}); | ||
|
||
const receiveEnableDisableService = () => ({ | ||
type: t.SERVICE_ENABLE_RECEIVE | ||
}); | ||
|
||
const requestServiceSettings = () => ({ | ||
type: t.SERVICE_SETTINGS_REQUEST | ||
}); | ||
|
||
const receiveServiceSettings = serviceSettings => ({ | ||
type: t.SERVICE_SETTINGS_RECEIVE, | ||
serviceSettings | ||
}); | ||
|
||
const receiveServiceLogs = serviceLogs => ({ | ||
type: t.SERVICE_LOGS_RECEIVE, | ||
serviceLogs | ||
}); | ||
|
||
export const fetchAccount = () => (dispatch, getState) => { | ||
return api.webstore.account.retrieve().then(({ status, json }) => { | ||
dispatch(receiveAccount(json)); | ||
}); | ||
}; | ||
|
||
export const updateAccount = account => (dispatch, getState) => { | ||
return api.webstore.account.update(account).then(({ status, json }) => { | ||
dispatch(receiveAccount(json)); | ||
}); | ||
}; | ||
|
||
export const updateDeveloperAccount = account => (dispatch, getState) => { | ||
return api.webstore.account | ||
.updateDeveloper(account) | ||
.then(({ status, json }) => { | ||
dispatch(receiveAccount(json)); | ||
}); | ||
}; | ||
|
||
export const fetchServices = () => (dispatch, getState) => { | ||
return api.webstore.services.list().then(({ status, json }) => { | ||
dispatch(receiveServices(json)); | ||
}); | ||
}; | ||
|
||
export const fetchService = serviceId => (dispatch, getState) => { | ||
return api.webstore.services.retrieve(serviceId).then(({ status, json }) => { | ||
const service = json; | ||
dispatch(receiveService(service)); | ||
if (service.enabled) { | ||
dispatch(fetchServiceSettings(serviceId)); | ||
dispatch(fetchServiceLogs(serviceId)); | ||
} | ||
}); | ||
}; | ||
|
||
export const enableService = serviceId => (dispatch, getState) => { | ||
dispatch(requestEnableDisableService()); | ||
return api.webstore.services.enable(serviceId).then(({ status, json }) => { | ||
dispatch(receiveEnableDisableService()); | ||
dispatch(fetchService(serviceId)); | ||
}); | ||
}; | ||
|
||
export const disableService = serviceId => (dispatch, getState) => { | ||
dispatch(requestEnableDisableService()); | ||
return api.webstore.services.disable(serviceId).then(({ status, json }) => { | ||
dispatch(receiveEnableDisableService()); | ||
dispatch(fetchService(serviceId)); | ||
}); | ||
}; | ||
|
||
export const fetchServiceSettings = serviceId => (dispatch, getState) => { | ||
dispatch(requestServiceSettings()); | ||
return api.webstore.services.settings | ||
.retrieve(serviceId) | ||
.then(({ status, json }) => { | ||
const serviceSettings = json; | ||
dispatch(receiveServiceSettings(serviceSettings)); | ||
}) | ||
.catch(error => {}); | ||
}; | ||
|
||
export const updateServiceSettings = (serviceId, settings) => ( | ||
dispatch, | ||
getState | ||
) => { | ||
return api.webstore.services.settings | ||
.update(serviceId, settings) | ||
.then(({ status, json }) => { | ||
dispatch(fetchServiceSettings(serviceId)); | ||
}) | ||
.catch(error => {}); | ||
}; | ||
|
||
export const fetchServiceLogs = serviceId => (dispatch, getState) => { | ||
return api.webstore.services.logs | ||
.list(serviceId) | ||
.then(({ status, json }) => { | ||
dispatch(receiveServiceLogs(json)); | ||
}) | ||
.catch(error => {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as t from './actionTypes'; | ||
|
||
const initialState = { | ||
account: null, | ||
services: [], | ||
service: null, | ||
serviceSettings: null, | ||
serviceLogs: null, | ||
loadingEnableDisableService: false | ||
}; | ||
|
||
export default (state = initialState, action) => { | ||
switch (action.type) { | ||
case t.ACCOUNT_RECEIVE: | ||
return Object.assign({}, state, { account: action.account }); | ||
case t.SERVICES_RECEIVE: | ||
return Object.assign({}, state, { services: action.services }); | ||
case t.SERVICE_RECEIVE: | ||
return Object.assign({}, state, { service: action.service }); | ||
case t.SERVICE_SETTINGS_REQUEST: | ||
return Object.assign({}, state, { serviceSettings: null }); | ||
case t.SERVICE_SETTINGS_RECEIVE: | ||
return Object.assign({}, state, { | ||
serviceSettings: action.serviceSettings | ||
}); | ||
case t.SERVICE_LOGS_RECEIVE: | ||
return Object.assign({}, state, { serviceLogs: action.serviceLogs }); | ||
case t.SERVICE_ENABLE_REQUEST: | ||
return Object.assign({}, state, { loadingEnableDisableService: true }); | ||
case t.SERVICE_ENABLE_RECEIVE: | ||
return Object.assign({}, state, { loadingEnableDisableService: false }); | ||
default: | ||
return state; | ||
} | ||
}; |