woocommerce/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts

50 lines
1.1 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { apiFetch } from '@wordpress/data-controls';
/**
* Internal dependencies
*/
2023-01-19 11:33:51 +00:00
import {
receiveRegisteredChannelsSuccess,
receiveRegisteredChannelsError,
2023-01-19 11:33:51 +00:00
receiveRecommendedChannelsSuccess,
receiveRecommendedChannelsError,
} from './actions';
import { RegisteredChannel, RecommendedChannel } from './types';
import { API_NAMESPACE } from './constants';
import { isApiFetchError } from './guards';
export function* getRegisteredChannels() {
try {
const data: RegisteredChannel[] = yield apiFetch( {
path: `${ API_NAMESPACE }/channels`,
} );
yield receiveRegisteredChannelsSuccess( data );
} catch ( error ) {
if ( isApiFetchError( error ) ) {
yield receiveRegisteredChannelsError( error );
}
throw error;
}
}
2023-01-19 11:33:51 +00:00
export function* getRecommendedChannels() {
try {
2023-01-20 18:14:36 +00:00
const data: RecommendedChannel[] = yield apiFetch( {
2023-01-19 11:33:51 +00:00
path: `${ API_NAMESPACE }/recommendations?category=channels`,
} );
yield receiveRecommendedChannelsSuccess( data );
} catch ( error ) {
if ( isApiFetchError( error ) ) {
yield receiveRecommendedChannelsError( error );
}
throw error;
}
}