File size: 1,269 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import { translate } from 'i18n-calypso';
import { ALL_DOMAINS_REQUEST } from 'calypso/state/action-types';
import {
getAllDomainsRequestFailure,
getAllDomainsRequestSuccess,
} from 'calypso/state/all-domains/actions';
import { registerHandlers } from 'calypso/state/data-layer/handler-registry';
import { http } from 'calypso/state/data-layer/wpcom-http/actions';
import { dispatchRequest } from 'calypso/state/data-layer/wpcom-http/utils';
import { errorNotice } from 'calypso/state/notices/actions';
export const getAllDomains = ( action ) => {
return http( { path: '/all-domains', method: 'GET' }, action );
};
export const getAllDomainsError = ( action, error ) => {
return [
errorNotice( translate( 'Failed to retrieve all domains' ) ),
getAllDomainsRequestFailure( error ),
];
};
export const getAllDomainsSuccess = ( action, response ) => {
if ( response ) {
return getAllDomainsRequestSuccess( response.domains );
}
return getAllDomainsError( action, 'Failed to retrieve your domains. No response was received' );
};
registerHandlers( 'state/data-layer/wpcom/all-domains/index.js', {
[ ALL_DOMAINS_REQUEST ]: [
dispatchRequest( {
fetch: getAllDomains,
onSuccess: getAllDomainsSuccess,
onError: getAllDomainsError,
} ),
],
} );
|