--- a/client/src/reducers/authReducer.js Tue Oct 09 19:07:47 2018 +0200
+++ b/client/src/reducers/authReducer.js Mon Oct 08 18:35:47 2018 +0200
@@ -1,10 +1,10 @@
-import Immutable from 'immutable';
+import * as R from 'ramda';
import * as types from '../constants/actionTypes';
import UserRecord from '../store/userRecord';
import GroupRecord from '../store/groupRecord';
import asyncRequest from '../constants/asyncRequest';
import uuidV4 from 'uuid/v4';
-import _ from 'lodash';
+
export const isAuthenticated = (state = false, action) => {
switch (action.type) {
@@ -26,7 +26,7 @@
case types.AUTH_LOGIN_SUCCESS:
return new UserRecord(action.user);
case types.USER_UPDATE_SETTINGS:
- return state.merge({
+ return R.merge(state,{
first_name: action.firstname,
last_name: action.lastname
});
@@ -84,19 +84,19 @@
export const login = (state = asyncRequest, action) => {
switch (action.type) {
case types.AUTH_LOGIN_REQUEST:
- return Immutable.Map({
+ return {
loading: true,
success: false,
error: false,
- })
+ }
case types.AUTH_LOGIN_SUCCESS:
case types.AUTH_LOGIN_ERROR:
- return Immutable.Map({
+ return {
loading: false,
success: action.type === types.AUTH_LOGIN_SUCCESS,
error: action.type === types.AUTH_LOGIN_ERROR,
- errorMessages: action.type === types.AUTH_LOGIN_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
- })
+ errorMessages: action.type === types.AUTH_LOGIN_ERROR ? action.error : {}
+ }
default:
return state
}
@@ -105,40 +105,46 @@
export const register = (state = asyncRequest, action) => {
switch (action.type) {
case types.AUTH_REGISTER_REQUEST:
- return Immutable.Map({
+ return {
loading: true,
success: false,
error: false,
- })
+ }
case types.AUTH_LOGIN_SUCCESS:
case types.AUTH_REGISTER_ERROR:
- return Immutable.Map({
+ return {
loading: false,
success: action.type === types.AUTH_LOGIN_SUCCESS,
error: action.type === types.AUTH_REGISTER_ERROR,
- errorMessages: action.type === types.AUTH_REGISTER_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
- })
+ errorMessages: action.type === types.AUTH_REGISTER_ERROR ? action.error : {}
+ }
default:
return state
}
}
-export const groups = (state = Immutable.List([]), action) => {
+const groupTransformIsPersonal = R.compose(
+ GroupRecord,
+ R.converge(
+ R.merge,
+ [
+ R.omit('is_personal'),
+ R.compose(
+ R.objOf('isPersonal'),
+ R.propOr(false, 'is_personal')
+ )
+ ]
+ )
+);
+
+export const groups = (state = [], action) => {
switch (action.type) {
case types.GROUP_LOAD_SUCCESS:
- return Immutable.List(
- action.groups.map((group) => GroupRecord({
- ...(_.omit(group, 'is_personal')),
- isPersonal: group['is_personal']
- }))
- );
+ return R.map(groupTransformIsPersonal, action.groups)
case types.GROUP_CREATE_SUCCESS:
- return state.push(GroupRecord({
- ...(_.omit(action.group, 'is_personal')),
- isPersonal: action.group['is_personal']
- }));
+ return R.append(groupTransformIsPersonal(action.group), state);
case types.AUTH_LOGOUT: {
- return Immutable.List(); // empty note list on logout
+ return []; // empty note list on logout
}
default:
return state
@@ -148,19 +154,19 @@
export const createGroup = (state = asyncRequest, action) => {
switch (action.type) {
case types.GROUP_CREATE_ASYNC:
- return Immutable.Map({
+ return {
loading: true,
success: false,
error: false,
- })
+ }
case types.GROUP_CREATE_SUCCESS:
case types.GROUP_CREATE_ERROR:
- return Immutable.Map({
+ return {
loading: false,
success: action.type === types.GROUP_CREATE_SUCCESS,
error: action.type === types.GROUP_CREATE_ERROR,
- errorMessages: action.type === types.GROUP_CREATE_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
- })
+ errorMessages: action.type === types.GROUP_CREATE_ERROR ? action.error : {}
+ }
default:
return state
}