File size: 896 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
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 { TEAMS_REQUEST, TEAMS_RECEIVE } from 'calypso/state/teams/action-types';

export const handleTeamsRequest = ( action ) =>
	http(
		{
			method: 'GET',
			path: '/read/teams',
			apiVersion: '1.2',
		},
		action
	);

export const teamRequestReceived = ( action, apiResponse ) => ( {
	type: TEAMS_RECEIVE,
	payload: apiResponse,
} );

export const teamRequestFailure = ( error ) => ( {
	type: TEAMS_RECEIVE,
	payload: error,
	error: true,
} );

registerHandlers( 'state/data-layer/wpcom/read/teams/index.js', {
	[ TEAMS_REQUEST ]: [
		dispatchRequest( {
			fetch: handleTeamsRequest,
			onSuccess: teamRequestReceived,
			onError: teamRequestFailure,
		} ),
	],
} );