completed deleted contact
This commit is contained in:
parent
acb7e8ee7a
commit
221bf31259
5 changed files with 25 additions and 8 deletions
|
|
@ -8,7 +8,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="btn">
|
||||
<div class="btn-delete" (click)="deleteContact()">
|
||||
<div class="btn-delete-contact" (click)="deleteContact()">
|
||||
{{ "contact-delete-dialog.btn-delete" | translate }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ section {
|
|||
}
|
||||
}
|
||||
|
||||
.btn-delete {
|
||||
.btn-delete-contact {
|
||||
padding: 12px;
|
||||
margin: 12px 12px;
|
||||
border-radius: 10px;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { Component, Input } from '@angular/core';
|
||||
import { SharedService } from '../../../services/shared.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { UserService } from '../../../services/user.service';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contact-delete',
|
||||
|
|
@ -12,10 +14,15 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||
export class ContactDeleteComponent {
|
||||
@Input() currentUserId!: string;
|
||||
|
||||
constructor(private sharedService: SharedService) {}
|
||||
constructor(
|
||||
private sharedService: SharedService,
|
||||
private userService: UserService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
deleteContact() {
|
||||
console.log('Contact deleted');
|
||||
this.userService.deleteUser(this.currentUserId);
|
||||
this.router.navigate(['contacts']);
|
||||
this.sharedService.isDeleteContactDialogOpen = false;
|
||||
this.sharedService.isAnyDialogOpen = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,8 +57,9 @@ export class ContactFormComponent implements OnChanges {
|
|||
}
|
||||
|
||||
deleteContact() {
|
||||
this.sharedService.isDeleteContactDialogOpen = true;
|
||||
this.sharedService.isAnyDialogOpen = true;
|
||||
this.userService.deleteUser(this.currentUserId);
|
||||
this.sharedService.isDeleteContactDialogOpen = false;
|
||||
this.sharedService.isAnyDialogOpen = false;
|
||||
}
|
||||
|
||||
closeEditDialog() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Injectable, OnDestroy, inject } from '@angular/core';
|
|||
import {
|
||||
Firestore,
|
||||
collection,
|
||||
deleteDoc,
|
||||
doc,
|
||||
onSnapshot,
|
||||
updateDoc,
|
||||
|
|
@ -50,9 +51,17 @@ export class UserService implements OnDestroy {
|
|||
.map((user) => user[query]);
|
||||
}
|
||||
|
||||
async updateUserData(userId: string, data: any) {
|
||||
async deleteUser(docId: string) {
|
||||
await deleteDoc(doc(collection(this.firestore, 'users'), docId)).catch(
|
||||
(err) => {
|
||||
console.error(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async updateUserData(docId: string, data: any) {
|
||||
await updateDoc(
|
||||
doc(collection(this.firestore, 'users'), userId),
|
||||
doc(collection(this.firestore, 'users'), docId),
|
||||
data
|
||||
).catch((err) => {
|
||||
console.error(err);
|
||||
|
|
|
|||
Loading…
Reference in a new issue