File size: 1,366 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 |
import {
JETPACK_SCAN_ENQUEUE_UPDATE,
JETPACK_SCAN_ENQUEUE_REQUEST,
JETPACK_SCAN_ENQUEUE_REQUEST_SUCCESS,
JETPACK_SCAN_ENQUEUE_REQUEST_FAILURE,
} 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';
// NOTE: This is currently a mock endpoint.
// It always returns the following payload:
// ```
// { "enqueue": true }
// ```
const enqueueScan = ( action ) => {
return http(
{
apiNamespace: 'wpcom/v2',
method: 'POST',
path: `/sites/${ action.siteId }/scan/enqueue`,
body: {},
},
action
);
};
const onEnqueueScanSuccess = ( action, enqueueResult ) => {
return [
{
type: JETPACK_SCAN_ENQUEUE_REQUEST_SUCCESS,
siteId: action.siteId,
},
{
type: JETPACK_SCAN_ENQUEUE_UPDATE,
siteId: action.siteId,
payload: enqueueResult,
},
];
};
const onEnqueueScanFailure = ( ...response ) => {
return [
{
type: JETPACK_SCAN_ENQUEUE_REQUEST_FAILURE,
siteId: response.siteId,
},
];
};
registerHandlers( 'state/data-layer/wpcom/sites/scan/enqueue', {
[ JETPACK_SCAN_ENQUEUE_REQUEST ]: [
dispatchRequest( {
fetch: enqueueScan,
onSuccess: onEnqueueScanSuccess,
onError: onEnqueueScanFailure,
} ),
],
} );
|