import { Action } from 'lib/types/interfaces';
import { get } from 'services/requests';
import { put, call } from 'redux-saga/effects';
import * as actions from 'lib/redux/actions/cms-actions';
import { Api } from 'routes/Api';



export function* fetchCMS(action: Action) {
	try {
		const uniqueName = action.options?.uniqueName ?? '';
		const res = yield call(() => get({
			url: Api.cms + action.endpoint + '/' + uniqueName
		}));

		yield put(actions.fetchedCMS({ data: res.data, id: action.options?.id }));
	}
	catch (error) {
		yield put(actions.failedFetchCMS({ error }));
	}
}