feat: propagate created ID via UpdateNotifierService and call newly created contact in ContactsComponent

This commit is contained in:
Chneemann 2025-03-31 20:25:48 +02:00
parent d6675bb439
commit eca837b0ea
3 changed files with 11 additions and 8 deletions

View file

@ -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();
});
}

View file

@ -5,15 +5,15 @@ import { Subject } from 'rxjs';
providedIn: 'root',
})
export class UpdateNotifierService {
private updateSubjects: Record<string, Subject<void>> = {
task: new Subject<void>(),
contact: new Subject<void>(),
private updateSubjects: Record<string, Subject<string>> = {
task: new Subject<string>(),
contact: new Subject<string>(),
};
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 ?? '');
}
}

View file

@ -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);