Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ayyagaries/624a799d87847068b6d59ec8ea5ebd91 to your computer and use it in GitHub Desktop.
Save Ayyagaries/624a799d87847068b6d59ec8ea5ebd91 to your computer and use it in GitHub Desktop.
Saga
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