add confirm delete to collection

This commit is contained in:
X4Lo committed 2024-05-11 05:10:08 +01:00
1 parent e991329e71
commit 01e79b262a
2 files changed
+52 -13

No files matched your search

@@ -18,11 +18,18 @@
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5 class="mb-0">{{collection.name}}</h5>
<button type="button" class="btn btn-primary btn-sm" (click)="openEditModal()">
<span class="material-symbols-outlined">
edit
</span>
</button>
<div class="dropdown">
<a href="javascript:;" class="dropdown-toggle-nocaret options dropdown-toggle" data-bs-toggle="dropdown">
<span class="material-icons-outlined fs-5">more_vert</span>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="javascript:;" (click)="openEditModal()">Edit</a>
</li>
<li><a class="dropdown-item" href="javascript:;" (click)="changeOrder()">Change order</a></li>
<li><a class="dropdown-item" href="javascript:;" (click)="deleteCollection()">Delete</a></li>
</ul>
</div>
</div>
<div>Created - {{createdAt}} | Updated - {{updatedAt}}
<div class="d-flex justify-content-right rating">
@@ -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');
}
});
}