From e600a1284ffa9d629f54ff181ee20369d1a65ecc Mon Sep 17 00:00:00 2001 From: Aashutosh soni Date: Sat, 19 Oct 2024 13:52:35 +0530 Subject: [PATCH] fixed: #395 Incorrect SKU search retains previous results instead of displaying an empty state in the add product modal --- src/views/AddProductToPOModal.vue | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/views/AddProductToPOModal.vue b/src/views/AddProductToPOModal.vue index a45a0065..5c8c03f9 100644 --- a/src/views/AddProductToPOModal.vue +++ b/src/views/AddProductToPOModal.vue @@ -10,7 +10,7 @@ - + -
- empty-state -

{{ translate("Enter a SKU, or product name to search a product") }}

-
+ +
@@ -85,6 +92,8 @@ export default defineComponent({ data() { return { queryString: this.selectedSKU ? this.selectedSKU : '', + products: [], + hasSearched: false, isScrollingEnabled: false } }, @@ -121,6 +130,30 @@ export default defineComponent({ showToast(translate("Enter product sku to search")) } }, + async searchProducts() { + this.hasSearched = true; + this.products = []; // Clear the products array before each search + + if (this.queryString) { + const viewSize = process.env.VUE_APP_VIEW_SIZE; + const payload = { + viewSize, + viewIndex: 0, + queryString: this.queryString, + }; + + try { + const response = await this.store.dispatch("product/findProduct", payload); + if (response && response.data && response.data.response && response.data.response.docs) { + this.products = response.data.response.docs; + } else { + console.error("Unexpected response structure:", response); + } + } catch (error) { + console.error("Error fetching products:", error); + } + } + }, enableScrolling() { const parentElement = (this as any).$refs.contentRef.$el const scrollEl = parentElement.shadowRoot.querySelector("main[part='scroll']")