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

Implemented: functionality to product store card on facility details page (#10) #14

Merged
merged 25 commits into from
Nov 27, 2023

Conversation

amansinghbais
Copy link
Contributor

Related Issues

Closes #10

Short Description and Why It's Useful

Made product store card dynamic and functional on the facility details page.

  • Displayed all product stores inside the modal
  • Displayed associated product stores in the product store card at facility details page.
  • Api and functionality to remove product store association with facility.
  • Api and functionality to associate a product store with facility.

Screenshots of Visual Changes before/after (If There Are Any)

Contribution and Currently Important Rules Acceptance

import { mapGetters, useStore } from "vuex";
import { FacilityService } from "@/services/FacilityService";
import { DateTime } from "luxon";
import { hasError } from "@hotwax/oms-api";
Copy link
Contributor

Choose a reason for hiding this comment

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

Import from adapter instead of importing from oms-api

import { FacilityService } from "@/services/FacilityService";
import { DateTime } from "luxon";
import { hasError } from "@hotwax/oms-api";
import { showToast } from "@/utils";

export default defineComponent({
name: "OpenStorePopover",
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
name: "OpenStorePopover",
name: "ProductStorePopover",

await this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId })
}
} catch(err) {
console.error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use logger instead of console.


// refetching product stores with updated roles
await this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId })
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In case of error throw resp.data from else section.

@@ -141,6 +141,33 @@ const actions: ActionTree<FacilityState, RootState> = {
facilityTypeId: ''
})
commit(types.FACILITY_LIST_UPDATED , { facilities: [], total: 0 });
},

async getFacilityProductStores({ commit, state }, params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused params.

try {
const resp = await FacilityService.getFacilityProductStores(payload)

if (!hasError(resp) || resp.data.error === 'No record found') {
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to check for exact error message explicitly, hasError method already checks for error in resp. Instead check for resp.data.count field.

const resp = await FacilityService.getFacilityProductStores(payload)

if (!hasError(resp) || resp.data.error === 'No record found') {
productStores = resp.data.docs ? resp.data.docs : []
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use ternary, as we will already check whether the resp has some data or not, using count param

throw resp.data
}
} catch (error) {
console.error('Failed to fetch user associated product stores.', error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unwanted console statements

@@ -140,27 +140,17 @@
<ion-card-title>
{{ translate("Product Stores") }}
</ion-card-title>
<ion-button @click="addProductStore" fill="clear">
<ion-button @click="selectProductStore()" fill="clear">
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
<ion-button @click="selectProductStore()" fill="clear">
<ion-button @click="selectProductStores()" fill="clear">


const hasFailedResponse = [...updateResponses, ...createResponses].some((response: any) => response.status === 'rejected')
if(hasFailedResponse) {
showToast(translate('Failed to update some facility stores'))
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
showToast(translate('Failed to update some facility stores'))
showToast(translate('Failed to update product stores'))

this.removeProductFromPrimaryMember()
}
})
showToast(translate('Facility stores updated successfully.'))
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
showToast(translate('Facility stores updated successfully.'))
showToast(translate('Product stores updated successfully.'))

"facilityId": this.facilityId,
"facilityGroupId": this.primaryMember.facilityGroupId,
"fromDate": this.primaryMember.fromDate,
"thruDate": DateTime.now().toMillis()
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle case when having error in the resp.

IonContent,
IonList,
IonListHeader,
IonIcon,
Copy link
Contributor

Choose a reason for hiding this comment

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

Arrange imports in alphabetical order.

@ravilodhi ravilodhi merged commit 123f8ab into hotwax:main Nov 27, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the product store card dynamic and functional on the facility details page
3 participants