From 5c83674cd0c83e55f4b6147a0824b616f843662c Mon Sep 17 00:00:00 2001 From: Ridwa Date: Thu, 1 Aug 2024 00:25:09 +0530 Subject: [PATCH 1/2] Implemented: added product identifier in setting page (#220) --- src/App.vue | 10 ++++-- src/adapter/index.ts | 4 +++ src/components/PurchaseOrderDetail.vue | 13 ++++--- src/main.ts | 6 ++-- src/services/UserService.ts | 43 +++++++++++++++++++++++- src/store/modules/product/getters.ts | 3 +- src/store/modules/user/UserState.ts | 1 + src/store/modules/user/actions.ts | 33 +++++++++++++++--- src/store/modules/user/getters.ts | 5 ++- src/store/modules/user/index.ts | 1 + src/store/modules/user/mutation-types.ts | 1 + src/store/modules/user/mutations.ts | 3 ++ src/views/InventoryReview.vue | 14 +++++--- src/views/Settings.vue | 3 +- 14 files changed, 119 insertions(+), 21 deletions(-) diff --git a/src/App.vue b/src/App.vue index 9014ac24..d8c5efa2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,7 +15,7 @@ import emitter from "@/event-bus" import { mapGetters, useStore } from 'vuex'; import { initialise, resetConfig } from '@/adapter' import { showToast } from "@/utils"; -import { translate } from "@hotwax/dxp-components"; +import { translate , useProductIdentificationStore } from "@hotwax/dxp-components"; import { useRouter } from 'vue-router'; export default defineComponent({ @@ -100,6 +100,11 @@ export default defineComponent({ emitter.on('presentLoader', this.presentLoader); emitter.on('dismissLoader', this.dismissLoader); emitter.on('playAnimation', this.playAnimation); + + if(this.userToken) { + await useProductIdentificationStore().getIdentificationPref(this.currentEComStore?.productStoreId) + .catch((error) => console.log(error)); + } }, created() { initialise({ @@ -132,7 +137,8 @@ export default defineComponent({ computed: { ...mapGetters({ userToken: 'user/getUserToken', - instanceUrl: 'user/getInstanceUrl' + instanceUrl: 'user/getInstanceUrl', + currentEComStore: 'user/getCurrentEComStore', }) }, setup(){ diff --git a/src/adapter/index.ts b/src/adapter/index.ts index 803ace03..7f3c83f8 100644 --- a/src/adapter/index.ts +++ b/src/adapter/index.ts @@ -2,6 +2,7 @@ import { api, client, getConfig, + getProductIdentificationPref, hasError, fetchProducts, initialise, @@ -12,6 +13,7 @@ import { updateToken, updateInstanceUrl, setUserTimeZone, + setProductIdentificationPref, getAvailableTimeZones } from '@hotwax/oms-api' @@ -19,6 +21,7 @@ export { api, client, getConfig, + getProductIdentificationPref, hasError, fetchProducts, initialise, @@ -29,5 +32,6 @@ export { updateToken, updateInstanceUrl, setUserTimeZone, + setProductIdentificationPref, getAvailableTimeZones } \ No newline at end of file diff --git a/src/components/PurchaseOrderDetail.vue b/src/components/PurchaseOrderDetail.vue index 8c838cf3..35f83393 100644 --- a/src/components/PurchaseOrderDetail.vue +++ b/src/components/PurchaseOrderDetail.vue @@ -27,8 +27,8 @@ -

{{ item.pseudoId }}

-

{{ item.initialSKU }}

+ {{ getProduct.state.cached(item.productId)}} +

{{ getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) ? getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) : getProduct(item.productId).productName }}

@@ -67,9 +67,10 @@ import { import { sendOutline, ellipsisVerticalOutline } from 'ionicons/icons'; import { defineComponent } from "@vue/runtime-core"; import { mapGetters, useStore } from "vuex"; +import { computed } from 'vue' import ProductPopover from '@/components/ProductPopover.vue' import { DateTime } from 'luxon'; -import { translate } from "@hotwax/dxp-components"; +import { translate, getProductIdentificationValue, useProductIdentificationStore } from "@hotwax/dxp-components"; export default defineComponent({ name: "PurchaseOrderDetails", @@ -158,11 +159,15 @@ export default defineComponent({ }, setup() { const store = useStore(); + const productIdentificationStore = useProductIdentificationStore(); + let productIdentificationPref = computed(() => productIdentificationStore.getProductIdentificationPref); return { sendOutline, store, ellipsisVerticalOutline, - translate + translate, + productIdentificationPref, + getProductIdentificationValue } } }) diff --git a/src/main.ts b/src/main.ts index 445a4e8e..2f423cbc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,7 +34,7 @@ import { dxpComponents } from '@hotwax/dxp-components' import { login, logout, loader } from './user-utils'; import { getConfig, initialise } from '@hotwax/oms-api'; import localeMessages from './locales'; -import { setUserTimeZone, getAvailableTimeZones} from '@/adapter' +import { setUserTimeZone, getAvailableTimeZones , getProductIdentificationPref , setProductIdentificationPref} from '@/adapter' const app = createApp(App) .use(IonicVue, { @@ -60,7 +60,9 @@ const app = createApp(App) initialise, localeMessages, setUserTimeZone, - getAvailableTimeZones + getAvailableTimeZones, + getProductIdentificationPref, + setProductIdentificationPref }); // Filters are removed in Vue 3 and global filter introduced https://v3.vuejs.org/guide/migration/filters.html#global-filters diff --git a/src/services/UserService.ts b/src/services/UserService.ts index 5c847ebe..7fd0c2a9 100644 --- a/src/services/UserService.ts +++ b/src/services/UserService.ts @@ -13,6 +13,46 @@ const login = async (username: string, password: string): Promise => { }); } +const getCurrentEComStore = async (token: any, facilityId: any): Promise => { + + // If the facilityId is not provided, it may be case of user not associated with any facility or the logout + if (!facilityId) { + return Promise.resolve({}); + } + + const baseURL = store.getters['user/getBaseUrl']; + try { + const data = { + "inputFields": { + "facilityId": facilityId, + }, + "fieldList": ["defaultCurrencyUomId", "productStoreId"], + "entityName": "ProductStoreFacilityDetail", + "noConditionFind": "Y", + "filterByDate": 'Y', + "viewSize": 1 + } + const resp = await client({ + url: "performFind", + method: "post", + data, + baseURL, + headers: { + Authorization: 'Bearer ' + token, + 'Content-Type': 'application/json' + } + }); + if (hasError(resp)) { + throw resp.data; + } + + return Promise.resolve(resp.data.docs?.length ? resp.data.docs[0] : {}); + } catch(error: any) { + console.error(error) + return Promise.resolve({}) + } +} + const getProfile = async (): Promise => { return api({ url: "user-profile", @@ -148,5 +188,6 @@ export const UserService = { getFieldMappings, getProfile, getUserPermissions, - updateFieldMapping + updateFieldMapping, + getCurrentEComStore } \ No newline at end of file diff --git a/src/store/modules/product/getters.ts b/src/store/modules/product/getters.ts index fc9604c7..476b2a7e 100644 --- a/src/store/modules/product/getters.ts +++ b/src/store/modules/product/getters.ts @@ -5,7 +5,8 @@ import RootState from "../../RootState"; const getters: GetterTree = { getProduct: (state) => (productId: string) => { // Returning empty object so that it doesn't breaks the UI + console.log(state.cached) return state.cached[productId] ? state.cached[productId] : {}; - } + }, }; export default getters; \ No newline at end of file diff --git a/src/store/modules/user/UserState.ts b/src/store/modules/user/UserState.ts index 275b1568..ea19c002 100644 --- a/src/store/modules/user/UserState.ts +++ b/src/store/modules/user/UserState.ts @@ -13,4 +13,5 @@ export default interface UserState { value: object; }; permissions: any; + currentEComStore: any; } \ No newline at end of file diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index fdc070f3..fade0f7c 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -6,7 +6,7 @@ import * as types from './mutation-types' import { hasError, showToast } from '@/utils' import { logout, updateInstanceUrl, updateToken, resetConfig } from '@/adapter' import logger from "@/logger"; -import { useAuthStore, translate } from '@hotwax/dxp-components'; +import { useAuthStore, translate , useProductIdentificationStore } from '@hotwax/dxp-components'; import emitter from '@/event-bus' import { getServerPermissionsFromRules, @@ -60,9 +60,15 @@ const actions: ActionTree = { commit(types.USER_PERMISSIONS_UPDATED, appPermissions); commit(types.USER_TOKEN_CHANGED, { newToken: token }) - await dispatch('getProfile') + await dispatch('getProfile' , token) dispatch('setPreferredDateTimeFormat', process.env.VUE_APP_DATE_FORMAT ? process.env.VUE_APP_DATE_FORMAT : 'MM/dd/yyyy'); } + else { + commit(types.USER_TOKEN_CHANGED, { newToken: token }) + updateToken(token) + await dispatch('getProfile') + await dispatch('getProfile', token) + } } catch (err: any) { showToast(translate('Something went wrong')); logger.error("error", err); @@ -129,21 +135,40 @@ const actions: ActionTree = { /** * Get User profile */ - async getProfile ( { commit, dispatch }) { + async getProfile ( { commit, dispatch }, token) { const resp = await UserService.getProfile() if (resp.status === 200) { dispatch('getFieldMappings') commit(types.USER_INFO_UPDATED, resp.data); + const currentFacility = resp.data.facilities.length > 0 ? resp.data.facilities[0] : {}; + + commit(types.USER_CURRENT_FACILITY_UPDATED, currentFacility); + + // get and set current ecom store in state + const currentEComStore = await UserService.getCurrentEComStore(token, currentFacility?.facilityId); + commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore); + + // Get product identification from api using dxp-component + await useProductIdentificationStore().getIdentificationPref(currentEComStore?.productStoreId) + .catch((error) => console.error(error)); } }, /** * update current facility information */ - async setFacility ({ commit }, payload) { + async setFacility ({ commit, state }, payload) { commit(types.USER_CURRENT_FACILITY_UPDATED, payload.facility); + + // get and set current ecom store in state + const currentEComStore = await UserService.getCurrentEComStore(state.token, payload.facility.facilityId); + commit(types.USER_CURRENT_ECOM_STORE_UPDATED, currentEComStore); + + await useProductIdentificationStore().getIdentificationPref(currentEComStore?.productStoreId) + .catch((error) => console.error(error)); }, + setPreferredDateTimeFormat ({ commit }, payload) { commit(types.USER_DATETIME_FORMAT_UPDATED, payload) }, diff --git a/src/store/modules/user/getters.ts b/src/store/modules/user/getters.ts index 88b13241..06999f5d 100644 --- a/src/store/modules/user/getters.ts +++ b/src/store/modules/user/getters.ts @@ -12,11 +12,14 @@ const getters: GetterTree = { getBaseUrl(state) { let baseURL = process.env.VUE_APP_BASE_URL; if (!baseURL) baseURL = state.instanceUrl; - return baseURL.startsWith('http') ? baseURL.includes('/api') ? baseURL : `${baseURL}/api/` : `https://${baseURL}.hotwax.io/api/`; + return baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`; }, getUserToken (state) { return state.token }, + getCurrentEComStore(state) { + return state.currentEComStore; + }, getUserProfile (state) { return state.current }, diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 8cd2d3e3..b8941eed 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -11,6 +11,7 @@ const userModule: Module = { token: '', current: null, currentFacility: {}, + currentEComStore: {}, instanceUrl: '', fieldMappings: {}, preferredDateTimeFormat: '', diff --git a/src/store/modules/user/mutation-types.ts b/src/store/modules/user/mutation-types.ts index 817fa913..d3f49f28 100644 --- a/src/store/modules/user/mutation-types.ts +++ b/src/store/modules/user/mutation-types.ts @@ -10,3 +10,4 @@ export const USER_CURRENT_FIELD_MAPPING_UPDATED = SN_USER + '/_CURRENT_FIELD_MAP export const USER_FIELD_MAPPINGS_UPDATED = SN_USER + '/FIELD_MAPPINGS_UPDATED' export const USER_FIELD_MAPPING_CREATED = SN_USER + '/FIELD_MAPPING_CREATED' export const USER_PERMISSIONS_UPDATED = SN_USER + '/PERMISSIONS_UPDATED' +export const USER_CURRENT_ECOM_STORE_UPDATED = SN_USER + '/CURRENT_ECOM_STORE_UPDATED' diff --git a/src/store/modules/user/mutations.ts b/src/store/modules/user/mutations.ts index a6ba5803..2c40ffbd 100644 --- a/src/store/modules/user/mutations.ts +++ b/src/store/modules/user/mutations.ts @@ -20,6 +20,9 @@ const mutations: MutationTree = { [types.USER_INSTANCE_URL_UPDATED] (state, payload) { state.instanceUrl = payload; }, + [types.USER_CURRENT_ECOM_STORE_UPDATED] (state, payload) { + state.currentEComStore = payload + }, [types.USER_PWA_STATE_UPDATED] (state, payload) { state.pwaState.registration = payload.registration; state.pwaState.updateExists = payload.updateExists; diff --git a/src/views/InventoryReview.vue b/src/views/InventoryReview.vue index 5861c97c..2ae15d83 100644 --- a/src/views/InventoryReview.vue +++ b/src/views/InventoryReview.vue @@ -61,8 +61,8 @@ -

{{ item.pseudoId }}

-

{{ item.initialSKU }}

+

{{ getProductIdentificationValue(productIdentificationPref.primaryId, item) ? getProductIdentificationValue(productIdentificationPref.primaryId, item) : item.productName }}

+

{{ getProductIdentificationValue(productIdentificationPref.secondaryId, item) }}

@@ -95,10 +95,10 @@