From 211b68b41c1215eb8c2baf5f16599fa958ad9fe6 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sat, 18 May 2024 11:40:44 +0200 Subject: [PATCH] check whether the contact is assigned when deleting --- .../contact-delete/contact-delete.component.ts | 18 +++++++++++++++++- .../contact-detail.component.html | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/app/components/contacts/contact-delete/contact-delete.component.ts b/src/app/components/contacts/contact-delete/contact-delete.component.ts index f68c7bb..b1a05c0 100644 --- a/src/app/components/contacts/contact-delete/contact-delete.component.ts +++ b/src/app/components/contacts/contact-delete/contact-delete.component.ts @@ -12,7 +12,7 @@ import { FirebaseService } from '../../../services/firebase.service'; styleUrl: './contact-delete.component.scss', }) export class ContactDeleteComponent { - @Input() currentUserId!: string; + @Input() currentUserId: string = ''; constructor( private sharedService: SharedService, @@ -25,6 +25,22 @@ export class ContactDeleteComponent { this.router.navigate(['contacts']); this.sharedService.isDeleteContactDialogOpen = false; this.sharedService.isAnyDialogOpen = false; + this.checkIfContactAnAssigned(); + } + + checkIfContactAnAssigned() { + const tasks = this.firebaseService.getAllTasks(); + + tasks.forEach((task) => { + const index = task.assigned.indexOf(this.currentUserId); + if (index !== -1) { + task.assigned.splice(index, 1); + const { id, ...taskWithoutIds } = task; + if (task.id) { + this.firebaseService.replaceTaskData(task.id, taskWithoutIds); + } + } + }); } deleteCancle() { diff --git a/src/app/components/contacts/contact-detail/contact-detail.component.html b/src/app/components/contacts/contact-detail/contact-detail.component.html index a588c6b..1b18e77 100644 --- a/src/app/components/contacts/contact-detail/contact-detail.component.html +++ b/src/app/components/contacts/contact-detail/contact-detail.component.html @@ -45,6 +45,7 @@

 (du)

} + @if(user.uId === "") {
@@ -62,6 +63,7 @@
check
+ }
@@ -77,13 +79,13 @@ {{ user.phone }} - } + } @if(user.uId !== "") {

{{ "contacts.contactLastOnline" | translate }}

@if(user.status) { {{ "contacts.contactLastOnlineTxt" | translate }} } @else { {{ convertTimestamp(user.lastLogin) }} - } + } }