File size: 686 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { ACTION, UserActionTypes } from '../actions/types';

export interface UserStore {
  isSignedIn: boolean;
  isAdmin: boolean;
  userId: string;
  userName: string;
}

const initialState = {
  isSignedIn: false,
  isAdmin: false,
  userId: '',
  userName: ''
};

export const userReducer = (state: UserStore = initialState, action: UserActionTypes): UserStore => {
  switch (action.type) {
    case ACTION.SIGN_IN:
      return { ...state, isSignedIn: true, userId: action.payload.userId, userName: action.payload.userName };
    case ACTION.SIGN_OUT:
      return { ...state, isSignedIn: false, userId: '', userName: '', isAdmin: false };
    default:
      return state;
  }
};