From 3af6dd47834bff0f6dc8931a0d7db069ebed8bca Mon Sep 17 00:00:00 2001 From: R-Sourabh Date: Mon, 18 Nov 2024 18:17:24 +0530 Subject: [PATCH] Improved: used getCurrentFacilityId util function to get current facility instead of useUserStore from dxp-component in various files(#dxp/288) --- src/services/UtilService.ts | 7 ++----- src/store/modules/carrier/actions.ts | 8 +++----- src/store/modules/stock/actions.ts | 8 +++----- src/store/modules/stock/getters.ts | 7 ++----- src/store/modules/transferorder/actions.ts | 5 ++--- src/store/modules/user/actions.ts | 9 ++++----- 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 34a87065..7757f694 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -1,8 +1,7 @@ import { api, hasError } from '@/adapter'; import logger from '@/logger'; import store from '@/store'; -import { isPdf } from '@/utils'; -import { useUserStore } from '@hotwax/dxp-components' +import { isPdf, getCurrentFacilityId } from '@/utils'; const fetchShipmentMethods = async (query: any): Promise => { return api({ @@ -30,8 +29,6 @@ const fetchPicklistInformation = async (query: any): Promise => { const findShipmentIdsForOrders = async(picklistBinIds: Array, orderIds: Array, statusId = ["SHIPMENT_APPROVED", "SHIPMENT_INPUT"]): Promise => { let shipmentIdsForOrders = {}; - const currentFacility: any = useUserStore().getCurrentFacility - const facilityId = currentFacility?.facilityId const params = { "entityName": "Shipment", @@ -40,7 +37,7 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array, orderIds: "primaryOrderId_op": "in", "picklistBinId": picklistBinIds, "picklistBinId_op": "in", - "originFacilityId": facilityId, + "originFacilityId": getCurrentFacilityId(), "statusId": statusId, "statusId_op": "in" }, diff --git a/src/store/modules/carrier/actions.ts b/src/store/modules/carrier/actions.ts index e57cdd5c..137da673 100644 --- a/src/store/modules/carrier/actions.ts +++ b/src/store/modules/carrier/actions.ts @@ -6,8 +6,8 @@ import { hasError } from '@/adapter' import * as types from './mutation-types' import logger from '@/logger' import store from '@/store'; -import { translate, useUserStore } from '@hotwax/dxp-components'; -import { showToast, isValidCarrierCode, isValidDeliveryDays } from '@/utils'; +import { translate } from '@hotwax/dxp-components'; +import { showToast, isValidCarrierCode, isValidDeliveryDays, getCurrentFacilityId } from '@/utils'; const actions: ActionTree = { @@ -358,8 +358,6 @@ const actions: ActionTree = { async fetchFacilityCarriers({ state, commit }, payload) { let facilityCarriers = [] as any; let viewIndex = 0, resp, docCount = 0; - const currentFacility: any = useUserStore().getCurrentFacility - const facilityId = currentFacility?.facilityId try { do { @@ -367,7 +365,7 @@ const actions: ActionTree = { "entityName": "FacilityAndParty", "inputFields": { "roleTypeId": "CARRIER", - "facilityId": facilityId + "facilityId": getCurrentFacilityId() }, "fieldList": ["facilityId", "partyId", "firstName", "lastName", "groupName", "roleTypeId", "fromDate"], "noConditionFind": "Y", diff --git a/src/store/modules/stock/actions.ts b/src/store/modules/stock/actions.ts index fd46e5cf..5330f324 100644 --- a/src/store/modules/stock/actions.ts +++ b/src/store/modules/stock/actions.ts @@ -5,14 +5,12 @@ import StockState from './StockState' import * as types from './mutation-types' import { hasError } from '@/adapter' import logger from '@/logger' -import { showToast } from '@/utils' -import { translate, useUserStore } from '@hotwax/dxp-components' +import { showToast, getCurrentFacilityId } from '@/utils' +import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { async fetchStock({ commit }, { productId, facilityId = '' }) { - const getCurrentFacility: any = useUserStore().getCurrentFacility - const currentFacilityId = getCurrentFacility?.facilityId - const id = facilityId ? facilityId : currentFacilityId + const id = facilityId ? facilityId : getCurrentFacilityId() try { const payload = { diff --git a/src/store/modules/stock/getters.ts b/src/store/modules/stock/getters.ts index 4c76cc9b..40bf6469 100644 --- a/src/store/modules/stock/getters.ts +++ b/src/store/modules/stock/getters.ts @@ -1,14 +1,11 @@ import { GetterTree } from 'vuex' import StockState from './StockState' import RootState from '../../RootState' -import { useUserStore } from "@hotwax/dxp-components"; +import { getCurrentFacilityId } from '@/utils'; const getters: GetterTree = { getProductStock: (state, getters) => (productId: any, facilityId?: any) => { - const getCurrentFacility: any = useUserStore().getCurrentFacility - const currentFacilityId = getCurrentFacility?.facilityId - const id = facilityId ? facilityId : currentFacilityId - + const id = facilityId ? facilityId : getCurrentFacilityId() return state.products[productId] ? state.products[productId][id] ? state.products[productId][id] : {} : {} } } diff --git a/src/store/modules/transferorder/actions.ts b/src/store/modules/transferorder/actions.ts index 1af53047..c926cb8f 100644 --- a/src/store/modules/transferorder/actions.ts +++ b/src/store/modules/transferorder/actions.ts @@ -7,7 +7,7 @@ import { hasError } from '@/adapter' import * as types from './mutation-types' import { escapeSolrSpecialChars, prepareOrderQuery } from '@/utils/solrHelper' import logger from '@/logger' -import { getProductIdentificationValue, translate, useUserStore } from '@hotwax/dxp-components' +import { getProductIdentificationValue, translate } from '@hotwax/dxp-components' import { showToast, getCurrentFacilityId } from "@/utils"; import { UtilService } from '@/services/UtilService' import store from "@/store"; @@ -18,7 +18,6 @@ const actions: ActionTree = { emitter.emit('presentLoader'); let resp; const transferOrderQuery = JSON.parse(JSON.stringify(state.transferOrder.query)) - const currentFacilityId = getCurrentFacilityId(); const params = { ...payload, @@ -30,7 +29,7 @@ const actions: ActionTree = { sort: payload.sort ? payload.sort : "orderDate asc", filters: { orderTypeId: { value: 'TRANSFER_ORDER' }, - facilityId: { value: escapeSolrSpecialChars(currentFacilityId) }, + facilityId: { value: escapeSolrSpecialChars(getCurrentFacilityId()) }, productStoreId: { value: this.state.user.currentEComStore.productStoreId } } } diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index e5ad980d..bfa48e46 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -4,7 +4,7 @@ import RootState from '@/store/RootState' import store from '@/store'; import UserState from './UserState' import * as types from './mutation-types' -import { showToast } from '@/utils' +import { showToast, getCurrentFacilityId } from '@/utils' import { hasError } from '@/adapter' import { translate } from '@hotwax/dxp-components' import { DateTime, Settings } from 'luxon'; @@ -71,7 +71,7 @@ const actions: ActionTree = { // TODO Use a separate API for getting facilities, this should handle user like admin accessing the app const currentFacility: any = useUserStore().getCurrentFacility - userProfile.stores = await UserService.getEComStores(token, currentFacility?.facilityId); + userProfile.stores = await UserService.getEComStores(token, currentFacility); let preferredStore = userProfile.stores[0] @@ -658,8 +658,7 @@ const actions: ActionTree = { async fetchNotificationPreferences({ commit, state }) { let resp = {} as any - const currentFacility: any = useUserStore().getCurrentFacility - const facilityId = currentFacility?.facilityId + let notificationPreferences = [], enumerationResp = [], userPrefIds = [] as any try { resp = await getNotificationEnumIds(process.env.VUE_APP_NOTIF_ENUM_TYPE_ID as any) @@ -673,7 +672,7 @@ const actions: ActionTree = { // data and getNotificationUserPrefTypeIds fails or returns empty response (all disbaled) if (enumerationResp.length) { notificationPreferences = enumerationResp.reduce((notifactionPref: any, pref: any) => { - const userPrefTypeIdToSearch = generateTopicName(facilityId, pref.enumId) + const userPrefTypeIdToSearch = generateTopicName(getCurrentFacilityId(), pref.enumId) notifactionPref.push({ ...pref, isEnabled: userPrefIds.includes(userPrefTypeIdToSearch) }) return notifactionPref }, [])