Skip to content

Commit

Permalink
Merge pull request #448 from bcgov/user-details-isactive-fix
Browse files Browse the repository at this point in the history
DSS-500: (FE) User Information Page - Adopted `isEnabled` property
  • Loading branch information
ychung-mot authored Jul 2, 2024
2 parents ee80c30 + bc7a5d4 commit a423b80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
1 change: 1 addition & 0 deletions frontend/src/app/common/services/user-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class UserDataService {
userIdentityId: number,
representedByOrganizationId: string,
roleCds: Array<string>,
isEnabled: boolean,
updDtm: string
}): Observable<any> {
return this.httpClient.put<UserDetails>(`${environment.API_HOST}/users/${data.userIdentityId}`, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,12 @@ export class UserDetailsComponent implements OnInit {

ngOnInit(): void {
this.id = Number(this.route.snapshot.params['id']);
console.log(this.id);

if (isNaN(this.id)) {
this.errorService.showError('Invalid User ID: User ID must consist of numbers only.');
this.router.navigate(['/user-management']);
}

this.loaderService.loadingStart();

this.init();
}

Expand All @@ -85,41 +82,18 @@ export class UserDetailsComponent implements OnInit {
}

onSave(): void {
// TODO: this part needs to be reconsidered. Either use concatMap or do everything in one API call (backend involvement required);
this.userService.updateUser({
roleCds: this.user.roleCds,
updDtm: this.user.updDtm,
userIdentityId: this.user.userIdentityId,
isEnabled: this.state === 'Active',
representedByOrganizationId: this.selectedOrg
}).subscribe({
next: (_) => {

if ((this.user.isEnabled && this.state === 'Disabled') || (!this.user.isEnabled && this.state === 'Active')) {
this.loaderService.loadingStart();

this.userService.getUserById(this.id).subscribe({
next: (user) => {
this.loaderService.loadingStart();

this.userService.updateIsEnabled(this.user.userIdentityId, this.state === 'Active', user.updDtm).subscribe({
next: () => {
this.init();
}, complete: () => {
this.loaderService.loadingEnd();
}
});

}, complete: () => {
this.loaderService.loadingEnd();
}
});
}

this.onCancel();
this.errorService.showSuccess('User has been successfully updated');
this.init();
this.isEdit = false;
},
complete: () => {

this.loaderService.loadingEnd();
this.cd.detectChanges();
}
Expand All @@ -139,6 +113,8 @@ export class UserDetailsComponent implements OnInit {
}

private init(): void {
this.loaderService.loadingStart();

forkJoin([
this.userService.getUserById(this.id),
this.rolesService.getRoles(),
Expand Down

0 comments on commit a423b80

Please sign in to comment.