From 01e79b262a5983a84d800f36384cc10f66ed914a Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Sat, 11 May 2024 05:10:08 +0100 Subject: [PATCH] add confirm delete to collection --- .../userCollection-info-page.component.html | 17 +++++-- .../userCollection-info-page.component.ts | 48 +++++++++++++++---- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html index 4ff9f25..2d28a28 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.html @@ -18,11 +18,18 @@
{{collection.name}}
- +
Created - {{createdAt}} | Updated - {{updatedAt}}
diff --git a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts index 3a97d5b..f882d7a 100644 --- a/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts +++ b/frontend/src/app/features/collections/user-collection-info/userCollection-info-page/userCollection-info-page.component.ts @@ -1,11 +1,12 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { UserCollectionService } from '../../../../core/services/userCollection.service'; import { UserCollection } from '../../../../shared/models/userCollection.model'; import { DatePipe } from '@angular/common'; import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto'; import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component'; import { MatDialog } from '@angular/material/dialog'; +import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component'; @Component({ selector: 'app-userCollection-info-page', @@ -21,8 +22,9 @@ export class UserCollectionInfoPageComponent implements OnInit { constructor( private route: ActivatedRoute, private userCollectionService: UserCollectionService, + private datePipe: DatePipe, public dialog: MatDialog, - private datePipe: DatePipe + private router: Router ) {} ngOnInit(): void { @@ -107,30 +109,60 @@ export class UserCollectionInfoPageComponent implements OnInit { }, }); - console.log('Edit dialog opened'); dialogRef.afterClosed().subscribe((result) => { if (result) { if (result.formData == null) return; - console.log('Edit dialog closed with:', result); this.userCollectionService .updateCollection(this.collection.id, result.formData) .subscribe({ next: (userCollection) => { if (userCollection) { - // TODO show confirm notification + // TODO confirm notification console.log(`User Collection updated: `, userCollection); this.collection = userCollection; } }, error: (error) => { console.error('Error updating userCollection:', error); - // TODO show notification + // TODO error notification + }, + }); + } + }); + } + + changeOrder() {} + deleteCollection() { + if (!this.collection) return; + + const dialogRef = this.dialog.open(ConfirmModalComponent, { + width: '400px', + data: { + title: 'Confirmation', + message: + 'Are you sure you want to delete this collection? This action cannot be undone and you will be unable to recover any data.', + type: 'danger', + }, + }); + + dialogRef.afterClosed().subscribe((result) => { + if (result) { + if (result.confirmed != true) return; + + this.userCollectionService + .deleteCollection(this.collection.id) + .subscribe({ + next: () => { + // TODO confirm notification + this.router.navigate(['/collections']); + }, + error: (error) => { + console.error('Error updating userCollection:', error); + // TODO error notification }, }); - } else { - console.log('Edit dialog was cancelled'); } }); }