diff --git a/package-lock.json b/package-lock.json index 8114907a..6e8a15e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.2.0", "postcss-scss": "^4.0.9", + "primeng": "^15.4.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.12.0" @@ -11291,6 +11292,21 @@ "node": ">= 0.8" } }, + "node_modules/primeng": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/primeng/-/primeng-15.4.1.tgz", + "integrity": "sha512-j2unOQZk6756l6SgkzcmlHF6JlawF0bIjKTgAPWwT+S5RYeWEjpCPg/ABV8TylwW7CTNQX2oCHbyqCAuhtr++w==", + "dependencies": { + "tslib": "^2.3.0" + }, + "peerDependencies": { + "@angular/common": "^15.2.1", + "@angular/core": "^15.2.1", + "@angular/forms": "^15.2.1", + "rxjs": "^6.0.0 || ^7.5.0", + "zone.js": "^0.10.2 || ^0.11.0 || ^0.12.0 || ^0.13.0" + } + }, "node_modules/proc-log": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-3.0.0.tgz", diff --git a/package.json b/package.json index c7417f6a..37ef0b0e 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.2.0", "postcss-scss": "^4.0.9", + "primeng": "^15.4.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.12.0" diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 85123e85..0afeb240 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -24,6 +24,7 @@ import { AuthService } from './services/auth.service'; import { EditUserComponent } from './pages/edit-user/edit-user.component'; import { SuggestAgendaComponent } from './pages/suggest-agenda/suggest-agenda.component'; import { ParticipateComponent } from './pages/participate/participate.component'; +import { MessageService } from 'primeng/api'; @NgModule({ declarations: [ @@ -50,7 +51,7 @@ import { ParticipateComponent } from './pages/participate/participate.component' AppRoutingModule, HttpClientModule, ReactiveFormsModule, - HttpClientModule, + HttpClientModule ], providers: [ AuthGuard, @@ -60,6 +61,7 @@ import { ParticipateComponent } from './pages/participate/participate.component' useClass: UserTokenInterceptor, multi: true, }, + MessageService ], bootstrap: [AppComponent], }) diff --git a/src/app/pages/active-account/active-account.component.ts b/src/app/pages/active-account/active-account.component.ts index f0cfa1f4..a1890800 100644 --- a/src/app/pages/active-account/active-account.component.ts +++ b/src/app/pages/active-account/active-account.component.ts @@ -1,12 +1,13 @@ -import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormBuilder, Validators } from '@angular/forms'; -import { Router } from '@angular/router'; -import { AuthService } from '../../services/auth.service'; +import { Component, OnInit } from "@angular/core"; +import { FormGroup, FormBuilder, Validators } from "@angular/forms"; +import { Router } from "@angular/router"; +import { AuthService } from "../../services/auth.service"; +import { AlertService } from "../../services/alert.service"; @Component({ - selector: 'app-active-account', - templateUrl: './active-account.component.html', - styleUrls: ['./active-account.component.css'], + selector: "app-active-account", + templateUrl: "./active-account.component.html", + styleUrls: ["./active-account.component.css"], }) export class ActiveAccountComponent implements OnInit { userForm!: FormGroup; @@ -14,12 +15,13 @@ export class ActiveAccountComponent implements OnInit { constructor( private router: Router, private fb: FormBuilder, - private authService: AuthService + private authService: AuthService, + private alertService: AlertService, ) {} ngOnInit(): void { this.userForm = this.fb.group({ - email: ['', [Validators.required]], + email: ["", [Validators.required]], code: [, [Validators.required]], }); } @@ -29,18 +31,18 @@ export class ActiveAccountComponent implements OnInit { this.authService.activeAccount(this.userForm.value).subscribe({ next: (data) => { console.log(data); - if (data.status === 'error') { - alert(data.message); - this.navigator('/login'); + if (data.status === "error") { + this.alertService.showMessage("error", "Erro", data.message); + this.navigator("/login"); } - this.navigator('/login'); + this.navigator("/login"); }, error: (error) => { console.error(error); }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } @@ -55,7 +57,7 @@ export class ActiveAccountComponent implements OnInit { }, }); } else { - alert('Você deve preencher o email.'); + this.alertService.showMessage("info", "Alerta", "Você deve preencher o email."); } } diff --git a/src/app/pages/check-code-rest-password/check-code-rest-password.component.ts b/src/app/pages/check-code-rest-password/check-code-rest-password.component.ts index f75a5f13..8101ecbc 100644 --- a/src/app/pages/check-code-rest-password/check-code-rest-password.component.ts +++ b/src/app/pages/check-code-rest-password/check-code-rest-password.component.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import { Router } from '@angular/router'; +import { AlertService } from 'src/app/services/alert.service'; import { AuthService } from 'src/app/services/auth.service'; @Component({ @@ -15,7 +16,8 @@ export class CheckCodeRestPasswordComponent { constructor( private router: Router, private fb: FormBuilder, - private authService: AuthService + private authService: AuthService, + private alertService: AlertService, ) {} ngOnInit(): void { @@ -43,7 +45,7 @@ export class CheckCodeRestPasswordComponent { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } @@ -59,7 +61,7 @@ export class CheckCodeRestPasswordComponent { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } diff --git a/src/app/pages/edit-user/edit-user.component.ts b/src/app/pages/edit-user/edit-user.component.ts index cbdb211d..26503879 100644 --- a/src/app/pages/edit-user/edit-user.component.ts +++ b/src/app/pages/edit-user/edit-user.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; +import { AlertService } from 'src/app/services/alert.service'; import { UserService } from 'src/app/services/user.service'; @Component({ @@ -18,6 +19,7 @@ export class EditUserComponent implements OnInit { private fb: FormBuilder, private userService: UserService, private route: ActivatedRoute, + private alertService: AlertService, ) {} ngOnInit(): void { @@ -39,7 +41,7 @@ export class EditUserComponent implements OnInit { this.userService.updateUser(this.userId, this.userForm.value).subscribe({ next: (data) => { console.log(data); - alert('Usuário cadastrado com sucesso!'); + this.alertService.showMessage("success", "Sucesso", "Usuário cadastrado com sucesso!"); this.navigator('/profile'); }, error: (error) => { @@ -47,7 +49,7 @@ export class EditUserComponent implements OnInit { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 7ef3aea2..f8ceeb32 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { MustMatch } from 'src/app/helper/must-match.validator'; import { AuthService } from '../../services/auth.service'; +import { AlertService } from 'src/app/services/alert.service'; @Component({ @@ -15,7 +16,8 @@ export class LoginComponent implements OnInit { constructor( private router: Router, private fb: FormBuilder, - private authService: AuthService + private authService: AuthService, + private alertService: AlertService, ) { } ngOnInit(): void { @@ -39,7 +41,7 @@ export class LoginComponent implements OnInit { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } diff --git a/src/app/pages/register/register.component.ts b/src/app/pages/register/register.component.ts index dba1f497..149ed2d5 100644 --- a/src/app/pages/register/register.component.ts +++ b/src/app/pages/register/register.component.ts @@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { MustMatch } from 'src/app/helper/must-match.validator'; import { AuthService } from '../../services/auth.service'; +import { AlertService } from 'src/app/services/alert.service'; @Component({ selector: 'app-register', @@ -15,7 +16,8 @@ export class RegisterComponent implements OnInit { constructor( private router: Router, private fb: FormBuilder, - private authService: AuthService + private authService: AuthService, + private alertService: AlertService, ) {} ngOnInit(): void { @@ -46,7 +48,7 @@ export class RegisterComponent implements OnInit { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } diff --git a/src/app/pages/reset-password/reset-password.component.ts b/src/app/pages/reset-password/reset-password.component.ts index f2b547a9..c2c5741d 100644 --- a/src/app/pages/reset-password/reset-password.component.ts +++ b/src/app/pages/reset-password/reset-password.component.ts @@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthService } from '../../services/auth.service'; import { MustMatch } from 'src/app/helper/must-match.validator'; +import { AlertService } from 'src/app/services/alert.service'; @Component({ selector: 'app-reset-password', @@ -15,7 +16,8 @@ export class ResetPasswordComponent implements OnInit { constructor( private router: Router, private fb: FormBuilder, - private authService: AuthService + private authService: AuthService, + private alertService: AlertService, ) { } ngOnInit(): void { @@ -44,7 +46,7 @@ export class ResetPasswordComponent implements OnInit { }, }); } else { - alert('Preencha todos os campos corretamente!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); } } diff --git a/src/app/pages/suggest-agenda/suggest-agenda.component.ts b/src/app/pages/suggest-agenda/suggest-agenda.component.ts index e53faaf3..c1121ffd 100644 --- a/src/app/pages/suggest-agenda/suggest-agenda.component.ts +++ b/src/app/pages/suggest-agenda/suggest-agenda.component.ts @@ -58,7 +58,7 @@ export class SuggestAgendaComponent implements OnInit { this.isSendingEmail = false; }); } else { - alert('Preencha os campos obrigatórios!'); + this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); os campos obrigatórios!'); } } diff --git a/src/app/services/alert.service.spec.ts b/src/app/services/alert.service.spec.ts new file mode 100644 index 00000000..b20ed8c3 --- /dev/null +++ b/src/app/services/alert.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AlertService } from './alert.service'; + +describe('AlertService', () => { + let service: AlertService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AlertService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/alert.service.ts b/src/app/services/alert.service.ts new file mode 100644 index 00000000..ecbb15d0 --- /dev/null +++ b/src/app/services/alert.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@angular/core'; +import { MessageService } from 'primeng/api'; + +@Injectable({ providedIn: 'root' }) +export class AlertService { + constructor( + private messageService: MessageService, + ) { } + + showMessage(severity: string, summary: string, detail: string) { + this.messageService.add({ + severity: severity, + summary: summary, + key: 'myToast', + detail: detail + }); + } + + errorMessage(message: string) { + this.messageService.add({ severity: 'error', summary: 'Error', key: 'myToast', detail: `${message}` }); + } + + infoMessage(message: string) { + this.messageService.add({ severity: 'info', summary: 'Info', key: 'myToast', detail: `${message}` }); + } + + warnMessage(message: string) { + this.messageService.add({ severity: 'warn', summary: 'Warn', key: 'myToast', detail: `${message}` }); + } +} diff --git a/src/styles.css b/src/styles.css index f4274417..3b7de8ab 100644 --- a/src/styles.css +++ b/src/styles.css @@ -3,6 +3,9 @@ @import "tailwindcss/components"; @import "tailwindcss/utilities"; +@import 'primeng/resources/primeng.min.css'; +@import 'primeng/resources/themes/omega/theme.css'; + @font-face { font-family: "unb-pro"; src: url("/src/assets/fonts") format("woff");