requestStatsActions.js 2.22 KB
'use strict';
import Request from '../../services/Request';
import RequestStatsService from '../../services/HomeService';

const {
    REQUEST_STATS_REQUEST,
    REQUEST_STATS_SUCCESS,
    REQUEST_STATS_FAILURE,
    CHOOSE_REQUEST_START_DATE,
    CHOOSE_REQUEST_END_DATE,
} = require('../../constants/actionTypes').default;

export function chooseStartDate(startDay) {
    return {
        type: CHOOSE_REQUEST_START_DATE,
        payload: startDay,
    }
}

export function chooseEndDate(endDay) {
    return {
        type: CHOOSE_REQUEST_END_DATE,
        payload: endDay,
    }
}

export function newDatePicked(pickedDate, ifStartDate) {
    return ifStartDate ? chooseStartDate(pickedDate) : chooseEndDate(pickedDate);
}

export function request() {
    return {
        type: REQUEST_STATS_REQUEST,
    }
}

export function success(json) {
    return {
        type: REQUEST_STATS_SUCCESS,
        payload: json,
    }
}

export function failure(error) {
    return {
        type: REQUEST_STATS_FAILURE,
        payload: error,
    }
}

export function requestData() {
    // return dispatch => {
    //     dispatch(request());
    //     return new RequestStatsService()
    //     .requestStatsData()
    //     .then(json => {
    //         dispatch(success(json));
    //     })
    //     .catch(error => {
    //         dispatch(failure(error));
    //     })
    // };
    return success(testStockStatsData);
}

let testStockStatsData = {
	sum: '100',
	totalAmount: '100000.00',
	list: [
		{
			id: '1234',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '1111',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
		{
            id: '0000',
			date: '2016-05-06',
			num: '222222',
			amount: '1111.00',
		},
	]
}