From 68107bb33a1510f9d2af75334910f518513e376c Mon Sep 17 00:00:00 2001 From: Jitu007-Bunde Date: Tue, 26 May 2020 19:04:04 +0530 Subject: [PATCH] create recognitionSaga file for run sagaMiddleware for Api call --- react-frontend/src/sagas/recognitionSaga.js | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 react-frontend/src/sagas/recognitionSaga.js diff --git a/react-frontend/src/sagas/recognitionSaga.js b/react-frontend/src/sagas/recognitionSaga.js new file mode 100644 index 000000000..4249c5a4c --- /dev/null +++ b/react-frontend/src/sagas/recognitionSaga.js @@ -0,0 +1,35 @@ +import { put, takeEvery, spawn, call } from "redux-saga/effects"; +import GetJson from "utils/getJson"; + +export function* getRecognitionList(action) { + try { + const response = yield call(GetJson, { + path: "recognitions", + apiToken: + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJub2RlLnBlZXJseS5jb20iLCJzdWIiOjE4LCJhdWQiOiJwZWVybHkuY29tIiwibmJmIjoxNTkwNDY1MDM0LCJodHRwczovL3BlZXJseS5jb20iOnsicm9sZUlkIjozLCJvcmdJZCI6Mywib3JnTmFtZSI6Impvc2gifSwiaWF0IjoxNTkwNDY1MDM0LCJleHAiOjE1OTA1MDEwMzR9.on9odD7zsg4sjoEX_iEhY5A9u5oaqJANIN5B4_pJAHM", + paramsObj: action.payload, + }); + const responseObj = yield response.json(); + if (responseObj.data) { + yield put({ + type: "GET_RECOGNITION_LIST_SUCCESS", + payload: responseObj.data, + }); + } else { + yield put({ + type: "GET_RECOGNITION_LIST_FAILURE", + payload: responseObj.error, + }); + } + } catch (error) { + yield put({ type: "GET_RECOGNITION_LIST_FAILURE", payload: error }); + } +} + +export function* recognitionApi() { + yield takeEvery("RECOGNITION_GET_API", getRecognitionList); +} + +export default function* rootSaga() { + yield spawn(recognitionApi); +}