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/directory-listings-actions';



export function* fetchDirectoryListing(action) {
	try {
		const res = yield call(() => get({
			url: Api.directory_listings+'/'+action.slug
		}));

		// dispatch a success action to the store with the fetched classifieds
		yield put(actions.fetchedDirectoryListing({ data: res.data }));
	}
	catch (error) {
		// dispatch a failure action to the store with the error
		yield put(actions.failedFetchDirectoryListing({ error: error.message }));

		handleError(error);
	}
}
