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() { private subscribeToUserUpdates() {
this.updateNotifierService.contactUpdated$ this.updateNotifierService.contactUpdated$
.pipe(takeUntil(this.destroy$)) .pipe(takeUntil(this.destroy$))
.subscribe(() => { .subscribe((userId: string) => {
this.selectedUserId = userId;
this.loadAllUsers(); this.loadAllUsers();
}); });
} }

View file

@ -5,15 +5,15 @@ import { Subject } from 'rxjs';
providedIn: 'root', providedIn: 'root',
}) })
export class UpdateNotifierService { export class UpdateNotifierService {
private updateSubjects: Record<string, Subject<void>> = { private updateSubjects: Record<string, Subject<string>> = {
task: new Subject<void>(), task: new Subject<string>(),
contact: new Subject<void>(), contact: new Subject<string>(),
}; };
taskUpdated$ = this.updateSubjects['task'].asObservable(); taskUpdated$ = this.updateSubjects['task'].asObservable();
contactUpdated$ = this.updateSubjects['contact'].asObservable(); contactUpdated$ = this.updateSubjects['contact'].asObservable();
notifyUpdate(type: 'task' | 'contact') { notifyUpdate(type: 'task' | 'contact', payload?: string) {
this.updateSubjects[type].next(); this.updateSubjects[type].next(payload ?? '');
} }
} }

View file

@ -242,9 +242,11 @@ export class ContactFormComponent implements OnInit, OnChanges {
}; };
const snakeCaseUserData = this.convertCamelToSnake(userData); const snakeCaseUserData = this.convertCamelToSnake(userData);
await lastValueFrom(this.apiService.saveNewUser(snakeCaseUserData)); const savedUser = await lastValueFrom(
this.apiService.saveNewUser(snakeCaseUserData)
);
this.toastNotificationService.createContactSuccessToast(); this.toastNotificationService.createContactSuccessToast();
this.updateNotifierService.notifyUpdate('contact'); this.updateNotifierService.notifyUpdate('contact', savedUser.id);
this.closeDialog(); this.closeDialog();
} catch (error) { } catch (error) {
console.error('Fehler beim Speichern des Kontakts:', error); console.error('Fehler beim Speichern des Kontakts:', error);