Commit 0480bed5 authored by RenanMontenegro3's avatar RenanMontenegro3

feat:"reconhecimento do enter + alteração da página inicial de users"

parent 4d6a8f7a
<div class="input-wrapper"> <div class="input-wrapper">
<label [for]="inputName">{{ label }}</label> <label [for]="inputName">{{ label }}</label>
<div class="input-content"> <div class="input-content">
<input <input
[type]="type" [type]="type"
[placeholder]="placeholder" [placeholder]="placeholder"
[value]="value" [value]="value"
(input)="onInput($event)" (input)="onInput($event)"
(keydown.enter)="enterPressed.emit($event)"
/> />
</div> </div>
</div> </div>
import { Component, Input, forwardRef } from '@angular/core'; import { Component, Input, Output, EventEmitter, forwardRef } from '@angular/core';
import { ControlValueAccessor, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; import { ControlValueAccessor, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
type InputTypes = "text" | "email" | "password" type InputTypes = "text" | "email" | "password"
...@@ -25,6 +25,8 @@ export class PrimaryInputComponent implements ControlValueAccessor { ...@@ -25,6 +25,8 @@ export class PrimaryInputComponent implements ControlValueAccessor {
@Input() label: string = ""; @Input() label: string = "";
@Input() inputName: string = ""; @Input() inputName: string = "";
@Output() enterPressed = new EventEmitter<Event>();
value: string = '' value: string = ''
onChange: any = () => {} onChange: any = () => {}
onTouched: any = () => {} onTouched: any = () => {}
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
type="email" type="email"
label="Email" label="Email"
placeholder="johndoe@gmail.com" placeholder="johndoe@gmail.com"
(enterPressed)="submit()"
> >
</app-primary-input> </app-primary-input>
<app-primary-input <app-primary-input
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
type="password" type="password"
label="Your Password" label="Your Password"
placeholder="Senha" placeholder="Senha"
(enterPressed)="submit()"
> >
</app-primary-input> </app-primary-input>
<span>Forgot password?</span> <span>Forgot password?</span>
......
...@@ -12,7 +12,7 @@ import { Router } from '@angular/router'; ...@@ -12,7 +12,7 @@ import { Router } from '@angular/router';
import { LoginService } from '../../services/login.service'; import { LoginService } from '../../services/login.service';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { AuthService } from '../../auth.service'; import { AuthService } from '../../auth.service';
import { JwtDecoderService } from '../../jwt-decoder.service';
interface LoginForm { interface LoginForm {
email: FormControl; email: FormControl;
password: FormControl; password: FormControl;
...@@ -37,7 +37,8 @@ export class LoginComponent { ...@@ -37,7 +37,8 @@ export class LoginComponent {
private router: Router, private router: Router,
private authService: AuthService, private authService: AuthService,
private loginService: LoginService, private loginService: LoginService,
private toastService: ToastrService private toastService: ToastrService,
private jwtDecoderService: JwtDecoderService
) { ) {
this.loginForm = new FormGroup({ this.loginForm = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email]), email: new FormControl('', [Validators.required, Validators.email]),
...@@ -49,20 +50,23 @@ export class LoginComponent { ...@@ -49,20 +50,23 @@ export class LoginComponent {
} }
submit() { submit() {
this.loginService this.loginService
.login(this.loginForm.value.email, this.loginForm.value.password) .login(this.loginForm.value.email, this.loginForm.value.password)
.subscribe({ .subscribe({
next: () => { next: (response) => {
this.authService.updateAuthTokenStatus(true); this.authService.updateAuthTokenStatus(true);
const decodedToken = this.jwtDecoderService.decodeToken(response.accessToken);
if (decodedToken.role === 'COMPANY') {
this.router.navigate(['/dashboard']); this.router.navigate(['/dashboard']);
this.toastService.success('Login feito com sucesso!'); } else {
}, this.router.navigate(['/navio']);
error: () => }
this.toastService.error( this.toastService.success('Login feito com sucesso!');
'Erro inesperado! Tente novamente mais tarde' },
), error: () =>
}); this.toastService.error('Erro inesperado! Tente novamente mais tarde'),
} });
}
navigate() { navigate() {
this.router.navigate(['/signup']); this.router.navigate(['/signup']);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
type="text" type="text"
label="Your name" label="Your name"
placeholder="John Doe" placeholder="John Doe"
(enterPressed)="submit()"
> >
<img src="/assets/svg/email-icon.svg"/> <img src="/assets/svg/email-icon.svg"/>
</app-primary-input> </app-primary-input>
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
type="email" type="email"
label="Email" label="Email"
placeholder="johndoe@gmail.com" placeholder="johndoe@gmail.com"
(enterPressed)="submit()"
> >
<img src="/assets/svg/email-icon.svg"/> <img src="/assets/svg/email-icon.svg"/>
</app-primary-input> </app-primary-input>
...@@ -30,6 +32,7 @@ ...@@ -30,6 +32,7 @@
inputName="password" inputName="password"
type="password" type="password"
label="Your Password" label="Your Password"
(enterPressed)="submit()"
> >
<img src="/assets/svg/password-icon.svg"/> <img src="/assets/svg/password-icon.svg"/>
</app-primary-input> </app-primary-input>
...@@ -38,6 +41,7 @@ ...@@ -38,6 +41,7 @@
inputName="passwordConfirm" inputName="passwordConfirm"
type="password" type="password"
label="Confirm your Password" label="Confirm your Password"
(enterPressed)="submit()"
> >
<img src="/assets/svg/password-icon.svg"/> <img src="/assets/svg/password-icon.svg"/>
</app-primary-input> </app-primary-input>
...@@ -46,6 +50,7 @@ ...@@ -46,6 +50,7 @@
inputName="role" inputName="role"
type="text" type="text"
label="Your role" label="Your role"
(enterPressed)="submit()"
> >
<img src="/assets/svg/password-icon.svg"/> <img src="/assets/svg/password-icon.svg"/>
</app-primary-input> </app-primary-input>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment