messageActions.js 1.19 KB
/**
 * # guideActions.js
 *
 * App user guide
 *
 */
'use strict';

import {Actions} from 'react-native-router-flux';
import MessageService from '../../services/MessageService';

const {
    MESSAGE_DETAIL,
    REQUEST_MSG_LIST,
    REQUEST_MSG_LIST_SUCCESS,
    REQUEST_MSG_LIST_FAILURE,
} = require('../../constants/actionTypes').default;

export function checkMessageDetail(item) {
    Actions.MessageDetail();
	return {
		type: MESSAGE_DETAIL,
		payload: item,
	};
}

export function requestMsgList(shopsId) {
    return {
        type: REQUEST_MSG_LIST,
        payload: shopsId,
    }
}

export function requestMsgListSuccess(json) {
    return {
        type: REQUEST_MSG_LIST_SUCCESS,
        payload: json,
    }
}

export function requestMsgListFailure(error) {
    return {
        type: REQUEST_MSG_LIST_FAILURE,
        payload: error,
    }
}

export function getMsgList(shopsId) {
    return dispatch => {
		dispatch(requestMsgList(shopsId));
        return new MessageService().getMsgList(shopsId)
            .then(json => {
                dispatch(requestMsgListSuccess(json));
            })
            .catch(error => {
                dispatch(requestMsgListFailure(error));
            });
	};
}