client/src/sagas/index.js
changeset 87 dbcee57de2c6
parent 86 fa8ef84a1780
child 88 2a861fed6bde
--- a/client/src/sagas/index.js	Fri Jun 23 18:50:57 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-import { put, take, all } from 'redux-saga/effects'
-import * as types from '../constants/actionTypes';
-
-// ---
-
-export function* watchLoginSubmit() {
-  while (true) {
-    const { username, password } = yield take(types.AUTH_LOGIN_SUBMIT);
-    yield put({ type: types.AUTH_LOGIN_REQUEST, username, password });
-  }
-}
-
-function* watchLoginRequest(context) {
-  while (true) {
-    try {
-
-        const { username, password } = yield take(types.AUTH_LOGIN_REQUEST);
-        const client = context.client;
-        const response = yield client.post('/api/auth/login/', { username, password });
-
-        const actions = [{
-          type: types.AUTH_LOGIN_SUCCESS,
-          user: response.user,
-          token: response.token,
-        //   meta: {
-        //     transition: (prevState, nextState, action) => ({
-        //       pathname: '/sessions',
-        //     }),
-        //   },
-        }, {
-          type: types.AUTH_STORE_TOKEN_ASYNC,
-          token: response.token,
-        }];
-
-        yield all(actions.map(action => put(action)));
-        context.history.push('/sessions');
-
-    } catch(e) {
-        yield put({ type: types.AUTH_LOGIN_ERROR, error: e });
-    }
-  }
-}
-
-function* watchStoreToken() {
-  while (true) {
-    const { token } = yield take(types.AUTH_STORE_TOKEN_ASYNC);
-    yield put({ type: types.AUTH_STORE_TOKEN, token });
-  }
-}
-
-function* watchUpdateSettings(context) {
-  while (true) {
-    const { username, firstname, lastname } = yield take(types.USER_UPDATE_SETTINGS_ASYNC);
-    const client = context.client;
-    try {
-      yield client.put('/api/auth/user/', {
-        username,
-        first_name: firstname,
-        last_name: lastname
-      });
-      yield put({ type: types.USER_UPDATE_SETTINGS, firstname, lastname });
-    } catch (e) {
-
-    }
-  }
-}
-
-// ---
-
-export default function* rootSaga(context) {
-  yield all([
-    watchLoginSubmit(),
-    watchLoginRequest(context),
-    watchStoreToken(),
-    watchUpdateSettings(context),
-  ])
-}