167. Refactor and test adding new user (#22)
This commit is contained in:
@ -186,7 +186,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div>
|
<div>
|
||||||
<form>
|
<form #newUserForm="ngForm" (ngSubmit)="onAddNewUser(newUserForm)" >
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="firstName">First Name</label>
|
<label for="firstName">First Name</label>
|
||||||
<input type="text" name="firstName" required ngModel class="form-control">
|
<input type="text" name="firstName" required ngModel class="form-control">
|
||||||
@ -222,8 +222,8 @@
|
|||||||
(change)="onProfileImageChange($any($event).target.files)"
|
(change)="onProfileImageChange($any($event).target.files)"
|
||||||
class="custom-file-input">
|
class="custom-file-input">
|
||||||
<label class="custom-file-label">
|
<label class="custom-file-label">
|
||||||
<span [hidden]="true"> fileName </span>
|
<span [hidden]="!profileImageFileName">{{profileImageFileName}}</span>
|
||||||
<span [hidden]="false">Choose File</span>
|
<span [hidden]="profileImageFileName">Choose File</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -247,7 +247,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" id="new-user-close">Close</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" id="new-user-close">Close</button>
|
||||||
<button type="button" class="btn btn-primary" (click)="saveNewUser()">Save changes</button>
|
<button type="button" class="btn btn-primary" (click)="saveNewUser()" [disabled]="newUserForm.invalid">Save changes</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
public onSelectUser(selectedUser: User): void {
|
public onSelectUser(selectedUser: User): void {
|
||||||
this.selectedUser = selectedUser;
|
this.selectedUser = selectedUser;
|
||||||
document.getElementById('openUserInfo')?.click();
|
this.clickButton('openUserInfo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public onProfileImageChange(fileList: FileList): void {
|
public onProfileImageChange(fileList: FileList): void {
|
||||||
@ -82,7 +82,7 @@ export class UserComponent implements OnInit, OnDestroy {
|
|||||||
let subscription = this.userService.addUser(formData)
|
let subscription = this.userService.addUser(formData)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(user: User) => {
|
(user: User) => {
|
||||||
document.getElementById('new-user-close')?.click();
|
this.clickButton('new-user-close');
|
||||||
this.getUsers(false);
|
this.getUsers(false);
|
||||||
this.invalidateVariables();
|
this.invalidateVariables();
|
||||||
userForm.reset();
|
userForm.reset();
|
||||||
@ -101,6 +101,10 @@ export class UserComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public saveNewUser(): void {
|
public saveNewUser(): void {
|
||||||
document.getElementById('new-user-save')?.click();
|
this.clickButton('new-user-save');
|
||||||
|
}
|
||||||
|
|
||||||
|
private clickButton(buttonId: string): void {
|
||||||
|
document.getElementById(buttonId)?.click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user