add confirm delete to collection
This commit is contained in:
1 parent
e991329e71
commit
01e79b262a
2 files changed
+52
-13
No files matched your search
+12
-5
@@ -18,11 +18,18 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||||
<h5 class="mb-0">{{collection.name}}</h5>
|
<h5 class="mb-0">{{collection.name}}</h5>
|
||||||
<button type="button" class="btn btn-primary btn-sm" (click)="openEditModal()">
|
<div class="dropdown">
|
||||||
<span class="material-symbols-outlined">
|
<a href="javascript:;" class="dropdown-toggle-nocaret options dropdown-toggle" data-bs-toggle="dropdown">
|
||||||
edit
|
<span class="material-icons-outlined fs-5">more_vert</span>
|
||||||
</span>
|
</a>
|
||||||
</button>
|
<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>
|
||||||
<div>Created - {{createdAt}} | Updated - {{updatedAt}}
|
<div>Created - {{createdAt}} | Updated - {{updatedAt}}
|
||||||
<div class="d-flex justify-content-right rating">
|
<div class="d-flex justify-content-right rating">
|
||||||
|
|||||||
+40
-8
@@ -1,11 +1,12 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
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 { UserCollectionService } from '../../../../core/services/userCollection.service';
|
||||||
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
import { UserCollection } from '../../../../shared/models/userCollection.model';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto';
|
import { CollectionEntry } from '../../../../shared/models/dtos/collection-entry.dto';
|
||||||
import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component';
|
import { CollectionEditModalComponent } from '../collection-edit-modal/collection-edit-modal.component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { ConfirmModalComponent } from '../../../../shared/components/modals/confirm-modal/confirm-modal.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-userCollection-info-page',
|
selector: 'app-userCollection-info-page',
|
||||||
@@ -21,8 +22,9 @@ export class UserCollectionInfoPageComponent implements OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private userCollectionService: UserCollectionService,
|
private userCollectionService: UserCollectionService,
|
||||||
|
private datePipe: DatePipe,
|
||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
private datePipe: DatePipe
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -107,30 +109,60 @@ export class UserCollectionInfoPageComponent implements OnInit {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Edit dialog opened');
|
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result.formData == null) return;
|
if (result.formData == null) return;
|
||||||
console.log('Edit dialog closed with:', result);
|
|
||||||
|
|
||||||
this.userCollectionService
|
this.userCollectionService
|
||||||
.updateCollection(this.collection.id, result.formData)
|
.updateCollection(this.collection.id, result.formData)
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: (userCollection) => {
|
next: (userCollection) => {
|
||||||
if (userCollection) {
|
if (userCollection) {
|
||||||
// TODO show confirm notification
|
// TODO confirm notification
|
||||||
console.log(`User Collection updated: `, userCollection);
|
console.log(`User Collection updated: `, userCollection);
|
||||||
this.collection = userCollection;
|
this.collection = userCollection;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Error updating userCollection:', 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');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user