gestion des retours de l'api via les toasts partie 2, pour les éditions

pull/15/head
Clement FERRERE 2 years ago
parent cc7b99274b
commit 70fde1ce9f
  1. 12
      src/app/components/agence/agence-edit/agence-edit.component.ts
  2. 12
      src/app/components/agence/agence.component.ts
  3. 12
      src/app/components/businessunit/businessunit-edit/businessunit-edit.component.ts
  4. 20
      src/app/components/collaborateur/collaborateur-add/collaborateur-add.component.ts
  5. 19
      src/app/components/collaborateur/collaborateur-edit/collaborateur-edit.component.ts
  6. 20
      src/app/components/periode-essai/periode-essai-edit/periode-essai-edit.component.ts
  7. 12
      src/app/components/periode-essai/periode-essai.component.ts

@ -65,7 +65,13 @@ export class AgenceEditComponent implements OnInit {
this.agence.name = this.registerForm.value.name
this.agence.businessUnitId = this.registerForm.value.businessUnitId
this.agenceService.updateAgence(this.agence)
.subscribe(()=>this.goBack());
.subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
}
}
@ -77,11 +83,11 @@ export class AgenceEditComponent implements OnInit {
}
showSuccess() {
this.toastr.success('Création réussie', 'Business Unit');
this.toastr.success('Modification réussie', 'Business Unit');
}
showError() {
this.toastr.error('Création échouée', 'Business Unit');
this.toastr.error('Modification échouée', 'Business Unit');
}
}

@ -51,8 +51,12 @@ export class AgenceComponent implements OnInit {
add(agence: Agence): void {
this.agenceService.addAgence(agence)
.subscribe(agence => {
this.agences.push(agence);
});
this.agences.push(agence);
this.showSuccess();
},
() => {
this.showError()
});
}
onSubmit() {
@ -74,11 +78,11 @@ export class AgenceComponent implements OnInit {
}
showSuccess() {
this.toastr.success('Création réussie', 'Business Unit');
this.toastr.success('Création réussie', 'Agence');
}
showError() {
this.toastr.error('Création échouée', 'Business Unit');
this.toastr.error('Création échouée', 'Agence');
}
}

@ -49,7 +49,13 @@ export class BusinessunitEditComponent implements OnInit {
if (this.businessunit) {
this.businessunitService.updateBusinessunit(this.bu, this.id)
.subscribe(() => this.goBack());
.subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
}
}
@ -65,11 +71,11 @@ export class BusinessunitEditComponent implements OnInit {
}
showSuccess() {
this.toastr.success('Création réussie', 'Business Unit');
this.toastr.success('Modification réussie', 'Business Unit');
}
showError() {
this.toastr.error('Création échouée', 'Business Unit');
this.toastr.error('Modification échouée', 'Business Unit');
}
}

@ -76,13 +76,13 @@ export class CollaborateurAddComponent implements OnInit {
}
this.collaborateur = this.registerForm.value
if (this.collaborateur) {
this.collaborateurService.addCollaborateur(this.collaborateur).subscribe({
next: () => {
this.collaborateurService.addCollaborateur(this.collaborateur).subscribe(collaborateur => {
this.collaborateurs.push(collaborateur);
this.showSuccess();
},
error: () => {
this.errorValue = 1;
}
})
() => {
this.showError()
})
}
}
@ -104,4 +104,12 @@ export class CollaborateurAddComponent implements OnInit {
this.collaborateur.birthDate = new Date($event.target.value);
}
showSuccess() {
this.toastr.success('Création réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Création échouée', 'Collaborateur');
}
}

@ -114,14 +114,13 @@ export class CollaborateurEditComponent implements OnInit {
this.collaborateur.status = this.registerForm.value.status
if (this.collaborateur) {
this.collaborateurService.updateCollaborateur(this.collaborateur).subscribe({
next: () => {
this.collaborateurService.updateCollaborateur(this.collaborateur).subscribe(() => {
this.showSuccess();
this.goBack();
},
error: () => {
this.errorValue = 1;
}
})
() => {
this.showError()
})
}
}
@ -141,4 +140,12 @@ export class CollaborateurEditComponent implements OnInit {
onBirthDateChange($event: any):void {
this.collaborateur.birthDate = new Date($event.target.value);
}
showSuccess() {
this.toastr.success('Modification réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Modification échouée', 'Collaborateur');
}
}

@ -8,6 +8,7 @@ import {Observable} from "rxjs";
import {ActivatedRoute} from "@angular/router";
import {take, tap} from "rxjs/operators";
import {Location} from "@angular/common";
import {ToastrService} from "ngx-toastr";
@Component({
selector: 'app-periode-essai-edit',
@ -37,7 +38,8 @@ export class PeriodeEssaiEditComponent implements OnInit {
private location: Location,
private collaborateurService: CollaborateurService,
private periodeEssaiService: PeriodeEssaiService,
private formBuilder: FormBuilder
private formBuilder: FormBuilder,
private toastr: ToastrService
) {
this.id = Number(this.route.snapshot.paramMap.get('id'))
}
@ -96,7 +98,13 @@ export class PeriodeEssaiEditComponent implements OnInit {
if (this.periodeEssai){
this.periodeEssaiService.updatePeriodeEssai(this.periodeEssai)
.subscribe(()=>this.goBack());
.subscribe(() => {
this.showSuccess();
this.goBack();
},
() => {
this.showError()
});
}
}
@ -119,6 +127,14 @@ export class PeriodeEssaiEditComponent implements OnInit {
this.periodeEssai.realEndingDate = new Date($event.target.value);
}
showSuccess() {
this.toastr.success('Modification réussie', 'Période d\'essai');
}
showError() {
this.toastr.error('Modification échouée', 'Collaborateur');
}
}

@ -5,6 +5,7 @@ import {PeriodeEssai} from "../../interfaces/periode-essai";
import {Collaborateur} from "../../interfaces/collaborateur";
import {CollaborateurService} from "../../services/collaborateur.service";
import {PeriodeEssaiService} from "../../services/periode-essai.service";
import {ToastrService} from "ngx-toastr";
@Component({
selector: 'app-periode-essai',
@ -30,7 +31,8 @@ export class PeriodeEssaiComponent implements OnInit {
private http : HttpClient,
private collaborateurService: CollaborateurService,
private periodeEssaiService: PeriodeEssaiService,
private formBuilder: FormBuilder
private formBuilder: FormBuilder,
private toastr: ToastrService
) { }
ngOnInit(): void {
@ -104,4 +106,12 @@ export class PeriodeEssaiComponent implements OnInit {
this.periodeEssaiService.getPeriodeEssais()
.subscribe(periodeEssais => this.periodeEssais = periodeEssais);
}
showSuccess() {
this.toastr.success('Création réussie', 'Collaborateur');
}
showError() {
this.toastr.error('Création échouée', 'Collaborateur');
}
}

Loading…
Cancel
Save