--- a/client/src/sagas/groupSaga.js Tue Jun 27 18:12:10 2017 +0200
+++ b/client/src/sagas/groupSaga.js Wed Jun 28 12:54:48 2017 +0200
@@ -14,8 +14,50 @@
}
}
+function* watchCreateGroupAndUpdateSession(context) {
+ while (true) {
+ const { session, group } = yield take(types.GROUP_CREATE_AND_UPDATE_ASYNC);
+ const client = context.client;
+ try {
+ const response = yield client.post('/api/auth/group/', group);
+
+ const actions = [
+ {
+ type: types.GROUP_CREATE_SUCCESS,
+ group: response
+ },
+ {
+ type: types.UPDATE_SESSION,
+ session: session,
+ values: { group: response },
+ }
+ ];
+
+ yield all(actions.map(action => put(action)));
+
+ } catch (e) {
+ yield put({ type: types.GROUP_CREATE_ERROR, error: e });
+ }
+ }
+}
+
+function* watchLoadGroups(context) {
+ const client = context.client;
+ while (true) {
+ yield take(types.GROUP_LOAD_ASYNC);
+ try {
+ const response = yield client.get('/api/auth/group/');
+ yield put({ type: types.GROUP_LOAD_SUCCESS, groups: response });
+ } catch (e) {
+ yield put({ type: types.GROUP_LOAD_ERROR, error: e });
+ }
+ }
+}
+
export default function* rootSaga(context) {
yield all([
watchCreateGroup(context),
+ watchCreateGroupAndUpdateSession(context),
+ watchLoadGroups(context),
])
}