Installed redux-actions dependency and used it for selectedServer reducer

This commit is contained in:
Alejandro Celaya
2019-03-17 08:49:24 +01:00
parent 2ba86767fe
commit 724c804971
3 changed files with 62 additions and 14 deletions

View File

@@ -1,24 +1,14 @@
import { createAction, handleActions } from 'redux-actions';
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
/* eslint-disable padding-line-between-statements, newline-after-var */
/* eslint-disable padding-line-between-statements */
export const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
export const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
/* eslint-enable padding-line-between-statements, newline-after-var */
/* eslint-enable padding-line-between-statements */
const defaultState = null;
export default function reducer(state = defaultState, action) {
switch (action.type) {
case SELECT_SERVER:
return action.selectedServer;
case RESET_SELECTED_SERVER:
return defaultState;
default:
return state;
}
}
export const resetSelectedServer = () => ({ type: RESET_SELECTED_SERVER });
export const resetSelectedServer = createAction(RESET_SELECTED_SERVER);
export const selectServer = (serversService) => (serverId) => (dispatch) => {
dispatch(resetShortUrlParams());
@@ -30,3 +20,10 @@ export const selectServer = (serversService) => (serverId) => (dispatch) => {
selectedServer,
});
};
const reducer = handleActions({
[RESET_SELECTED_SERVER]: () => defaultState,
[SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
}, defaultState);
export default reducer;