-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
reducer.js
82 lines (78 loc) · 1.87 KB
/
reducer.js
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
72
73
74
75
76
77
78
79
80
81
82
/**
* Internal dependencies
*/
import TYPES from './action-types';
const DEFAULT_STATE = {
queue: [],
cesModalData: undefined,
showCESModal: false,
showProductMVPFeedbackModal: false,
};
const reducer = ( state = DEFAULT_STATE, action ) => {
switch ( action.type ) {
case TYPES.SET_CES_SURVEY_QUEUE:
return {
...state,
queue: [ ...state.queue, ...action.queue ],
};
case TYPES.HIDE_CES_MODAL:
return {
...state,
showCESModal: false,
cesModalData: undefined,
};
case TYPES.SHOW_CES_MODAL:
const cesModalData = {
action: action.surveyProps.action,
title: action.surveyProps.title,
onSubmitLabel: action.onSubmitLabel,
firstQuestion: action.surveyProps.firstQuestion,
secondQuestion: action.surveyProps.secondQuestion,
onSubmitNoticeProps: action.onSubmitNoticeProps || {},
props: action.props,
};
return {
...state,
showCESModal: true,
cesModalData,
};
case TYPES.ADD_CES_SURVEY:
// Prevent duplicate
const hasDuplicate = state.queue.filter(
( track ) => track.action === action.action
);
if ( hasDuplicate.length ) {
return state;
}
const newTrack = {
action: action.action,
title: action.title,
description: action.description,
noticeLabel: action.noticeLabel,
firstQuestion: action.firstQuestion,
secondQuestion: action.secondQuestion,
icon: action.icon,
pagenow: action.pageNow,
adminpage: action.adminPage,
onSubmitLabel: action.onSubmitLabel,
props: action.props,
};
return {
...state,
queue: [ ...state.queue, newTrack ],
};
case TYPES.SHOW_PRODUCT_MVP_FEEDBACK_MODAL:
return {
...state,
showProductMVPFeedbackModal: true,
};
case TYPES.HIDE_PRODUCT_MVP_FEEDBACK_MODAL:
return {
...state,
showProductMVPFeedbackModal: false,
};
default:
return state;
}
};
export default reducer;