Skip to content

Commit ef8e059

Browse files
authored
feat(sign-in): add feedback on sign-in page (#79)
* feat(sign-in): add feedback on sign-in page Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> * refactor: apply suggestions from code review * refactor: apply suggestions from code review * fix: adjust toast from user-configs page Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> --------- Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 884babd commit ef8e059

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
<router-outlet />
2-
3-
<p-toast position="bottom-right" key="toast"> </p-toast>

timeless-api/src/main/webui/src/app/app.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Component } from '@angular/core';
22
import { RouterOutlet } from '@angular/router';
33
import { MessageService } from 'primeng/api';
4-
import { ToastModule } from 'primeng/toast';
54

65
@Component({
76
selector: 'app-root',
8-
imports: [RouterOutlet, ToastModule],
7+
imports: [RouterOutlet],
98
templateUrl: './app.component.html',
109
styleUrl: './app.component.scss',
1110
providers: [MessageService],

timeless-api/src/main/webui/src/app/pages/sign/sign-in/sign-in.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ <h1 class="text-xl font-thin my-2">
4242
<a [routerLink]="['sign-up']" class="primary-emphasis font-normal">aqui</a>.
4343
</p>
4444
</form>
45+
46+
<p-toast position="bottom-right" key="toast"> </p-toast>

timeless-api/src/main/webui/src/app/pages/sign/sign-in/sign-in.component.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { TimelessApiService } from '../../../timeless-api.service';
88
import { FloatLabel } from 'primeng/floatlabel';
99
import { MessageService } from 'primeng/api';
1010
import { timelessLocalStorageKey } from '../../../constants';
11+
import { catchError, throwError } from 'rxjs';
12+
import { Toast } from 'primeng/toast';
1113

1214
@Component({
1315
selector: 'app-sign-in',
@@ -18,6 +20,7 @@ import { timelessLocalStorageKey } from '../../../constants';
1820
CardModule,
1921
RouterLink,
2022
FloatLabel,
23+
Toast,
2124
],
2225
templateUrl: './sign-in.component.html',
2326
styleUrl: './sign-in.component.scss',
@@ -48,11 +51,26 @@ export class SignInComponent {
4851
return;
4952
}
5053

51-
this.timelessApiService.signIn(this.form.value).subscribe((value) => {
52-
localStorage.setItem(timelessLocalStorageKey, JSON.stringify(value));
53-
this.router.navigate(['/home']).then((r) => {
54-
console.log('logged in');
54+
this.timelessApiService
55+
.signIn(this.form.value)
56+
.pipe(
57+
catchError((error) => {
58+
console.error('Login error:', error);
59+
this.messageService.add({
60+
key: 'toast',
61+
severity: 'error',
62+
summary: 'Erro ao fazer login',
63+
detail:
64+
'Não foi possível fazer login, verifique suas credenciais e tente novamente.',
65+
});
66+
return throwError(() => error);
67+
}),
68+
)
69+
.subscribe((value) => {
70+
localStorage.setItem(timelessLocalStorageKey, JSON.stringify(value));
71+
this.router.navigate(['/home']).then((r) => {
72+
console.log('logged in');
73+
});
5574
});
56-
});
5775
}
5876
}

timeless-api/src/main/webui/src/app/pages/user-config/user-config.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@
7676
</ng-template>
7777
</p-card>
7878
</form>
79+
80+
<p-toast position="bottom-right" key="toast"> </p-toast>

timeless-api/src/main/webui/src/app/pages/user-config/user-config.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@angular/forms';
1212
import { TimelessApiService } from '../../timeless-api.service';
1313
import { MessageService } from 'primeng/api';
14+
import { Toast } from 'primeng/toast';
1415

1516
@Component({
1617
selector: 'app-user-config',
@@ -21,6 +22,7 @@ import { MessageService } from 'primeng/api';
2122
InputMask,
2223
FormsModule,
2324
ReactiveFormsModule,
25+
Toast,
2426
],
2527
templateUrl: './user-config.component.html',
2628
styleUrl: './user-config.component.scss',

0 commit comments

Comments
 (0)