accountSettlementActions.js 1.43 KB
'use strict';
import Request from '../../services/Request';
import HomeService from '../../services/HomeService';

const {
    ACCOUNT_LIST_REQUEST,
    ACCOUNT_LIST_SUCCESS,
    ACCOUNT_LIST_FAILURE,
    ACCOUNT_LIST_CLEAN,

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

export function requestNextPage() {
    return {
        type: ACCOUNT_LIST_REQUEST,
    }
}

/**
 * Success to fetch data..
 * @method nextPageOfDataSuccess
 * @param  {Maybe array}              json remote data
 * @return {[type]}                   [description]
 */
export function nextPageOfDataSuccess(json) {
    return {
        type: ACCOUNT_LIST_SUCCESS,
        payload: json,
    }
}

export function nextPageOfDataFailure(error) {
    return {
        type: ACCOUNT_LIST_FAILURE,
        payload: error,
    }
}

/**
 * Request next page of account settlement data list...
 * @method nextPageOfDataRequest
 * @return {JS Objecrt}
 */
export function nextPageOfDataRequest() {

    return (dispatch,getState) => {
        const {home, actStmt} = getState();

        dispatch(requestNextPage());

        return new HomeService().accountSettlementData(home.shopId)
            .then(json => {
                dispatch(nextPageOfDataSuccess(json));
            })
            .catch(error => {
                dispatch(nextPageOfDataFailure(error));
            })
    };

}

export function accountSettlementClean() {
    return {
        type: ACCOUNT_LIST_CLEAN,
    }
}