179. Update user / test user update (#26)

This commit is contained in:
Art
2021-09-22 12:30:24 +03:00
parent c8d22c6b37
commit 72a32b5d31
2 changed files with 21 additions and 5 deletions

View File

@ -168,9 +168,8 @@
</div>
<div class="tab-content pt-3">
<div class="tab-pane active">
<form #profileUserForm="ngForm" (ngSubmit)="onUpdateCurrentUser(profileUserForm)"
class="form"
novalidate>
<form #profileUserForm="ngForm" (ngSubmit)="onUpdateCurrentUser(profileUserForm.value)"
class="form" novalidate>
<div class="row">
<div class="col">
<div class="row">

View File

@ -200,8 +200,25 @@ export class UserComponent implements OnInit, OnDestroy {
this.subscriptions.push(subscription);
}
onUpdateCurrentUser(profileUserForm: any) {
onUpdateCurrentUser(user: User) {
this.currentUsername = this.authenticationService.getUserFromLocalStorage().username;
this.refreshing = true;
const formData = this.userService.createUserFormData(this.currentUsername, user, this.profileImage);
let subscription = this.userService.updateUser(formData)
.subscribe(
(user: User) => {
this.authenticationService.addUserToLocalStorage(user);
this.getUsers(false);
this.invalidateVariables();
this.notificationService.notify(NotificationType.SUCCESS, `User ${user.username} updated successfully`);
this.refreshing = false;
},
(errorResponse: HttpErrorResponse) => {
this.sendErrorNotification(errorResponse.error.message);
this.refreshing = false;
}
);
this.subscriptions.push(subscription);
}
onLogOut() {