requestStatsReducer.js
2.82 KB
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
'use strict';
import RequestStatsInitialState from './requestStatsInitialState'
import Immutable, {List, Record} from 'immutable';
const {
REQUEST_STATS_REQUEST,
REQUEST_STATS_SUCCESS,
REQUEST_STATS_FAILURE,
REQUEST_STATS_CLEAN,
CHOOSE_REQUEST_START_DATE,
CHOOSE_REQUEST_END_DATE,
SHOW_REQUEST_DATEPICKER_IOS,
SELECT_REQUEST_DATE_IOS,
SWITCH_SHOP,
LOGOUT,
} = require('../../constants/actionTypes').default;
const initialState = new RequestStatsInitialState;
export default function requestStatsReducer(state = initialState, action) {
if (!(state instanceof RequestStatsInitialState)) return initialState.merge(state);
switch (action.type) {
case REQUEST_STATS_REQUEST: {
let nextState = state.set('isFetching', true).set('error', null);
return nextState;
}
case REQUEST_STATS_SUCCESS: {
const {jsonData} = state;
let origin = jsonData.toJS();
let {additionInfo, list} = action.payload;
let data = [...origin, ...(list || [])];
let nextState = state.set('isFetching', false)
.set('sum', additionInfo.allNumber || '0')
.set('totalAmount', additionInfo.allAmount || '0.00')
.set('currentPage', action.payload.page)
.set('pageCount', action.payload.totalPage)
.set('jsonData', Immutable.fromJS(data));
return nextState;
}
case REQUEST_STATS_FAILURE: {
let nextState = state.set('isFetching', false)
.set('error', action.playload);
return nextState;
}
case CHOOSE_REQUEST_START_DATE: {
let nextState = state.set('startDay', action.payload)
.set('isShowDatePickerIOS', false)
.set('currentPage', 0)
.set('pageCount', 1)
.set('jsonData', List());
return nextState;
}
case CHOOSE_REQUEST_END_DATE: {
let nextState = state.set('endDay', action.payload)
.set('isShowDatePickerIOS', false)
.set('currentPage', 0)
.set('pageCount', 1)
.set('jsonData', List());
return nextState;
}
case SHOW_REQUEST_DATEPICKER_IOS: {
let nextState = state.set('isShowDatePickerIOS', action.isShowDatePickerIOS)
.set('isStartDate', action.isStartDate);
return nextState;
}
case SELECT_REQUEST_DATE_IOS: {
let nextState = action.isStartDate ? state.set('startDay', action.selectedDate) : state.set('endDay', action.selectedDate);
return nextState;
}
case REQUEST_STATS_CLEAN:
case SWITCH_SHOP:
case LOGOUT:
return initialState;
}
return state;
}