-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatatable-actions.js
40 lines (35 loc) · 1.15 KB
/
datatable-actions.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
import { DATATABLE_FETCH_ROWS_SUCCESS, DATATABLE_FETCH_ROWS_ERROR, DATATABLE_FETCH_COLUMNS_SUCCESS } from '../constants/action-types';
import axios from 'axios';
import { getRequestUrl, getColumns } from '../utilities/datatable-utilities';
const fetchDatatableRowsSuccess = (data, type) => {
return {
type: DATATABLE_FETCH_ROWS_SUCCESS,
payload: data,
data_type: type
};
};
const fetchDatatableRowsError = (error, type) => {
return {
type: DATATABLE_FETCH_ROWS_ERROR,
payload: error,
data_type: type
};
};
export const fetchDatatableData = (type) => {
const url = getRequestUrl(type);
const request = axios.get(url);
return dispatch => request.then(
(data) => dispatch(fetchDatatableRowsSuccess(data, type)),
(error) => dispatch(fetchDatatableRowsError(error, type)),
);
};
const fetchColumnsSuccess = (data, type) => {
return {
type: DATATABLE_FETCH_COLUMNS_SUCCESS,
payload: data,
data_type: type
};
};
export const fetchDatatableColumns = (type) => {
return dispatch => dispatch(fetchColumnsSuccess(getColumns(type), type));
};