Fixed changing selected server

This commit is contained in:
Alejandro Celaya
2018-08-04 08:23:44 +02:00
parent daf67e1d43
commit 5517fcdde5
3 changed files with 23 additions and 8 deletions

View File

@@ -1,15 +1,18 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import ServersService from '../../servers/services/ServersService';
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams'
const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
export default function reducer(state = null, action) {
const defaultState = null;
export default function reducer(state = defaultState, action) {
switch (action.type) {
case SELECT_SERVER:
return action.selectedServer;
case RESET_SELECTED_SERVER:
return null;
return defaultState;
default:
return state;
}
@@ -17,12 +20,14 @@ export default function reducer(state = null, action) {
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
export const selectServer = serverId => {
export const selectServer = serverId => dispatch => {
dispatch(resetShortUrlParams());
const selectedServer = ServersService.findServerById(serverId);
ShlinkApiClient.setConfig(selectedServer);
return {
dispatch({
type: SELECT_SERVER,
selectedServer
}
})
};