diff --git a/package-lock.json b/package-lock.json index c0d99be..2ecfdba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hotwax/dxp-components", - "version": "1.15.2", + "version": "1.15.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@hotwax/dxp-components", - "version": "1.15.2", + "version": "1.15.4", "license": "Apache-2.0", "dependencies": { "@hotwax/oms-api": "^1.8.1", diff --git a/package.json b/package.json index 1b488b3..f1f91b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hotwax/dxp-components", - "version": "1.15.2", + "version": "1.15.4", "description": "", "type": "module", "main": "lib/index.cjs", diff --git a/src/components/DxpFacilitySwitcher.vue b/src/components/DxpFacilitySwitcher.vue new file mode 100644 index 0000000..edf7ea5 --- /dev/null +++ b/src/components/DxpFacilitySwitcher.vue @@ -0,0 +1,162 @@ + + + + + \ No newline at end of file diff --git a/src/components/DxpOmsInstanceNavigator.vue b/src/components/DxpOmsInstanceNavigator.vue index 80bd152..5f4beb9 100644 --- a/src/components/DxpOmsInstanceNavigator.vue +++ b/src/components/DxpOmsInstanceNavigator.vue @@ -11,7 +11,7 @@ {{ $t('This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.') }} - + {{ $t('Go to OMS') }} @@ -32,6 +32,7 @@ import { goToOms } from '../utils'; import { openOutline } from 'ionicons/icons' import { computed } from 'vue'; import { useAuthStore } from "../store/auth"; +import { appContext } from "src"; const authStore = useAuthStore(); diff --git a/src/components/DxpProductIdentifier.vue b/src/components/DxpProductIdentifier.vue index cf1040c..42940ca 100644 --- a/src/components/DxpProductIdentifier.vue +++ b/src/components/DxpProductIdentifier.vue @@ -11,12 +11,12 @@ {{ 'Choosing a product identifier allows you to view products with your preferred identifiers.' }} - + {{ identification }} - + {{ identification }} {{ "None" }} diff --git a/src/components/index.ts b/src/components/index.ts index 5d51913..993fe25 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -15,6 +15,7 @@ import '@ionic/vue/css/flex-utils.css'; import '@ionic/vue/css/display.css'; export { default as DxpAppVersionInfo } from './DxpAppVersionInfo.vue'; +export { default as DxpFacilitySwitcher } from './DxpFacilitySwitcher.vue' export { default as DxpGitBookSearch } from './DxpGitBookSearch.vue'; export { default as DxpImage } from './DxpImage.vue'; export { default as DxpLanguageSwitcher } from './DxpLanguageSwitcher.vue'; diff --git a/src/index.ts b/src/index.ts index 083a791..ed451aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ declare var process: any; import { createPinia } from "pinia"; import { useProductIdentificationStore } from "./store/productIdentification"; import { useAuthStore } from "./store/auth"; -import { DxpAppVersionInfo, DxpGitBookSearch, DxpImage, DxpLanguageSwitcher, DxpLogin, DxpMenuFooterNavigation, DxpOmsInstanceNavigator, DxpProductIdentifier, DxpProductStoreSelector, DxpShopifyImg, DxpTimeZoneSwitcher, DxpUserProfile } from "./components"; +import { DxpAppVersionInfo, DxpFacilitySwitcher, DxpGitBookSearch, DxpImage, DxpLanguageSwitcher, DxpLogin, DxpMenuFooterNavigation, DxpOmsInstanceNavigator, DxpProductIdentifier, DxpProductStoreSelector, DxpShopifyImg, DxpTimeZoneSwitcher, DxpUserProfile } from "./components"; import { goToOms, getProductIdentificationValue } from "./utils"; import { initialiseFirebaseApp } from "./utils/firebase" import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' @@ -25,6 +25,7 @@ let loginContext = {} as any let shopifyImgContext = {} as any let appContext = {} as any let productIdentificationContext = {} as any +let facilityContext = {} as any let productStoreContext = {} as any let notificationContext = {} as any let gitBookContext = {} as any @@ -68,6 +69,7 @@ export let dxpComponents = { }) app.component('DxpAppVersionInfo', DxpAppVersionInfo) + app.component('DxpFacilitySwitcher', DxpFacilitySwitcher) app.component('DxpGitBookSearch', DxpGitBookSearch) app.component('DxpImage', DxpImage) app.component('DxpLanguageSwitcher', DxpLanguageSwitcher) @@ -98,6 +100,10 @@ export let dxpComponents = { productIdentificationContext.getProductIdentificationPref = options.getProductIdentificationPref productIdentificationContext.setProductIdentificationPref = options.setProductIdentificationPref + + facilityContext.getUserFacilities = options.getUserFacilities + facilityContext.setUserPreference = options.setUserPreference + facilityContext.getUserPreference = options.getUserPreference productStoreContext.getEComStoresByFacility = options.getEComStoresByFacility productStoreContext.setUserPreference = options.setUserPreference @@ -115,6 +121,9 @@ export let dxpComponents = { loginContext.getConfig = options.getConfig loginContext.initialise = options.initialise + appContext.Actions = options.Actions + appContext.hasPermission = options.hasPermission + // set a default locale in the state i18n.global.locale.value = useUserStore().getLocale @@ -141,6 +150,7 @@ export { loginContext, notificationContext, productIdentificationContext, + facilityContext, productStoreContext, shopifyImgContext, translate, diff --git a/src/store/productIdentification.ts b/src/store/productIdentification.ts index 8e5fc46..b6d87f4 100644 --- a/src/store/productIdentification.ts +++ b/src/store/productIdentification.ts @@ -8,7 +8,7 @@ export const useProductIdentificationStore = defineStore('productIdentification' primaryId: '', secondaryId: '' }, - productIdentificationOptions: ["productId", "groupId", "groupName", "internalName", "parentProductName", "primaryProductCategoryName", "sku", "title", "SHOPIFY_PROD_SKU"] + productIdentificationOptions: ["productId", "groupId", "groupName", "internalName", "parentProductName", "primaryProductCategoryName", "sku", "title", "SHOPIFY_PROD_SKU", "upc"] } }, getters: { diff --git a/src/store/user.ts b/src/store/user.ts index c2e3e10..048745d 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,7 +1,8 @@ import { defineStore } from "pinia"; -import { appContext, i18n, translate, userContext, useAuthStore } from "../../src"; +import { i18n, translate, userContext, useAuthStore } from "../../src"; import { DateTime } from "luxon"; import { showToast } from "src/utils"; +import { facilityContext } from "../index"; import { productStoreContext } from "../index"; declare let process: any; @@ -14,16 +15,20 @@ export const useUserStore = defineStore('user', { localeOptions: process.env.VUE_APP_LOCALES ? JSON.parse(process.env.VUE_APP_LOCALES) : { "en-US": "English" }, locale: 'en-US', currentTimeZoneId: '', - timeZones: [] + timeZones: [], + facilities: [], + currentFacility: {} as any } }, getters: { getLocale: (state) => state.locale, getLocaleOptions: (state) => state.localeOptions, getTimeZones: (state) => state.timeZones, - getCurrentEComStore: (state) => state.currentEComStore, + getCurrentTimeZone: (state) => state.currentTimeZoneId, + getFacilites: (state) => state.facilities, + getCurrentFacility: (state) => state.currentFacility, getProductStores: (state) => state.eComStores, - getCurrentTimeZone: (state) => state.currentTimeZoneId + getCurrentEComStore: (state) => state.currentEComStore, }, actions: { async setLocale(locale: string) { @@ -79,6 +84,48 @@ export const useUserStore = defineStore('user', { updateTimeZone(tzId: string) { this.currentTimeZoneId = tzId }, + async getUserFacilities(partyId: any, facilityGroupId: any, isAdminUser: boolean) { + const authStore = useAuthStore(); + + try { + const response = await facilityContext.getUserFacilities(authStore.getToken.value, authStore.getBaseUrl, partyId, facilityGroupId, isAdminUser); + this.facilities = response; + } catch (error) { + console.error(error); + } + return this.facilities + }, + async getFacilityPreference(userPrefTypeId: any) { + const authStore = useAuthStore(); + + if (!this.facilities.length) { + return; + } + let preferredFacility = this.facilities[0]; + + try { + let preferredFacilityId = await facilityContext.getUserPreference(authStore.getToken.value, authStore.getBaseUrl, userPrefTypeId); + if(preferredFacilityId) { + const facility = this.facilities.find((facility: any) => facility.facilityId === preferredFacilityId); + facility && (preferredFacility = facility) + } + } catch (error) { + console.error(error); + } + this.currentFacility = preferredFacility; + }, + async setFacilityPreference(payload: any) { + + try { + await facilityContext.setUserPreference({ + userPrefTypeId: 'SELECTED_FACILITY', + userPrefValue: payload.facilityId + }) + } catch (error) { + console.error('error', error) + } + this.currentFacility = payload; + }, async getEComStoresByFacility(facilityId?: any) { const authStore = useAuthStore(); @@ -120,7 +167,7 @@ export const useUserStore = defineStore('user', { console.error('error', error) } this.currentEComStore = payload; - }, + } }, persist: true })