| import { ACTIVE_PROMOTIONS_REQUEST } from 'calypso/state/action-types'; |
| import { |
| activePromotionsReceiveAction, |
| activePromotionsRequestFailureAction, |
| activePromotionsRequestSuccessAction, |
| } from 'calypso/state/active-promotions/actions'; |
| 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'; |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| export const requestActivePromotions = ( action ) => |
| http( |
| { |
| apiVersion: '1.1', |
| method: 'GET', |
| path: '/me/active-promotions', |
| }, |
| action |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| |
| export const receiveActivePromotions = ( action, { active_promotions } ) => [ |
| activePromotionsRequestSuccessAction(), |
| activePromotionsReceiveAction( active_promotions ), |
| ]; |
|
|
| |
| |
| |
| |
| |
| |
| export const receiveError = ( action, rawError ) => |
| activePromotionsRequestFailureAction( rawError instanceof Error ? rawError.message : rawError ); |
|
|
| export const dispatchActivePromotionsRequest = dispatchRequest( { |
| fetch: requestActivePromotions, |
| onSuccess: receiveActivePromotions, |
| onError: receiveError, |
| } ); |
|
|
| registerHandlers( 'state/data-layer/wpcom/active-promotions/index.js', { |
| [ ACTIVE_PROMOTIONS_REQUEST ]: [ dispatchActivePromotionsRequest ], |
| } ); |
|
|