completed deleted contact

This commit is contained in:
Chneemann 2024-04-01 19:06:10 +02:00
parent acb7e8ee7a
commit 221bf31259
5 changed files with 25 additions and 8 deletions

View file

@ -8,7 +8,7 @@
</div> </div>
</div> </div>
<div class="btn"> <div class="btn">
<div class="btn-delete" (click)="deleteContact()"> <div class="btn-delete-contact" (click)="deleteContact()">
{{ "contact-delete-dialog.btn-delete" | translate }} {{ "contact-delete-dialog.btn-delete" | translate }}
</div> </div>
</div> </div>

View file

@ -62,7 +62,7 @@ section {
} }
} }
.btn-delete { .btn-delete-contact {
padding: 12px; padding: 12px;
margin: 12px 12px; margin: 12px 12px;
border-radius: 10px; border-radius: 10px;

View file

@ -1,6 +1,8 @@
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { SharedService } from '../../../services/shared.service'; import { SharedService } from '../../../services/shared.service';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { UserService } from '../../../services/user.service';
import { Router } from '@angular/router';
@Component({ @Component({
selector: 'app-contact-delete', selector: 'app-contact-delete',
@ -12,10 +14,15 @@ import { TranslateModule } from '@ngx-translate/core';
export class ContactDeleteComponent { export class ContactDeleteComponent {
@Input() currentUserId!: string; @Input() currentUserId!: string;
constructor(private sharedService: SharedService) {} constructor(
private sharedService: SharedService,
private userService: UserService,
private router: Router
) {}
deleteContact() { deleteContact() {
console.log('Contact deleted'); this.userService.deleteUser(this.currentUserId);
this.router.navigate(['contacts']);
this.sharedService.isDeleteContactDialogOpen = false; this.sharedService.isDeleteContactDialogOpen = false;
this.sharedService.isAnyDialogOpen = false; this.sharedService.isAnyDialogOpen = false;
} }

View file

@ -57,8 +57,9 @@ export class ContactFormComponent implements OnChanges {
} }
deleteContact() { deleteContact() {
this.sharedService.isDeleteContactDialogOpen = true; this.userService.deleteUser(this.currentUserId);
this.sharedService.isAnyDialogOpen = true; this.sharedService.isDeleteContactDialogOpen = false;
this.sharedService.isAnyDialogOpen = false;
} }
closeEditDialog() { closeEditDialog() {

View file

@ -2,6 +2,7 @@ import { Injectable, OnDestroy, inject } from '@angular/core';
import { import {
Firestore, Firestore,
collection, collection,
deleteDoc,
doc, doc,
onSnapshot, onSnapshot,
updateDoc, updateDoc,
@ -50,9 +51,17 @@ export class UserService implements OnDestroy {
.map((user) => user[query]); .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( await updateDoc(
doc(collection(this.firestore, 'users'), userId), doc(collection(this.firestore, 'users'), docId),
data data
).catch((err) => { ).catch((err) => {
console.error(err); console.error(err);