Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing reflecting changes without page reload #545

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions ui/src/app/shared/components/price-list/price-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,23 @@ export class PriceListComponent implements OnInit, OnChanges {
}

onSaveItem(itemPrice): void {
// this.store.dispatch(saveItemPrice({ itemPrice }));
this.pricingService.saveItemPrice(itemPrice).subscribe((response) => {
if (response && !response?.error) {
this.loadData();
if (
(this.itemSearchTerm && this.itemSearchTerm.length >= 3) ||
this.itemSearchTerm === ""
) {
this.store.dispatch(clearPricingItems());
this.store.dispatch(
loadPricingItems({
filterInfo: {
limit: 25,
startIndex: this.currentPage,
searchTerm:
this.itemSearchTerm !== "" ? this.itemSearchTerm : null,
conceptSet: this.currentDepartmentId,
},
})
);
console.log('Price saved successfully');

// Find the item in the local data and update it
const index = this.priceList.findIndex(
(item) => item.uuid === itemPrice.uuid
);
if (index > -1) {
// Update the specific item
this.priceList[index] = { ...this.priceList[index], ...response };
} else {
// If not found, optionally add it to the list (for new entries)
this.priceList = [...this.priceList, response];
}
} else {
console.error('Error saving item price:', response);
}
});
}
Expand Down