File size: 1,535 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 64 65 66 67 68 |
import {
STATS_MODULE_TOGGLES_REQUEST,
STATS_MODULE_TOGGLES_UPDATE,
} from 'calypso/state/action-types';
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 { receiveModuleToggles } from 'calypso/state/stats/module-toggles/actions';
import type { AnyAction } from 'redux';
export const doUpdateModuleToggles = ( action: AnyAction ) => {
const { siteId } = action;
return [
http(
{
method: 'POST',
apiNamespace: 'wpcom/v2',
path: `/sites/${ siteId }/jetpack-stats-dashboard/modules`,
body: action.payload,
},
action
),
];
};
export const fetch = ( action: AnyAction ) => {
const { siteId } = action;
return [
http(
{
method: 'GET',
apiNamespace: 'wpcom/v2',
path: `/sites/${ siteId }/jetpack-stats-dashboard/modules`,
body: {
dismissed: true,
},
},
action
),
];
};
export const onSuccess = ( { siteId }: AnyAction, data: object ) =>
receiveModuleToggles( siteId, data );
registerHandlers( 'state/data-layer/wpcom/sites/stats/module-toggles/index.js', {
[ STATS_MODULE_TOGGLES_REQUEST ]: [
dispatchRequest( {
fetch,
onSuccess,
onError: () => null,
// fromApi,
} ),
],
[ STATS_MODULE_TOGGLES_UPDATE ]: [
dispatchRequest( {
fetch: doUpdateModuleToggles,
onSuccess: () => null,
onError: () => null,
// fromApi,
} ),
],
} );
export default {};
|