From eca837b0ea018df6a01c710e360db679ad890dd1 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Mon, 31 Mar 2025 20:25:48 +0200 Subject: [PATCH] feat: propagate created ID via UpdateNotifierService and call newly created contact in ContactsComponent --- src/app/components/contacts/contacts.component.ts | 3 ++- src/app/services/update-notifier.service.ts | 10 +++++----- .../contact-form/contact-form.component.ts | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/components/contacts/contacts.component.ts b/src/app/components/contacts/contacts.component.ts index 82e7a0c..6e90989 100644 --- a/src/app/components/contacts/contacts.component.ts +++ b/src/app/components/contacts/contacts.component.ts @@ -61,7 +61,8 @@ export class ContactsComponent { private subscribeToUserUpdates() { this.updateNotifierService.contactUpdated$ .pipe(takeUntil(this.destroy$)) - .subscribe(() => { + .subscribe((userId: string) => { + this.selectedUserId = userId; this.loadAllUsers(); }); } diff --git a/src/app/services/update-notifier.service.ts b/src/app/services/update-notifier.service.ts index 6f2fc99..f2a4529 100644 --- a/src/app/services/update-notifier.service.ts +++ b/src/app/services/update-notifier.service.ts @@ -5,15 +5,15 @@ import { Subject } from 'rxjs'; providedIn: 'root', }) export class UpdateNotifierService { - private updateSubjects: Record> = { - task: new Subject(), - contact: new Subject(), + private updateSubjects: Record> = { + task: new Subject(), + contact: new Subject(), }; taskUpdated$ = this.updateSubjects['task'].asObservable(); contactUpdated$ = this.updateSubjects['contact'].asObservable(); - notifyUpdate(type: 'task' | 'contact') { - this.updateSubjects[type].next(); + notifyUpdate(type: 'task' | 'contact', payload?: string) { + this.updateSubjects[type].next(payload ?? ''); } } diff --git a/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.ts b/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.ts index 4a7771c..07596d8 100644 --- a/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.ts +++ b/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.ts @@ -242,9 +242,11 @@ export class ContactFormComponent implements OnInit, OnChanges { }; const snakeCaseUserData = this.convertCamelToSnake(userData); - await lastValueFrom(this.apiService.saveNewUser(snakeCaseUserData)); + const savedUser = await lastValueFrom( + this.apiService.saveNewUser(snakeCaseUserData) + ); this.toastNotificationService.createContactSuccessToast(); - this.updateNotifierService.notifyUpdate('contact'); + this.updateNotifierService.notifyUpdate('contact', savedUser.id); this.closeDialog(); } catch (error) { console.error('Fehler beim Speichern des Kontakts:', error);