Implementation of Better Error Handling on SignUp
This commit is contained in:
@@ -1,73 +1,85 @@
|
||||
<app-popup [state]="state"
|
||||
(stateChange)="onStateChange($event)"
|
||||
(stateChange)="onStateChange($event)"
|
||||
[ignoreClickOutside]="ignoreClickOutside">
|
||||
{{errorMessage}}
|
||||
<div class="container authentication-container">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 auth-body auth-body-form">
|
||||
<form [formGroup]="signupForm" (ngSubmit)="onSignUp()">
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_fullnameIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="fullname"
|
||||
formControlName="fullname"
|
||||
class="form-control"
|
||||
placeholder="Full Name">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_emailIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="email"
|
||||
formControlName="email"
|
||||
class="form-control"
|
||||
placeholder="Email">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_userIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="username"
|
||||
formControlName="username"
|
||||
class="form-control"
|
||||
placeholder="Username">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_passwordIcon">
|
||||
</fa-icon>
|
||||
<input type="password" id="password"
|
||||
formControlName="password"
|
||||
class="form-control"
|
||||
placeholder="Password">
|
||||
</div>
|
||||
<button class="btn"
|
||||
type="submit">
|
||||
SignUp
|
||||
|
||||
|
||||
<div class="container m-0 overflow-hidden"
|
||||
[@resizeContainerForErrorMessage]="hideErrorMessage()">
|
||||
|
||||
<app-error-box [errorMessage]="errorMessage"
|
||||
[@showErrorMessage]="showErrorMessage()">
|
||||
</app-error-box>
|
||||
|
||||
<div class="container authentication-container"
|
||||
[@hideAuthContainer]="hideErrorMessage()"
|
||||
(@hideAuthContainer.done)="hideAuthContainer($event)">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 auth-body auth-body-form">
|
||||
<form [formGroup]="signupForm" (ngSubmit)="onSignUp()">
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_fullnameIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="fullname"
|
||||
formControlName="fullname"
|
||||
class="form-control"
|
||||
placeholder="Full Name">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_emailIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="email"
|
||||
formControlName="email"
|
||||
class="form-control"
|
||||
placeholder="Email">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_userIcon">
|
||||
</fa-icon>
|
||||
<input type="text" id="username"
|
||||
formControlName="username"
|
||||
class="form-control"
|
||||
placeholder="Username">
|
||||
</div>
|
||||
<div class="input-div">
|
||||
<fa-icon class="input-div-icon"
|
||||
[icon]="_passwordIcon">
|
||||
</fa-icon>
|
||||
<input type="password" id="password"
|
||||
formControlName="password"
|
||||
class="form-control"
|
||||
placeholder="Password">
|
||||
</div>
|
||||
<button class="btn"
|
||||
type="submit">
|
||||
SignUp
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="separator-line">
|
||||
<div class="line"></div>
|
||||
</div>
|
||||
<div class="col-lg-6 auth-body auth-body-links">
|
||||
<button mat-button
|
||||
class="oauth-button d-flex justify-content-center align-items-center"
|
||||
(click)="onGoogleLogin()">
|
||||
<mat-icon style="width: 50px; height:30px"
|
||||
svgIcon="google-logo"></mat-icon>
|
||||
Login With Google
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="separator-line">
|
||||
<div class="line"></div>
|
||||
</div>
|
||||
<div class="col-lg-6 auth-body auth-body-links">
|
||||
<button mat-button
|
||||
class="oauth-button d-flex justify-content-center align-items-center"
|
||||
(click)="onGoogleLogin()">
|
||||
<mat-icon style="width: 50px; height:30px"
|
||||
svgIcon="google-logo"></mat-icon>
|
||||
Login With Google
|
||||
</button>
|
||||
<button mat-button
|
||||
class="oauth-button d-flex justify-content-center align-items-center"
|
||||
(click)="onGithubLogin()">
|
||||
<mat-icon style="width: 50px; height:30px"
|
||||
svgIcon="github-logo"></mat-icon>
|
||||
Login With Github
|
||||
</button>
|
||||
<button mat-button
|
||||
class="oauth-button d-flex justify-content-center align-items-center"
|
||||
(click)="onGithubLogin()">
|
||||
<mat-icon style="width: 50px; height:30px"
|
||||
svgIcon="github-logo"></mat-icon>
|
||||
Login With Github
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</app-popup>
|
||||
</app-popup>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { HttpError } from 'src/app/shared/model/httpError/httpError.model';
|
||||
import HttpErrorChecker from 'src/app/shared/model/httpError/httpErrorChecker';
|
||||
import UserChecker from 'src/app/shared/model/user/user.checker';
|
||||
import { User } from 'src/app/shared/model/user/user.model';
|
||||
import {animate, animateChild, group, query, state, style, transition, trigger} from "@angular/animations";
|
||||
|
||||
|
||||
const GOOGLE_LOGO_SVG = "assets/img/providers/google.svg";
|
||||
@@ -17,18 +18,81 @@ const GITHUB_LOGO_SVG = "assets/img/providers/github.svg";
|
||||
@Component({
|
||||
selector: 'app-signup',
|
||||
templateUrl: './signup.component.html',
|
||||
styleUrls: ['./signup.component.css']
|
||||
styleUrls: ['./signup.component.css'],
|
||||
animations: [
|
||||
trigger('resizeContainerForErrorMessage', [
|
||||
state('hide',
|
||||
style({
|
||||
height: '100px',
|
||||
width: '320px',
|
||||
})
|
||||
),
|
||||
transition(
|
||||
'show => hide',
|
||||
group([
|
||||
query(
|
||||
"@*",
|
||||
animateChild(),
|
||||
{ optional: true }
|
||||
),
|
||||
animate('1s ease')
|
||||
])
|
||||
)
|
||||
]),
|
||||
trigger('showErrorMessage', [
|
||||
state('show',
|
||||
style({
|
||||
opacity: 1,
|
||||
height: '100px',
|
||||
width: '320px',
|
||||
})
|
||||
),
|
||||
state('hide',
|
||||
style({
|
||||
opacity: 0,
|
||||
height: '0px',
|
||||
width: '0px',
|
||||
})
|
||||
),
|
||||
transition(
|
||||
'* => show',
|
||||
animate(
|
||||
'500ms ease-in'
|
||||
)
|
||||
),
|
||||
]),
|
||||
trigger('hideAuthContainer', [
|
||||
state('hide',
|
||||
style({
|
||||
opacity: 0,
|
||||
})
|
||||
),
|
||||
transition(
|
||||
'show => hide',
|
||||
group([
|
||||
query(
|
||||
"@*",
|
||||
animateChild(),
|
||||
{ optional: true }
|
||||
),
|
||||
animate(
|
||||
'250ms ease-out'
|
||||
)
|
||||
])
|
||||
)
|
||||
]),
|
||||
]
|
||||
})
|
||||
export class SignupComponent implements OnInit {
|
||||
|
||||
@Input()
|
||||
state: boolean = false;
|
||||
state: boolean = false;
|
||||
|
||||
@Input()
|
||||
ignoreClickOutside!: HTMLDivElement[];
|
||||
ignoreClickOutside!: HTMLDivElement[];
|
||||
|
||||
@Output()
|
||||
stateChange = new EventEmitter<boolean>();
|
||||
stateChange = new EventEmitter<boolean>();
|
||||
|
||||
signupForm!: FormGroup;
|
||||
|
||||
@@ -36,6 +100,8 @@ export class SignupComponent implements OnInit {
|
||||
|
||||
errorMessage!: string | null;
|
||||
|
||||
isShowErrorMessage = false;
|
||||
|
||||
_fullnameIcon = faFingerprint;
|
||||
|
||||
_emailIcon = faEnvelope;
|
||||
@@ -47,15 +113,15 @@ export class SignupComponent implements OnInit {
|
||||
constructor(private authService: AuthService,
|
||||
private matIconRegistry: MatIconRegistry,
|
||||
private domSanitizer: DomSanitizer) {
|
||||
this.matIconRegistry.addSvgIcon(
|
||||
"google-logo",
|
||||
this.domSanitizer.bypassSecurityTrustResourceUrl(GOOGLE_LOGO_SVG)
|
||||
);
|
||||
this.matIconRegistry.addSvgIcon(
|
||||
"github-logo",
|
||||
this.domSanitizer.bypassSecurityTrustResourceUrl(GITHUB_LOGO_SVG)
|
||||
);
|
||||
}
|
||||
this.matIconRegistry.addSvgIcon(
|
||||
"google-logo",
|
||||
this.domSanitizer.bypassSecurityTrustResourceUrl(GOOGLE_LOGO_SVG)
|
||||
);
|
||||
this.matIconRegistry.addSvgIcon(
|
||||
"github-logo",
|
||||
this.domSanitizer.bypassSecurityTrustResourceUrl(GITHUB_LOGO_SVG)
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.signupForm = new FormGroup({
|
||||
@@ -110,5 +176,26 @@ export class SignupComponent implements OnInit {
|
||||
this.signupForm.reset();
|
||||
}
|
||||
|
||||
public showErrorMessage(): string {
|
||||
if (this.isShowErrorMessage) {
|
||||
return "show";
|
||||
}
|
||||
return "hide";
|
||||
}
|
||||
|
||||
public hideErrorMessage(): string {
|
||||
if (!!this.errorMessage) {
|
||||
return "hide";
|
||||
}
|
||||
return "show";
|
||||
}
|
||||
|
||||
hideAuthContainer(event: any) {
|
||||
if (event.toState === "hide") {
|
||||
event.element.style.display = "none";
|
||||
this.isShowErrorMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user