Make UI work with wp.data new campaign types.

This commit is contained in:
Gan Eng Chin 2023-02-28 00:51:34 +08:00
parent 9526608fbc
commit d111370d1e
No known key found for this signature in database
GPG Key ID: 94D5D972860ADB01
2 changed files with 35 additions and 27 deletions

View File

@ -58,7 +58,7 @@ export const CreateNewCampaignModal = ( props: CreateCampaignModalProps ) => {
) } ) }
</div> </div>
<div> <div>
{ newCampaignTypes.map( ( el ) => { { newCampaignTypes?.map( ( el ) => {
return ( return (
<Flex <Flex
key={ el.id } key={ el.id }

View File

@ -1,38 +1,46 @@
/**
* External dependencies
*/
import { useSelect } from '@wordpress/data';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import { STORE_KEY } from '~/marketing/data-multichannel/constants';
import {
CampaignTypesState,
CampaignType as APICampaignType,
ApiFetchError,
} from '~/marketing/data-multichannel/types';
import { CampaignType } from '~/marketing/types/CampaignType'; import { CampaignType } from '~/marketing/types/CampaignType';
type UseNewCampaignTypes = { type UseNewCampaignTypes = {
loading: boolean; loading: boolean;
data: Array< CampaignType >; data?: Array< CampaignType >;
error?: ApiFetchError;
}; };
export const useNewCampaignTypes = (): UseNewCampaignTypes => { export const useNewCampaignTypes = (): UseNewCampaignTypes => {
return { const convert = ( campaignType: APICampaignType ): CampaignType => {
loading: false, return {
data: [ id: campaignType.id,
{ icon: campaignType.icon_url,
id: 'google-ads', name: campaignType.name,
icon: 'https://woocommerce.com/wp-content/plugins/wccom-plugins/marketing-tab-rest-api/icons/google.svg', description: campaignType.description,
name: 'Google', createUrl: campaignType.create_url,
description: channelName: campaignType.channel.name,
'Boost your product listings with a campaign that is automatically optimized to meet your goals', channelSlug: campaignType.channel.slug,
createUrl: };
'https://wc1.test/wp-admin/admin.php?page=wc-admin&path=%2Fgoogle%2Fsetup-ads',
channelSlug: 'google-listings-and-ads',
channelName: 'Google Listings and Ads',
},
{
id: 'pinterest-ads',
icon: 'https://woocommerce.com/wp-content/plugins/wccom-plugins/marketing-tab-rest-api/icons/pinterest.svg',
name: 'Pinterest',
description:
'Create single or multi image ads that promote a product relevant to peoples interests (Opens in Pinterest Ads Manager)',
createUrl: 'https://pinterest.com/create-campaign',
channelSlug: 'pinterest-for-woocommerce',
channelName: 'Pinterest for WooCommerce',
},
],
}; };
return useSelect( ( select ) => {
const { hasFinishedResolution, getCampaignTypes } = select( STORE_KEY );
const campaignTypesState = getCampaignTypes< CampaignTypesState >();
return {
loading: ! hasFinishedResolution( 'getCampaignTypes' ),
data: campaignTypesState.data?.map( convert ),
error: campaignTypesState.error,
};
} );
}; };