Skip to content

Commit

Permalink
Improved: code for fullName creation at actions, roles state format (#12
Browse files Browse the repository at this point in the history
)
  • Loading branch information
amansinghbais committed Nov 21, 2023
1 parent 1336159 commit ef079e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
16 changes: 10 additions & 6 deletions src/components/AddStaffMemberModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ion-searchbar v-model="queryString" @keyup.enter="queryString = $event.target.value; findParties()"/>
<ion-row>
<ion-chip v-for="party in selectedPartyValues" :key="party.partyId">
<ion-label>{{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }}</ion-label>
<ion-label>{{ party.fullName }}</ion-label>
<ion-icon :icon="closeCircle" @click="removeSelectedParty(party.partyId)" />
</ion-chip>
</ion-row>
Expand All @@ -25,11 +25,11 @@
<div v-else>
<ion-item v-for="(party, index) in parties" :key="index">
<ion-label>
{{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }}
{{ party.fullName }}
<p>{{ party.partyId }}</p>
</ion-label>
<ion-select interface="popover" :placeholder="translate('Select')" :value="getPartyRoleTypeId(party.partyId)" @ion-change="updateSelectedParties($event, party.partyId)" required>
<ion-select-option v-for="(role, index) in roles" :key='index' :value="role.roleTypeId">{{ role.description }}</ion-select-option>
<ion-select-option v-for="[roleTypeId, description] in Object.entries(roles)" :key='roleTypeId' :value="roleTypeId">{{ description }}</ion-select-option>
</ion-select>
</ion-item>
</div>
Expand Down Expand Up @@ -146,8 +146,12 @@ export default defineComponent({
try {
const resp = await FacilityService.getPartyRoleAndPartyDetails(payload)
if(!hasError(resp)) {
this.parties = resp.data.docs
let parties = resp.data.docs
parties.map((party: any) => {
party.fullName = party.groupName ? party.groupName : `${party.firstName} ${party.lastName}`
})
this.parties = parties
} else {
throw resp.data
}
Expand Down Expand Up @@ -184,7 +188,7 @@ export default defineComponent({
if(this.isPartySelected(selectedPartyId)) {
party = this.selectedPartyValues.find((party: any) => party.partyId === selectedPartyId)
if(selectedRoleTypeId === 'none') {
if(selectedRoleTypeId === '') {
this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId)
} else if(selectedPartyId !== party.roleTypeId) {
this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId)
Expand All @@ -199,7 +203,7 @@ export default defineComponent({
return this.selectedPartyValues.find((party: any) => party.partyId === partyId)
},
getPartyRoleTypeId(partyId: string) {
return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : 'none'
return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : ''
}
},
async mounted() {
Expand Down
4 changes: 4 additions & 0 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ const actions: ActionTree<FacilityState, RootState> = {

if(!hasError(resp) && resp.data.count) {
parties = resp.data.docs

parties.map((party: any) => {
party.fullName = party.groupName ? party.groupName : `${party.firstName} ${party.lastName}`
});
} else {
throw resp.data
}
Expand Down
15 changes: 6 additions & 9 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const actions: ActionTree<UtilState, RootState> = {
return
}

let roles = []
const roles = {} as any
const params = {
inputFields: {
roleTypeGroupId: 'FACILITY_PARTY_ROLE'
Expand All @@ -84,20 +84,17 @@ const actions: ActionTree<UtilState, RootState> = {
try {
const resp = await UtilService.fetchRoles(params)
if (!hasError(resp)) {
roles = resp.data.docs
resp.data.docs.map((doc:any) => {
roles[doc.roleTypeId] = doc.description
})

// pushing none explicitly to show on UI
roles.push({
roleTypeId: 'none',
parentTypeId: 'none',
description: 'None',
})
roles[''] = 'none'
} else {
throw resp.data
}
} catch (error) {
showToast(translate('Something went wrong'));
console.error(error)
logger.error(error)
}

commit(types.UTIL_ROLES_UPDATED, roles)
Expand Down
10 changes: 3 additions & 7 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@
<ion-item lines="none">
<ion-icon :icon="personOutline" slot="start" />
<ion-label>
{{ party.groupName ? party.groupName : `${party.firstName} ${party.lastName}` }}
{{ party.fullName }}
<p>{{ party.partyId }}</p>
</ion-label>
</ion-item>

<ion-label class="tablet">
<ion-chip outline>{{ getRoleTypeDesc(party.roleTypeId) }}</ion-chip>
<ion-chip outline>{{ roles[party.roleTypeId] }}</ion-chip>
<p>{{ translate("role") }}</p>
</ion-label>

Expand Down Expand Up @@ -476,8 +476,7 @@ export default defineComponent({
props: ["facilityId"],
async ionViewWillEnter() {
await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId })
await this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId })
await this.store.dispatch('util/fetchRoles')
await Promise.all([ this.store.dispatch('facility/getFacilityParties', { facilityId: this.facilityId }), this.store.dispatch('util/fetchRoles')])
this.isLoading = false
},
methods: {
Expand Down Expand Up @@ -608,9 +607,6 @@ export default defineComponent({
logger.error(err)
}
},
getRoleTypeDesc(id: any) {
return this.roles.find((role: any) => role.roleTypeId === id)?.description
},
async changeOrderLimitPopover(ev: Event) {
const popover = await popoverController.create({
component: OrderLimitPopover,
Expand Down

0 comments on commit ef079e8

Please sign in to comment.