{"size": 1257, "ext": "js", "max_stars_repo_path": "src/actions/sms-actions.js", "max_stars_repo_name": "pekkis/finnkino-ticket", "max_stars_repo_stars_event_min_datetime": "2016-02-12T20:27:26.000Z", "max_stars_repo_stars_event_max_datetime": "2016-02-12T20:27:26.000Z", "max_issues_repo_path": "src/actions/sms-actions.js", "max_issues_repo_name": "pekkis/finnkino-ticket", "max_issues_repo_issues_event_min_datetime": "2016-02-13T18:23:11.000Z", "max_issues_repo_issues_event_max_datetime": "2016-02-13T18:23:11.000Z", "max_forks_repo_path": "src/actions/sms-actions.js", "max_forks_repo_name": "pekkis/finnkino-ticket", "max_forks_repo_forks_event_min_datetime": "2016-02-12T22:04:54.000Z", "max_forks_repo_forks_event_max_datetime": "2016-02-12T22:04:54.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 20.2741935484, "max_line_length": 61, "alphanum_fraction": 0.5879077168}
import axios from 'axios';
import { List } from 'immutable';
import smss from 'services/sms';

export const SEND_SMS = 'SEND_SMS';
export const SEND_SMS_SUCCESS = 'SEND_SMS_SUCCESS';
export const SEND_SMS_FAILED = 'SEND_SMS_FAILED';
export const SEND_SMS_READY = 'SEND_SMS_READY';

function sendSmsReady() {
    return function(dispatch) {

        setTimeout(function() {
            dispatch({
                type: SEND_SMS_READY
            });
        }, 5000);
    };
}

function sendSmsSuccess(msisdn) {

    return function(dispatch) {

        dispatch(sendSmsReady());

        return dispatch({
            type: SEND_SMS_SUCCESS,
            payload: msisdn
        });
    };
}

function sendSmsFailed(error) {

    return function(dispatch) {

        dispatch(sendSmsReady());

        return dispatch({
            type: SEND_SMS_FAILED,
            payload: error
        });
    };

}

export function sendSms(msisdn, eventId, ticketId) {

    return function(dispatch, getState) {

        dispatch({
            type: SEND_SMS
        });

        return smss
            .send(msisdn, eventId, ticketId)
            .then(msisdn => dispatch(sendSmsSuccess(msisdn)))
            .catch(error => dispatch(sendSmsFailed(error)));
    };
}
