Commit 0480bed5 authored by RenanMontenegro3's avatar RenanMontenegro3

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

parent 4d6a8f7a
......@@ -6,6 +6,7 @@
[placeholder]="placeholder"
[value]="value"
(input)="onInput($event)"
(keydown.enter)="enterPressed.emit($event)"
/>
</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';
type InputTypes = "text" | "email" | "password"
......@@ -25,6 +25,8 @@ export class PrimaryInputComponent implements ControlValueAccessor {
@Input() label: string = "";
@Input() inputName: string = "";
@Output() enterPressed = new EventEmitter<Event>();
value: string = ''
onChange: any = () => {}
onTouched: any = () => {}
......
......@@ -13,6 +13,7 @@
type="email"
label="Email"
placeholder="johndoe@gmail.com"
(enterPressed)="submit()"
>
</app-primary-input>
<app-primary-input
......@@ -21,6 +22,7 @@
type="password"
label="Your Password"
placeholder="Senha"
(enterPressed)="submit()"
>
</app-primary-input>
<span>Forgot password?</span>
......
......@@ -12,7 +12,7 @@ import { Router } from '@angular/router';
import { LoginService } from '../../services/login.service';
import { ToastrService } from 'ngx-toastr';
import { AuthService } from '../../auth.service';
import { JwtDecoderService } from '../../jwt-decoder.service';
interface LoginForm {
email: FormControl;
password: FormControl;
......@@ -37,7 +37,8 @@ export class LoginComponent {
private router: Router,
private authService: AuthService,
private loginService: LoginService,
private toastService: ToastrService
private toastService: ToastrService,
private jwtDecoderService: JwtDecoderService
) {
this.loginForm = new FormGroup({
email: new FormControl('', [Validators.required, Validators.email]),
......@@ -52,17 +53,20 @@ export class LoginComponent {
this.loginService
.login(this.loginForm.value.email, this.loginForm.value.password)
.subscribe({
next: () => {
next: (response) => {
this.authService.updateAuthTokenStatus(true);
const decodedToken = this.jwtDecoderService.decodeToken(response.accessToken);
if (decodedToken.role === 'COMPANY') {
this.router.navigate(['/dashboard']);
} else {
this.router.navigate(['/navio']);
}
this.toastService.success('Login feito com sucesso!');
},
error: () =>
this.toastService.error(
'Erro inesperado! Tente novamente mais tarde'
),
this.toastService.error('Erro inesperado! Tente novamente mais tarde'),
});
}
}
navigate() {
this.router.navigate(['/signup']);
......
......@@ -13,6 +13,7 @@
type="text"
label="Your name"
placeholder="John Doe"
(enterPressed)="submit()"
>
<img src="/assets/svg/email-icon.svg"/>
</app-primary-input>
......@@ -22,6 +23,7 @@
type="email"
label="Email"
placeholder="johndoe@gmail.com"
(enterPressed)="submit()"
>
<img src="/assets/svg/email-icon.svg"/>
</app-primary-input>
......@@ -30,6 +32,7 @@
inputName="password"
type="password"
label="Your Password"
(enterPressed)="submit()"
>
<img src="/assets/svg/password-icon.svg"/>
</app-primary-input>
......@@ -38,6 +41,7 @@
inputName="passwordConfirm"
type="password"
label="Confirm your Password"
(enterPressed)="submit()"
>
<img src="/assets/svg/password-icon.svg"/>
</app-primary-input>
......@@ -46,6 +50,7 @@
inputName="role"
type="text"
label="Your role"
(enterPressed)="submit()"
>
<img src="/assets/svg/password-icon.svg"/>
</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