dashboard.ts 662 Bytes
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1
2
import {RECEIVE_USER_PROFILE} from 'constants/user';
import update from 'immutability-helper';
3
import {User} from 'model/user/User';
4
import {LOGOUT} from 'constants/login';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

const INITIAL_STATE: {
  userProfile: User;
} = {
  userProfile: null,
};

export default function user(state = INITIAL_STATE, action: { type?: string, payload?: any } = {type: '', payload: {}}) {

  switch (action.type) {
    case RECEIVE_USER_PROFILE: {
      return update(state, {
        userProfile: { $set: action.payload },
      });
    }
20
21
22
23
24
    case LOGOUT: {
      return update(state, {
        userProfile: { $set: null },
      });
    }
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
25
26
27
28
    default:
      return state;
  }
}