Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: centralized facility switcher to be used in all app (#138) #159

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
349c2ca
Implemented: centralized facility switcher to be used in all app (#138)
amansinghbais Sep 14, 2023
c2f0a98
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais Sep 18, 2023
b9e5f52
Improved: updated to dxp version 1.6.0 (#138)
amansinghbais Sep 18, 2023
139c15b
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais Sep 21, 2023
2ca991f
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais Sep 25, 2023
10595c7
Improved: code to use deep-clone for the computed properties, method …
amansinghbais Sep 25, 2023
525f934
Improved: unwanted changes in package-lock.json
amansinghbais Sep 25, 2023
8437048
Improved: emitting methods from child modal without promise.all (#138)
amansinghbais Sep 26, 2023
37ab41b
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais Oct 3, 2023
1534a58
Improved: facility switcher logic to use before/after emit for apps (…
amansinghbais Oct 4, 2023
902bf7c
Improved: calling normally without the help of finally (#138)
amansinghbais Oct 5, 2023
1c9bdcf
Improved: emitting function without catching them (#138)
amansinghbais Oct 6, 2023
1614a90
Improved: added Dxp prefix in component name (dxp/138)
amansinghbais Oct 9, 2023
40558c4
Improved: emits name and if condition code (#138)
amansinghbais Oct 10, 2023
d890841
Merge branch 'main' of https://github.com/hotwax/dxp-components into …
amansinghbais Oct 12, 2023
30c28d4
Improved: variable name and used arrow function in computed(#138)
amansinghbais Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/components/DxpFacilitySwitcher.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<ion-card>
<ion-card-header>
<ion-card-title>
{{ $t('Facility') }}
</ion-card-title>
</ion-card-header>
<ion-card-content>
{{ $t('Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.') }}
</ion-card-content>
<ion-item lines="none">
<ion-label>{{ $t('Select facility') }}</ion-label>
<ion-select interface="popover" :value="userAppState.currentFacility.facilityId" @ionChange="setFacility($event)">
<ion-select-option v-for="facility in (userAppState.userProfile ? userAppState.userProfile.facilities : [])" :key="facility.facilityId" :value="facility.facilityId" >{{ facility.facilityName ? facility.facilityName : facility.name }}</ion-select-option>
</ion-select>
</ion-item>
</ion-card>
</template>

<script setup lang="ts">
import {
IonCard,
IonCardContent,
IonCardHeader,
IonCardTitle,
IonItem,
IonLabel,
IonSelect,
IonSelectOption
} from '@ionic/vue';
import { appContext } from '../index';
import { computed } from 'vue';

const emit = defineEmits(['before-set-facility', 'after-set-facility']);
const appState = appContext.config.globalProperties.$store;

const userAppState = computed(() => ({
currentFacility: appState.getters['user/getCurrentFacility'],
userProfile: appState.getters['user/getUserProfile']
}));

const setFacility = async (event: CustomEvent) => {
const currentUserAppState = JSON.parse(JSON.stringify(userAppState.value))
const facilityId = event.detail.value

if(currentUserAppState.currentFacility.facilityId !== facilityId && currentUserAppState.userProfile?.facilities) {
// before-set-facility is emitted before setFacility action.
emit('before-set-facility', facilityId)

await appState.dispatch('user/setFacility', {
'facility': currentUserAppState.userProfile.facilities.find((facility: any) => facility.facilityId === facilityId)
});

// after-set-facility is emitted after setFacility action.
emit('after-set-facility', facilityId)
}
}
</script>
11 changes: 10 additions & 1 deletion src/components/LanguageSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
</template>

<script setup lang="ts">
import { IonCard, IonCardContent, IonCardHeader, IonItem, IonLabel, IonSelect, IonSelectOption, IonCardTitle } from '@ionic/vue';
import {
IonCard,
IonCardContent,
IonCardHeader,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
IonCardTitle
} from '@ionic/vue';
import { computed } from "vue";
import { useUserStore } from '../store/user'

Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import '@ionic/vue/css/display.css';
export { default as DxpImage } from './DxpImage.vue';
export { default as DxpUserProfile } from './DxpUserProfile.vue'
export { default as AppVersionInfo } from './AppVersionInfo.vue';
export { default as DxpFacilitySwitcher } from './DxpFacilitySwitcher.vue';
export { default as LanguageSwitcher } from './LanguageSwitcher.vue';
export { default as MenuFooterNavigation } from './MenuFooterNavigation.vue';
export { default as OmsInstanceNavigator } from './OmsInstanceNavigator.vue'
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare var process: any;
import { createPinia } from "pinia";
import { useProductIdentificationStore } from "./store/productIdentification";
import { useAuthStore } from "./store/auth";
import { AppVersionInfo, DxpImage, DxpUserProfile, LanguageSwitcher, MenuFooterNavigation, OmsInstanceNavigator, ProductIdentifier, Scanner, ShopifyImg } from "./components";
import { AppVersionInfo, DxpFacilitySwitcher, DxpImage, DxpUserProfile, LanguageSwitcher, MenuFooterNavigation, OmsInstanceNavigator, ProductIdentifier, Scanner, ShopifyImg } from "./components";
import Login from "./components/Login";
import { goToOms, getProductIdentificationValue } from "./utils";
import { initialiseFirebaseApp } from "./utils/firebase"
Expand Down Expand Up @@ -44,6 +44,7 @@ export let dxpComponents = {
app.use(i18n);

app.component('AppVersionInfo', AppVersionInfo)
app.component('DxpFacilitySwitcher', DxpFacilitySwitcher)
app.component('DxpImage', DxpImage)
app.component('DxpUserProfile', DxpUserProfile)
app.component('LanguageSwitcher', LanguageSwitcher)
Expand Down Expand Up @@ -85,6 +86,7 @@ export let dxpComponents = {

export {
appContext,
DxpFacilitySwitcher,
DxpImage,
DxpUserProfile,
getProductIdentificationValue,
Expand Down
Loading