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

Users should be directly able to navigate to the product detail page (#1yzcv99). #81

Merged
merged 12 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/components/ProductListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default defineComponent({
props: ["product"],
methods: {
async viewProduct () {
await this.store.dispatch('product/updateCurrentProduct', {product: this.product});
this.router.push({ path: `/count/${this.product.sku}` })
}
},
Expand Down
22 changes: 17 additions & 5 deletions src/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const actions: ActionTree<ProductState, RootState> = {
// Remove added loader only when new query and not the infinite scroll
if (payload.viewIndex === 0) emitter.emit("dismissLoader");
} catch(error){
console.log(error)
console.error(error)
showToast(translate("Something went wrong"));
}
// TODO Handle specific error
Expand Down Expand Up @@ -72,7 +72,7 @@ const actions: ActionTree<ProductState, RootState> = {

emitter.emit("dismissLoader");
} catch (error) {
console.log(error);
console.error(error);
showToast(translate("Something went wrong"));
}

Expand All @@ -83,10 +83,22 @@ const actions: ActionTree<ProductState, RootState> = {
commit(types.PRODUCT_ADD_TO_UPLD_PRDTS, { product: payload })
},

updateCurrentProduct ({ commit, state }, payload) {
async updateCurrentProduct ({ commit, state }, payload) {
// search in uploadProducts that if the clicked product is already in the upload list and set it as current product
const currentProduct = state.uploadProducts[payload.product.sku]
commit(types.PRODUCT_CURRENT_UPDATED, { product: currentProduct ? currentProduct : payload.product })
const currentProduct = state.uploadProducts[payload]
if(currentProduct) {
commit(types.PRODUCT_CURRENT_UPDATED, { product: currentProduct })
} else {
const resp = await ProductService.fetchProducts({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the case when API returns an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir, updated code.

// used sku as we are currently only using sku to search for the product
"filters": ['sku: ' + '*' + payload + '*', 'isVirtual: false'],
})
if(resp.status === 200 && resp.data.response?.numFound > 0 && !hasError(resp)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(resp.status === 200 && resp.data.response?.numFound > 0 && !hasError(resp)) {
if(resp.status === 200 && !hasError(resp) && resp.data.response?.numFound > 0 ) {

commit(types.PRODUCT_CURRENT_UPDATED, { product: resp.data.response.docs[0] })
} else {
showToast(translate("Something went wrong"));
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/views/count.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
location: ""
}
},
ionViewWillEnter() {
this.fetchProduct(this.$route.params.sku)
},
async mounted(){
await this.getFacilityLocations();
},
Expand Down Expand Up @@ -162,6 +165,9 @@
showToast(translate("Enter the stock count for the product"))
}
},
fetchProduct(sku: any) {
this.store.dispatch("product/updateCurrentProduct", sku)
},
async getFacilityLocations() {
let resp;
try {
Expand Down