import { call, put } from 'redux-saga/effects';
import { get } from 'services/requests';
import { Api } from 'routes/Api';
import { handleError } from 'modules/error-handler';
import * as actions from 'lib/redux/actions/ashantis-abroad-actions';



export function* fetchAshantisAbroad() {
	try {
		const res = yield call(() => get({
			url: Api.ashantis_abroad
		}));

		// dispatch a success action to the store with the fetched classifieds
		yield put(actions.fetchedAshantisAbroad({ data: res.data }));
	}
	catch (error) {
		// dispatch a failure action to the store with the error
		yield put(actions.failedFetchAshantisAbroad({ error: error.message }));

		handleError(error);
	}
}



export function* fetchAshantiAbroad(action) {
	try {
		const res = yield call(() => get({
			url: Api.ashantis_abroad + '/' + action.slug
		}));

		// dispatch a success action to the store with the fetched classifieds
		yield put(actions.fetchedAshantiAbroad({ data: res.data }));
	}
	catch (error) {
		// dispatch a failure action to the store with the error
		yield put(actions.failedFetchAshantiAbroad({ error: error.message }));

		handleError(error);
	}
}
