|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
import api from '../api'; |
|
|
|
|
import { importFetchedPoll } from './importer'; |
|
|
|
|
|
|
|
|
|
export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; |
|
|
|
|
export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS'; |
|
|
|
@ -12,7 +13,10 @@ export const vote = (pollId, choices) => (dispatch, getState) => { |
|
|
|
|
dispatch(voteRequest()); |
|
|
|
|
|
|
|
|
|
api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices }) |
|
|
|
|
.then(({ data }) => dispatch(voteSuccess(data))) |
|
|
|
|
.then(({ data }) => { |
|
|
|
|
dispatch(importFetchedPoll(data)); |
|
|
|
|
dispatch(voteSuccess(data)); |
|
|
|
|
}) |
|
|
|
|
.catch(err => dispatch(voteFail(err))); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -20,7 +24,10 @@ export const fetchPoll = pollId => (dispatch, getState) => { |
|
|
|
|
dispatch(fetchPollRequest()); |
|
|
|
|
|
|
|
|
|
api(getState).get(`/api/v1/polls/${pollId}`) |
|
|
|
|
.then(({ data }) => dispatch(fetchPollSuccess(data))) |
|
|
|
|
.then(({ data }) => { |
|
|
|
|
dispatch(importFetchedPoll(data)); |
|
|
|
|
dispatch(fetchPollSuccess(data)); |
|
|
|
|
}) |
|
|
|
|
.catch(err => dispatch(fetchPollFail(err))); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|