homeReducer.js
1.78 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
/**
* # guideReducer.js
*
* The reducer for all the actions from the various log states
*/
'use strict';
/**
* ## Imports
*
* InitialState
*/
import InitialState from './homeInitialState';
const {
HOME_OVERVIEW_REQUEST,
HOME_OVERVIEW_SUCCESS,
HOME_OVERVIEW_FAILURE,
GO_TO_SALE_STATS,
GO_TO_RETURN_STATS,
GO_TO_STOCK_STATS,
GO_TO_DELIVERY_STATS,
GO_TO_REQUEST_STATS,
GO_TO_ACCOUNT_SETTLEMENT,
SWITCH_SHOP,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
/**
* ## guideReducer function
* @param {Object} state - initialState
* @param {Object} action - type and payload
*/
export default function userReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case HOME_OVERVIEW_REQUEST: {
let nextState = state.set('isFetching', true)
.set('error', null)
.set('shopId', action.payload);
return nextState;
}
case HOME_OVERVIEW_SUCCESS: {
let nextState = state.set('isFetching', false)
.set('error', null)
.setIn(['overview', 'rank'], action.payload.rank)
.setIn(['overview', 'rise'], action.payload.rise)
.setIn(['overview', 'riseCount'], action.payload.riseCount)
.setIn(['overview', 'goodsCount'], action.payload.goodsCount)
.setIn(['overview', 'goodsAmount'], action.payload.goodsAmount);
return nextState;
}
case HOME_OVERVIEW_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case GO_TO_SALE_STATS:
case GO_TO_RETURN_STATS:
case GO_TO_STOCK_STATS:
case GO_TO_DELIVERY_STATS:
case GO_TO_REQUEST_STATS:
case GO_TO_ACCOUNT_SETTLEMENT:
return state;
}
return state;
}