saleStatisticsActions.js 1.29 KB
/**
 * # guideActions.js
 *
 * App user guide
 *
 */
'use strict';

import {Actions} from 'react-native-router-flux';
import CONFIG from '../../constants/config';
import HomeService from '../../services/HomeService';

const {

	SALE_STATS_REQUEST,
	SALE_STATS_SUCCESS,
	SALE_STATS_FAILURE,

} = require('../../constants/actionTypes').default;

export function saleStatsRequest(shopId) {
    return {
        type: SALE_STATS_REQUEST,
        payload: shopId
    };
}

export function saleStatsSuccess(json) {
    return {
        type: SALE_STATS_SUCCESS,
        payload: json
    };
}

export function saleStatsFailure(error) {
    return {
        type: SALE_STATS_FAILURE,
        payload: error
    };
}

export function saleStats(shopId) {

	return dispatch => {
		dispatch(saleStatsRequest(shopId));
        return new HomeService().saleStats(shopId)
            .then(json => {
                dispatch(saleStatsSuccess({
                    goodsCount: 7600,
                    amountRise: true,
                    amountRisePercent: '20%',
                    goodsAmount: 19800.00,
                    countRise: false,
                    countRisePercent: '10%'
                }));
            })
            .catch(error => {
                dispatch(saleStatsFailure(error));
            });
	};

}