changes are done
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Component, OnInit, AfterViewInit, OnDestroy, signal, ViewChild, ElementRef } from '@angular/core';
|
||||
import { Component, OnInit, AfterViewInit, OnDestroy, signal, ViewChild, ElementRef, DestroyRef, inject } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@@ -14,6 +15,7 @@ import { MatToolbarModule } from '@angular/material/toolbar';
|
||||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { ApiService } from '../../services';
|
||||
import { ToastService } from '../../services/toast.service';
|
||||
import { Item } from '../../models';
|
||||
import { CreateDialogComponent } from '../../components/create-dialog/create-dialog.component';
|
||||
import { ConfirmDialogComponent } from '../../components/confirm-dialog/confirm-dialog.component';
|
||||
@@ -58,10 +60,13 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
subcategoryId = signal<string>('');
|
||||
projectId = signal<string>('');
|
||||
|
||||
private destroyRef = inject(DestroyRef);
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private apiService: ApiService,
|
||||
private toast: ToastService,
|
||||
private snackBar: MatSnackBar,
|
||||
private dialog: MatDialog,
|
||||
public lang: LanguageService
|
||||
@@ -74,7 +79,7 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.projectId.set(parentParams['projectId']);
|
||||
}
|
||||
|
||||
this.route.params.subscribe(params => {
|
||||
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
||||
this.subcategoryId.set(params['subcategoryId']);
|
||||
this.page.set(1);
|
||||
this.items.set([]);
|
||||
@@ -113,7 +118,7 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Failed to load items', err);
|
||||
this.snackBar.open('Failed to load items', 'Close', { duration: 3000 });
|
||||
this.toast.error(this.lang.t('FAILED_LOAD_ITEMS'));
|
||||
this.loading.set(false);
|
||||
}
|
||||
});
|
||||
@@ -177,7 +182,7 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
bulkToggleVisibility(visible: boolean) {
|
||||
const itemIds = Array.from(this.selectedItems());
|
||||
if (!itemIds.length) {
|
||||
this.snackBar.open('No items selected', 'Close', { duration: 2000 });
|
||||
this.toast.warning(this.lang.t('NO_ITEMS_SELECTED'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -188,11 +193,11 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
itemIds.includes(item.id) ? { ...item, visible } : item
|
||||
)
|
||||
);
|
||||
this.snackBar.open(`Updated ${itemIds.length} items`, 'Close', { duration: 2000 });
|
||||
this.toast.success(`${this.lang.t('UPDATED')} ${itemIds.length} ${this.lang.t('ITEMS_COUNT')}`);
|
||||
this.selectedItems.set(new Set());
|
||||
},
|
||||
error: (err) => {
|
||||
this.snackBar.open('Failed to update items', 'Close', { duration: 3000 });
|
||||
this.toast.error(this.lang.t('FAILED_UPDATE_ITEMS'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -220,12 +225,12 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
const dialogRef = this.dialog.open(CreateDialogComponent, {
|
||||
width: '500px',
|
||||
data: {
|
||||
title: 'Create New Item',
|
||||
title: this.lang.t('CREATE_NEW_ITEM'),
|
||||
fields: [
|
||||
{ name: 'name', label: 'Item Name', type: 'text', required: true },
|
||||
{ name: 'simpleDescription', label: 'Simple Description', type: 'text', required: false },
|
||||
{ name: 'price', label: 'Price', type: 'number', required: true },
|
||||
{ name: 'currency', label: 'Currency', type: 'select', required: true, value: 'USD',
|
||||
{ name: 'name', label: this.lang.t('ITEM_NAME'), type: 'text', required: true },
|
||||
{ name: 'simpleDescription', label: this.lang.t('SIMPLE_DESCRIPTION'), type: 'text', required: false },
|
||||
{ name: 'price', label: this.lang.t('PRICE'), type: 'number', required: true },
|
||||
{ name: 'currency', label: this.lang.t('CURRENCY'), type: 'select', required: true, value: 'USD',
|
||||
options: [
|
||||
{ value: 'USD', label: '🇺🇸 USD' },
|
||||
{ value: 'EUR', label: '🇪🇺 EUR' },
|
||||
@@ -234,8 +239,8 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
{ value: 'UAH', label: '🇺🇦 UAH' }
|
||||
]
|
||||
},
|
||||
{ name: 'quantity', label: 'Quantity', type: 'number', required: true, value: 0 },
|
||||
{ name: 'visible', label: 'Visible', type: 'toggle', required: false, value: true }
|
||||
{ name: 'quantity', label: this.lang.t('QUANTITY'), type: 'number', required: true, value: 0 },
|
||||
{ name: 'visible', label: this.lang.t('VISIBLE'), type: 'toggle', required: false, value: true }
|
||||
]
|
||||
}
|
||||
});
|
||||
@@ -247,14 +252,14 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
this.apiService.createItem(subcategoryId, result).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Item created successfully', 'Close', { duration: 3000 });
|
||||
this.toast.success(this.lang.t('ITEM_CREATED'));
|
||||
this.page.set(1);
|
||||
this.items.set([]);
|
||||
this.loadItems();
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error creating item:', err);
|
||||
this.snackBar.open('Failed to create item', 'Close', { duration: 3000 });
|
||||
this.toast.error(this.lang.t('FAILED_CREATE_ITEM'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -266,10 +271,10 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
data: {
|
||||
title: 'Delete Item',
|
||||
message: `Are you sure you want to delete "${item.name}"? This action cannot be undone.`,
|
||||
confirmText: 'Delete',
|
||||
cancelText: 'Cancel',
|
||||
title: this.lang.t('DELETE_ITEM'),
|
||||
message: `${this.lang.t('CONFIRM_DELETE')} "${item.name}"?`,
|
||||
confirmText: this.lang.t('DELETE'),
|
||||
cancelText: this.lang.t('CANCEL'),
|
||||
dangerous: true
|
||||
}
|
||||
});
|
||||
@@ -278,14 +283,14 @@ export class ItemsListComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
if (result) {
|
||||
this.apiService.deleteItem(item.id).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Item deleted successfully', 'Close', { duration: 3000 });
|
||||
this.toast.success(this.lang.t('ITEM_DELETED'));
|
||||
this.page.set(1);
|
||||
this.items.set([]);
|
||||
this.loadItems();
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error deleting item:', err);
|
||||
this.snackBar.open('Failed to delete item', 'Close', { duration: 3000 });
|
||||
this.toast.error(this.lang.t('FAILED_DELETE_ITEM'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user