Skip to content

Commit

Permalink
create survey reducer and combine it in index reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
bipinstha7 committed Feb 23, 2019
1 parent 6c76f6f commit e78fe57
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/src/actions/Types.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const FETCH_USER = 'FETCH_USER'
export const FETCH_SURVEYS = 'FETCH_SURVEYS'
8 changes: 7 additions & 1 deletion client/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios'
import { FETCH_USER } from './Types'
import { FETCH_USER, FETCH_SURVEYS } from './Types'

export const fetchUser = () => async dispatch => {
const res = await axios.get('/api/current_user')
Expand All @@ -19,3 +19,9 @@ export const submitSurvey = (values, history) => async dispatch => {
history.push('/surveys')
dispatch({ type: FETCH_USER, payload: res.data })
}

export const fetchSurveys = () => async dispatch => {
const res = await axios.get('/api/surveys')

dispatch({ type: FETCH_SURVEYS, payload: res.data })
}
4 changes: 3 additions & 1 deletion client/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { combineReducers } from 'redux'
import { reducer as reduxForm } from 'redux-form'

import authReducer from './authReducer'
import surveyReducer from './surveysReducer'

export default combineReducers({
auth: authReducer,
form: reduxForm
form: reduxForm,
surveys: surveyReducer
})
10 changes: 10 additions & 0 deletions client/src/reducers/surveysReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { FETCH_SURVEYS } from '../actions/types'

export default function(state = [], action) {
switch (action.type) {
case FETCH_SURVEYS:
return action.payload
default:
return state
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"client": "npm run start --prefix client",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client",
"webhook": "./sendgrid_webhook.sh"
// "webhook": "lt -s luv2codenode --port 5000"
},
"author": "bipin",
"license": "ISC",
Expand Down

0 comments on commit e78fe57

Please sign in to comment.