transferShipmentReducer.js
2.47 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
82
83
84
85
86
87
88
89
90
91
92
'use strict';
/**
* ## Imports
*
* InitialState
*/
import InitialState from './transferShipmentInitialState';
import Immutable, {List, Record} from 'immutable';
const {
GO_TO_OUT_STOCK,
GO_TO_OUT_DELIVERGOODS,
GET_PURCHASE_LIST_REQUEST,
GET_PURCHASE_LIST_SUCCESS,
GET_PURCHASE_LIST_FAILURE,
CHECKUP_REQUEST,
SET_PURCHASE_NUM,
RETSET_DATA,
} = 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 GO_TO_OUT_STOCK:{
return state;
}
case GO_TO_OUT_DELIVERGOODS:{
return state;
}
case GET_PURCHASE_LIST_REQUEST:{
return state.setIn(['purchaseList', 'isFetching'], true)
.setIn(['purchaseList', 'error'], null)
.setIn(['purchaseList', 'pageNo'], 0)
.setIn(['purchaseList', 'totalPage'], 0)
.setIn(['purchaseList', 'totalCount'], 0)
.setIn(['purchaseList', 'endReached'], false);
}
case GET_PURCHASE_LIST_SUCCESS:{
let {
records,
pageNo,
totalPage,
totalCount,
endReached,
} = action.payload;
return state.setIn(['purchaseList', 'isFetching'], false)
.setIn(['purchaseList', 'error'], null)
.setIn(['purchaseList', 'records'], Immutable.fromJS(records))
.setIn(['purchaseList', 'pageNo'], pageNo)
.setIn(['purchaseList', 'totalPage'], totalPage)
.setIn(['purchaseList', 'totalCount'], totalCount)
.setIn(['purchaseList', 'endReached'], endReached);
}
case GET_PURCHASE_LIST_FAILURE:{
return state.setIn(['purchaseList', 'isFetching'], false)
.setIn(['purchaseList', 'error'], action.payload)
}
case CHECKUP_REQUEST:{
return state.setIn(['purchaseList', 'records'], Immutable.fromJS(action.payload));
}
case SET_PURCHASE_NUM:{
return state.setIn(['purchaseList', 'records'], Immutable.fromJS(action.payload));
}
case RETSET_DATA: {
return state.setIn(['purchaseList', 'isFetching'], false)
.setIn(['purchaseList', 'error'], null)
.setIn(['purchaseList', 'records'], null)
.setIn(['purchaseList', 'pageNo'], 0)
.setIn(['purchaseList', 'totalPage'], 0)
.setIn(['purchaseList', 'totalCount'], 0)
.setIn(['purchaseList', 'endReached'], false);
}
return state;
}
return state;
}