homeActions.js 3.07 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 {

	HOME_OVERVIEW_REQUEST,
    HOME_OVERVIEW_SUCCESS,
    HOME_OVERVIEW_FAILURE,

	HOME_BRABDRANK_REQUEST,
    HOME_BRABDRANK_SUCCESS,
    HOME_BRABDRANK_FAILURE,

    GO_TO_SALE_STATS,
    GO_TO_REFOUND_STATS,
    GO_TO_STOCK_STATS,
    GO_TO_DELIVERY_STATS,
    GO_TO_REQUEST_STATS,
    GO_TO_ACCOUNT_SETTLEMENT,

    SWITCH_SHOP,

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

export function overviewRequest(brandId) {
    return {
        type: HOME_OVERVIEW_REQUEST,
        payload: brandId
    };
}

export function overviewSuccess(json) {
    return {
        type: HOME_OVERVIEW_SUCCESS,
        payload: json
    };
}

export function overviewFailure(error) {
    return {
        type: HOME_OVERVIEW_FAILURE,
        payload: error
    };
}

export function brandRankRequest(brandId) {
    return {
        type: HOME_BRABDRANK_REQUEST,
        payload: brandId
    };
}

export function brandRankSuccess(json) {
    return {
        type: HOME_BRABDRANK_SUCCESS,
        payload: json
    };
}

export function brandRankFailure(error) {
    return {
        type: HOME_BRABDRANK_FAILURE,
        payload: error
    };
}

export function overview(brandId) {

	return dispatch => {
		dispatch(overviewRequest(brandId));
        return new HomeService().overview(brandId)
            .then(json => {
                dispatch(overviewSuccess(json));
            })
            .catch(error => {
                dispatch(overviewFailure(error));
            });
	};
}

export function brandRank(brandId) {

	return dispatch => {
		dispatch(brandRankRequest(brandId));
        return new HomeService().brandRank(brandId)
            .then(json => {
                dispatch(brandRankSuccess(json));
            })
            .catch(error => {
                dispatch(brandRankFailure(error));
            });
	};
}

export function goToStatsPage(type) {

    switch (type) {
        case CONFIG.statsKey.saleStats:
            Actions.SaleStats();
            return {
                type: GO_TO_SALE_STATS,
            };
        case CONFIG.statsKey.refoundStats:
            Actions.RefoundStats();
            return {
                type: GO_TO_REFOUND_STATS,
            };
        case CONFIG.statsKey.stockStats:
            Actions.StockStats();
            return {
                type: GO_TO_STOCK_STATS,
            };
        case CONFIG.statsKey.deliveryStats:
            Actions.DeliveryStats();
            return {
                type: GO_TO_DELIVERY_STATS,
            };
        case CONFIG.statsKey.requestStats:
            Actions.RequestStats();
            return {
                type: GO_TO_REQUEST_STATS,
            };
        case CONFIG.statsKey.accountSettlement:
            Actions.AccountSettlement();
            return {
                type: GO_TO_ACCOUNT_SETTLEMENT,
            };
    }
}

export function switchShop(shopId) {
    return overview(shopId);
}