File size: 1,873 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
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
	ACTIVE_PROMOTIONS_RECEIVE,
	ACTIVE_PROMOTIONS_REQUEST,
	ACTIVE_PROMOTIONS_REQUEST_SUCCESS,
	ACTIVE_PROMOTIONS_REQUEST_FAILURE,
} from 'calypso/state/action-types';

// WP REST-API error response
export const ERROR_MESSAGE_RESPONSE =
	'There was a problem fetching activePromotions. Please try again later or contact support.';

export const ACTIVE_PROMOTION_1 = 'spring_sale';
export const ACTIVE_PROMOTION_1003 = 'valentine_promotion';
export const ACTIVE_PROMOTION_1008 = 'spring_sale_2';
export const ACTIVE_PROMOTION_1009 = 'spring_sale_3';
export const ACTIVE_PROMOTION_1029 = 'spring_sale_4';
export const ACTIVE_PROMOTION_2000 = 'spring_sale_5';
export const ACTIVE_PROMOTION_2001 = 'spring_sale_6';
export const ACTIVE_PROMOTION_2002 = 'spring_sale_7';
export const ACTIVE_PROMOTION_2003 = 'spring_sale_8';

export const WPCOM_RESPONSE = [
	ACTIVE_PROMOTION_1,
	ACTIVE_PROMOTION_1003,
	ACTIVE_PROMOTION_1008,
	ACTIVE_PROMOTION_1009,
	ACTIVE_PROMOTION_1029,
	ACTIVE_PROMOTION_2000,
	ACTIVE_PROMOTION_2001,
	ACTIVE_PROMOTION_2002,
	ACTIVE_PROMOTION_2003,
];

export const ACTIVE_PROMOTIONS = WPCOM_RESPONSE;

// actions
export const ACTION_ACTIVE_PROMOTIONS_RECEIVE = {
	type: ACTIVE_PROMOTIONS_RECEIVE,
	activePromotions: ACTIVE_PROMOTIONS,
};

export const ACTION_ACTIVE_PROMOTIONS_REQUEST = {
	type: ACTIVE_PROMOTIONS_REQUEST,
};

export const ACTION_ACTIVE_PROMOTIONS_REQUEST_SUCCESS = {
	type: ACTIVE_PROMOTIONS_REQUEST_SUCCESS,
};

export const ACTION_ACTIVE_PROMOTIONS_REQUEST_FAILURE = {
	type: ACTIVE_PROMOTIONS_REQUEST_FAILURE,
	error: ERROR_MESSAGE_RESPONSE,
};

/**
 * Return a whole state instance
 *
 * - requesting: false
 * - error: false
 * @returns {Object} an state instance
 */
export const getStateInstance = () => {
	return {
		activePromotions: {
			items: [ ...ACTIVE_PROMOTIONS ],
			requesting: false,
			error: false,
		},
	};
};