Skip to content

Commit

Permalink
Merge pull request #808 from amansinghbais/#807
Browse files Browse the repository at this point in the history
Improved: show message on login error page on no product store, dismissing loader and not changing facility on no store for new facility (#807)
  • Loading branch information
ravilodhi authored Oct 14, 2024
2 parents 5e84834 + da2a176 commit ded55cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
17 changes: 13 additions & 4 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ const recycleOutstandingOrders = async(payload: any): Promise<any> => {
})
}

const getEComStores = async (token: any, facilityId: any): Promise<any> => {
const getEComStores = async (token: any, facility: any): Promise<any> => {
try {
const params = {
"inputFields": {
"storeName_op": "not-empty",
facilityId
facilityId: facility.facilityId
},
"fieldList": ["productStoreId", "storeName"],
"entityName": "ProductStoreFacilityDetail",
Expand All @@ -110,12 +110,21 @@ const getEComStores = async (token: any, facilityId: any): Promise<any> => {
}
});
if (hasError(resp)) {
return Promise.reject(resp.data);
// Following promise reject pattern as OMS api, to show error message on the login page.
return Promise.reject({
code: 'error',
message: `Failed to fetch product stores for ${facility.facilityName} facility.`,
serverResponse: resp.data
})
} else {
return Promise.resolve(resp.data.docs);
}
} catch(error: any) {
return Promise.reject(error)
return Promise.reject({
code: 'error',
message: 'Something went wrong',
serverResponse: error
})
}
}

Expand Down
34 changes: 20 additions & 14 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const actions: ActionTree<UserState, RootState> = {

// TODO Use a separate API for getting facilities, this should handle user like admin accessing the app
const currentFacility = userProfile.facilities[0];
userProfile.stores = await UserService.getEComStores(token, currentFacility.facilityId);
userProfile.stores = await UserService.getEComStores(token, currentFacility);

let preferredStore = userProfile.stores[0]

Expand Down Expand Up @@ -187,22 +187,28 @@ const actions: ActionTree<UserState, RootState> = {
// Hence displaying loader to not allowing user to navigate to orders page to avoid wrong results.
emitter.emit('presentLoader', {message: 'Updating facility', backdropDismiss: false})

const userProfile = JSON.parse(JSON.stringify(state.current as any));
userProfile.stores = await UserService.getEComStores(undefined, payload.facility.facilityId);
try {
const userProfile = JSON.parse(JSON.stringify(state.current as any));
userProfile.stores = await UserService.getEComStores(undefined, payload.facility);

let preferredStore = userProfile.stores[0];
const preferredStoreId = await UserService.getPreferredStore(undefined);
let preferredStore = userProfile.stores[0];
const preferredStoreId = await UserService.getPreferredStore(undefined);

if (preferredStoreId) {
const store = userProfile.stores.find((store: any) => store.productStoreId === preferredStoreId);
store && (preferredStore = store)
if (preferredStoreId) {
const store = userProfile.stores.find((store: any) => store.productStoreId === preferredStoreId);
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')
await dispatch('getDisableUnpackConfig')
} catch(error: any) {
logger.error(error);
showToast(error?.message ? error.message : translate("Something went wrong"))
}
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')
await dispatch('getDisableUnpackConfig')

emitter.emit('dismissLoader')
},

Expand Down

0 comments on commit ded55cc

Please sign in to comment.