Rename Channel to RegisteredChannel.
This is for better clarity and consistency.
This commit is contained in:
parent
177fc59dea
commit
f050bb79b5
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
>;
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ) => {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue