From 0b1ab2183675960b25d3395d15d337a6b9de9cb1 Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Sat, 21 Jan 2023 02:14:36 +0800 Subject: [PATCH] Rename types. --- .../client/marketing/data-multichannel/actions.ts | 4 ++-- .../client/marketing/data-multichannel/resolvers.ts | 4 ++-- .../client/marketing/data-multichannel/types.ts | 12 ++++++------ .../marketing/hooks/useRecommendedChannels.ts | 5 +++-- .../client/marketing/hooks/useRegisteredChannels.ts | 13 +++---------- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts index 74785dbc5ce..b07417e420e 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts @@ -2,7 +2,7 @@ * Internal dependencies */ import { TYPES } from './action-types'; -import { ApiFetchError, Channel, RecommendedPlugin } from './types'; +import { ApiFetchError, Channel, RecommendedChannel } from './types'; export const receiveChannelsSuccess = ( channels: Array< Channel > ) => { return { @@ -20,7 +20,7 @@ export const receiveChannelsError = ( error: ApiFetchError ) => { }; export const receiveRecommendedChannelsSuccess = ( - channels: Array< RecommendedPlugin > + channels: Array< RecommendedChannel > ) => { return { type: TYPES.RECEIVE_RECOMMENDED_CHANNELS_SUCCESS, diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts index deb68f3b9cf..c0feb6b2985 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts @@ -12,7 +12,7 @@ import { receiveRecommendedChannelsSuccess, receiveRecommendedChannelsError, } from './actions'; -import { Channel, RecommendedPlugin } from './types'; +import { Channel, RecommendedChannel } from './types'; import { API_NAMESPACE } from './constants'; import { isApiFetchError } from './guards'; @@ -34,7 +34,7 @@ export function* getChannels() { export function* getRecommendedChannels() { try { - const data: RecommendedPlugin[] = yield apiFetch( { + const data: RecommendedChannel[] = yield apiFetch( { path: `${ API_NAMESPACE }/recommendations?category=channels`, } ); diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts index 9f412d0b445..054130b917d 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts @@ -17,7 +17,7 @@ export type Channel = { icon: string; }; -export type Channels = { +export type ChannelsState = { data?: Array< Channel >; error?: ApiFetchError; }; @@ -35,7 +35,7 @@ type Tag = { name: string; }; -export type RecommendedPlugin = { +export type RecommendedChannel = { title: string; description: string; url: string; @@ -48,12 +48,12 @@ export type RecommendedPlugin = { tags: Array< Tag >; }; -export type RecommendedChannels = { - data?: Array< RecommendedPlugin >; +export type RecommendedChannelsState = { + data?: Array< RecommendedChannel >; error?: ApiFetchError; }; export type State = { - channels: Channels; - recommendedChannels: RecommendedChannels; + channels: ChannelsState; + recommendedChannels: RecommendedChannelsState; }; diff --git a/plugins/woocommerce-admin/client/marketing/hooks/useRecommendedChannels.ts b/plugins/woocommerce-admin/client/marketing/hooks/useRecommendedChannels.ts index 7111f776d59..402b81e00f5 100644 --- a/plugins/woocommerce-admin/client/marketing/hooks/useRecommendedChannels.ts +++ b/plugins/woocommerce-admin/client/marketing/hooks/useRecommendedChannels.ts @@ -10,7 +10,7 @@ import { differenceWith } from 'lodash'; */ import { STORE_KEY } from '~/marketing/data-multichannel/constants'; import { RecommendedChannel } from '~/marketing/types'; -import { RecommendedChannels } from '~/marketing/data-multichannel/types'; +import { RecommendedChannelsState } from '~/marketing/data-multichannel/types'; type UseRecommendedChannels = { loading: boolean; @@ -21,7 +21,8 @@ export const useRecommendedChannels = (): UseRecommendedChannels => { return useSelect( ( select ) => { const { hasFinishedResolution, getRecommendedChannels } = select( STORE_KEY ); - const { data, error } = getRecommendedChannels< RecommendedChannels >(); + const { data, error } = + getRecommendedChannels< RecommendedChannelsState >(); const { getActivePlugins } = select( PLUGINS_STORE_NAME ); const activePlugins = getActivePlugins(); diff --git a/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts b/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts index bafa4c66351..fee4a4af1ec 100644 --- a/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts +++ b/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts @@ -3,14 +3,7 @@ */ import { useDispatch, useSelect } from '@wordpress/data'; import { __, sprintf } from '@wordpress/i18n'; -import { - createElement, - useCallback, - useState, - useEffect, - useMemo, - useRef, -} from '@wordpress/element'; +import { useCallback } from '@wordpress/element'; /** * Internal dependencies @@ -20,7 +13,7 @@ import { STORE_KEY } from '~/marketing/data-multichannel/constants'; import { ApiFetchError, Channel, - Channels, + ChannelsState, } from '~/marketing/data-multichannel/types'; type UseRegisteredChannels = { @@ -151,7 +144,7 @@ export const useRegisteredChannels = (): UseRegisteredChannels => { return useSelect( ( select ) => { const { hasFinishedResolution, getChannels } = select( STORE_KEY ); - const channels = getChannels< Channels >(); + const channels = getChannels< ChannelsState >(); return { loading: ! hasFinishedResolution( 'getChannels' ),