Skip to content

Commit

Permalink
Improved: used getCurrentFacilityId util function to get current faci…
Browse files Browse the repository at this point in the history
…lity instead of useUserStore from dxp-component in various files(#dxp/288)
  • Loading branch information
R-Sourabh committed Nov 18, 2024
1 parent 107530e commit 3af6dd4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
7 changes: 2 additions & 5 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
@@ -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 <any> => {
return api({
Expand Down Expand Up @@ -30,8 +29,6 @@ const fetchPicklistInformation = async (query: any): Promise <any> => {

const findShipmentIdsForOrders = async(picklistBinIds: Array<string>, orderIds: Array<string>, statusId = ["SHIPMENT_APPROVED", "SHIPMENT_INPUT"]): Promise<any> => {
let shipmentIdsForOrders = {};
const currentFacility: any = useUserStore().getCurrentFacility
const facilityId = currentFacility?.facilityId

const params = {
"entityName": "Shipment",
Expand All @@ -40,7 +37,7 @@ const findShipmentIdsForOrders = async(picklistBinIds: Array<string>, orderIds:
"primaryOrderId_op": "in",
"picklistBinId": picklistBinIds,
"picklistBinId_op": "in",
"originFacilityId": facilityId,
"originFacilityId": getCurrentFacilityId(),
"statusId": statusId,
"statusId_op": "in"
},
Expand Down
8 changes: 3 additions & 5 deletions src/store/modules/carrier/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CarrierState, RootState> = {
Expand Down Expand Up @@ -358,16 +358,14 @@ const actions: ActionTree<CarrierState, RootState> = {
async fetchFacilityCarriers({ state, commit }, payload) {

Check warning on line 358 in src/store/modules/carrier/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'state' is defined but never used

Check warning on line 358 in src/store/modules/carrier/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'payload' is defined but never used

Check warning on line 358 in src/store/modules/carrier/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'state' is defined but never used

Check warning on line 358 in src/store/modules/carrier/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'payload' is defined but never used
let facilityCarriers = [] as any;
let viewIndex = 0, resp, docCount = 0;
const currentFacility: any = useUserStore().getCurrentFacility
const facilityId = currentFacility?.facilityId

try {
do {
const params = {
"entityName": "FacilityAndParty",
"inputFields": {
"roleTypeId": "CARRIER",
"facilityId": facilityId
"facilityId": getCurrentFacilityId()
},
"fieldList": ["facilityId", "partyId", "firstName", "lastName", "groupName", "roleTypeId", "fromDate"],
"noConditionFind": "Y",
Expand Down
8 changes: 3 additions & 5 deletions src/store/modules/stock/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StockState, RootState> = {
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 = {
Expand Down
7 changes: 2 additions & 5 deletions src/store/modules/stock/getters.ts
Original file line number Diff line number Diff line change
@@ -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 <StockState, RootState> = {
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] : {} : {}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/store/modules/transferorder/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,7 +18,6 @@ const actions: ActionTree<TransferOrderState, RootState> = {
emitter.emit('presentLoader');
let resp;
const transferOrderQuery = JSON.parse(JSON.stringify(state.transferOrder.query))
const currentFacilityId = getCurrentFacilityId();

const params = {
...payload,
Expand All @@ -30,7 +29,7 @@ const actions: ActionTree<TransferOrderState, RootState> = {
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 }
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -71,7 +71,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: any = useUserStore().getCurrentFacility
userProfile.stores = await UserService.getEComStores(token, currentFacility?.facilityId);
userProfile.stores = await UserService.getEComStores(token, currentFacility);

let preferredStore = userProfile.stores[0]

Expand Down Expand Up @@ -658,8 +658,7 @@ const actions: ActionTree<UserState, RootState> = {

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)
Expand All @@ -673,7 +672,7 @@ const actions: ActionTree<UserState, RootState> = {
// 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
}, [])
Expand Down

0 comments on commit 3af6dd4

Please sign in to comment.