File size: 1,018 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
import {
	REWIND_CAPABILITIES_REQUEST,
	REWIND_CAPABILITIES_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';

const fetchCapabilities = ( action ) =>
	http(
		{
			apiNamespace: 'wpcom/v2',
			method: 'GET',
			path: `/sites/${ action.siteId }/rewind/capabilities`,
			query: {
				force: 'wpcom',
			},
		},
		action
	);

const updateCapabilities = ( { siteId }, data ) => {
	return {
		type: REWIND_CAPABILITIES_UPDATE,
		siteId,
		data: data.capabilities,
	};
};

const onError = ( { siteId } ) => {
	return {
		type: REWIND_CAPABILITIES_UPDATE,
		siteId,
		data: [],
	};
};

registerHandlers( 'state/data-layer/wpcom/sites/rewind/capabilities', {
	[ REWIND_CAPABILITIES_REQUEST ]: [
		dispatchRequest( {
			fetch: fetchCapabilities,
			onSuccess: updateCapabilities,
			onError,
		} ),
	],
} );