Skip to content

Commit

Permalink
Adiciona mensagens personalizadas
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviMarinho committed Nov 14, 2023
1 parent c6e1786 commit 3c5992a
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 28 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -50,7 +51,7 @@ import { ParticipateComponent } from './pages/participate/participate.component'
AppRoutingModule,
HttpClientModule,
ReactiveFormsModule,
HttpClientModule,
HttpClientModule
],
providers: [
AuthGuard,
Expand All @@ -60,6 +61,7 @@ import { ParticipateComponent } from './pages/participate/participate.component'
useClass: UserTokenInterceptor,
multi: true,
},
MessageService
],
bootstrap: [AppComponent],
})
Expand Down
32 changes: 17 additions & 15 deletions src/app/pages/active-account/active-account.component.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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;

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]],
});
}
Expand All @@ -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!");
}
}

Expand All @@ -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.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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 {
Expand Down Expand Up @@ -43,7 +45,7 @@ export class CheckCodeRestPasswordComponent {
},
});
} else {
alert('Preencha todos os campos corretamente!');
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
}
}

Expand All @@ -59,7 +61,7 @@ export class CheckCodeRestPasswordComponent {
},
});
} else {
alert('Preencha todos os campos corretamente!');
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/edit-user/edit-user.component.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -18,6 +19,7 @@ export class EditUserComponent implements OnInit {
private fb: FormBuilder,
private userService: UserService,
private route: ActivatedRoute,
private alertService: AlertService,
) {}

ngOnInit(): void {
Expand All @@ -39,15 +41,15 @@ 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) => {
console.error(error);
},
});
} else {
alert('Preencha todos os campos corretamente!');
this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 {
Expand All @@ -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!");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 {
Expand Down Expand Up @@ -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!");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/pages/reset-password/reset-password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 {
Expand Down Expand Up @@ -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!");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/suggest-agenda/suggest-agenda.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/app/services/alert.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
30 changes: 30 additions & 0 deletions src/app/services/alert.service.ts
Original file line number Diff line number Diff line change
@@ -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}` });
}
}
3 changes: 3 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 3c5992a

Please sign in to comment.