File size: 1,039 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
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 {
	READER_ORGANIZATIONS_REQUEST,
	READER_ORGANIZATIONS_RECEIVE,
} from 'calypso/state/reader/action-types';

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

export const organizationRequestReceived = ( action, apiResponse ) => ( {
	type: READER_ORGANIZATIONS_RECEIVE,
	payload: apiResponse,
} );

export const organizationRequestFailure = ( error ) => ( {
	type: READER_ORGANIZATIONS_RECEIVE,
	payload: error,
	error: true,
} );

registerHandlers( 'state/data-layer/wpcom/read/organizations/index.js', {
	[ READER_ORGANIZATIONS_REQUEST ]: [
		dispatchRequest( {
			fetch: handleOrganizationsRequest,
			onSuccess: organizationRequestReceived,
			onError: organizationRequestFailure,
		} ),
	],
} );