Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default defineComponent({
...mapGetters({
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl',
currentEComStore: 'user/getCurrentEComStore',
currentProductStore: 'user/getCurrentProductStore',
allNotificationPrefs: 'user/getAllNotificationPrefs'
})
},
Expand Down Expand Up @@ -100,7 +100,7 @@ export default defineComponent({
// token is available which results in api failure as unauthenticated, thus making logout call and then login call again and so on.
if(this.userToken) {
// Get product identification from api using dxp-component
await useProductIdentificationStore().getIdentificationPref(this.currentEComStore?.productStoreId)
await useProductIdentificationStore().getIdentificationPref(this.currentProductStore?.productStoreId)
.catch((error) => logger.error(error));

// check if firebase configurations are there.
Expand Down
4 changes: 2 additions & 2 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getUserProfile = async (token: any): Promise<any> => {
}
}

const getCurrentEComStore = async (token: any, facilityId: any): Promise<any> => {
const getCurrentProductStore = async (token: any, facilityId: any): Promise<any> => {

// If the facilityId is not provided, it may be case of user not associated with any facility or the logout
if (!facilityId) {
Expand Down Expand Up @@ -264,7 +264,7 @@ const ensurePartyRole = async (payload: any): Promise <any> => {
export const UserService = {
ensurePartyRole,
login,
getCurrentEComStore,
getCurrentProductStore,
getRerouteFulfillmentConfig,
getUserPermissions,
getUserProfile,
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default interface UserState {
current: any;
instanceUrl: string;
permissions: any;
currentEComStore: any;
currentProductStore: any;
partialOrderRejectionConfig: any
notifications: any;
notificationPrefs: any;
Expand Down
40 changes: 20 additions & 20 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ const actions: ActionTree<UserState, RootState> = {
return uniqueFacilities
}, []);
// TODO Use a separate API for getting facilities, this should handle user like admin accessing the app
const currentEComStore = await UserService.getCurrentEComStore(token, getCurrentFacilityId());
const currentProductStore = await UserService.getCurrentProductStore(token, getCurrentFacilityId());



updateToken(token)

// The setEComStorePreference method requires userId, Hence setting userProfile in the following line
// The setProductStorePreference method requires userId, Hence setting userProfile in the following line
commit(types.USER_INFO_UPDATED, userProfile);
await useUserStore().setEComStorePreference(currentEComStore);
await useUserStore().setEComStorePreference(currentProductStore);
/* ---- Guard clauses ends here --- */

setPermissions(appPermissions);
Expand All @@ -104,12 +104,12 @@ const actions: ActionTree<UserState, RootState> = {
}

// TODO user single mutation
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore)
commit(types.USER_CURRENT_PRODUCT_STORE_UPDATED, currentProductStore)
commit(types.USER_PERMISSIONS_UPDATED, appPermissions);
commit(types.USER_TOKEN_CHANGED, { newToken: token })

// Get product identification from api using dxp-component
await useProductIdentificationStore().getIdentificationPref(currentEComStore?.productStoreId)
await useProductIdentificationStore().getIdentificationPref(currentProductStore?.productStoreId)

//fetching partial order rejection config for BOPIS orders
await dispatch("getPartialOrderRejectionConfig");
Expand Down Expand Up @@ -199,17 +199,17 @@ const actions: ActionTree<UserState, RootState> = {
// clearing the orders state whenever changing the facility
dispatch("order/clearOrders", null, {root: true})
dispatch("product/clearProducts", null, {root: true})
const previousEComStore = await useUserStore().getCurrentEComStore as any
// fetching the eComStore for updated facility
const eComStore = await UserService.getCurrentEComStore(token, facilityId);
const previousProductStore = await useUserStore().getCurrentEComStore as any

Choose a reason for hiding this comment

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

medium

For consistency and to rely on the local state as the source of truth, it's better to get the previous product store from the Vuex state directly. This avoids calling an external library with a now-inconsistent name (getCurrentEComStore) and also removes a potentially unnecessary await. The local state this.state.user.currentProductStore holds the correct value before the facility is updated.

    const previousProductStore = this.state.user.currentProductStore;

// fetching the ProductStore for updated facility
const productStore = await UserService.getCurrentProductStore(token, facilityId);

if(previousEComStore.productStoreId !== eComStore.productStoreId) {
await useUserStore().setEComStorePreference(eComStore);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, eComStore)
if(previousProductStore.productStoreId !== productStore.productStoreId) {
await useUserStore().setEComStorePreference(productStore);
commit(types.USER_CURRENT_PRODUCT_STORE_UPDATED, productStore)
//fetching partial order rejection config for BOPIS orders aftering updating facility
await dispatch("getPartialOrderRejectionConfig");
await dispatch("fetchBopisProductStoreSettings");
await useProductIdentificationStore().getIdentificationPref(eComStore?.productStoreId)
await useProductIdentificationStore().getIdentificationPref(productStore?.productStoreId)
}
},
/**
Expand All @@ -235,7 +235,7 @@ const actions: ActionTree<UserState, RootState> = {
let config = {};
const params = {
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"productStoreId": this.state.user.currentProductStore.productStoreId,
"settingTypeEnumId": "BOPIS_PART_ODR_REJ"
},
"entityName": "ProductStoreSetting",
Expand Down Expand Up @@ -277,7 +277,7 @@ const actions: ActionTree<UserState, RootState> = {
//Create Product Store Setting
payload = {
...payload,
"productStoreId": this.state.user.currentEComStore.productStoreId,
"productStoreId": this.state.user.currentProductStore.productStoreId,
"settingTypeEnumId": "BOPIS_PART_ODR_REJ"
}
resp = await UserService.createPartialOrderRejectionConfig(payload) as any
Expand Down Expand Up @@ -360,7 +360,7 @@ const actions: ActionTree<UserState, RootState> = {

const payload = {
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"productStoreId": this.state.user.currentProductStore.productStoreId,
"settingTypeEnumId": Object.keys(productStoreSettings),
"settingTypeEnumId_op": "in"
},
Expand Down Expand Up @@ -403,7 +403,7 @@ const actions: ActionTree<UserState, RootState> = {
}

const params = {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"productStoreId": this.state.user.currentProductStore.productStoreId,
"settingTypeEnumId": enumeration.enumId,
"settingValue": "false"
}
Expand All @@ -420,18 +420,18 @@ const actions: ActionTree<UserState, RootState> = {
async setProductStoreSetting({ commit, dispatch, state }, payload) {
const productStoreSettings = JSON.parse(process.env.VUE_APP_PRODUCT_STORE_SETTING_ENUMS);
let prefValue = state.bopisProductStoreSettings[payload.enumId]
const eComStoreId = this.state.user.currentEComStore.productStoreId;
const productStoreId = this.state.user.currentProductStore.productStoreId;

// when selecting none as ecom store, not updating the pref as it's not possible to save pref with empty productStoreId
if(!eComStoreId) {
if(!productStoreId) {
showToast(translate("Unable to update product store setting."))
return;
}

try {
let resp = await UtilService.getProductStoreSettings({
"inputFields": {
"productStoreId": this.state.user.currentEComStore.productStoreId,
"productStoreId": this.state.user.currentProductStore.productStoreId,
"settingTypeEnumId": payload.enumId
},
"entityName": "ProductStoreSetting",
Expand All @@ -440,7 +440,7 @@ const actions: ActionTree<UserState, RootState> = {
}) as any
if(!hasError(resp) && resp.data.docs[0]?.settingTypeEnumId) {
const params = {
"productStoreId": eComStoreId,
"productStoreId": productStoreId,
"settingTypeEnumId": payload.enumId,
"settingValue": `${payload.value}`
}
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const getters: GetterTree <UserState, RootState> = {
return baseUrl ? baseUrl : state.instanceUrl;
},
getCurrency (state) {
return state.currentEComStore.defaultCurrencyUomId ? state.currentEComStore.defaultCurrencyUomId : 'USD';
return state.currentProductStore.defaultCurrencyUomId ? state.currentProductStore.defaultCurrencyUomId : 'USD';
},
getUserPermissions (state) {
return state.permissions;
},
getCurrentEComStore(state) {
return state.currentEComStore;
getCurrentProductStore(state) {
return state.currentProductStore;
},
getPartialOrderRejectionConfig(state) {
return state.partialOrderRejectionConfig;
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const userModule: Module<UserState, RootState> = {
token: '',
current: {},
instanceUrl: '',
currentEComStore: {},
currentProductStore: {},
partialOrderRejectionConfig: {},
permissions: [],
notifications: [],
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED'
export const USER_CURRENT_PRODUCT_STORE_UPDATED = SN_USER + '/CURRENT_PRODUCT_STORE_UPDATED'
export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED'
export const USER_PARTIAL_ORDER_REJECTION_CONFIG_UPDATED = SN_USER + '/PARTIAL_ORDER_REJECTION_CONFIG_UPDATED'
export const USER_NOTIFICATIONS_UPDATED = SN_USER + '/NOTIFICATIONS_UPDATED'
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const mutations: MutationTree <UserState> = {
[types.USER_INSTANCE_URL_UPDATED] (state, payload) {
state.instanceUrl = payload;
},
[types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) {
state.currentEComStore = payload
[types.USER_CURRENT_PRODUCT_STORE_UPDATED] (state, payload) {
state.currentProductStore = payload
},
[types.USER_PERMISSIONS_UPDATED] (state, payload) {
state.permissions = payload
Expand Down
6 changes: 3 additions & 3 deletions src/views/OrderDetailUpdated.vue
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export default defineComponent({
getBopisProductStoreSettings: 'user/getBopisProductStoreSettings',
rejectReasons: 'util/getRejectReasons',
cancelReasons: 'util/getCancelReasons',
currentEComStore: 'user/getCurrentEComStore',
currentProductStore: 'user/getCurrentProductStore',
getFacilityName: "util/getFacilityName",
getEnumDescription: "util/getEnumDescription"
})
Expand Down Expand Up @@ -922,7 +922,7 @@ export default defineComponent({
statusId_op: "in",
systemJobEnumId: "JOB_UL_CNCLD_ORD",
systemJobEnumId_op: "equals",
productStoreId: this.currentEComStore?.productStoreId,
productStoreId: this.currentProductStore?.productStoreId,
},
orderBy: "runTime DESC",
noConditionFind: "Y",
Expand Down Expand Up @@ -950,7 +950,7 @@ export default defineComponent({
try {
const params = {
inputFields: {
productStoreId: this.currentEComStore?.productStoreId,
productStoreId: this.currentProductStore?.productStoreId,
productStoreId_op: "equals"
},
entityName: "ShopifyConfig",
Expand Down
4 changes: 2 additions & 2 deletions src/views/ProductDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default defineComponent({
getInventoryInformation: 'stock/getInventoryInformation',
orders: 'order/getOrders',
getProduct: 'product/getProduct',
currentEComStore: 'user/getCurrentEComStore',
currentProductStore: 'user/getCurrentProductStore',
}),
},
async beforeMount() {
Expand Down Expand Up @@ -277,7 +277,7 @@ export default defineComponent({

try {
const resp: any = await StockService.checkShippingInventory({
productStoreId: this.currentEComStore.productStoreId,
productStoreId: this.currentProductStore.productStoreId,
productIds: this.currentVariant.productId,
});

Expand Down
12 changes: 6 additions & 6 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export default defineComponent({
computed: {
...mapGetters({
userProfile: 'user/getUserProfile',
currentEComStore: 'user/getCurrentEComStore',
currentProductStore: 'user/getCurrentProductStore',
partialOrderRejectionConfig: 'user/getPartialOrderRejectionConfig',
firebaseDeviceId: 'user/getFirebaseDeviceId',
notificationPrefs: 'user/getNotificationPrefs',
Expand Down Expand Up @@ -312,10 +312,10 @@ export default defineComponent({
},
methods: {
async updateFacility(facility: any) {
const previousEComStoreId = this.currentEComStore.productStoreId
const previousProductStoreId = this.currentProductStore.productStoreId
await this.store.dispatch('user/setFacility', facility?.facilityId);
await this.store.dispatch('user/fetchNotificationPreferences')
if(Object.keys(this.rerouteFulfillmentConfigMapping).length > 0 && previousEComStoreId !== this.currentEComStore.productStoreId) {
if(Object.keys(this.rerouteFulfillmentConfigMapping).length > 0 && previousProductStoreId !== this.currentProductStore.productStoreId) {
this.getAvailableShipmentMethods();
this.getRerouteFulfillmentConfiguration();
}
Expand Down Expand Up @@ -413,7 +413,7 @@ export default defineComponent({
try {
const resp = await UserService.getRerouteFulfillmentConfig({
"inputFields": {
"productStoreId": this.currentEComStore?.productStoreId,
"productStoreId": this.currentProductStore?.productStoreId,
"shipmentMethodTypeId": "STOREPICKUP",
"shipmentMethodTypeId_op": "notEqual"
},
Expand All @@ -433,7 +433,7 @@ export default defineComponent({
try {
const payload = {
"inputFields": {
"productStoreId": this.currentEComStore?.productStoreId,
"productStoreId": this.currentProductStore?.productStoreId,
settingTypeEnumId
},
"entityName": "ProductStoreSetting",
Expand Down Expand Up @@ -469,7 +469,7 @@ export default defineComponent({
},
async updateRerouteFulfillmentConfiguration(config: any, value: any) {
const params = {
"productStoreId": this.currentEComStore?.productStoreId,
"productStoreId": this.currentProductStore?.productStoreId,
"settingTypeEnumId": config.settingTypeEnumId,
"settingValue": value
}
Expand Down
Loading