fix bug where tables reload on action cancel

This commit is contained in:
Constantin Simonis 2025-01-09 13:52:08 +01:00
parent 89bea09476
commit ddb67fc40d
Signed by: csimonis
GPG Key ID: 758DD9C506603183
4 changed files with 17 additions and 11 deletions

View File

@ -56,6 +56,6 @@ export class CreateComponent implements OnInit {
} }
this.employeeService.create(this.employeeForm.value as Employee).subscribe(); this.employeeService.create(this.employeeForm.value as Employee).subscribe();
this.dialogRef.close(); this.dialogRef.close(true);
} }
} }

View File

@ -31,6 +31,6 @@ export class DeleteComponent {
deleteEmployee(id: number) { deleteEmployee(id: number) {
this.apiService.deleteById(id).subscribe(); this.apiService.deleteById(id).subscribe();
this.dialogRef.close() this.dialogRef.close(true);
} }
} }

View File

@ -63,6 +63,6 @@ export class EditComponent implements OnInit {
} }
this.employeeService.update(this.employeeForm.value as Employee, this.employee.id).subscribe(); this.employeeService.update(this.employeeForm.value as Employee, this.employee.id).subscribe();
this.dialogRef.close(); this.dialogRef.close(true);
} }
} }

View File

@ -40,7 +40,7 @@ import {DetailsComponent} from "../details/details.component";
templateUrl: './table.component.html', templateUrl: './table.component.html',
styleUrl: './table.component.css' styleUrl: './table.component.css'
}) })
export class TableComponent implements OnInit{ export class TableComponent implements OnInit {
private readonly apiService: EmployeeApiService = inject(EmployeeApiService); private readonly apiService: EmployeeApiService = inject(EmployeeApiService);
private readonly snackBar: MatSnackBar = inject(MatSnackBar); private readonly snackBar: MatSnackBar = inject(MatSnackBar);
private readonly matDialog: MatDialog = inject(MatDialog); private readonly matDialog: MatDialog = inject(MatDialog);
@ -76,24 +76,30 @@ export class TableComponent implements OnInit{
protected openDeleteDialogue(employee: Employee): void { protected openDeleteDialogue(employee: Employee): void {
this.matDialog.open(DeleteComponent, {data: employee}) this.matDialog.open(DeleteComponent, {data: employee})
.afterClosed() .afterClosed()
.subscribe(() => { .subscribe((deleted: boolean) => {
this.employees$ = this.fetchEmployees(); if (deleted) {
this.employees$ = this.fetchEmployees();
}
}); });
} }
protected showCreateEmployeeModal() { protected showCreateEmployeeModal() {
this.matDialog.open(CreateComponent) this.matDialog.open(CreateComponent)
.afterClosed() .afterClosed()
.subscribe(() => { .subscribe((created: boolean) => {
this.employees$ = this.fetchEmployees(); if (created) {
}); this.employees$ = this.fetchEmployees();
}
});
} }
protected showEditEmployeeModal(employee: Employee) { protected showEditEmployeeModal(employee: Employee) {
this.matDialog.open(EditComponent, {data: employee}) this.matDialog.open(EditComponent, {data: employee})
.afterClosed() .afterClosed()
.subscribe(() => { .subscribe((edited: boolean) => {
this.employees$ = this.fetchEmployees(); if (edited) {
this.employees$ = this.fetchEmployees();
}
}); });
} }