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

const {
    ACCOUNT_LIST_REQUEST,
    ACCOUNT_LIST_SUCCESS,
    ACCOUNT_LIST_FAILURE,

} = 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 => {
        dispatch(requestNextPage());

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

}