From d8667d9574c4592e673d0bda61dc9ec313933e6b Mon Sep 17 00:00:00 2001 From: mandihamza Date: Wed, 22 Jul 2020 16:09:47 -0600 Subject: [PATCH] Adds resource hub reducers --- src/state/reducers/index.js | 2 ++ src/state/reducers/resourceHub.js | 60 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/state/reducers/resourceHub.js diff --git a/src/state/reducers/index.js b/src/state/reducers/index.js index 0750082a..38a38a2a 100644 --- a/src/state/reducers/index.js +++ b/src/state/reducers/index.js @@ -8,6 +8,7 @@ import feedbackReducer from './feedback'; import marketplaceReducer from './marketplace'; import interviewReducer from './interview'; import chatReducer from './chat'; +import resourceHubReducer from './resourceHub'; const appReducer = combineReducers({ userReducer, @@ -19,6 +20,7 @@ const appReducer = combineReducers({ marketplaceReducer, interviewReducer, chatReducer, + resourceHubReducer, }); const rootReducer = (state, action) => { diff --git a/src/state/reducers/resourceHub.js b/src/state/reducers/resourceHub.js new file mode 100644 index 00000000..bac6e6f7 --- /dev/null +++ b/src/state/reducers/resourceHub.js @@ -0,0 +1,60 @@ +import * as types from '../actions/resourceHubActions'; + +const initialState = { + resources: null, + isLoading: false, + error: null, + submitResource: null, + updateResource: null, +}; + +function resourceHubReducer(state = initialState, action) { + switch (action.type) { + case types.GET_RESOURCE_START: + return { + ...state, + isLoading: true, + }; + + case types.GET_RESOURCE_SUCCESS: + return { + ...state, + isLoading: false, + resources: action.payload, + }; + + case types.GET_RESOURCE_ERROR: + return { ...state, error: action.payload, isLoading: false }; + + case types.SUBMIT_RESOURCE_START: + return { ...state, submitResource: action.payload }; + + case types.SUBMIT_RESOURCE_ERROR: + return { ...state, error: action.payload, isLoading: false }; + + case types.SUBMIT_RESOURCE_SUCCESS: + return { + ...state, + isLoading: false, + resource: action.payload, + }; + + case types.UPDATE_RESOURCE_START: + return { ...state, updateResource: action.payload }; + + case types.UPDATE_RESOURCE_ERROR: + return { ...state, error: action.payload, isLoading: false }; + + case types.UPDATE_RESOURCE_SUCCESS: + return { + ...state, + isLoading: false, + resource: action.payload, + }; + + default: + return state; + } +} + +export default resourceHubReducer;