Skip to content

Commit

Permalink
Improved: added support to update productStore after updating the fac…
Browse files Browse the repository at this point in the history
…ility(#dxp-288)
  • Loading branch information
R-Sourabh committed Nov 19, 2024
1 parent 40c4515 commit 3542fae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current facility information
*/
async setFacility ({ commit, dispatch, state }, payload) {
async setFacility ({ commit, dispatch, state }, facility) {
// On slow api response, setFacility takes long to update facility in state.
// Hence displaying loader to not allowing user to navigate to orders page to avoid wrong results.
emitter.emit('presentLoader', {message: 'Updating facility', backdropDismiss: false})

try {
const token = store.getters['user/getUserToken'];
const userProfile = JSON.parse(JSON.stringify(state.current as any));
userProfile.stores = await UserService.getEComStores(token, payload.facility);
userProfile.stores = await UserService.getEComStores(token, facility);

let preferredStore = userProfile.stores[0];
const preferredStoreId = await UserService.getPreferredStore(token);
Expand All @@ -200,7 +200,6 @@ const actions: ActionTree<UserState, RootState> = {
store && (preferredStore = store)
}
commit(types.USER_INFO_UPDATED, userProfile);
commit(types.USER_CURRENT_FACILITY_UPDATED, payload.facility);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, preferredStore);
this.dispatch('order/clearOrders')
await dispatch('getDisableShipNowConfig')
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export const SN_USER = 'user'
export const USER_TOKEN_CHANGED = SN_USER + '/TOKEN_CHANGED'
export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_PREFERENCE_UPDATED = SN_USER + '/PREFERENCE_UPDATED'
Expand Down
6 changes: 3 additions & 3 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<section>
<DxpOmsInstanceNavigator />
<DxpFacilitySwitcher @updateFacility="updateFacility()"/>
<DxpFacilitySwitcher @updateFacility="updateFacility($event)"/>

<ion-card>
<ion-card-header>
Expand Down Expand Up @@ -452,9 +452,9 @@ export default defineComponent({
this.updateOrderLimitType()
}
},
async updateFacility() {
async updateFacility(facility: any) {
await this.store.dispatch('user/setFacility', facility);
await this.store.dispatch('user/fetchNotificationPreferences')
this.store.dispatch('order/clearOrders')
this.getCurrentFacilityDetails();
this.getFacilityOrderCount();
this.getEcomInvStatus();
Expand Down

0 comments on commit 3542fae

Please sign in to comment.