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