Showing
4 changed files
with
44 additions
and
0 deletions
src/api/getQuestion.js
0 → 100644
src/api/getResult.js
0 → 100644
| 1 | +import getResultApi from '../../api/getResult'; | ||
| 2 | + | ||
| 1 | // action | 3 | // action |
| 2 | const GET_RESULT = 'GET_RESULT'; | 4 | const GET_RESULT = 'GET_RESULT'; |
| 3 | const GET_RESULT_SUCCESS = 'GET_RESULT_SUCCESS'; | 5 | const GET_RESULT_SUCCESS = 'GET_RESULT_SUCCESS'; |
| ... | @@ -14,6 +16,18 @@ const initialState = { | ... | @@ -14,6 +16,18 @@ const initialState = { |
| 14 | error: null | 16 | error: null |
| 15 | } | 17 | } |
| 16 | 18 | ||
| 19 | +export function getResultThunk(answer){ | ||
| 20 | + return async (dispatch) => { | ||
| 21 | + dispatch(getResult()); | ||
| 22 | + try{ | ||
| 23 | + const { data } = await getResultApi(answer); | ||
| 24 | + dispatch(getResultSuccess(data)); | ||
| 25 | + }catch(err){ | ||
| 26 | + dispatch(getResultError()); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 17 | function result( | 31 | function result( |
| 18 | state = initialState, | 32 | state = initialState, |
| 19 | action | 33 | action | ... | ... |
| 1 | +import getQuestionApi from '../../api/getQuestion'; | ||
| 2 | + | ||
| 1 | // action | 3 | // action |
| 2 | const GET_SURVEY = 'GET_SURVEY'; | 4 | const GET_SURVEY = 'GET_SURVEY'; |
| 3 | const GET_SURVEY_SUCCESS = 'GET_SURVEY_SUCCESS'; | 5 | const GET_SURVEY_SUCCESS = 'GET_SURVEY_SUCCESS'; |
| ... | @@ -14,6 +16,18 @@ const initialState = { | ... | @@ -14,6 +16,18 @@ const initialState = { |
| 14 | error: null | 16 | error: null |
| 15 | } | 17 | } |
| 16 | 18 | ||
| 19 | +export function getQuestionThunk(){ | ||
| 20 | + return async (dispatch) => { | ||
| 21 | + dispatch(getSurvey()); | ||
| 22 | + try{ | ||
| 23 | + const { data } = await getQuestionApi(); | ||
| 24 | + dispatch(getSurveySuccess(data)); | ||
| 25 | + }catch(err){ | ||
| 26 | + dispatch(getSurveyError()); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 17 | function survey( | 31 | function survey( |
| 18 | state = initialState, | 32 | state = initialState, |
| 19 | action | 33 | action | ... | ... |
-
Please register or login to post a comment