after adding a new user, this user is displayed
This commit is contained in:
parent
766cd02774
commit
d301df0580
3 changed files with 12 additions and 4 deletions
|
|
@ -100,7 +100,7 @@
|
|||
: ('contactDialogForm.phone' | translate)
|
||||
}}"
|
||||
[(ngModel)]="contactData.phone"
|
||||
pattern="[0-9]{7,15}"
|
||||
pattern="[\d\+\-\(\)\/]{7,15}"
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { SharedService } from '../../../../services/shared.service';
|
|||
import { FirebaseService } from '../../../../services/firebase.service';
|
||||
import { FormBtnComponent } from '../../../../shared/components/buttons/form-btn/form-btn.component';
|
||||
import { User } from '../../../../interfaces/user.interface';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contact-form',
|
||||
|
|
@ -29,6 +30,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
@Output() inititalsEmitter = new EventEmitter<string>();
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private firebaseService: FirebaseService,
|
||||
public sharedService: SharedService
|
||||
) {
|
||||
|
|
@ -169,7 +171,9 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
? (this.userData.color = this.newColor)
|
||||
: (this.userData.color = this.randomColor);
|
||||
const { id, ...taskWithoutIds } = this.userData;
|
||||
this.firebaseService.addNewUser(taskWithoutIds);
|
||||
this.firebaseService.addNewUser(taskWithoutIds).then((docRef) => {
|
||||
this.router.navigate([`/contacts/${docRef.id}`]);
|
||||
});
|
||||
}
|
||||
this.closeDialog();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { Injectable, OnDestroy, inject } from '@angular/core';
|
||||
import {
|
||||
DocumentReference,
|
||||
Firestore,
|
||||
addDoc,
|
||||
arrayUnion,
|
||||
|
|
@ -149,9 +150,12 @@ export class FirebaseService implements OnDestroy {
|
|||
}
|
||||
|
||||
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);
|
||||
});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue