File size: 1,486 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import {
MAILCHIMP_LISTS_LIST,
MAILCHIMP_LISTS_RECEIVE,
MAILCHIMP_SETTINGS_LIST,
MAILCHIMP_SETTINGS_RECEIVE,
} from 'calypso/state/action-types';
import { mergeHandlers } from 'calypso/state/action-watchers/utils';
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';
const noop = () => {};
export const handleMailchimpListsList = dispatchRequest( {
fetch: ( action ) =>
http(
{
method: 'GET',
path: `/sites/${ action.siteId }/mailchimp/lists`,
},
action
),
fromApi: function ( endpointResponse ) {
return endpointResponse;
},
onSuccess: ( { siteId }, lists ) => ( {
type: MAILCHIMP_LISTS_RECEIVE,
siteId,
lists,
} ),
onError: noop,
} );
export const handleMailchimpSettingsList = dispatchRequest( {
fetch: ( action ) =>
http(
{
method: 'GET',
path: `/sites/${ action.siteId }/mailchimp/settings`,
},
action
),
fromApi: function ( endpointResponse ) {
return endpointResponse;
},
onSuccess: ( { siteId }, settings ) => ( {
type: MAILCHIMP_SETTINGS_RECEIVE,
siteId,
settings,
} ),
onError: noop,
} );
registerHandlers(
'state/data-layer/wpcom/sites/mailchimp/index.js',
mergeHandlers( {
[ MAILCHIMP_LISTS_LIST ]: [ handleMailchimpListsList ],
[ MAILCHIMP_SETTINGS_LIST ]: [ handleMailchimpSettingsList ],
} )
);
export default {};
|