after adding a new user, this user is displayed

This commit is contained in:
Chneemann 2024-05-19 09:36:00 +02:00
parent 766cd02774
commit d301df0580
3 changed files with 12 additions and 4 deletions

View file

@ -100,7 +100,7 @@
: ('contactDialogForm.phone' | translate) : ('contactDialogForm.phone' | translate)
}}" }}"
[(ngModel)]="contactData.phone" [(ngModel)]="contactData.phone"
pattern="[0-9]{7,15}" pattern="[\d\+\-\(\)\/]{7,15}"
autocomplete="off" autocomplete="off"
required required
/> />

View file

@ -13,6 +13,7 @@ import { SharedService } from '../../../../services/shared.service';
import { FirebaseService } from '../../../../services/firebase.service'; import { FirebaseService } from '../../../../services/firebase.service';
import { FormBtnComponent } from '../../../../shared/components/buttons/form-btn/form-btn.component'; import { FormBtnComponent } from '../../../../shared/components/buttons/form-btn/form-btn.component';
import { User } from '../../../../interfaces/user.interface'; import { User } from '../../../../interfaces/user.interface';
import { Router } from '@angular/router';
@Component({ @Component({
selector: 'app-contact-form', selector: 'app-contact-form',
@ -29,6 +30,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
@Output() inititalsEmitter = new EventEmitter<string>(); @Output() inititalsEmitter = new EventEmitter<string>();
constructor( constructor(
private router: Router,
private firebaseService: FirebaseService, private firebaseService: FirebaseService,
public sharedService: SharedService public sharedService: SharedService
) { ) {
@ -169,7 +171,9 @@ export class ContactFormComponent implements OnInit, OnChanges {
? (this.userData.color = this.newColor) ? (this.userData.color = this.newColor)
: (this.userData.color = this.randomColor); : (this.userData.color = this.randomColor);
const { id, ...taskWithoutIds } = this.userData; const { id, ...taskWithoutIds } = this.userData;
this.firebaseService.addNewUser(taskWithoutIds); this.firebaseService.addNewUser(taskWithoutIds).then((docRef) => {
this.router.navigate([`/contacts/${docRef.id}`]);
});
} }
this.closeDialog(); this.closeDialog();
} }

View file

@ -1,5 +1,6 @@
import { Injectable, OnDestroy, inject } from '@angular/core'; import { Injectable, OnDestroy, inject } from '@angular/core';
import { import {
DocumentReference,
Firestore, Firestore,
addDoc, addDoc,
arrayUnion, arrayUnion,
@ -149,9 +150,12 @@ export class FirebaseService implements OnDestroy {
} }
async addNewUser(userData: User) { async addNewUser(userData: User) {
await addDoc(collection(this.firestore, 'users'), userData).catch((err) => { try {
return await addDoc(collection(this.firestore, 'users'), userData);
} catch (err) {
console.error(err); console.error(err);
}); throw err;
}
} }
ngOnDestroy() { ngOnDestroy() {