File size: 884 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
import { HOSTING_GEO_AFFINITY_REQUEST, HOSTING_GEO_AFFINITY_SET } 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 getGeoAffinity = ( action ) =>
	http(
		{
			method: 'GET',
			path: `/sites/${ action.siteId }/hosting/geo-affinity`,
			apiNamespace: 'wpcom/v2',
			body: {},
		},
		action
	);

const getGeoAffinitySuccess = ( action, geoAffinity ) => {
	return {
		type: HOSTING_GEO_AFFINITY_SET,
		siteId: action.siteId,
		setting: geoAffinity,
	};
};

registerHandlers( 'state/data-layer/wpcom/sites/hosting/geo-affinity.js', {
	[ HOSTING_GEO_AFFINITY_REQUEST ]: [
		dispatchRequest( {
			fetch: getGeoAffinity,
			onSuccess: getGeoAffinitySuccess,
		} ),
	],
} );