refs #1436 Fix create-multiple-client's toast
testing/ogGui-multibranch/pipeline/head This commit looks good
Details
testing/ogGui-multibranch/pipeline/head This commit looks good
Details
parent
45bf13e63a
commit
6e739270de
|
@ -125,6 +125,9 @@ export class CreateMultipleClientComponent implements OnInit{
|
|||
|
||||
onSubmit(): void {
|
||||
if (this.uploadedClients.length > 0) {
|
||||
let successCount = 0;
|
||||
let errorMessages: string[] = [];
|
||||
|
||||
this.uploadedClients.forEach(client => {
|
||||
const formData = {
|
||||
organizationalUnit: this.organizationalUnit,
|
||||
|
@ -135,23 +138,37 @@ export class CreateMultipleClientComponent implements OnInit{
|
|||
|
||||
this.http.post(`${this.baseUrl}/clients`, formData).subscribe(
|
||||
response => {
|
||||
this.toastService.success(`Cliente ${client.name} creado exitosamente`, 'Éxito');
|
||||
successCount++;
|
||||
if (successCount + errorMessages.length === this.uploadedClients.length) {
|
||||
this.showFinalToast(successCount, errorMessages);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
this.toastService.error(error.error['hydra:description'], `Error al crear el cliente ${client.name}`);
|
||||
errorMessages.push(`Error al crear el cliente ${client.name}: ${error.error['hydra:description']}`);
|
||||
if (successCount + errorMessages.length === this.uploadedClients.length) {
|
||||
this.showFinalToast(successCount, errorMessages);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
this.uploadedClients = [];
|
||||
this.dialogRef.close({
|
||||
success: true,
|
||||
organizationalUnit: this.organizationalUnit,
|
||||
});
|
||||
} else {
|
||||
this.toastService.error('No hay clientes cargados para añadir', 'Error');
|
||||
}
|
||||
}
|
||||
|
||||
showFinalToast(successCount: number, errorMessages: string[]): void {
|
||||
if (successCount > 0) {
|
||||
this.toastService.success(`${successCount} clientes creados exitosamente`, 'Éxito');
|
||||
}
|
||||
if (errorMessages.length > 0) {
|
||||
errorMessages.forEach(message => this.toastService.error(message, 'Error'));
|
||||
}
|
||||
this.dialogRef.close({
|
||||
success: successCount > 0,
|
||||
organizationalUnit: this.organizationalUnit,
|
||||
});
|
||||
}
|
||||
|
||||
onNoClick(): void {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue