File size: 1,249 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
import { JETPACK_SCAN_THREAT_FIX } from 'calypso/state/action-types';
import { registerHandlers } from 'calypso/state/data-layer/handler-registry';
import * as sitesAlertsFixHandlers from 'calypso/state/data-layer/wpcom/sites/alerts/fix';
import { dispatchRequest } from 'calypso/state/data-layer/wpcom-http/utils';
import {
	updateThreat,
	updateThreatCompleted,
	getFixThreatsStatus,
} from 'calypso/state/jetpack-scan/threats/actions';

export const request = ( action ) => {
	const defaultActions = sitesAlertsFixHandlers.request( action );
	return [ updateThreat( action.siteId, action.threatId ), ...defaultActions ];
};

export const success = ( action, rewindState ) => {
	const defaultActions = sitesAlertsFixHandlers.success( action, rewindState );
	return [ ...defaultActions, getFixThreatsStatus( action.siteId, [ action.threatId ] ) ];
};

export const failure = ( action ) => {
	const defaultAction = sitesAlertsFixHandlers.failure( action );
	return [ defaultAction, updateThreatCompleted( action.siteId, action.threatId ) ];
};

registerHandlers( 'state/data-layer/wpcom/sites/scan/threats/fix.js', {
	[ JETPACK_SCAN_THREAT_FIX ]: [
		dispatchRequest( {
			fetch: request,
			onSuccess: success,
			onError: failure,
		} ),
	],
} );