client/src/reducers/authReducer.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 168 ea92f4fe783d
child 199 c78d579f4b55
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
     1
import * as R from 'ramda';
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
     2
import * as types from '../constants/actionTypes';
67
9206af01f5e5 Change to UserRecord
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
     3
import UserRecord from '../store/userRecord';
132
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
     4
import GroupRecord from '../store/groupRecord';
91
Alexandre Segura <mex.zktk@gmail.com>
parents: 90
diff changeset
     5
import asyncRequest from '../constants/asyncRequest';
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
     6
import uuidV4 from 'uuid/v4';
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
     7
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
     8
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
     9
export const isAuthenticated = (state = false, action) => {
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    10
  switch (action.type) {
88
2a861fed6bde Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
    11
    case types.AUTH_DEAUTHENTICATE:
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    12
    case types.AUTH_LOGOUT:
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    13
      return false;
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    14
    case types.AUTH_LOGIN_SUCCESS:
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    15
      return true;
12
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    16
    default:
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    17
      return state;
48ddaa42b810 Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
diff changeset
    18
  }
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    19
}
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    20
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    21
export const currentUser = (state = null, action) => {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    22
  switch (action.type) {
88
2a861fed6bde Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
    23
    case types.AUTH_DEAUTHENTICATE:
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
    24
    case types.AUTH_LOGOUT:
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
    25
      return null;
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    26
    case types.AUTH_LOGIN_SUCCESS:
67
9206af01f5e5 Change to UserRecord
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
    27
      return new UserRecord(action.user);
53
d8588379529e Add settings page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 52
diff changeset
    28
    case types.USER_UPDATE_SETTINGS:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    29
      return R.merge(state,{
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    30
        first_name: action.firstname,
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    31
        last_name: action.lastname
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 53
diff changeset
    32
      });
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    33
    default:
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    34
      return state;
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    35
  }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    36
}
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    37
134
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    38
export const currentGroup = (state = null, action) => {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    39
  switch (action.type) {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    40
    case types.AUTH_DEAUTHENTICATE:
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    41
    case types.AUTH_LOGOUT:
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    42
      return null;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    43
    case types.AUTH_LOGIN_SUCCESS:
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    44
      if( state === null) {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    45
        return action.user.default_group;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    46
      }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    47
      return state;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    48
    case types.GROUP_CREATE_SUCCESS: {
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    49
      return action.group.name;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    50
    }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    51
    case types.GROUP_SET_GROUP:
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    52
      return action.group;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    53
    default:
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    54
      return state;
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    55
  }
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    56
}
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    57
be36eed5e6e0 add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents: 132
diff changeset
    58
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    59
export const token = (state = null, action) => {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    60
  switch (action.type) {
88
2a861fed6bde Deauthenticate user if refresh was not possible (session expired or total delta reached)
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
    61
    case types.AUTH_DEAUTHENTICATE:
52
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
    62
    case types.AUTH_LOGOUT:
96f8a4a59bd9 Implement logout.
Alexandre Segura <mex.zktk@gmail.com>
parents: 47
diff changeset
    63
      return null;
47
64428c7ebc19 Store token & user.
Alexandre Segura <mex.zktk@gmail.com>
parents: 44
diff changeset
    64
    case types.AUTH_STORE_TOKEN:
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    65
      return action.token;
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    66
    default:
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    67
      return state;
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    68
  }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    69
}
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    70
129
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    71
export const clientId = (state = null, action) => {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    72
  switch (action.type) {
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    73
    case types.AUTH_DEAUTHENTICATE:
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    74
    case types.AUTH_LOGOUT:
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    75
      return null;
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    76
    case types.AUTH_LOGIN_SUCCESS:
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    77
      return uuidV4();
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    78
    default:
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    79
      return state;
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    80
  }
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    81
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    82
}
d48946d164c6 Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents: 101
diff changeset
    83
91
Alexandre Segura <mex.zktk@gmail.com>
parents: 90
diff changeset
    84
export const login = (state = asyncRequest, action) => {
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    85
  switch (action.type) {
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    86
    case types.AUTH_LOGIN_REQUEST:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    87
      return {
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    88
        loading: true,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    89
        success: false,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    90
        error: false,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    91
      }
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    92
    case types.AUTH_LOGIN_SUCCESS:
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    93
    case types.AUTH_LOGIN_ERROR:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    94
      return {
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    95
        loading: false,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    96
        success: action.type === types.AUTH_LOGIN_SUCCESS,
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
    97
        error: action.type === types.AUTH_LOGIN_ERROR,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    98
        errorMessages: action.type === types.AUTH_LOGIN_ERROR ? action.error : {}
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
    99
      }
44
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
   100
    default:
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
   101
      return state
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
   102
  }
3b20e2b584fe Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
   103
}
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   104
91
Alexandre Segura <mex.zktk@gmail.com>
parents: 90
diff changeset
   105
export const register = (state = asyncRequest, action) => {
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   106
  switch (action.type) {
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   107
    case types.AUTH_REGISTER_REQUEST:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   108
      return {
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   109
        loading: true,
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   110
        success: false,
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   111
        error: false,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   112
      }
90
990f2c928b15 Improve login errors.
Alexandre Segura <mex.zktk@gmail.com>
parents: 89
diff changeset
   113
    case types.AUTH_LOGIN_SUCCESS:
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   114
    case types.AUTH_REGISTER_ERROR:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   115
      return {
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   116
        loading: false,
90
990f2c928b15 Improve login errors.
Alexandre Segura <mex.zktk@gmail.com>
parents: 89
diff changeset
   117
        success: action.type === types.AUTH_LOGIN_SUCCESS,
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   118
        error: action.type === types.AUTH_REGISTER_ERROR,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   119
        errorMessages: action.type === types.AUTH_REGISTER_ERROR ? action.error : {}
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   120
      }
89
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   121
    default:
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   122
      return state
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   123
  }
06f609adfbf8 Add registration page.
Alexandre Segura <mex.zktk@gmail.com>
parents: 88
diff changeset
   124
}
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   125
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   126
const groupTransformIsPersonal = R.compose(
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   127
  GroupRecord,
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   128
  R.converge(
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   129
    R.merge,
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   130
    [
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   131
      R.omit('is_personal'),
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   132
      R.compose(
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   133
        R.objOf('isPersonal'),
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   134
        R.propOr(false, 'is_personal')
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   135
      )
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   136
    ]
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   137
  )
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   138
);
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   139
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   140
export const groups = (state = [], action) => {
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   141
  switch (action.type) {
101
e165aa89ac82 Add group dropdown, update session after group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 100
diff changeset
   142
    case types.GROUP_LOAD_SUCCESS:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   143
      return R.map(groupTransformIsPersonal, action.groups)
101
e165aa89ac82 Add group dropdown, update session after group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 100
diff changeset
   144
    case types.GROUP_CREATE_SUCCESS:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   145
      return R.append(groupTransformIsPersonal(action.group), state);
132
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   146
    case types.AUTH_LOGOUT: {
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   147
      return []; // empty note list on logout
132
906a6c7c7943 add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   148
    }
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   149
    default:
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   150
      return state
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   151
  }
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   152
}
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   153
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   154
export const createGroup = (state = asyncRequest, action) => {
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   155
  switch (action.type) {
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   156
    case types.GROUP_CREATE_ASYNC:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   157
      return {
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   158
        loading: true,
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   159
        success: false,
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   160
        error: false,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   161
      }
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   162
    case types.GROUP_CREATE_SUCCESS:
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   163
    case types.GROUP_CREATE_ERROR:
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   164
      return {
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   165
        loading: false,
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   166
        success: action.type === types.GROUP_CREATE_SUCCESS,
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   167
        error: action.type === types.GROUP_CREATE_ERROR,
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   168
        errorMessages: action.type === types.GROUP_CREATE_ERROR ? action.error : {}
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 134
diff changeset
   169
      }
100
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   170
    default:
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   171
      return state
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   172
  }
6fd752d98933 Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents: 91
diff changeset
   173
}