client/src/sagas/groupSaga.js
author Alexandre Segura <mex.zktk@gmail.com>
Tue, 27 Jun 2017 18:12:10 +0200
changeset 100 6fd752d98933
child 101 e165aa89ac82
permissions -rw-r--r--
Introduce group creation.

import { put, take, all } from 'redux-saga/effects'
import * as types from '../constants/actionTypes';

function* watchCreateGroup(context) {
  while (true) {
    const { group } = yield take(types.GROUP_CREATE_ASYNC);
    const client = context.client;
    try {
      const response = yield client.post('/api/auth/group/', group);
      yield put({ type: types.GROUP_CREATE_SUCCESS, group: response });
    } catch (e) {
      yield put({ type: types.GROUP_CREATE_ERROR, error: e });
    }
  }
}

export default function* rootSaga(context) {
  yield all([
    watchCreateGroup(context),
  ])
}