diff --git a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html index 5654c52..fe7573b 100644 --- a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html +++ b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html @@ -100,7 +100,7 @@ : ('contactDialogForm.phone' | translate) }}" [(ngModel)]="contactData.phone" - pattern="[0-9]{7,15}" + pattern="[\d\+\-\(\)\/]{7,15}" autocomplete="off" required /> diff --git a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts index 17dff2e..53d3a2f 100644 --- a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts +++ b/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.ts @@ -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(); 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(); } diff --git a/src/app/services/firebase.service.ts b/src/app/services/firebase.service.ts index 80beb83..352e35f 100644 --- a/src/app/services/firebase.service.ts +++ b/src/app/services/firebase.service.ts @@ -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() {