Created
April 2, 2018 16:50
-
-
Save Ayyagaries/544c033133340f1a0e8d6c5e2b1c26ae 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_ADMIN_ATTACHED_FACILITIES, | |
netWorkError, | |
responseAdminAttachedFacilities, | |
showLoading, | |
} 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/js`; | |
console.log(`------This is the action--------${token}`); | |
console.log(`-----URL for request facility is ${URL}`); | |
try { | |
const response = yield call(fetchData, URL); | |
yield put(showLoading(true)); | |
const result = yield response; | |
console.log(result); | |
console.log(' i am here after result'); | |
console.log(result.data.data); | |
if (result.data.data !== undefined) { | |
yield put(showLoading(false)); | |
yield put(netWorkError('')); | |
yield put(responseAdminAttachedFacilities(result.data.data)); | |
} else { | |
yield put(showLoading(false)); | |
yield put(netWorkError('Network Error')); | |
} | |
// console.log(data); | |
} catch (error) { | |
console.log(error); | |
yield put(showLoading(false)); | |
yield put(netWorkError('Network Error')); | |
} | |
} | |
export default function* pickFacilitySaga() { | |
yield takeLatest(REQUEST_ADMIN_ATTACHED_FACILITIES, requestAdminAttachedFacility); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment