-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from 13 commits
349c2ca
c2f0a98
b9e5f52
139c15b
2ca991f
10595c7
525f934
8437048
37ab41b
1534a58
902bf7c
1c9bdcf
1614a90
40558c4
d890841
30c28d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,61 @@ | ||||||
<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(['check-facility', 'update-facility']) | ||||||
const appState = appContext.config.globalProperties.$store; | ||||||
|
||||||
const userAppState = computed(() => { | ||||||
return { | ||||||
currentFacility: appState.getters['user/getCurrentFacility'], | ||||||
userProfile: appState.getters['user/getUserProfile'], | ||||||
uploadProducts: appState.getters['product/getUploadProducts'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required now |
||||||
} | ||||||
}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use arrow function syntax |
||||||
|
||||||
const setFacility = async (event: any) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const currentUserAppState = JSON.parse(JSON.stringify(userAppState.value)) | ||||||
const selectedFacility = event['detail'].value | ||||||
|
||||||
if(currentUserAppState.currentFacility.facilityId && currentUserAppState.currentFacility.facilityId != selectedFacility && currentUserAppState.userProfile?.facilities) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// check-facility is emitted before setFacility action. | ||||||
emit('check-facility', selectedFacility) | ||||||
|
||||||
await appState.dispatch('user/setFacility', { | ||||||
'facility': currentUserAppState.userProfile.facilities.find((facility: any) => facility.facilityId == selectedFacility) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While implementing in apps, check if this is done in the actions already, and remove it if so. |
||||||
}); | ||||||
|
||||||
// update-facility is emitted after setFacility action. | ||||||
emit('update-facility', selectedFacility) | ||||||
} | ||||||
} | ||||||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update the emit names to before-set-facility and after-set-facility for more readability.