disable signup/signin button when loading.

This commit is contained in:
Jason Kulatunga 2022-12-18 22:37:50 -08:00
parent c62595f5dc
commit 0677a0393e
4 changed files with 12 additions and 3 deletions

View File

@ -50,7 +50,7 @@
</div>
</div>
</div><!-- form-group -->
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Sign In</button>
<button [disabled]="!userForm.form.valid || loading" type="submit" class="btn btn-az-primary btn-block">Sign In</button>
<div *ngIf="errorMsg" class="alert alert-danger mt-3" role="alert">
<strong>Error</strong> {{errorMsg}}

View File

@ -60,10 +60,15 @@ export class AuthSigninComponent implements OnInit {
signinSubmit(){
this.submitted = true;
this.loading = true
this.authService.Signin(this.existingUser.username, this.existingUser.password)
.then(() => this.router.navigateByUrl('/dashboard'))
.then(() => {
this.loading = false
this.router.navigateByUrl('/dashboard')
})
.catch((err)=>{
this.loading = false
if(err?.name){
this.errorMsg = "username or password is incorrect"
} else{

View File

@ -61,7 +61,7 @@
</div>
</div>
</div><!-- form-group -->
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Create Account</button>
<button [disabled]="!userForm.form.valid || loading" type="submit" class="btn btn-az-primary btn-block">Create Account</button>
<div *ngIf="errorMsg" class="alert alert-danger mt-3" role="alert">
<strong>Error</strong> {{errorMsg}}

View File

@ -14,6 +14,7 @@ export class AuthSignupComponent implements OnInit {
submitted: boolean = false
newUser: User = new User()
errorMsg: string = ""
loading: boolean = false
constructor(
private authService: AuthService,
@ -25,13 +26,16 @@ export class AuthSignupComponent implements OnInit {
}
signupSubmit(){
this.loading = true
this.submitted = true;
this.authService.Signup(this.newUser).then((tokenResp: any) => {
this.loading = false
console.log(tokenResp);
this.router.navigateByUrl('/dashboard');
},
(err)=>{
this.loading = false
console.error("an error occured while signup",err)
if(err.name === 'conflict') {
// "batman" already exists, choose another username