woocommerce/plugins/woocommerce-admin/client/marketing/hooks/useRecommendedChannels.ts

34 lines
902 B
TypeScript
Raw Normal View History

2023-01-19 11:33:51 +00:00
/**
* External dependencies
*/
import { useSelect } from '@wordpress/data';
2022-12-08 15:53:36 +00:00
/**
* Internal dependencies
*/
2023-01-19 11:33:51 +00:00
import { STORE_KEY } from '~/marketing/data-multichannel/constants';
2022-12-14 12:54:29 +00:00
import { RecommendedChannel } from '~/marketing/types';
2023-01-19 11:33:51 +00:00
import { RecommendedChannels } from '~/marketing/data-multichannel/types';
2022-12-08 15:53:36 +00:00
type UseRecommendedChannels = {
loading: boolean;
data: Array< RecommendedChannel >;
};
2023-01-19 11:33:51 +00:00
export const useRecommendedChannels = (): UseRecommendedChannels => {
return useSelect( ( select ) => {
const { hasFinishedResolution, getRecommendedChannels } =
select( STORE_KEY );
const channels = getRecommendedChannels< RecommendedChannels >();
2023-01-19 11:33:51 +00:00
// TODO: filter recommended channels against installed plugins,
// using @woocommerce/data/plugins.
2023-01-19 11:33:51 +00:00
return {
loading: ! hasFinishedResolution( 'getChannels' ),
data: channels.data || [],
error: channels.error,
};
} );
2022-12-08 15:53:36 +00:00
};