Skip to content

Commit

Permalink
Merge pull request #384 from R-Sourabh/#dxp/288-facility-selector
Browse files Browse the repository at this point in the history
Implemented: Added the support for using facility selector from dxp-component(#dxp/228)
  • Loading branch information
ravilodhi authored Nov 18, 2024
2 parents 2c6be87 + 7a2be33 commit 2a7e6b8
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 98 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@casl/ability": "^6.0.0",
"@hotwax/app-version-info": "^1.0.0",
"@hotwax/apps-theme": "^1.2.6",
"@hotwax/dxp-components": "^1.15.5",
"@hotwax/dxp-components": "^1.16.0",
"@hotwax/oms-api": "^1.16.0",
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
Expand Down
6 changes: 4 additions & 2 deletions src/adapter/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api, client, getConfig, fetchGoodIdentificationTypes, getUserFacilities, hasError, initialise, logout, resetConfig, updateInstanceUrl, updateToken, setUserTimeZone,
getAvailableTimeZones, getProductIdentificationPref, setProductIdentificationPref} from '@hotwax/oms-api'
import { api, client, getConfig, fetchGoodIdentificationTypes, getUserFacilities, getUserPreference, hasError, initialise, logout, resetConfig, updateInstanceUrl, updateToken, setUserTimeZone,
getAvailableTimeZones, getProductIdentificationPref, setProductIdentificationPref, setUserPreference} from '@hotwax/oms-api'

export {
api,
Expand All @@ -8,6 +8,7 @@ export {
getConfig,
getUserFacilities,
getProductIdentificationPref,
getUserPreference,
hasError,
initialise,
logout,
Expand All @@ -16,5 +17,6 @@ export {
updateToken,
setUserTimeZone,
setProductIdentificationPref,
setUserPreference,
getAvailableTimeZones
}
6 changes: 5 additions & 1 deletion src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { computed, defineComponent } from "vue";
import { mapGetters } from "vuex";
import { calendar, download, gitPullRequestOutline, settings } from "ionicons/icons";
import { useStore } from "@/store";
import { useUserStore } from "@hotwax/dxp-components"
import { useRouter } from "vue-router";
export default defineComponent({
Expand All @@ -55,12 +56,14 @@ export default defineComponent({
computed: {
...mapGetters({
isUserAuthenticated: 'user/isUserAuthenticated',
currentFacility: 'user/getCurrentFacility',
})
},
setup() {
const store = useStore();
const router = useRouter();
const userStore = useUserStore()
let currentFacility: any = computed(() => userStore.getCurrentFacility)
const appPages = [
{
title: "Shipments",
Expand Down Expand Up @@ -97,6 +100,7 @@ export default defineComponent({
})
return {
currentFacility,
selectedIndex,
appPages,
download,
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"facility location": "facility location",
"Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure.": "Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure.",
"Failed to update barcode identification preference.": "Failed to update barcode identification preference.",
"Fetching facilities": "Fetching facilities",
"Fetching time zones": "Fetching time zones",
"Force scan": "Force scan",
"Force scan preference updated successfully.": "Force scan preference updated successfully.",
Expand All @@ -56,6 +57,7 @@
"Logging out": "Logging out",
"Logout": "Logout",
"Make sure you have entered all the inventory you received. You cannot edit this information after proceeding.": "Make sure you have entered all the inventory you received. { space } You cannot edit this information after proceeding.",
"No facilities found": "No facilities found",
"No more shipments found": "No more shipments found",
"None": "None",
"No results found": "No results found",
Expand Down Expand Up @@ -111,6 +113,7 @@
"Searched item is not present within the shipment:": "Searched item is not present within the shipment: {itemName}",
"secondary identifier": "secondary identifier",
"Search": "Search",
"Search facilities": "Search facilities",
"Search purchase orders": "Search purchase orders",
"Search returns": "Search returns",
"Search time zones": "Search time zones",
Expand All @@ -120,6 +123,7 @@
"Select": "Select",
"Select all": "Select all",
"Select facility": "Select facility",
"Select Facility": "Select Facility",
"Selected TimeZone": "Selected TimeZone",
"Select a different time zone": "Select a different time zone",
"Select time zone": "Select time zone",
Expand Down
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import permissionRules from '@/authorization/Rules';
import permissionActions from '@/authorization/Actions';
import { dxpComponents } from '@hotwax/dxp-components'
import { login, logout, loader } from './user-utils';
import { fetchGoodIdentificationTypes, getConfig, initialise, setUserTimeZone, getAvailableTimeZones, getProductIdentificationPref, setProductIdentificationPref } from '@/adapter'
import { fetchGoodIdentificationTypes, getConfig, initialise, setUserTimeZone, getAvailableTimeZones, getProductIdentificationPref, getUserFacilities, getUserPreference, setProductIdentificationPref, setUserPreference } from '@/adapter'
import localeMessages from './locales';

const app = createApp(App)
Expand Down Expand Up @@ -61,7 +61,10 @@ const app = createApp(App)
setProductIdentificationPref,
getAvailableTimeZones,
hasPermission,
fetchGoodIdentificationTypes
fetchGoodIdentificationTypes,
getUserPreference,
getUserFacilities,
setUserPreference
});

// Filters are removed in Vue 3 and global filter introduced https://v3.vuejs.org/guide/migration/filters.html#global-filters
Expand Down
4 changes: 2 additions & 2 deletions src/services/ProductService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api, hasError } from '@/adapter';
import store from '@/store';
import { getCurrentFacilityId } from '@/utils';

const fetchProducts = async (query: any): Promise <any> => {
return api({
Expand All @@ -14,7 +14,7 @@ const getInventoryAvailableByFacility = async (productId: any): Promise<any> =>
let productQoh = ''
const payload = {
productId: productId,
facilityId: store.getters['user/getCurrentFacility']?.facilityId
facilityId: getCurrentFacilityId()
}

try {
Expand Down
12 changes: 6 additions & 6 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import OrderState from './OrderState'
import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { hasError, showToast, getCurrentFacilityId } from '@/utils'
import { getProductIdentificationValue, translate } from '@hotwax/dxp-components'
import emitter from "@/event-bus";
import store from "@/store";
Expand Down Expand Up @@ -82,7 +82,7 @@ const actions: ActionTree<OrderState, RootState> = {
},
"query": "docType:ORDER",
"filter": [
`orderTypeId: PURCHASE_ORDER AND orderId: ${orderId} AND orderStatusId: (ORDER_APPROVED OR ORDER_CREATED OR ORDER_COMPLETED) AND facilityId: ${this.state.user.currentFacility.facilityId}`
`orderTypeId: PURCHASE_ORDER AND orderId: ${orderId} AND orderStatusId: (ORDER_APPROVED OR ORDER_CREATED OR ORDER_COMPLETED) AND facilityId: ${getCurrentFacilityId()}`
]
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ const actions: ActionTree<OrderState, RootState> = {
try {
const params = {
orderId: payload.orderId,
facilityId: this.state.user.currentFacility.facilityId
facilityId: getCurrentFacilityId()
}

resp = await OrderService.createPurchaseShipment(params)
Expand Down Expand Up @@ -160,15 +160,15 @@ const actions: ActionTree<OrderState, RootState> = {

const params = {
orderId: payload.orderId,
destinationFacilityId: this.state.user.currentFacility.facilityId,
destinationFacilityId: getCurrentFacilityId(),
"type": "PURCHASE_SHIPMENT",
"status": "PURCH_SHIP_CREATED",
"items": payload.items
}
resp = await OrderService.createIncomingShipment({"payload": params})

if (resp.status === 200 && !hasError(resp) && resp.data.shipmentId) {
const facilityLocations = await this.dispatch('user/getFacilityLocations', this.state.user.currentFacility.facilityId);
const facilityLocations = await this.dispatch('user/getFacilityLocations', getCurrentFacilityId());
if (facilityLocations.length){
const locationSeqId = facilityLocations[0].locationSeqId
payload.items.map((item: any) => {
Expand Down Expand Up @@ -208,7 +208,7 @@ const actions: ActionTree<OrderState, RootState> = {
"orderBy": 'datetimeReceived DESC',
"viewSize": "250"
}
const facilityLocations = await this.dispatch('user/getFacilityLocations', this.state.user.currentFacility.facilityId);
const facilityLocations = await this.dispatch('user/getFacilityLocations', getCurrentFacilityId());
const locationSeqId = facilityLocations.length > 0 ? facilityLocations[0].locationSeqId : "";
resp = await OrderService.fetchPOHistory(params)
if (resp.status === 200 && !hasError(resp) && resp.data?.count > 0) {
Expand Down
11 changes: 5 additions & 6 deletions src/store/modules/shipment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import ShipmentState from './ShipmentState'
import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { getProductIdentificationValue, translate } from '@hotwax/dxp-components'
import { hasError, showToast, getCurrentFacilityId } from '@/utils'
import { getProductIdentificationValue, translate, useUserStore } from '@hotwax/dxp-components'

Check warning on line 7 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'useUserStore' is defined but never used

Check warning on line 7 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'useUserStore' is defined but never used

Check warning on line 7 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'useUserStore' is defined but never used
import emitter from '@/event-bus'
import store from "@/store";
import { DateTime } from 'luxon';
Expand Down Expand Up @@ -72,8 +72,7 @@ const actions: ActionTree<ShipmentState, RootState> = {
const shipmentAttributes = await ShipmentService.fetchShipmentAttributes([shipmentDetail.shipmentId])
shipmentDetail.externalOrderId = shipmentAttributes?.[shipmentDetail.shipmentId]?.['EXTERNAL_ORDER_ID']
shipmentDetail.externalOrderName = shipmentAttributes?.[shipmentDetail.shipmentId]?.['EXTERNAL_ORDER_NAME']

const facilityLocations = await this.dispatch('user/getFacilityLocations', this.state.user.currentFacility.facilityId);
const facilityLocations = await this.dispatch('user/getFacilityLocations', getCurrentFacilityId());
if(facilityLocations.length){
const locationSeqId = facilityLocations[0].locationSeqId
resp.data.items.map((item: any) => {
Expand Down Expand Up @@ -118,7 +117,7 @@ const actions: ActionTree<ShipmentState, RootState> = {

const params = {
shipmentId: payload.shipmentId,
facilityId: this.state.user.currentFacility.facilityId,
facilityId: getCurrentFacilityId(),
shipmentItemSeqId: item.itemSeqId,
productId: item.productId,
quantityAccepted: item.quantityAccepted,
Expand Down Expand Up @@ -153,7 +152,7 @@ const actions: ActionTree<ShipmentState, RootState> = {
const uploadData = payload.items.map((item: any) => {
return {
shipmentId: payload.shipmentId,
facilityId: this.state.user.currentFacility.facilityId,
facilityId: getCurrentFacilityId(),
shipmentItemSeqId: item.itemSeqId,
productId: item.productId,
quantityAccepted: item.quantityAccepted,
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default interface UserState {
token: string;
current: any;
currentFacility: object | null;
currentEComStore: object;
instanceUrl: string;
facilityLocationsByFacilityId: any;
Expand Down
23 changes: 10 additions & 13 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { ActionTree } from 'vuex'
import RootState from '@/store/RootState'
import UserState from './UserState'
import * as types from './mutation-types'
import { hasError, showToast } from '@/utils'
import { getCurrentFacilityId, hasError, showToast } from '@/utils'
import { Settings } from 'luxon';
import { getUserFacilities, logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import { logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter'
import {
getServerPermissionsFromRules,
prepareAppPermissions,
resetPermissions,
setPermissions
} from '@/authorization'
import { translate, useAuthStore, useProductIdentificationStore } from '@hotwax/dxp-components'
import { translate, useAuthStore, useProductIdentificationStore, useUserStore } from '@hotwax/dxp-components'
import emitter from '@/event-bus'
import store from '@/store'

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

//fetching user facilities
const isAdminUser = appPermissions.some((appPermission: any) => appPermission?.action === "APP_RECVG_ADMIN");
const baseURL = store.getters['user/getBaseUrl'];
const facilities = await getUserFacilities(token, baseURL, userProfile?.partyId, "", isAdminUser);
const facilities = await useUserStore().getUserFacilities(userProfile?.partyId, "", isAdminUser)
await useUserStore().getFacilityPreference('SELECTED_FACILITY')

if (!facilities.length) throw 'Unable to login. User is not assocaited with any facility'

Expand All @@ -71,9 +71,8 @@ const actions: ActionTree<UserState, RootState> = {
return uniqueFacilities
}, []);

const currentFacility = userProfile.facilities[0];
const currentEComStore = await UserService.getEComStores(token, currentFacility.facilityId);

const currentFacility: any = getCurrentFacilityId();
const currentEComStore = await UserService.getEComStores(token, currentFacility?.facilityId);
const productStoreId = currentEComStore?.productStoreId;

await useProductIdentificationStore().getIdentificationPref(productStoreId)
Expand All @@ -87,7 +86,6 @@ const actions: ActionTree<UserState, RootState> = {

// TODO user single mutation
commit(types.USER_INFO_UPDATED, userProfile);
commit(types.USER_CURRENT_FACILITY_UPDATED, currentFacility);
commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore);
commit(types.USER_PERMISSIONS_UPDATED, appPermissions);
commit(types.USER_TOKEN_CHANGED, { newToken: token })
Expand Down Expand Up @@ -173,13 +171,12 @@ const actions: ActionTree<UserState, RootState> = {
/**
* update current facility information
*/
async setFacility ({ commit, dispatch }, payload) {
async setFacility ({ commit, dispatch }, facilityId) {
const token = store.getters['user/getUserToken'];
const eComStore = await UserService.getEComStores(token, payload.facility.facilityId);
const eComStore = await UserService.getEComStores(token, facilityId);

commit(types.USER_CURRENT_ECOM_STORE_UPDATED, eComStore);
commit(types.USER_CURRENT_FACILITY_UPDATED, payload.facility);
await dispatch('getFacilityLocations', payload.facility.facilityId)
await dispatch('getFacilityLocations', facilityId)
eComStore?.productStoreId ? this.dispatch('util/getForceScanSetting', eComStore.productStoreId) : this.dispatch('util/updateForceScanStatus', false)
eComStore?.productStoreId ? this.dispatch('util/getBarcodeIdentificationPref', eComStore.productStoreId) : this.dispatch('util/updateBarcodeIdentificationPref', "internalName")
},
Expand Down
3 changes: 0 additions & 3 deletions src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ const getters: GetterTree <UserState, RootState> = {
getUserProfile (state) {
return state.current
},
getCurrentFacility (state){
return state.currentFacility
},
getInstanceUrl (state) {
const baseUrl = process.env.VUE_APP_BASE_URL;
return baseUrl ? baseUrl : state.instanceUrl;
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const userModule: Module<UserState, RootState> = {
state: {
token: '',
current: {},
currentFacility: {},
currentEComStore: {},
permissions: [],
instanceUrl: '',
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_FACILITY_LOCATIONS_BY_FACILITY_ID = SN_USER + '/FACILITY_LOCATIONS_BY_FACILITY_ID'
Expand Down
4 changes: 0 additions & 4 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ const mutations: MutationTree <UserState> = {
[types.USER_END_SESSION] (state) {
state.token = ''
state.current = {}
state.currentFacility = {},
state.facilityLocationsByFacilityId = {},
state.permissions = []
},
[types.USER_INFO_UPDATED] (state, payload) {
state.current = payload
},
[types.USER_CURRENT_FACILITY_UPDATED] (state, payload) {
state.currentFacility = payload;
},
[types.USER_INSTANCE_URL_UPDATED] (state, payload) {
state.instanceUrl = payload;
},
Expand Down
9 changes: 7 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toastController } from '@ionic/vue';
import { translate } from '@hotwax/dxp-components'
import { translate, useUserStore } from '@hotwax/dxp-components'
import { Plugins } from '@capacitor/core';
import { DateTime } from "luxon";

Expand Down Expand Up @@ -52,4 +52,9 @@ const handleDateTimeInput = (dateTimeValue: any) => {
return DateTime.fromISO(dateTime).toMillis()
}

export { handleDateTimeInput, showToast, hasError, copyToClipboard }
const getCurrentFacilityId = () => {
const currentFacility: any = useUserStore().getCurrentFacility;
return currentFacility?.facilityId
}

export { handleDateTimeInput, getCurrentFacilityId, showToast, hasError, copyToClipboard }
Loading

0 comments on commit 2a7e6b8

Please sign in to comment.