Skip to content

Commit

Permalink
Fix user email (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
jggoebel authored Jun 14, 2024
1 parent 20a0921 commit 226d638
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
"cli": {
"schematicCollections": [
"@angular-eslint/schematics"
]
],
"analytics": false
},
"schematics": {
"@angular-eslint/schematics:application": {
Expand Down
8 changes: 1 addition & 7 deletions src/app/user/edit-user/edit-user.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
</clr-input-container>
<clr-input-container>
<label for="email">Email</label>
<input clrInput name="email" formControlName="email" required />
<clr-control-error *clrIfError="'required'"
>Email is required</clr-control-error
>
<clr-control-error *clrIfError="'email'"
>Input must be an email</clr-control-error
>
<input clrInput name="email" value="{{ this.user.email }}" disabled />
</clr-input-container>
<clr-input-container *rbac="['users.update']">
<label for="password">Password</label>
Expand Down
52 changes: 22 additions & 30 deletions src/app/user/edit-user/edit-user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ export class EditUserComponent implements OnInit, OnChanges {
}

public userDetailsForm: FormGroup<{
email: FormControl<string>;
password: FormControl<string>;
}> = new FormGroup({
email: new FormControl<string>(this.user.email, {
validators: [Validators.required, Validators.email],
nonNullable: true,
}),
password: new FormControl<string>('', { nonNullable: true }),
});

Expand All @@ -74,37 +69,34 @@ export class EditUserComponent implements OnInit, OnChanges {

saveDetails() {
this.saving = true;
var email = this.userDetailsForm.controls.email.value;
var password = this.userDetailsForm.controls.password.value;

if (email == null) {
email = '';
}

if (password == null) {
password = '';
}

this.userService.saveUser(this.user.id, email, password).subscribe({
next: (_s: ServerResponse) => {
this.alertText = 'User updated';
this.alertType = 'success';
this.alertClosed = false;
this.saving = false;
setTimeout(() => {
this.alertClosed = true;
}, 2000);
},
error: (s: ServerResponse) => {
this.alertText = 'Error updating user: ' + s.message;
this.alertType = 'danger';
this.alertClosed = false;
this.saving = false;
setTimeout(() => {
this.alertClosed = true;
}, 2000);
},
});
this.userService
.saveUser(this.user.id, this.user.email, password)
.subscribe({
next: (_s: ServerResponse) => {
this.alertText = 'User updated';
this.alertType = 'success';
this.alertClosed = false;
this.saving = false;
setTimeout(() => {
this.alertClosed = true;
}, 2000);
},
error: (s: ServerResponse) => {
this.alertText = 'Error updating user: ' + s.message;
this.alertType = 'danger';
this.alertClosed = false;
this.saving = false;
setTimeout(() => {
this.alertClosed = true;
}, 2000);
},
});
}

delete() {
Expand Down

0 comments on commit 226d638

Please sign in to comment.