DRY
authorAlexandre Segura <mex.zktk@gmail.com>
Mon, 26 Jun 2017 16:48:52 +0200
changeset 91 143ff08ec2cc
parent 90 990f2c928b15
child 92 5a73b44925f2
DRY
client/src/reducers/authReducer.js
client/src/store/configureStore.js
--- a/client/src/reducers/authReducer.js	Mon Jun 26 16:43:22 2017 +0200
+++ b/client/src/reducers/authReducer.js	Mon Jun 26 16:48:52 2017 +0200
@@ -1,6 +1,7 @@
 import Immutable from 'immutable';
 import * as types from '../constants/actionTypes';
 import UserRecord from '../store/userRecord';
+import asyncRequest from '../constants/asyncRequest';
 
 export const isAuthenticated = (state = false, action) => {
   switch (action.type) {
@@ -43,14 +44,7 @@
   }
 }
 
-const loginState = Immutable.Map({
-  loading: false,
-  success: false,
-  error: false,
-  errorMessages: Immutable.Map({})
-});
-
-export const login = (state = loginState, action) => {
+export const login = (state = asyncRequest, action) => {
   switch (action.type) {
     case types.AUTH_LOGIN_REQUEST:
       return Immutable.Map({
@@ -71,14 +65,7 @@
   }
 }
 
-const registerState = Immutable.Map({
-  loading: false,
-  success: false,
-  error: false,
-  errorMessages: Immutable.Map({})
-});
-
-export const register = (state = registerState, action) => {
+export const register = (state = asyncRequest, action) => {
   switch (action.type) {
     case types.AUTH_REGISTER_REQUEST:
       return Immutable.Map({
--- a/client/src/store/configureStore.js	Mon Jun 26 16:43:22 2017 +0200
+++ b/client/src/store/configureStore.js	Mon Jun 26 16:48:52 2017 +0200
@@ -16,6 +16,7 @@
 import createEffect from '../api';
 import config from '../config';
 import { offlineConfigInitialized } from '../actions/networkActions';
+import asyncRequest from '../constants/asyncRequest';
 
 // const composeEnhancers = (process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ?
 //     window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
@@ -31,18 +32,8 @@
   currentUser: null,
   token: '',
   autoSubmit: false,
-  login: Immutable.Map({
-    loading: false,
-    success: false,
-    error: false,
-    errorMessages: Immutable.Map({})
-  }),
-  register: Immutable.Map({
-    loading: false,
-    success: false,
-    error: false,
-    errorMessages: Immutable.Map({})
-  }),
+  login: asyncRequest,
+  register: asyncRequest,
 };
 
 const immutableTransformConfig = {