diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/action-types.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/action-types.ts index c53be7bbd49..ab0e40f15ae 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/action-types.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/action-types.ts @@ -1,6 +1,8 @@ export const TYPES = { - RECEIVE_CHANNELS_SUCCESS: 'RECEIVE_CHANNELS_SUCCESS' as const, - RECEIVE_CHANNELS_ERROR: 'RECEIVE_CHANNELS_ERROR' as const, + RECEIVE_REGISTERED_CHANNELS_SUCCESS: + 'RECEIVE_REGISTERED_CHANNELS_SUCCESS' as const, + RECEIVE_REGISTERED_CHANNELS_ERROR: + 'RECEIVE_REGISTERED_CHANNELS_ERROR' as const, RECEIVE_RECOMMENDED_CHANNELS_SUCCESS: 'RECEIVE_RECOMMENDED_CHANNELS_SUCCESS' as const, RECEIVE_RECOMMENDED_CHANNELS_ERROR: diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts index b07417e420e..685aa867c02 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/actions.ts @@ -2,18 +2,20 @@ * Internal dependencies */ import { TYPES } from './action-types'; -import { ApiFetchError, Channel, RecommendedChannel } from './types'; +import { ApiFetchError, RegisteredChannel, RecommendedChannel } from './types'; -export const receiveChannelsSuccess = ( channels: Array< Channel > ) => { +export const receiveRegisteredChannelsSuccess = ( + channels: Array< RegisteredChannel > +) => { return { - type: TYPES.RECEIVE_CHANNELS_SUCCESS, + type: TYPES.RECEIVE_REGISTERED_CHANNELS_SUCCESS, payload: channels, }; }; -export const receiveChannelsError = ( error: ApiFetchError ) => { +export const receiveRegisteredChannelsError = ( error: ApiFetchError ) => { return { - type: TYPES.RECEIVE_CHANNELS_ERROR, + type: TYPES.RECEIVE_REGISTERED_CHANNELS_ERROR, payload: error, error: true, }; @@ -37,8 +39,8 @@ export const receiveRecommendedChannelsError = ( error: ApiFetchError ) => { }; export type Action = ReturnType< - | typeof receiveChannelsSuccess - | typeof receiveChannelsError + | typeof receiveRegisteredChannelsSuccess + | typeof receiveRegisteredChannelsError | typeof receiveRecommendedChannelsSuccess | typeof receiveRecommendedChannelsError >; diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/reducer.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/reducer.ts index d9e95181bf6..82749ee49f6 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/reducer.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/reducer.ts @@ -12,7 +12,7 @@ import { Action } from './actions'; import { TYPES } from './action-types'; const initialState = { - channels: { + registeredChannels: { data: undefined, error: undefined, }, @@ -27,17 +27,17 @@ export const reducer: Reducer< State, Action > = ( action ) => { switch ( action.type ) { - case TYPES.RECEIVE_CHANNELS_SUCCESS: + case TYPES.RECEIVE_REGISTERED_CHANNELS_SUCCESS: return { ...state, - channels: { + registeredChannels: { data: action.payload, }, }; - case TYPES.RECEIVE_CHANNELS_ERROR: + case TYPES.RECEIVE_REGISTERED_CHANNELS_ERROR: return { ...state, - channels: { + registeredChannels: { error: action.payload, }, }; diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts index c0feb6b2985..771a3b084c3 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/resolvers.ts @@ -7,25 +7,25 @@ import { apiFetch } from '@wordpress/data-controls'; * Internal dependencies */ import { - receiveChannelsSuccess, - receiveChannelsError, + receiveRegisteredChannelsSuccess, + receiveRegisteredChannelsError, receiveRecommendedChannelsSuccess, receiveRecommendedChannelsError, } from './actions'; -import { Channel, RecommendedChannel } from './types'; +import { RegisteredChannel, RecommendedChannel } from './types'; import { API_NAMESPACE } from './constants'; import { isApiFetchError } from './guards'; -export function* getChannels() { +export function* getRegisteredChannels() { try { - const data: Channel[] = yield apiFetch( { + const data: RegisteredChannel[] = yield apiFetch( { path: `${ API_NAMESPACE }/channels`, } ); - yield receiveChannelsSuccess( data ); + yield receiveRegisteredChannelsSuccess( data ); } catch ( error ) { if ( isApiFetchError( error ) ) { - yield receiveChannelsError( error ); + yield receiveRegisteredChannelsError( error ); } throw error; diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/selectors.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/selectors.ts index c37bb8599ad..48df4625c01 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/selectors.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/selectors.ts @@ -3,8 +3,8 @@ */ import { State } from './types'; -export const getChannels = ( state: State ) => { - return state.channels; +export const getRegisteredChannels = ( state: State ) => { + return state.registeredChannels; }; export const getRecommendedChannels = ( state: State ) => { diff --git a/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts b/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts index 518cdb03df7..f9e4dc44ee7 100644 --- a/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts +++ b/plugins/woocommerce-admin/client/marketing/data-multichannel/types.ts @@ -6,7 +6,7 @@ export type ApiFetchError = { message: string; }; -export type Channel = { +export type RegisteredChannel = { slug: string; is_setup_completed: boolean; settings_url: string; @@ -18,7 +18,7 @@ export type Channel = { }; export type ChannelsState = { - data?: Array< Channel >; + data?: Array< RegisteredChannel >; error?: ApiFetchError; }; @@ -51,6 +51,6 @@ export type RecommendedChannelsState = { }; export type State = { - channels: ChannelsState; + registeredChannels: ChannelsState; recommendedChannels: RecommendedChannelsState; }; diff --git a/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts b/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts index 97337bc8d3d..1b4341d0694 100644 --- a/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts +++ b/plugins/woocommerce-admin/client/marketing/hooks/useRegisteredChannels.ts @@ -12,7 +12,7 @@ import { RegisteredChannel, SyncStatusType } from '~/marketing/types'; import { STORE_KEY } from '~/marketing/data-multichannel/constants'; import { ApiFetchError, - Channel, + RegisteredChannel as APIRegisteredChannel, ChannelsState, } from '~/marketing/data-multichannel/types'; @@ -34,7 +34,7 @@ const statusMap: Record< string, SyncStatusType > = { synced: 'synced', }; -const convert = ( data: Channel ): RegisteredChannel => { +const convert = ( data: APIRegisteredChannel ): RegisteredChannel => { const issueType = data.errors_count >= 1 ? 'error' : 'none'; const issueText = data.errors_count >= 1 @@ -63,15 +63,16 @@ export const useRegisteredChannels = (): UseRegisteredChannels => { const { invalidateResolution } = useDispatch( STORE_KEY ); const refetch = useCallback( () => { - invalidateResolution( 'getChannels' ); + invalidateResolution( 'getRegisteredChannels' ); }, [ invalidateResolution ] ); return useSelect( ( select ) => { - const { hasFinishedResolution, getChannels } = select( STORE_KEY ); - const channels = getChannels< ChannelsState >(); + const { hasFinishedResolution, getRegisteredChannels } = + select( STORE_KEY ); + const channels = getRegisteredChannels< ChannelsState >(); return { - loading: ! hasFinishedResolution( 'getChannels' ), + loading: ! hasFinishedResolution( 'getRegisteredChannels' ), data: channels.data?.map( convert ), error: channels.error, refetch,