From e991329e7165bad31a7229a52981b6fb33092bb1 Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sat, 11 May 2024 05:08:59 +0100 Subject: [PATCH] add confirm modal when removing an entry from collection --- .../userCollection-grid-card.component.ts | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts index 21e03bf..8bd9931 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-grid-card/userCollection-grid-card.component.ts @@ -5,6 +5,7 @@ import { Entry } from '../../../../shared/models/entry.model'; import { trigger, transition, style, animate } from '@angular/animations'; import { UserCollectionService } from '../../../../core/services/userCollection.service'; import { Router } from '@angular/router'; +import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component'; @Component({ selector: 'app-userCollection-grid-card', @@ -80,19 +81,36 @@ export class UserCollectionGridCardComponent { } removeEntryFromList() { - // TODO: add confirm modal - this.userCollectionService - .removeEntryFromCollection(this.listId, this.entry.id) - .subscribe({ - next: (response) => { - console.log('Entry successfully removed from list.', response); - this.entry.id = 0; - this.entry.isInLibrary = false; - }, - error: (error) => { - console.error('Error removing entry from list:', error); - }, - }); + const dialogRef = this.dialog.open(ConfirmModalComponent, { + width: '400px', + data: { + title: 'Confirmation', + message: `Are you sure you want to remove ${this.entry.title} from this collection?`, + type: 'danger', + }, + }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + if (result.confirmed != true) return; + + this.userCollectionService + .removeEntryFromCollection(this.listId, this.entry.id) + .subscribe({ + next: (response) => { + // TODO confirm notification + + console.log('Entry successfully removed from list.', response); + this.entry.id = 0; + this.entry.isInLibrary = false; + }, + error: (error) => { + // TODO error notification + console.error('Error removing entry from list:', error); + }, + }); + } + }); } // ? EVENTS