Created
April 2, 2018 20:38
-
-
Save Ayyagaries/624a799d87847068b6d59ec8ea5ebd91 to your computer and use it in GitHub Desktop.
Saga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { call, put, select, take, fork, all, takeLatest } from 'redux-saga/effects'; | |
import axios from 'axios'; | |
import querystring from 'query-string'; | |
import Config from 'react-native-config'; | |
import { | |
REQUEST_ATTACHED_FACILITIES, | |
responseAdminAttachedFacilities, | |
errorFetchFacilties, | |
} from '../../../actions/pickFacility'; | |
import endpoints from '../../endpoints/endpoints'; | |
const fetchData = url => axios.get(url); | |
function* requestAdminAttachedFacility(action) { | |
const token = yield select(state => state.login.token); | |
let URL = Config.BASE_URL + endpoints.ATTACHED_FACITIES; | |
URL += `${token}/format/json`; | |
try { | |
const response = yield call(fetchData, URL); | |
const result = yield response; | |
if (result.data.data !== undefined) { | |
yield put(responseAdminAttachedFacilities({ | |
attachedFacilities: result.data.data, | |
})); | |
} else { | |
yield put(errorFetchFacilties()); | |
} | |
// console.log(data); | |
} catch (error) { | |
console.log('i am here in catch'); | |
console.log(error); | |
yield put(errorFetchFacilties()); | |
} | |
} | |
export default function* pickFacilitySaga() { | |
yield takeLatest(REQUEST_ATTACHED_FACILITIES, requestAdminAttachedFacility); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment