File size: 1,311 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 48 49 50 51 52 53 54 55 56 57 58 | import {
REWIND_POLICIES_REQUEST,
REWIND_POLICIES_REQUEST_FAILURE,
REWIND_POLICIES_REQUEST_SUCCESS,
REWIND_POLICIES_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';
import fromApi from './from-api';
import type { RewindPolicies } from 'calypso/state/rewind/policies/types';
import type { AnyAction } from 'redux';
type RequestActionType = AnyAction & {
siteId: number;
};
const fetch = ( action: RequestActionType ) =>
http(
{
apiNamespace: 'wpcom/v2',
method: 'GET',
path: `/sites/${ action.siteId }/rewind/policies`,
query: {
force: 'wpcom',
},
},
action
);
const onSuccess = ( { siteId }: RequestActionType, policies: RewindPolicies ) => [
{
type: REWIND_POLICIES_REQUEST_SUCCESS,
siteId,
},
{
type: REWIND_POLICIES_SET,
siteId,
policies,
},
];
const onError = ( { siteId }: RequestActionType ) => ( {
type: REWIND_POLICIES_REQUEST_FAILURE,
siteId,
} );
registerHandlers( 'state/data-layer/wpcom/sites/rewind/policies', {
[ REWIND_POLICIES_REQUEST ]: [
dispatchRequest( {
fetch,
fromApi,
onSuccess,
onError,
} ),
],
} );
|