File size: 1,256 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
# ActivePromotions

A module for managing activePromotions data.

## Actions

Used in combination with the Redux store instance `dispatch` function, actions can be used in manipulating the current global state.

### Action creators

> Action creators are exactly that—functions that create actions.

#### activePromotionsReceiveAction( activePromotions )

#### activePromotionsRequestSuccessAction()

#### activePromotionsRequestFailureAction( error )

#### requestActivePromotions()

```js
import {
	activePromotionsReceiveAction,
	activePromotionsRequestSuccessAction,
	activePromotionsRequestFailureAction,
	requestActivePromotions,
} from 'calypso/state/activePromotions/actions';

dispatch( requestActivePromotions() );

wpcom
	.activePromotions()
	.list()
	.then( ( response ) => {
		dispatch( activePromotionsRequestSuccessAction() );
		dispatch( activePromotionsReceiveAction( response ) );
	} )
	.catch( ( error ) => {
		dispatch( activePromotionsRequestFailureAction( error.message ) );
	} );
```

## Reducer

Data from the aforementioned actions is added to the global state tree, under `activePromotions`, with the following structure:

```js
state.activePromotions = {
	items: [ 'spring_sale' ],

	requesting: false,

	errors: false,
};
```