Skip to content

Commit

Permalink
Merge pull request #235 from ymaheshwari1/fix/qoh-card
Browse files Browse the repository at this point in the history
Improved: logic to fetch the qoh config when productStore is changed
  • Loading branch information
ymaheshwari1 authored Dec 22, 2023
2 parents e7ff66e + b5818d8 commit 001e54e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
14 changes: 11 additions & 3 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const actions: ActionTree<UserState, RootState> = {
commit(types.USER_CURRENT_FACILITY_UPDATED, currentFacility);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore)
commit(types.USER_PERMISSIONS_UPDATED, appPermissions);
commit(types.USER_VIEW_QOH_CNFG_UPDATED, currentQOHViewConfig.settingValue == "true" )
commit(types.USER_VIEW_QOH_CNFG_UPDATED, { currentQOHViewConfig, viewQOH: currentQOHViewConfig.settingValue == "true" })
commit(types.USER_TOKEN_CHANGED, { newToken: token })
} catch (err: any) {
// If any of the API call in try block has status code other than 2xx it will be handled in common catch block.
Expand Down Expand Up @@ -166,14 +166,22 @@ const actions: ActionTree<UserState, RootState> = {
},

// update current facility information
async setFacility ({ commit, state }, payload) {
async setFacility ({ commit, dispatch, state }, payload) {
let facility = payload.facility;
if(!facility && state.current?.facilities) {
facility = state.current.facilities.find((facility: any) => facility.facilityId === payload.facilityId);
}
commit(types.USER_CURRENT_FACILITY_UPDATED, facility);
const eComStore = await UserService.getCurrentEComStore(undefined, facility?.facilityId);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, eComStore)

let currentQOHViewConfig = {} as any

// fetching QOH config value for the updated eComStore
if(eComStore?.productStoreId) {
currentQOHViewConfig = await UserService.getQOHViewConfig(undefined, eComStore.productStoreId) as any;
}
dispatch('updateViewQOHConfig', { currentQOHViewConfig, viewQOH: currentQOHViewConfig.settingValue == "true" });
},

// Set User Instance Url
Expand All @@ -182,7 +190,7 @@ const actions: ActionTree<UserState, RootState> = {
updateInstanceUrl(payload)
},

updateViewQOHConfig( { commit }, config){
updateViewQOHConfig({ commit }, config) {
commit(types.USER_VIEW_QOH_CNFG_UPDATED, config)
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getters: GetterTree <UserState, RootState> = {
return state.currentEComStore;
},
getViewQOHConfig (state) {
return state.config.viewQOH;
return state.config;
}
}
export default getters;
1 change: 1 addition & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const userModule: Module<UserState, RootState> = {
instanceUrl: '',
permissions: [],
config: {
currentQOHViewConfig: {},
viewQOH: false
},
currentEComStore: {}
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const mutations: MutationTree <UserState> = {
state.permissions = payload
},
[types.USER_VIEW_QOH_CNFG_UPDATED] (state, payload) {
state.config.viewQOH = payload;
state.config.viewQOH = payload.viewQOH;
state.config.currentQOHViewConfig = payload.currentQOHViewConfig;
}
}
export default mutations;
15 changes: 8 additions & 7 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ export default defineComponent({
currentFacility: 'user/getCurrentFacility',
uploadProducts: 'product/getUploadProducts',
currentEComStore: 'user/getCurrentEComStore',
QOHConfig: 'user/getViewQOHConfig'
})
},
methods: {
async getViewQOHConfig() {
this.currentQOHViewConfig = await UserService.getQOHViewConfig(undefined, this.currentEComStore?.productStoreId) as any;
if (Object.keys(this.currentQOHViewConfig).length > 0) {
this.store.dispatch('user/updateViewQOHConfig', this.currentQOHViewConfig.settingValue == "true");
}
this.store.dispatch('user/updateViewQOHConfig', { currentQOHViewConfig: this.currentQOHViewConfig, viewQOH: this.currentQOHViewConfig.settingValue == "true" });
},
async updateViewQOHConfig(config: any, value: any) {
// Handled initial programmatical update
Expand Down Expand Up @@ -190,17 +189,18 @@ export default defineComponent({
// Fetch the updated configuration
await this.getViewQOHConfig();
},
setFacility (event: any) {
async setFacility (event: any) {
// adding check for this.currentFacility.facilityId as it gets set to undefined on logout
// but setFacility is called again due to :value="currentFacility.facilityId" in ion-select
if (this.userProfile && this.currentFacility.facilityId && event.detail.value != this.currentFacility.facilityId ) {
if (Object.keys(this.uploadProducts).length > 0) {
this.presentAlertOnFacilityChange(event.detail.value);
} else {
this.store.dispatch('user/setFacility', {
await this.store.dispatch('user/setFacility', {
'facility': this.userProfile.facilities.find((fac: any) => fac.facilityId == event.detail.value)
});
this.currentFacilityId = this.currentFacility.facilityId;
this.currentQOHViewConfig = this.QOHConfig.currentQOHViewConfig
}
}
},
Expand Down Expand Up @@ -238,12 +238,13 @@ export default defineComponent({
},
{
text: this.$t('Ok'),
handler: () => {
handler: async () => {
this.store.dispatch('product/clearUploadProducts');
this.store.dispatch('user/setFacility', {
await this.store.dispatch('user/setFacility', {
'facility': this.userProfile.facilities.find((fac: any) => fac.facilityId == facilityId)
});
this.currentFacilityId = this.currentFacility.facilityId
this.currentQOHViewConfig = this.QOHConfig.currentQOHViewConfig
}
}]
});
Expand Down
6 changes: 3 additions & 3 deletions src/views/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
<ion-label>{{ $filters.getFeature(product.featureHierarchy, '1/SIZE/') }}</ion-label>
</ion-chip>
</ion-item>
<ion-item v-if="viewQOH && product.availableQOH">
<ion-item v-if="QOHConfig.viewQOH && product.availableQOH">
<ion-label>{{ $t("In stock") }}</ion-label>
<ion-label slot="end">{{ product.availableQOH }}</ion-label>
</ion-item>
<ion-item v-if="viewQOH && product.availableQOH">
<ion-item v-if="QOHConfig.viewQOH && product.availableQOH">
<ion-label>{{ $t("Variance") }}</ion-label>
<ion-label slot="end">{{ product.quantity - product.availableQOH }}</ion-label>
</ion-item>
Expand Down Expand Up @@ -97,7 +97,7 @@ export default defineComponent({
...mapGetters({
uploadProducts: 'product/getUploadProducts',
currentFacility: 'user/getCurrentFacility',
viewQOH: 'user/getViewQOHConfig'
QOHConfig: 'user/getViewQOHConfig'
})
},
methods: {
Expand Down
8 changes: 4 additions & 4 deletions src/views/count.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
<ion-icon :icon="locationOutline" />
</ion-chip>
</ion-item>
<ion-item v-if="viewQOH">
<ion-item v-if="QOHConfig.viewQOH">
<ion-label>{{ $t("In stock") }}</ion-label>
<ion-label slot="end">{{ availableQOH }}</ion-label>
</ion-item>
<ion-item v-if="viewQOH">
<ion-item v-if="QOHConfig.viewQOH">
<ion-label>{{ $t("Variance") }}</ion-label>
<ion-label slot="end">{{ availableQOH && quantity ? quantity - availableQOH : "-" }}</ion-label>
</ion-item>
Expand Down Expand Up @@ -166,7 +166,7 @@
...mapGetters({
product: "product/getCurrent",
facility: 'user/getCurrentFacility',
viewQOH: 'user/getViewQOHConfig'
QOHConfig: 'user/getViewQOHConfig'
})
},
data(){
Expand All @@ -184,7 +184,7 @@
await this.store.dispatch("product/updateCurrentProduct", this.$route.params.sku);
this.quantity = this.product.quantity
await this.getFacilityLocations();
if (this.viewQOH) await this.getInventory()
if (this.QOHConfig.viewQOH) await this.getInventory()
},
methods: {
async selectLocation() {
Expand Down

0 comments on commit 001e54e

Please sign in to comment.