Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
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,
} ),
],
} );