-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.ts
More file actions
49 lines (45 loc) · 1.37 KB
/
index.ts
File metadata and controls
49 lines (45 loc) · 1.37 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
import { message } from 'antd';
import { combineReducers } from 'redux';
import * as Actions from '../actions';
import { routerReducer } from 'react-router-redux';
import { handleActions, ActionMeta } from 'redux-actions';
import * as request from 'superagent';
import * as moment from 'moment';
import { clientReducer, ClientState } from './client';
export class State {
public readonly client: ClientState;
public readonly data: Object;
public readonly dateRange: { end: moment.Moment, start: moment.Moment};
public readonly routing: any;
}
export const dataReducer = handleActions({
FETCH: (state, action: ActionMeta<string, { url: string }>) => {
if (action.error) {
message.error(`Error fetching: ${action.meta.url}`);
} else {
return Object.assign({}, state, {
[action.meta.url]: action.payload,
});
}
return state;
},
}, {});
export const dateRangeReducer = handleActions({
UPDATE_DATE_RANGE: (state,
action: ActionMeta<{ end: moment.Moment, start: moment.Moment}, {}>) => {
if (action.error) {
message.error(`Error updating date range.`);
} else {
return Object.assign({}, state, action.payload);
}
},
}, {
end: moment().startOf('year'),
start: moment(),
});
export default combineReducers<State>({
client: clientReducer,
data: dataReducer,
dateRange: dateRangeReducer,
routing: routerReducer,
});