feat: Refactor select components to use IPaginatedResponse and streamline data fetching

- Updated select components for bank accounts, bank branches, customers, inventories, product brands, product categories, products, and suppliers to extend AbstractSelectComponent with IPaginatedResponse.
- Replaced getData() method with getDataService() to return observables directly from service calls.
- Enhanced filters component to set default inventory and product selections.
- Modified inventory component to conditionally render columns based on variant type.
- Introduced InventoryStore for managing inventory state and fetching single inventory details.
- Added empty state messages in cardex and other components for better user experience.
- Updated inner pages header to use h4 for titles and improved layout in empty state component.
This commit is contained in:
2025-12-28 17:51:54 +03:30
parent 879e29f54f
commit 2583bc7ad5
26 changed files with 308 additions and 170 deletions
@@ -1,6 +1,7 @@
import { Maybe } from '@/core';
import { Component, EventEmitter, Input, model, Output, signal } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
export interface ISelectItem {
id: number;
@@ -11,7 +12,7 @@ export interface ISelectItem {
selector: 'abstract-select-field',
template: '',
})
export abstract class AbstractSelectComponent<T = ISelectItem> {
export abstract class AbstractSelectComponent<T = ISelectItem, serviceResponse = T[]> {
@Input() control = new FormControl<Maybe<number | T>>(null);
@Input() canInsert: boolean = false;
@Input() showLabel: boolean = true;
@@ -20,6 +21,7 @@ export abstract class AbstractSelectComponent<T = ISelectItem> {
@Input() isFullDataOptionValue: boolean = false;
@Input() optionValue = 'id';
@Output() onChange = new EventEmitter<Maybe<T>>();
@Output() onSetDefaultDataItem = new EventEmitter<T>();
loading = signal(false);
items = signal<Maybe<T[]>>(null);
@@ -36,7 +38,40 @@ export abstract class AbstractSelectComponent<T = ISelectItem> {
});
}
abstract getData(): void;
abstract getDataService(): Observable<serviceResponse>;
getData() {
this.loading.set(true);
this.getDataService().subscribe({
next: (res) => {
if (Array.isArray(res)) {
this.items.set(res);
// @ts-ignore
} else if ('data' in res) {
// @ts-ignore
this.items.set(res.data);
}
const defaultValue = this.control.value;
if (defaultValue) {
const selectedItem = this.items()?.find(
(item) => (item as Record<string, any>)[this.optionValue] == defaultValue,
) as T;
if (selectedItem) {
this.onSetDefaultDataItem.emit(selectedItem);
}
}
this.loading.set(false);
},
error: () => {
this.loading.set(false);
},
});
}
setDefaultDataItem(item: T) {
this.onSetDefaultDataItem.emit(item);
}
refresh() {
this.getData();
@@ -54,6 +89,8 @@ export abstract class AbstractSelectComponent<T = ISelectItem> {
}
change(value: Maybe<T>) {
console.log('first');
if (typeof value !== 'object') {
// @ts-ignore
this.onChange.emit(this.items()?.find((item) => item[this.optionValue] === value));
@@ -64,4 +64,15 @@
<td class="text-center!"><span [appPriceMask]="item.totalCost"></span></td> -->
</tr>
</ng-template>
<ng-template pTemplate="emptymessage">
<tr>
<td [attr.colspan]="11">
<uikit-empty-state
[title]="'هیچ رکوردی یافت نشد'"
[description]="'برای این بازه زمانی و فیلترهای انتخاب شده، رکوردی وجود ندارد.'"
></uikit-empty-state>
</td>
</tr>
</ng-template>
</p-table>
@@ -1,5 +1,6 @@
import { CatalogMovementReferenceTagComponent } from '@/shared/catalog/movementReferenceTypes';
import { JalaliDateDirective, PriceMaskDirective } from '@/shared/directives';
import { UikitEmptyStateComponent } from '@/uikit';
import { Component, Input } from '@angular/core';
import { TableModule } from 'primeng/table';
import { ICardexItem } from './type';
@@ -12,6 +13,7 @@ import { ICardexItem } from './type';
JalaliDateDirective,
CatalogMovementReferenceTagComponent,
PriceMaskDirective,
UikitEmptyStateComponent,
],
hostDirectives: [PriceMaskDirective],
})
@@ -4,7 +4,7 @@
@if (backRoute) {
<p-button icon="pi pi-arrow-right" aria-label="بازگشت" outlined [routerLink]="backRoute" />
}
<h3 class="m-0">{{ pageTitle }}</h3>
<h4 class="m-0">{{ pageTitle }}</h4>
</div>
</div>
@if (actions) {