2017-09-01 19:42:50 +00:00
|
|
|
import { delay } from 'redux-saga';
|
2017-09-21 17:08:00 +00:00
|
|
|
import { select, put, call, take, takeEvery } from 'redux-saga/effects';
|
2017-09-01 19:42:50 +00:00
|
|
|
import { CREATE_CHANNEL, LOGIN } from '../actions/actionsTypes';
|
|
|
|
import { createChannelSuccess, createChannelFailure } from '../actions/createChannel';
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
|
|
|
|
|
|
|
|
|
|
|
const create = function* create(data) {
|
|
|
|
return yield RocketChat.createChannel(data);
|
|
|
|
};
|
|
|
|
|
2017-09-21 17:08:00 +00:00
|
|
|
const get = function* get({ data }) {
|
|
|
|
try {
|
|
|
|
const auth = yield select(state => state.login.isAuthenticated);
|
|
|
|
if (!auth) {
|
|
|
|
yield take(LOGIN.SUCCESS);
|
2017-09-01 19:42:50 +00:00
|
|
|
}
|
2017-09-21 17:08:00 +00:00
|
|
|
const result = yield call(create, data);
|
|
|
|
yield put(createChannelSuccess(result));
|
|
|
|
select(({ navigator }) => navigator).dismissModal({
|
|
|
|
animationType: 'slide-down'
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
yield delay(2000);
|
|
|
|
yield put(createChannelFailure(err));
|
2017-09-01 19:42:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const getData = function* getData() {
|
2017-09-21 17:08:00 +00:00
|
|
|
yield takeEvery(CREATE_CHANNEL.REQUEST, get);
|
2017-09-01 19:42:50 +00:00
|
|
|
};
|
|
|
|
export default getData;
|