35 lines
791 B
TypeScript
35 lines
791 B
TypeScript
import { UserAction, UserActions } from "@/state/actions/user";
|
|
|
|
export type UserState = {
|
|
loggedIn: boolean;
|
|
token?: string;
|
|
isManager: boolean;
|
|
isStudent: boolean;
|
|
}
|
|
|
|
const initialUserState: UserState = {
|
|
loggedIn: false,
|
|
isManager: false,
|
|
isStudent: false,
|
|
}
|
|
|
|
const userReducer = (state: UserState = initialUserState, action: UserAction): UserState => {
|
|
switch (action.type) {
|
|
case UserActions.Login:
|
|
return {
|
|
...state,
|
|
loggedIn: true,
|
|
token: action.token,
|
|
isManager: action.isManager,
|
|
isStudent: action.isManager,
|
|
}
|
|
|
|
case UserActions.Logout:
|
|
return initialUserState;
|
|
}
|
|
|
|
return state;
|
|
}
|
|
|
|
export default userReducer;
|