Repository navigation
Expand file tree
/
Copy pathmanage-orders.component.ts
More file actions
97 lines (84 loc) · 2.43 KB
/
Copy pathmanage-orders.component.ts
File metadata and controls
97 lines (84 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Component, OnInit } from '@angular/core';
import { OrderDTO } from '../../../dtos/order.model';
import { OrderService } from '../../../services/order.service';
import { ToastrService } from 'ngx-toastr';
@Component({
selector: 'app-admin-manage-orders',
templateUrl: './manage-orders.component.html',
styleUrls: ['./manage-orders.component.css']
})
export class AdminManageOrdersComponent implements OnInit {
public orders: OrderDTO[] = [];
public isLoading = true;
public showEditPopup = false;
public selectedOrder: OrderDTO | null = null;
public newStatus: string = '';
public newTotalPrice: number = 0;
public newAddress: string = '';
constructor(
private orderService: OrderService,
private toastr: ToastrService
) {}
ngOnInit(): void {
this.loadOrders();
}
loadOrders(): void {
this.isLoading = true;
this.orderService.getAll().subscribe({
next: (data) => {
this.orders = data;
this.isLoading = false;
},
error: (err) => {
console.error('Error loading orders:', err);
this.isLoading = false;
}
});
}
openEditPopup(order: OrderDTO): void {
this.selectedOrder = order;
this.newStatus = order.status;
this.newTotalPrice = order.totalPrice;
this.newAddress = order.address;
this.showEditPopup = true;
}
cancelEditPopup(): void {
this.showEditPopup = false;
this.selectedOrder = null;
this.newStatus = '';
this.newTotalPrice = 0;
this.newAddress = '';
}
confirmEditOrder(): void {
if (!this.selectedOrder) return;
const updates = {
status: this.newStatus,
totalPrice: this.newTotalPrice,
address: this.newAddress
};
console.log('Order update payload:', updates);
this.orderService.updateOrderFields(this.selectedOrder.id, updates).subscribe({
next: () => {
this.toastr.success('Order updated successfully!');
this.loadOrders();
this.cancelEditPopup();
},
error: () => {
this.toastr.error('Error updating order.');
}
});
}
confirmDelete(order: OrderDTO): void {
this.selectedOrder = order;
if (!this.selectedOrder) return;
this.orderService.delete(this.selectedOrder.id).subscribe({
next: () => {
this.toastr.success('Order deleted successfully!');
this.loadOrders();
},
error: () => {
this.toastr.error('Error deleting order.');
}
});
}
}