Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: TT-155 create user module and model
  • Loading branch information
Angeluz-07 committed Mar 19, 2021
commit cf2c16a9a8748065b5f53d8a76b028e9ffae7abc
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { ProjectTypeListComponent } from './modules/customer-management/componen
import { CreateProjectTypeComponent } from './modules/customer-management/components/projects-type/components/create-project-type/create-project-type.component';
import { CustomerEffects } from './modules/customer-management/store/customer-management.effects';
import { UserEffects as UsersEffects } from './modules/users/store/user.effects';
import { UserEffects } from './modules/login/store/user.effects';
import { UserEffects } from './modules/user/store/user.effects';
import { EntryEffects } from './modules/time-clock/store/entry.effects';
import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.token.interceptor';
import { SubstractDatePipe } from './modules/shared/pipes/substract-date/substract-date.pipe';
Expand Down
13 changes: 1 addition & 12 deletions src/app/modules/shared/components/user/user.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { AzureAdB2CService } from '../../../login/services/azure.ad.b2c.service';

import { select, Store } from '@ngrx/store';
import { getUserInfo } from '../../../login/store/user.selectors';
import { Subscription } from 'rxjs';
import { LoadUser } from '../../../login/store/user.actions';

@Component({
selector: 'app-user',
Expand All @@ -13,19 +9,12 @@ import { LoadUser } from '../../../login/store/user.actions';
})
export class UserComponent implements OnInit {
name: string;
userSubscription: Subscription;

constructor(private azureAdB2CService: AzureAdB2CService, private store: Store) {}
constructor(private azureAdB2CService: AzureAdB2CService) {}

ngOnInit(): void {
if (this.azureAdB2CService.isLogin()) {
this.name = this.azureAdB2CService.getName();
const userId = this.azureAdB2CService.getUserId();

this.store.dispatch(new LoadUser(userId));
this.userSubscription = this.store.pipe(select(getUserInfo)).subscribe((response) => {
console.log('from Store: ', response);
});
this.azureAdB2CService.setTenantId();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/modules/user/models/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface User {
name: string;
email: string;
roles?: string[];
groups?: string[];
id: string;
tenant_id?: string;
deleted?: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Action } from '@ngrx/store';
import { User } from '../models/user';

export enum UserActionTypes {
LOAD_USER = '[User] LOAD_USER',
Expand All @@ -14,7 +15,7 @@ export class LoadUser implements Action {
export class LoadUserSuccess implements Action {
public readonly type = UserActionTypes.LOAD_USER_SUCCESS;

constructor(readonly payload: any) {}
constructor(readonly payload: User) {}
}

export class LoadUserFail implements Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { UserActions, UserActionTypes } from './user.actions';

export const initialState = {
name: '',
email: '',
roles: [],
groups: [],
};

Expand All @@ -10,11 +12,7 @@ export const userReducer = (state: any = initialState, action: UserActions): any
case UserActionTypes.LOAD_USER:
return state;
case UserActionTypes.LOAD_USER_SUCCESS:
return {
...state,
name: action.payload.name,
groups: action.payload.groups,
};
return action.payload;
case UserActionTypes.LOAD_USER_FAIL:
return state;
default: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { customerManagementReducer } from '../modules/customer-management/store/
import { projectTypeReducer } from '../modules/customer-management/components/projects-type/store/project-type.reducers';
import { entryReducer } from '../modules/time-clock/store/entry.reducer';
import { environment } from '../../environments/environment';
import { userReducer } from '../modules/login/store/user.reducer';
import { userReducer } from '../modules/user/store/user.reducer';
import { userReducer as usersReducer } from '../modules/users/store/user.reducers';
export interface State {
projects;
Expand Down